private static void UploadResults(string uploadPath, string results, string leagueName) { var client = new HttpClient(); var response = client .PostAsync(string.Format(uploadPath, FilePrefix, leagueName), new StringContent(results, Encoding.UTF8, "application/json")).Result; FakeConsole.WriteLine(response.Content.ReadAsStringAsync().Result); }
private static bool HasValidLanguage(ExcelWorksheet worksheet, string fileName) { if (worksheet.Cells["O3"].Value.ToString() != "Language: Norwegian") { FakeConsole.WriteLine($"Language not Norwegian for: {fileName}"); FakeConsole.WriteLine("Excel sheet will be omitted. Press enter to continue processing the next sheet"); return(false); } return(true); }
private static async Task CreateFile(DropboxClient dropboxClient, Metadata item, string basePath) { var response = await dropboxClient.Files.DownloadAsync(item.PathLower); using (var content = await response.GetContentAsStreamAsync().ConfigureAwait(false)) using (var fileStream = System.IO.File.Create($"{basePath}{item.PathDisplay}")) { await content.CopyToAsync(fileStream); FakeConsole.WriteLine($"Created file {basePath}{item.PathDisplay}"); } }
public static void Main(String[] args) { int n = int.Parse(Console.ReadLine()); string s = Console.ReadLine(); foreach (char c in s) { if (c == '-') { n -= 2; } } Console.WriteLine(Math.Max(n, 0)); }
public void RunCalculation(bool upload) { FakeConsole.Init(); var sourceDirectory = "Leagues"; foreach (var league in Directory.GetDirectories(sourceDirectory)) { FakeConsole.WriteLine($"Processing league {Path.GetFileName(league)}"); var results = Calculate(sourceDirectory, league); if (upload) { UploadResults(_configuration["Tournament:Upload"], results, Path.GetFileName(league)); } } ViewData["Status"] = "Results updated"; ViewData["Log"] = FakeConsole.Print(); }
private static void CreateDirectory(string path) { Directory.CreateDirectory(path); FakeConsole.WriteLine($"Created directory {path}"); }
public static void AddScoreForTeamInBronzeFinals(ref int score, string finalist) { score += 10; FakeConsole.WriteLine($"+10 for {finalist} videre til bronsefinale"); }
public static void AddScoreForTeamInFinals(ref int score, string finalist) { score += 12; FakeConsole.WriteLine($"+12 for {finalist} videre til finale"); }
public static void AddScoreForSemifinals(ref int score, string semifinalist) { score += 8; FakeConsole.WriteLine($"+8 for {semifinalist} videre til semifinale"); }
public static void AddScoreForQuarterfinals(ref int score, string quarterfinalist) { score += 6; FakeConsole.WriteLine($"+6 for {quarterfinalist} videre til kvartfinale"); }
public static void AddScoreForEightFinals(ref int score, string eightfinalists) { score += 4; //Console.OutputEncoding = Encoding.UTF8; FakeConsole.WriteLine($"+4 for {eightfinalists} videre til åttendelsfinale"); }
public static void AddScoreForCorrectPlacementInGroup(ref int score, dynamic pos) { score += 2; //Console.OutputEncoding = Encoding.UTF8; FakeConsole.WriteLine($"+2 for {pos} på korrekt plass i gruppen"); }
public static void AddScoreForCorrectOutcomeInGroupMatch(ref int score) { score += 2; //Console.OutputEncoding = Encoding.UTF8; FakeConsole.WriteLine("+2 for gruppespillkamp : korrekt utfall"); }
public static int AddScoreForBronzeWinner(ref int score, string bronzeWinner) { FakeConsole.WriteLine($"+14 for korrekt bronsefinalevinner : {bronzeWinner}"); score += 14; return(score); }
public static int AddScoreForWinner(ref int score, string winner) { FakeConsole.WriteLine($"+16 for korrekt finalevinner : {winner}"); score += 16; return(score); }
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; } FakeConsole.WriteLine($"Processing {file}"); var worksheet = ExcelService.GetWorksheet(file); if (!HasValidLanguage(worksheet, file)) { Console.ReadLine(); } 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) { FakeConsole.WriteLine($"Group stage not correctly filled out for: {filename}"); FakeConsole.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)) { 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) { FakeConsole.WriteLine($"Bronze final not correctly filled out for: {filename}"); FakeConsole.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) }); }