public ProgressionValue GetValueAt(DateTime when, bool strictlyEarlier)
        {
            ListItemStats <DateTime, WillingnessSummary> stats = this.searchHelper.FindPreviousItem(when, strictlyEarlier);

            if (stats == null)
            {
                return(null);
            }

            // get some statistics
            DateTime latestDate = stats.Key;
            // compute how long ago that rating was given
            TimeSpan duration = when.Subtract(latestDate);
            // create another date that is twice as far in the past
            DateTime earlierDate = latestDate.Subtract(duration);
            // add up everything that occurred between the earlier day and now
            WillingnessSummary sum = this.searchHelper.CombineBetweenKeys(earlierDate, true, when, !strictlyEarlier);
            double             numParticipations = sum.NumUnpromptedParticipations + sum.NumPromptedParticipations;
            double             numSkips          = sum.NumSkips;
            double             mean         = numParticipations / (numParticipations + numSkips);
            double             weight       = numParticipations + numSkips;
            Distribution       distribution = Distribution.MakeDistribution(mean, 0, weight);
            ProgressionValue   result       = new ProgressionValue(when, distribution);

            return(result);
        }
        public WillingnessSummary Combine(WillingnessSummary a, WillingnessSummary b)
        {
            this.numAdditions++;
            WillingnessSummary result = a.Plus(b);

            return(result);
        }
        public WillingnessSummary Minus(WillingnessSummary other)
        {
            WillingnessSummary difference = new WillingnessSummary();

            difference.numUnpromptedParticipations = this.numUnpromptedParticipations - other.numUnpromptedParticipations;
            difference.numPromptedParticipations   = this.numPromptedParticipations - other.numPromptedParticipations;
            difference.numSkips = this.numSkips - other.numSkips;

            return(difference);
        }
        public WillingnessSummary Plus(WillingnessSummary other)
        {
            WillingnessSummary sum = new WillingnessSummary();

            sum.numUnpromptedParticipations = this.numUnpromptedParticipations + other.numUnpromptedParticipations;
            sum.numPromptedParticipations   = this.numPromptedParticipations + other.numPromptedParticipations;
            sum.numSkips = this.numSkips + other.numSkips;

            return(sum);
        }
 public void AddValue(DateTime when, WillingnessSummary value)
 {
     this.searchHelper.Add(when, value);
 }
        public void AddSkip(ActivitySkip newSkip)
        {
            WillingnessSummary willingness = WillingnessSummary.Skipped;

            this.AddValue(newSkip.SuggestionStartDate, willingness);
        }