public static bool CalculateResults(List <GuestModel> guests, List <CategoryModel> categories, TPercent percents, out List <ResultModel> results, bool excludeNotEligibleForMoney = true) { results = new List <ResultModel>(); if (IsAcademyChoiceFilled(categories)) { foreach (GuestModel guest in guests) { var result = CalculateGuestResults(guest, categories, excludeNotEligibleForMoney); if (result != null) { result.NbPointsWithoutPenality = result.NbPointsWithPenality; if (guest.Penality) { result.NbPointsWithPenality -= PENALITY; } if (result.IsEligibleToMoney) { result.Remboursement = m_montant * result.NbResponses; } else { result.Remboursement = 0; } result.IsPresent = guest.IsPresent; results.Add(result); } } FillPositions(ref results, 1); FillRemb(percents, ref results); results = results.OrderBy(r => r.Position).ToList(); return(true); } return(false); }
private static void FillRemb(TPercent percents, ref List <ResultModel> results) { float[] prices = new float[5]; float total = 0; int[] nbInPos = new int[5]; int[] totalGoodVotes = new int[5]; for (int i = 0; i < results.Count; i++) { ResultModel result = results[i]; if (result.Position > 0 && result.Position <= 5) { totalGoodVotes[result.Position - 1] = result.NbResponses; } total += (NB_CATEGORIES - result.NbResponses) * Montant; for (int j = 0; j < 5; j++) { if (result.Position == j + 1) { nbInPos[j]++; } } } prices[0] = total * percents.First / 100; prices[1] = total * percents.Second / 100; prices[2] = total * percents.Third / 100; prices[3] = total * percents.Fourth / 100; prices[4] = total * percents.Fifth / 100; float[] finalPrices = new float[] { 0, 0, 0, 0, 0 }; int startPos = 0; for (int i = 0; i < 5; i++) { for (int j = startPos; j < (startPos + nbInPos[i]) && j < 5; j++) { finalPrices[i] += prices[j]; } if (nbInPos[i] > 1) { finalPrices[i] /= nbInPos[i]; } startPos += nbInPos[i]; } for (int i = 0; i < results.Count; i++) { ResultModel result = results[i]; for (int j = 0; j < 5; j++) { if (result.Position == j + 1) { result.Remboursement += finalPrices[j]; result.Remboursement = RoundToClosest25Cent(result.Remboursement); results[i] = result; break; } } } }