protected virtual async Task <List <PollingStation> > CalculateVotesByCounty(string csvContent, ElectionsConfig electionsConfig) { var csvParser = new CsvParser(new StringReader(csvContent)); var pollingStations = new List <PollingStation>(); var headers = (await csvParser.ReadAsync()).ToList(); do { var rowValues = await csvParser.ReadAsync(); if (rowValues == null) { break; } var pollingStation = new PollingStation(); pollingStation.County = rowValues[1].StartsWith("SECTOR") ? "BUCUREȘTI" : rowValues[1]; pollingStation.Name = rowValues[4]; foreach (var candidate in electionsConfig.Candidates) { var votes = int.Parse(rowValues[headers.IndexOf(candidate.CsvId)]); pollingStation.Candidates.Add(new CandidateConfig { Id = candidate.CsvId, Votes = votes }); pollingStation.TotalVotes += votes; } pollingStations.Add(pollingStation); } while (true); return(pollingStations); }
public async Task <Result> UpdateElectionConfig(ElectionsConfig config) { var putParameterRequest = new PutParameterRequest { Name = $"/{Consts.PARAMETER_STORE_NAME}/settings/electionsConfig", Value = JsonConvert.SerializeObject(config), Type = ParameterType.String, Overwrite = true }; var response = await _amazonSettingsClient.PutParameterAsync(putParameterRequest); if (response.HttpStatusCode == HttpStatusCode.OK) { return(Result.Ok()); } return(Result.Failure("Couldn't update the job timer")); }
public async Task <ActionResult> UpdateSettings([FromBody] ElectionsConfig config) { //temporary config until the admin frontend is ready var newConfig = new ElectionsConfig(); newConfig.Candidates = new List <CandidateConfig> { new CandidateConfig { Name = "Candidate A", Id = "1", CsvId = "g1", ImageUrl = "https://code4-presidential-2019.s3.eu-central-1.amazonaws.com/c1.png" }, new CandidateConfig { Name = "Candidate B", Id = "2", CsvId = "g2", ImageUrl = "https://code4-presidential-2019.s3.eu-central-1.amazonaws.com/c2.png" }, new CandidateConfig { Name = "Candidate C", Id = "3", CsvId = "g3", ImageUrl = "https://code4-presidential-2019.s3.eu-central-1.amazonaws.com/c1.png" }, new CandidateConfig { Name = "Candidate D", Id = "4", CsvId = "g4", ImageUrl = "https://code4-presidential-2019.s3.eu-central-1.amazonaws.com/c2.png" }, new CandidateConfig { Name = "Candidate E", Id = "5", CsvId = "g5", ImageUrl = "https://code4-presidential-2019.s3.eu-central-1.amazonaws.com/c1.png" }, new CandidateConfig { Name = "Candidate F", Id = "6", CsvId = "g6", ImageUrl = "https://code4-presidential-2019.s3.eu-central-1.amazonaws.com/c2.png" }, new CandidateConfig { Name = "Candidate G", Id = "7", CsvId = "g7", ImageUrl = "https://code4-presidential-2019.s3.eu-central-1.amazonaws.com/c1.png" }, new CandidateConfig { Name = "Candidate H", Id = "8", CsvId = "g8", ImageUrl = "https://code4-presidential-2019.s3.eu-central-1.amazonaws.com/c2.png" }, new CandidateConfig { Name = "Candidate I", Id = "9", CsvId = "g9", ImageUrl = "https://code4-presidential-2019.s3.eu-central-1.amazonaws.com/c1.png" }, new CandidateConfig { Name = "Candidate J", Id = "10", CsvId = "g10", ImageUrl = "https://code4-presidential-2019.s3.eu-central-1.amazonaws.com/c2.png" }, new CandidateConfig { Name = "Candidate K", Id = "11", CsvId = "g11", ImageUrl = "https://code4-presidential-2019.s3.eu-central-1.amazonaws.com/c1.png" }, new CandidateConfig { Name = "Candidate L", Id = "12", CsvId = "g12", ImageUrl = "https://code4-presidential-2019.s3.eu-central-1.amazonaws.com/c2.png" }, new CandidateConfig { Name = "Candidate M", Id = "13", CsvId = "g13", ImageUrl = "https://code4-presidential-2019.s3.eu-central-1.amazonaws.com/c1.png" }, new CandidateConfig { Name = "Candidate N", Id = "14", CsvId = "g14", ImageUrl = "https://code4-presidential-2019.s3.eu-central-1.amazonaws.com/c2.png" }, new CandidateConfig { Name = "Candidate O", Id = "15", CsvId = "g15", ImageUrl = "https://code4-presidential-2019.s3.eu-central-1.amazonaws.com/c1.png" }, new CandidateConfig { Name = "Candidate P", Id = "16", CsvId = "g16", ImageUrl = "https://code4-presidential-2019.s3.eu-central-1.amazonaws.com/c2.png" } }; newConfig.Files = new List <ElectionResultsFile> { new ElectionResultsFile { Active = true, ResultsType = ResultsType.Partial, ResultsLocation = ResultsLocation.Romania, URL = "https://prezenta.bec.ro/europarlamentare26052019/data/pv/csv/pv_RO_EUP_PART.csv" }, new ElectionResultsFile { Active = true, ResultsType = ResultsType.Partial, ResultsLocation = ResultsLocation.Diaspora, URL = "https://prezenta.bec.ro/europarlamentare26052019/data/pv/csv/pv_SR_EUP_PART.csv" }, new ElectionResultsFile { Active = true, ResultsType = ResultsType.Final, ResultsLocation = ResultsLocation.Romania, URL = "https://prezenta.bec.ro/europarlamentare26052019/data/pv/csv/pv_RO_EUP_FINAL.csv" }, new ElectionResultsFile { Active = true, ResultsType = ResultsType.Final, ResultsLocation = ResultsLocation.Diaspora, URL = "https://prezenta.bec.ro/europarlamentare26052019/data/pv/csv/pv_SR_EUP_FINAL.csv" }, new ElectionResultsFile { Active = true, ResultsType = ResultsType.Provisional, ResultsLocation = ResultsLocation.Romania, URL = "https://prezenta.bec.ro/europarlamentare26052019/data/pv/csv/pv_RO_EUP_PROV.csv" }, new ElectionResultsFile { Active = true, ResultsType = ResultsType.Provisional, ResultsLocation = ResultsLocation.Diaspora, URL = "https://prezenta.bec.ro/europarlamentare26052019/data/pv/csv/pv_SR_EUP_PROV.csv" } }; await _electionConfigurationSource.UpdateElectionConfig(newConfig); return(Ok()); }
public async Task <ActionResult> UpdateSettings([FromBody] ElectionsConfig config) { await _electionConfigurationSource.UpdateElectionConfig(config); return(Ok()); }