public void Add(WeightChangeDistribution distribution) { foreach (var pair in distribution.Dictionary) { Add(pair.Key, pair.Value); } }
public WeightChangeDistribution Distribute(WeightSpan weightSpan, IList <ItemRecord> itemRecords) { var result = new WeightChangeDistribution(); if (!CanDistribute(weightSpan, itemRecords)) { return(result); } var itemWeightChange = weightSpan.Change / itemRecords.Count; foreach (var itemRecord in itemRecords) { result.Add(itemRecord.ItemId, new List <double> { itemWeightChange }); } return(result); }
public WeightChangeDistribution Distribute(WeightSpan weightSpan, IList <ItemRecord> itemRecords) { var result = new WeightChangeDistribution(); if (!CanDistribute(weightSpan, itemRecords)) { return(result); } var itemGroups = itemRecords.GroupBy(ir => ir.ItemId).ToList(); var groupWeightChange = weightSpan.Change / itemGroups.Count; itemGroups.ForEach(items => { var itemWeightChange = groupWeightChange / items.Count(); var weightChanges = Enumerable.Repeat(itemWeightChange, items.Count()).ToList(); result.Add(items.Key, weightChanges); }); return(result); }