public async Task<TennisFixtureViewModel> GetSingleTennisPrediction(string playerASurname, string playerAFirstname, string playerBSurname, string playerBFirstname, int year, string tournamentSlug, bool updateStats = true)
    {
      var sport = this.fixtureRepository.GetSport("Tennis");
      var tournament = this.fixtureRepository.GetTournamentFromSlug(tournamentSlug);
      var playerA = this.fixtureRepository.GetTeamOrPlayerFromNameAndMaybeFirstName(playerASurname, playerAFirstname);
      var playerB = this.fixtureRepository.GetTeamOrPlayerFromNameAndMaybeFirstName(playerBSurname, playerBFirstname);
      var safeDate = new DateTime(year, 06, 29);
      var valueOptions = new ValueOptions
      {
        CouponDate = safeDate,
        Tournament = tournament,
        DontUpdateTennisStats = !updateStats
      };

      var provider = this.predictionProvider.CreatePredictionStrategy(sport);
      var prediction = 
        (TennisPrediction)await provider.FetchSinglePredictionAsync(playerA, playerB, tournament, valueOptions);

      var tennisPredictionStat = new TennisPredictionStat
      {
        PlayerAGames = prediction.PlayerAGames,
        PlayerBGames = prediction.PlayerBGames,
        EPoints = (decimal?)prediction.EPoints,
        EGames = (decimal?)prediction.EGames,
        ESets = (decimal?)prediction.ESets
      };
      var tennisMatchDetail = new TennisMatchDetail()
      {
        TennisPredictionStat = tennisPredictionStat,
        TennisPrediction = prediction
      };

      return Mapper.Map<TennisMatchDetail, TennisFixtureViewModel>(tennisMatchDetail); //no idea what HydrateFullTennisMatchDetails was for in the first place, I only need predictions and number of games for now
    
    }
Ejemplo n.º 2
0
 public void AddOrUpdateTennisPredictionsStats(TennisPredictionStat stat)
 {
   var persistedStat = First<TennisPredictionStat>(s => s.Id == stat.Id);
   if (persistedStat == null)
   {
     Add<TennisPredictionStat>(stat);
   }
   else
   {
     persistedStat.PlayerAGames = stat.PlayerAGames;
     persistedStat.PlayerBGames = stat.PlayerBGames;
     persistedStat.EPoints = stat.EPoints;
     persistedStat.EGames = stat.EGames;
     persistedStat.ESets = stat.ESets;
   }
 }
Ejemplo n.º 3
0
    private IEnumerable<TennisMatchDetail> PersistTennisPredictions(IEnumerable<TennisPrediction> tennisPredictions, DateTime matchDate)
    {
      var persistedMatchIds = PersistGenericPredictions(tennisPredictions);
      var tennisPredictionsDic = new Dictionary<int, TennisPrediction>();
      var tennisPredictionStatsDic = new Dictionary<int, TennisPredictionStat>();
      var ret = new List<TennisMatchDetail>();
      
      persistedMatchIds.Zip(tennisPredictions, (m, p) => new
                        {
                          MatchID = m,
                          Prediction = p
                        })
                      .ToList()
                      .ForEach(m =>
                        {
                          var predictionStat = new TennisPredictionStat
                          {
                            Id = m.MatchID,
                            PlayerAGames = m.Prediction.PlayerAGames,
                            PlayerBGames = m.Prediction.PlayerBGames,
                            EPoints = (decimal?)m.Prediction.EPoints,
                            EGames = (decimal?)m.Prediction.EGames,
                            ESets = (decimal?)m.Prediction.ESets
                          };
                          this.predictionRepository
                              .AddOrUpdateTennisPredictionsStats(predictionStat);

                          tennisPredictionStatsDic.Add(m.MatchID, predictionStat);
                          tennisPredictionsDic.Add(m.MatchID, m.Prediction);
                        });
      this.predictionRepository.SaveChanges();

      return HydrateFullTennisMatchDetails(matchDate, tennisPredictionsDic, tennisPredictionStatsDic);

    }