Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }