public void UpdateSnowball(DateTime date) { if (!IsSnowball) { return; } // go through the pool until we find the next target or the pool is drained var currentSnowballTarget = SnowballTarget; while (CanBeSnowballTarget(SnowballTarget) == false) { SnowballTarget = SnowballPool.SafeDequeue(); } if (currentSnowballTarget != SnowballTarget) { AddNotice(date, $"Snowball Target Updated({currentSnowballTarget.Name} => {SnowballTarget?.Name})"); } }
public SimulationState(Profile profile, SimulationSetup setup) { IsSnowball = setup.UseSnowball; Accounts = profile.Accounts.Select(a => new SimulationBankAccount(a)).ToDictionary(a => a.Id); Bills = profile.Bills.Select(b => new SimulationBill(setup.Start, b)).ToDictionary(b => b.Id); Debts = profile.Debts.Select(d => new SimulationDebtAccount(setup.Start, d)).ToDictionary(d => d.Id); Paychecks = profile.Paychecks.Select(p => new SimulationPaycheck(setup.Start, p)).ToDictionary(p => p.Id); Transactions = profile.Transactions.Select(t => new SimulationTransaction(setup.Start, t)).ToDictionary(t => t.Id); Events = profile.Events.All().ToLookup(e => e.Date); SnowballPool = new Queue <SimulationDebtAccount>(Debts.Values .Select((d, i) => (debt: d, order: GetDebtOrder(d, profile.Snowball, i))) .OrderBy(t => t.order) .Select(t => t.debt)); SnowballTarget = SnowballPool.SafeDequeue(); SnowballAmount = profile.Snowball.InitialAmount; Results = new Dictionary <IAccount, List <SimulationResultItem> >(); AddToSnowball(setup.Start, 0); }