/// <summary> /// The first half of tallying posts involves doing the preprocessing /// work on the plans in the post list. /// </summary> private void PreprocessPosts(CancellationToken token) { // Collection of all the plans that we find in the post list. PlanDictionary planRepo = new PlanDictionary(Agnostic.StringComparer); // Scan the post list once. foreach (var post in VotingRecords.Instance.PostsList) { token.ThrowIfCancellationRequested(); // Pull out all plans from each post. var plans = Plan.GetPlansFromVote(post.Vote); // Examine each plan. foreach (var plan in plans) { if (VotingRecords.Instance.HasVoterName(plan.Identity.Name)) { // A voter may name a plan after themselves. No one else may. // If they do, they're considered proxy votes, and we can skip to the next plan. if (!Agnostic.StringComparer.Equals(plan.Identity.Name, post.Identity.Name)) { continue; } } if (planRepo.TryGetValue(plan.Identity.Name, out var existingPlans)) { if (plan.PlanType < existingPlans[0].PlanType) { // Lower types are never added continue; } else if (plan.PlanType > existingPlans[0].PlanType) { // A higher type wipes all existing plans, then adds itself as the new primary existingPlans.Clear(); existingPlans.Add(plan); } else if (existingPlans.All(p => p != plan)) { // If it's of the same tier, add it if it's a variant that's different from all existing plans. plan.Identity.Number = existingPlans.Count; existingPlans.Add(plan); } } else { // If the plan name doesn't already exist, add it. planRepo.Add(plan.Identity.Name, new List <Plan> { plan }); } } } // At the end, we should have a collection of the 'best' versions of each named plan. // Store them in the voting records. VotingRecords.Instance.AddPlans(planRepo); }
/// <summary> /// Adds the plans that were found. /// </summary> /// <param name="allPlans">The collection of discovered plans.</param> public void AddPlans(PlanDictionary allPlans) { PlansLookup = new PlanDictionary(allPlans, Agnostic.StringComparer); }