Ejemplo n.º 1
0
 private static Results GetResultsFromWorksheet(ExcelWorksheet correctResultsWorksheet)
 {
     return(new Results
     {
         TeamsInEightFinal = TeamPlacementReader.GetTeamsForEightFinal(correctResultsWorksheet),
         TeamsInQuarterFinal = TeamPlacementReader.GetTeamsForQuarterFinals(correctResultsWorksheet),
         TeamsInSemiFinal = TeamPlacementReader.GetTeamsForSemiFinals(correctResultsWorksheet),
         TeamsInBronzeFinal = TeamPlacementReader.GetTeamsForBronzeFinals(correctResultsWorksheet),
         TeamsInFinal = TeamPlacementReader.GetTeamsForFinals(correctResultsWorksheet),
         Winner = TeamPlacementReader.GetWinner(correctResultsWorksheet)
     });
 }
Ejemplo n.º 2
0
        private static void AddParticipantScore(string file, ExcelWorksheet correctResultsWorksheet, StringCollection tablePosistions, Results results, string sourceDirctory, List <UserScore> scoresForAllUsers)
        {
            var filename = Path.GetFileName(file);

            if (filename == null || !filename.StartsWith(FilePrefix))
            {
                return;
            }

            Console.WriteLine("Processing {0}", file);

            var worksheet = ExcelService.ExcelService.GetWorksheet(file);

            if (worksheet.Cells["A1"].Value.ToString() != "Verdensmesterskapet i fotball 2018")
            {
                Console.WriteLine($"Language not Norwegian for: {filename}");
                Console.WriteLine($"Excel sheets will be omitted. Press enter to continue processing the next sheet");
                Console.ReadLine();
                return;
            }

            var matchesInGroupStage = GroupStage.GetMatches();
            var score = 0;

            // innledende kamper
            foreach (var i in matchesInGroupStage)
            {
                var r = correctResultsWorksheet.Cells["F" + i.ToString(CultureInfo.InvariantCulture)];
                if (r.Value == null)
                {
                    continue;
                }

                if (worksheet.Cells["F" + i.ToString(CultureInfo.InvariantCulture)].Value == null || worksheet.Cells["G" + i.ToString(CultureInfo.InvariantCulture)].Value == null)
                {
                    Console.WriteLine($"Group stage not correctly filled out for: {filename}");
                    Console.WriteLine("Excel sheet will be omitted. Press enter to continue processing the next sheet");

                    Console.ReadLine();
                    return;
                }

                var fasitHome = correctResultsWorksheet.Cells["F" + i.ToString(CultureInfo.InvariantCulture)].Value.ToString();
                var fasitAway = correctResultsWorksheet.Cells["G" + i.ToString(CultureInfo.InvariantCulture)].Value.ToString();
                var home      = worksheet.Cells["F" + i.ToString(CultureInfo.InvariantCulture)].Value.ToString();
                var away      = worksheet.Cells["G" + i.ToString(CultureInfo.InvariantCulture)].Value.ToString();

                if (GetHub(fasitHome, fasitAway).Equals(GetHub(home, away)))
                {
                    PointCalculator.AddScoreForCorrectOutcomeInGroupMatch(ref score);
                }

                if (fasitHome.Equals(home) && fasitAway.Equals(away))
                {
                    PointCalculator.AddScoreForCorrectResultInGroupMatch(ref score);
                }
            }

            // The table postitions, only if all matches are played
            if (Tournament.IsGroupStageFinished(correctResultsWorksheet))
            {
                if (worksheet.Cells["BA10"].Value == null)
                {
                    Console.WriteLine($"Knockout stage not correctly filled out for: {filename}");
                    Console.WriteLine($"Excel sheets will be omitted. Press enter to continue processing the next sheet");
                    Console.ReadLine();
                    return;
                }

                foreach (var tablePos in tablePosistions)
                {
                    var fasitPos = correctResultsWorksheet.Cells[tablePos].Value.ToString();
                    var pos      = worksheet.Cells[tablePos].Value.ToString();
                    if (fasitPos.Equals(pos))
                    {
                        PointCalculator.AddScoreForCorrectPlacementInGroup(ref score, pos);
                    }
                }

                // The 1/8 finals
                var eight = TeamPlacementReader.GetTeamsForEightFinal(worksheet);
                foreach (var eightfinalists in results.TeamsInEightFinal.Cast <string>().Where(eight.Contains))
                {
                    PointCalculator.AddScoreForEightFinals(ref score, eightfinalists);
                }

                // The quarterfinals
                var quarter = TeamPlacementReader.GetTeamsForQuarterFinals(worksheet);
                foreach (var quarterfinalist in results.TeamsInQuarterFinal.Cast <string>().Where(quarter.Contains))
                {
                    PointCalculator.AddScoreForQuarterfinals(ref score, quarterfinalist);
                }

                // The semifinals
                var semis = TeamPlacementReader.GetTeamsForSemiFinals(worksheet);
                foreach (var semifinalist in results.TeamsInSemiFinal.Cast <string>().Where(semis.Contains))
                {
                    PointCalculator.AddScoreForSemifinals(ref score, semifinalist);
                }

                // The bronze final
                var bronzeFinal = TeamPlacementReader.GetTeamsForBronzeFinals(worksheet);
                foreach (var finalist in results.TeamsInBronzeFinal.Cast <string>().Where(bronzeFinal.Contains))
                {
                    PointCalculator.AddScoreForTeamInBronzeFinals(ref score, finalist);
                }

                // The final
                var final = TeamPlacementReader.GetTeamsForFinals(worksheet);
                foreach (var finalist in results.TeamsInFinal.Cast <string>().Where(final.Contains))
                {
                    PointCalculator.AddScoreForTeamInFinals(ref score, finalist);
                }

                // The bronze final
                if (Tournament.IsBronzeWinnerDecided(correctResultsWorksheet))
                {
                    var fasitHome = correctResultsWorksheet.Cells["BS35"].Value.ToString();
                    var fasitAway = correctResultsWorksheet.Cells["BS36"].Value.ToString();

                    if (worksheet.Cells["BS35"].Value == null || worksheet.Cells["BS36"].Value == null)
                    {
                        Console.WriteLine($"Bronze final not correctly filled out for: {filename}");
                        Console.WriteLine("Excel sheet will be omitted. Press enter to continue processing the next sheet");
                        Console.ReadLine();
                        return;
                    }

                    var home = worksheet.Cells["BS35"].Value.ToString();
                    var away = worksheet.Cells["BS36"].Value.ToString();

                    if (GetHub(fasitHome, fasitAway) == "H" && GetHub(home, away) == "H" && bronzeFinal[0] == results.TeamsInBronzeFinal[0])
                    {
                        PointCalculator.AddScoreForBronzeWinner(ref score, results.TeamsInBronzeFinal[0]);
                    }

                    if (GetHub(fasitHome, fasitAway) == "B" && GetHub(home, away) == "B" && bronzeFinal[1] == results.TeamsInBronzeFinal[1])
                    {
                        PointCalculator.AddScoreForBronzeWinner(ref score, results.TeamsInBronzeFinal[1]);
                    }
                }

                // The winner
                if (Tournament.IsWinnerDecided(worksheet))
                {
                    PointCalculator.AddScoreForWinner(worksheet, results, ref score);
                }
            }

            var name = file.Replace(sourceDirctory, "").Replace(FilePrefix, "").Replace("_", " ").Replace(".xlsx", "").Replace("\\", "").Trim();

            scoresForAllUsers.Add(new UserScore {
                Name = name, Points = score, Winner = TeamPlacementReader.GetWinner(worksheet)
            });
        }