public VoteStatisticsViewModel GetVoteOnResolutionStatisticsPercentage(string resolutionId) { VoteStatisticsViewModel voteStatisticsViewModel = new VoteStatisticsViewModel { VoteQuantity = _context.GetVotesQuantity(resolutionId), ArrayWithStatistics = _context.GetPercentageQuantityOfConcreteOptions(resolutionId) }; voteStatisticsViewModel.NoVoteQuantity = _context.GetNoVotesQuantity(voteStatisticsViewModel.VoteQuantity); return(voteStatisticsViewModel); }
public VoteStatisticsViewModel GetVoteOnResolutionStatistics(string resolutionId) { VoteStatisticsViewModel voteStatisticsViewModel = new VoteStatisticsViewModel { VoteQuantity = _context.GetVotesQuantity(resolutionId), ArrayWithStatistics = _context.GetQuantityOfConcreteOptions(resolutionId) }; voteStatisticsViewModel.NoVoteQuantity = _context.GetNoVotesQuantity(voteStatisticsViewModel.VoteQuantity); voteStatisticsViewModel.UsersData = _context.GetUsersWithLackOfVoteBasicCredentials(resolutionId); return(voteStatisticsViewModel); }
private VoteStatisticsViewModel GetPreviouseNationalVotesForBill(int billId) { var votes = _db.All <VoteDateModel>().Where(v => v.BillDataModelId == billId).ToList(); decimal signedupVotersCount = _db.All <ApplicationUser>().Where(u => u.IsIdentityVerified == true).Count(); decimal totalVoters = _db.All <ConstituencyDataModel>().Sum(c => c.RegisterdVoters); decimal numberOfVotes = 0; decimal turnOut = 0; decimal forCount = 0; decimal forPercent = 0; decimal againstCount = 0; decimal againstPercentage = 0; decimal abstainCount = 0; decimal abstainPercentage = 0.00M; decimal votersOnSitePercentage = 0.00M; if (votes.Count() > 0 && signedupVotersCount > 0) { numberOfVotes = votes.Count(); turnOut = (numberOfVotes / totalVoters) * 100; forCount = votes.Where(v => v.Vote == true).Count(); forPercent = (forCount / totalVoters) * 100; againstCount = votes.Where(v => v.Vote == false).Count(); againstPercentage = (againstCount / totalVoters) * 100; abstainCount = totalVoters - numberOfVotes; abstainPercentage = abstainCount / totalVoters * 100; votersOnSitePercentage = signedupVotersCount / totalVoters * 100; } var voteStatisticsViewModel = new VoteStatisticsViewModel() { ForCount = forCount, ForPercent = forPercent, AgainstCount = againstCount, AgainstPercent = againstPercentage, Turnout = turnOut, AbstainCount = abstainCount, AbstainPercentage = abstainPercentage, RegisterdVoters = totalVoters, SignedUpVoters = signedupVotersCount, SignedUpPercentage = votersOnSitePercentage }; return(voteStatisticsViewModel); }
private VoteStatisticsViewModel GetPreviouseParlimantaryVotesForBill(int id) { var bill = _db.Single <BillDataModel>(b => b.Id == id); var votes = _db.AllIncluding <MpVoteRecord>(v => v.Bill).Where(v => v.Bill.Id == bill.Id).ToList(); var publicVotes = _db.All <VoteDateModel>().Where(v => v.BillDataModelId == bill.Id); decimal totalpublicVoters = _db.All <ConstituencyDataModel>().Sum(c => c.RegisterdVoters); decimal publicForCount = 0; decimal publicAgainstCount = 0; decimal totalVotes = 0; decimal forVotes = 0; decimal againstVotes = 0; decimal abstainCount = 0; decimal forPercent = 0; decimal againstPercentage = 0; decimal abstainPercentage = 0; decimal publicForPercentage = 0; decimal publicAgainstPercentage = 0; if (votes.Count() > 0) { publicForCount = publicVotes.Count(v => v.Vote); publicAgainstCount = publicVotes.Count(v => v.Vote == false); totalVotes = votes.Count(); forVotes = votes.Count(v => v.Vote == VoteType.Aye || v.Vote == VoteType.TellAye); againstVotes = votes.Count(v => v.Vote == VoteType.No || v.Vote == VoteType.TellNo); abstainCount = votes.Count(v => v.Vote == VoteType.Missing); forPercent = forVotes / totalVotes * 100; againstPercentage = againstVotes / totalVotes * 100; abstainPercentage = againstVotes / totalVotes * 100; publicForPercentage = (publicForCount / totalpublicVoters) * 100; publicAgainstPercentage = (publicAgainstCount / totalpublicVoters) * 100; } decimal percentageRepresented = 0; if (forVotes > againstVotes) { percentageRepresented = publicForPercentage; } else { percentageRepresented = publicAgainstPercentage; } var voteStatisticsViewModel = new VoteStatisticsViewModel() { ForCount = forVotes, ForPercent = forPercent, AgainstCount = againstVotes, AgainstPercent = againstPercentage, Turnout = totalVotes, AbstainCount = abstainCount, AbstainPercentage = abstainPercentage, percentageRepresented = percentageRepresented }; return(voteStatisticsViewModel); }
private VoteStatisticsViewModel GetPreviouseLocalVotesForBill(int billId, ApplicationUser user) { var allLocalVotes = _db.AllIncluding <VoteDateModel>(v => v.ConstituencyDataModel).Where(v => v.ConstituencyDataModelId == user.ConstituencyDataModel.Id && v.BillDataModelId == billId); decimal totalConstituencyApplicationVotersCount = _db.AllIncluding <ApplicationUser>(u => u.ConstituencyDataModel).Count(u => u.ConstituencyDataModel.Id == user.ConstituencyDataModel.Id && u.IsIdentityVerified == true); decimal totalConstituencyRegisterdVotersCount = user.ConstituencyDataModel.RegisterdVoters; var mp = _db.SingleIncluding <MPDataModel>(m => m.Constituency.Id == user.ConstituencyDataModel.Id, m => m.Constituency); var mpVote = _db.SingleIncluding <MpVoteRecord>(v => v.Mp.Id == mp.Id && v.Bill.Id == billId, v => v.Mp, v => v.Bill); decimal representativePercentage = 0M; var vote = ""; decimal turnOut = 0.00M; decimal forCount = 0; decimal forPercent = 0.00M; decimal againstCount = 0; decimal againstPercentage = 0.00M; decimal abstainCount = 0; decimal abstainPercentage = 0.00M; decimal votersOnSitePercentage = 0.00M; if (allLocalVotes.Count() > 0 && totalConstituencyApplicationVotersCount > 0) { decimal numberOfVotes = allLocalVotes.Count(); turnOut = numberOfVotes / totalConstituencyRegisterdVotersCount * 100; forCount = allLocalVotes.Where(v => v.Vote == true).Count(); forPercent = forCount / totalConstituencyRegisterdVotersCount * 100; againstCount = allLocalVotes.Where(v => v.Vote == false).Count(); againstPercentage = againstCount / totalConstituencyRegisterdVotersCount * 100; abstainCount = totalConstituencyRegisterdVotersCount - numberOfVotes; abstainPercentage = abstainCount / totalConstituencyRegisterdVotersCount * 100; votersOnSitePercentage = totalConstituencyApplicationVotersCount / totalConstituencyRegisterdVotersCount * 100; } if (mpVote != null) { switch (mpVote.Vote) { case VoteType.Aye: case VoteType.TellAye: representativePercentage = forPercent; vote = "voted for"; break; case VoteType.No: case VoteType.TellNo: representativePercentage = againstPercentage; vote = "voted against"; break; case VoteType.Missing: representativePercentage = 0; vote = "did not vote on"; break; } } else { representativePercentage = 0; vote = "did not vote on"; } var voteStatisticsViewModel = new VoteStatisticsViewModel() { ForCount = forCount, ForPercent = forPercent, AgainstCount = againstCount, AgainstPercent = againstPercentage, Turnout = turnOut, AbstainCount = abstainCount, AbstainPercentage = abstainPercentage, RegisterdVoters = totalConstituencyRegisterdVotersCount, SignedUpVoters = totalConstituencyApplicationVotersCount, SignedUpPercentage = votersOnSitePercentage, percentageRepresented = representativePercentage, mpVoted = vote }; return(voteStatisticsViewModel); }