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