private static async Task <VoterTurnout> GetVoterTurnoutByUrl(HttpClient httpClient, string url)
        {
            var json = await httpClient.GetStringAsync(url);

            var voterTurnoutResponse = JsonConvert.DeserializeObject <VoterTurnoutResponce>(json);
            var permanentLists       = voterTurnoutResponse.Counties.Sum(c => c.VotersOnPermanentLists);
            var specialLists         = voterTurnoutResponse.Counties.Sum(c => c.VotersOnSpecialLists);
            var mobileVotes          = voterTurnoutResponse.Counties.Sum(c => c.MobileVotes);
            var mailDiasporaVotes    = voterTurnoutResponse.Precinct.Sum(p => p.MailDiasporaVotes);

            var diasporaVoters         = voterTurnoutResponse.Precinct.Sum(c => c.VotersOnSpecialLists);
            var enlistedVoters         = voterTurnoutResponse.Counties.Sum(c => c.InitialCount);
            var totalVoters            = permanentLists + mobileVotes + (specialLists - diasporaVoters);
            var voterTurnoutPercentage = totalVoters / (decimal)enlistedVoters;

            var voterTurnout = new VoterTurnout
            {
                EnlistedVoters           = enlistedVoters,
                TurnoutPercentage        = Math.Round(voterTurnoutPercentage * 100, 2),
                TotalNationalVotes       = totalVoters,
                TotalDiasporaVotes       = mailDiasporaVotes,
                PermanentLists           = permanentLists,
                AdditionalLists          = specialLists,
                MobileVotes              = mobileVotes,
                DiasporaWithoutMailVotes = diasporaVoters
            };

            return(voterTurnout);
        }
Beispiel #2
0
        public virtual async Task InsertCurrentVoterTurnout(VoterTurnout voterTurnout)
        {
            var electionStatistics = new ElectionStatistics
            {
                Id             = $"{DateTime.MaxValue.Ticks - DateTime.UtcNow.Ticks:D19}",
                Type           = ResultsType.VoterTurnout.ConvertEnumToString(),
                Location       = ResultsLocation.All.ConvertEnumToString(),
                Timestamp      = voterTurnout.Timestamp,
                StatisticsJson = JsonConvert.SerializeObject(voterTurnout)
            };

            await InsertResults(electionStatistics);
        }
Beispiel #3
0
        public virtual async Task InsertCurrentVoterTurnout(VoterTurnout voterTurnout)
        {
            var electionStatistics = new ElectionStatistics
            {
                Id             = $"{DateTime.MaxValue.Ticks - DateTime.UtcNow.Ticks:D19}",
                Type           = FileType.VoterTurnout.ConvertEnumToString(),
                Source         = Consts.VOTE_TURNOUT_KEY,
                Timestamp      = voterTurnout.Timestamp,
                ElectionId     = voterTurnout.ElectionId,
                StatisticsJson = JsonConvert.SerializeObject(voterTurnout)
            };

            await InsertResults(electionStatistics);
        }
 public override Task InsertCurrentVoterTurnout(VoterTurnout voterTurnout)
 {
     return(Task.CompletedTask);
 }