public IEnumerable<TennisFixtureViewModel> GetTennisPredictions(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
        {
          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);
    }
        public static Model.GenericPrediction ConvertAPIToGeneric(APITennisPrediction apiPrediction, Uri predictionURL)
        {
            var tennisPrediction = new Model.TennisPrediction()
            {
                TournamentName = apiPrediction.TournamentName,
                PredictionURL  = predictionURL,

                PlayerAFirstName = apiPrediction.PlayerAFirstname,
                TeamOrPlayerA    = apiPrediction.PlayerASurname,
                PlayerBFirstName = apiPrediction.PlayerBFirstname,
                TeamOrPlayerB    = apiPrediction.PlayerBSurname,

                PlayerAGames    = apiPrediction.PlayerAGames,
                PlayerBGames    = apiPrediction.PlayerBGames,
                MatchDate       = apiPrediction.StartTime,
                MatchIdentifier = string.Format("{0} vs. {1} @ {2} on {3}", apiPrediction.PlayerASurname, apiPrediction.PlayerBSurname,
                                                apiPrediction.TournamentName, apiPrediction.StartTime.ToShortDateString()),
                EPoints = apiPrediction.ExpectedPoints,
                EGames  = apiPrediction.ExpectedGames,
                ESets   = apiPrediction.ExpectedSets
            };

            tennisPrediction.OutcomeProbabilities.Add(Model.Outcome.HomeWin, apiPrediction.PlayerAProbability);
            tennisPrediction.OutcomeProbabilities.Add(Model.Outcome.AwayWin, apiPrediction.PlayerBProbability);

            if (apiPrediction.FiveSets)
            {
                tennisPrediction.ScoreLineProbabilities.Add("3-0", apiPrediction.ProbThreeLove);
                tennisPrediction.ScoreLineProbabilities.Add("3-1", apiPrediction.ProbThreeOne);
                tennisPrediction.ScoreLineProbabilities.Add("3-2", apiPrediction.ProbThreeTwo);
                tennisPrediction.ScoreLineProbabilities.Add("2-3", apiPrediction.ProbTwoThree);
                tennisPrediction.ScoreLineProbabilities.Add("1-3", apiPrediction.ProbOneThree);
                tennisPrediction.ScoreLineProbabilities.Add("0-3", apiPrediction.ProbLoveThree);
            }
            else
            {
                tennisPrediction.ScoreLineProbabilities.Add("2-0", apiPrediction.ProbTwoLove);
                tennisPrediction.ScoreLineProbabilities.Add("2-1", apiPrediction.ProbTwoOne);
                tennisPrediction.ScoreLineProbabilities.Add("1-2", apiPrediction.ProbOneTwo);
                tennisPrediction.ScoreLineProbabilities.Add("0-2", apiPrediction.ProbLoveTwo);
            }
            return(tennisPrediction);
        }
    public static Model.GenericPrediction ConvertAPIToGeneric(APITennisPrediction apiPrediction, Uri predictionURL)
    {
      var tennisPrediction = new Model.TennisPrediction()
      {
        TournamentName = apiPrediction.TournamentName,
        PredictionURL = predictionURL,

        PlayerAFirstName = apiPrediction.PlayerAFirstname,
        TeamOrPlayerA = apiPrediction.PlayerASurname,
        PlayerBFirstName = apiPrediction.PlayerBFirstname,
        TeamOrPlayerB = apiPrediction.PlayerBSurname,

        PlayerAGames = apiPrediction.PlayerAGames,
        PlayerBGames = apiPrediction.PlayerBGames,
        MatchDate = apiPrediction.StartTime,
        MatchIdentifier = string.Format("{0} vs. {1} @ {2} on {3}", apiPrediction.PlayerASurname, apiPrediction.PlayerBSurname,
          apiPrediction.TournamentName, apiPrediction.StartTime.ToShortDateString()),
        EPoints = apiPrediction.ExpectedPoints,
        EGames = apiPrediction.ExpectedGames,
        ESets = apiPrediction.ExpectedSets
      };

      tennisPrediction.OutcomeProbabilities.Add(Model.Outcome.HomeWin, apiPrediction.PlayerAProbability);
      tennisPrediction.OutcomeProbabilities.Add(Model.Outcome.AwayWin, apiPrediction.PlayerBProbability);

      if (apiPrediction.FiveSets)
      {
        tennisPrediction.ScoreLineProbabilities.Add("3-0", apiPrediction.ProbThreeLove);
        tennisPrediction.ScoreLineProbabilities.Add("3-1", apiPrediction.ProbThreeOne);
        tennisPrediction.ScoreLineProbabilities.Add("3-2", apiPrediction.ProbThreeTwo);
        tennisPrediction.ScoreLineProbabilities.Add("2-3", apiPrediction.ProbTwoThree);
        tennisPrediction.ScoreLineProbabilities.Add("1-3", apiPrediction.ProbOneThree);
        tennisPrediction.ScoreLineProbabilities.Add("0-3", apiPrediction.ProbLoveThree);
      }
      else
      {
        tennisPrediction.ScoreLineProbabilities.Add("2-0", apiPrediction.ProbTwoLove);
        tennisPrediction.ScoreLineProbabilities.Add("2-1", apiPrediction.ProbTwoOne);
        tennisPrediction.ScoreLineProbabilities.Add("1-2", apiPrediction.ProbOneTwo);
        tennisPrediction.ScoreLineProbabilities.Add("0-2", apiPrediction.ProbLoveTwo);
      }
      return tennisPrediction;
    }