public static IObservable <SentimentDelta> GetMatchProbabilities(Random random) { var matchStarts = DateTimeOffset.Now.AddMinutes(1); var matches = MatchSchedule.GetMatchSchedule() .OrderByDescending(x => x.TeamA) .ToObservable() .Zip(Observable.Interval(TimeSpan.FromSeconds(1)), (x, y) => x); return(matches.SelectMany(match => { return Observable.Create <SentimentDelta>(observer => { var probabilities = match.GenerateProbabilities((decimal)random.NextDouble(), matchStarts, random) .Publish() .RefCount(); var movements = probabilities.DistinctUntilChanged(x => (new { Home = x.HomeWinProbability, Draw = x.DrawProbability, Away = x.AwayWinProbability }).GetHashCode()); var mergedDeltas = movements.FirstProbabilityAsDelta(match) .Merge(movements.ProbabilityDeltas(2, 1, match)); return mergedDeltas.Subscribe(observer); }); }) .Publish() .RefCount()); }
public void GenerateMatchSchedules() { var random = new Random(); SentimentDeltas = Observable.Defer(() => Observable.Start(() => MatchSchedule.GetMatchProbabilities(random))) .Switch() .Delay(TimeSpan.FromSeconds(1)) //probably not necessary, giving signalr and the browser time to catch up .Repeat() .Publish() .RefCount(); var bills = new Bookmaker("Billy Hills"); var brokeLads = new Bookmaker("Brokelads", 0.89m); var panicAll = new Bookmaker("Panic-all", 0.92m); var billsFeed = bills.GetBookmakerOdds(SentimentDeltas, random); var brokeLadsFeed = brokeLads.GetBookmakerOdds(SentimentDeltas, random); var panicAllFeed = panicAll.GetBookmakerOdds(SentimentDeltas, random); CombinedBookmakerFeeds = billsFeed.Merge(brokeLadsFeed) .Merge(panicAllFeed) .Publish() .RefCount(); }