private IEnumerable <TennisFixtureViewModel> GetTennisPredictionsSync(DateTime matchDate) { var tennisPredictionsDic = new Dictionary <int, TennisPrediction>(); var matches = this.fixtureRepository .GetDaysMatches(matchDate, "Tennis") .ToList(); var tennisPredictionStatsDic = this.predictionRepository .GetTennisPredictionStatByMatchIDs(matches.Select(m => m.Id)) .ToDictionary(x => x.Id); foreach (var match in matches) { var playerA = this.fixtureRepository.GetTeamOrPlayerById(match.TeamAID); var playerB = this.fixtureRepository.GetTeamOrPlayerById(match.TeamBID); var tournamentEvent = this.fixtureRepository.GetTournamentEventById(match.TournamentEventID); var tournament = this.fixtureRepository.GetTournamentFromTournamentEvent(tournamentEvent.EventName); var identifier = string.Format("{0},{1}/vs/{2},{3}/{4}/{5}", playerA.Name, playerA.FirstName, playerB.Name, playerB.FirstName, tournamentEvent.EventName, matchDate.Date.ToShortDateString().Replace("/", "-")); var tennisPrediction = new TennisPrediction { MatchID = match.Id, MatchIdentifier = identifier, TournamentName = tournament.TournamentName, MatchDate = match.MatchDate, TeamOrPlayerA = playerA.Name, PlayerAFirstName = playerA.FirstName, TeamOrPlayerB = playerB.Name, PlayerBFirstName = playerB.FirstName, }; tennisPredictionsDic.Add(match.Id, tennisPrediction); } var outcomePredictions = this.predictionRepository.GetMatchOutcomeProbabilitiesInMatchByIDs(matches.Select(x => x.Id)); var scoreLinePredictions = this.predictionRepository.GetScoreOutcomeProbabilitiesInMatchByIDs(matches.Select(x => x.Id)); foreach (var id in matches.Select(x => x.Id)) { var tennisPrediction = tennisPredictionsDic[id]; tennisPrediction.OutcomeProbabilities = outcomePredictions[id].ToDictionary(o => (Outcome)o.MatchOutcomeID, o => (double)o.MatchOutcomeProbability); if (scoreLinePredictions.ContainsKey(id)) { tennisPrediction.ScoreLineProbabilities = scoreLinePredictions[id].ToDictionary(o => string.Format("{0}-{1}", o.ScoreOutcome.TeamAScore, o.ScoreOutcome.TeamBScore), o => (double?)o.ScoreOutcomeProbability); } } var combinedStats = HydrateFullTennisMatchDetails(matchDate, tennisPredictionsDic, tennisPredictionStatsDic); return(Mapper.Map <IEnumerable <TennisMatchDetail>, IEnumerable <TennisFixtureViewModel> >(combinedStats)); }
protected override Dictionary <string, double> ResolveCore(TennisPrediction source) { var ret = new Dictionary <string, double>(); foreach (var outcomeKVP in source.OutcomeProbabilities) { ret.Add(outcomeKVP.Key.ToString(), outcomeKVP.Value); } return(ret); }
protected override IEnumerable <ScoreLineProbabilityViewModel> ResolveCore(TennisPrediction source) { if (source.ScoreLineProbabilities.Any(x => !x.Value.HasValue)) { return(Enumerable.Empty <ScoreLineProbabilityViewModel>()); } else { return(source.ScoreLineProbabilities.Select(s => new ScoreLineProbabilityViewModel() { ScoreLine = s.Key, ScoreLineProbability = s.Value })); } }