Exemple #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);
        }
Exemple #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);
        }
Exemple #3
0
 private bool CanDistribute(WeightSpan weightSpan, IList <ItemRecord> itemRecords) =>
 weightSpan != null &&
 Math.Abs(weightSpan.Change) > double.Epsilon &&
 itemRecords != null &&
 itemRecords.Any();
Exemple #4
0
 private bool CanDistribute(WeightSpan weightSpan, IList <ItemRecord> itemRecords) =>
 weightSpan != null &&
 itemRecords != null &&
 itemRecords.Any();