public Calculation(ICalculationRules context) { _context = context; foreach (var attribute in _context.ContributingAttributes) { var value = GetOrAddPendingValue(attribute); } var prepared = GetPreparedAttributes(); while (prepared.Count > 0) { foreach (var attribute in prepared) { // this will remove the attribute from the 'pending' queue var removed = CompletePendingCalculation(attribute); foreach (var contribution in _context.ContributionsBy(attribute)) { AddContribution(contribution); } } prepared = GetPreparedAttributes(); } if (_pendingValues.Count > 0) { throw new Exception("not enough info to calculate all attributes"); } Result = new CalculationResult { AttributeValues = _completedValues.Values }; }
public CalculationResult Calculate(ICalculationRules context) { var calculation = new Calculation(context); return(calculation.Result); }
public CalculationResult Calculate(ICalculationRules context) { var calculation = new Calculation(context); return calculation.Result; }
public static IEnumerable <Campaigns.Model.AttributeContribution> ContributionsBy(this ICalculationRules ctx, int sourceId) { return(ctx.AllContributionsFrom(sourceId) .Where(c => ctx.IsAttributeContributing(c.Target))); }
public static IEnumerable <Campaigns.Model.AttributeContribution> ContributionsTo(this ICalculationRules ctx, int targetId) { return(ctx.AllContributionsTo(targetId) .Where(c => null == c.Source || ctx.IsAttributeContributing(c.Source))); }