public Task ProcessBatchAsync(IReadOnlyList <Contact> batch, CancellationToken token) { foreach (var contact in batch) { var runEnded = contact.Interactions.SelectMany(x => x.Events).OfType <RunEnded>() .ToArray(); var totalRuns = runEnded.Length; if (totalRuns == 0) { continue; } var totalRunsReciprocal = 1 / (double)totalRuns; var morningRunner = runEnded.Count(x => x.Time.Hour < _morningEndHours) * totalRunsReciprocal; var eveningRunner = runEnded.Count(x => x.Time.Hour > _eveningStartHours) * totalRunsReciprocal; var runnerFacet = contact.GetFacet <RunnerFacet>(); var averageMultiplier = 0.5; if (runnerFacet == null) { runnerFacet = new RunnerFacet(); averageMultiplier = 1; } runnerFacet.IsMorningRunner = (runnerFacet.IsMorningRunner + morningRunner) * averageMultiplier; runnerFacet.IsEveningRunner = (runnerFacet.IsEveningRunner + eveningRunner) * averageMultiplier; _xdbContext.SetFacet(contact, runnerFacet); } return(_xdbContext.SubmitAsync(token)); }
protected override double GetRunnerValue(RunnerFacet runnerFacet) { return(runnerFacet.IsMorningRunner); }
protected abstract double GetRunnerValue(RunnerFacet runnerFacet);