private Model.GenericPrediction ConvertAPIToGeneric(APIFootballPrediction apiPrediction, Tournament tournament, DateTime date, Uri predictionURL)
    {
      var tournamentEvent = this.fixtureRepository.GetTournamentEventFromTournamentAndDate(date, tournament.TournamentName);

      var footballPrediction = new Model.FootballPrediction()
      {
        TournamentName = tournament.TournamentName,
        TournamentEventName = tournamentEvent.EventName,
        TeamOrPlayerA = apiPrediction.HomeTeam,
        TeamOrPlayerB = apiPrediction.AwayTeam,
        MatchDate = date,
        MatchIdentifier = string.Format("{0}/vs/{1}/{2}/{3}", apiPrediction.HomeTeam, apiPrediction.AwayTeam,
          tournamentEvent.EventName, date.ToShortDateString().Replace("/", "-"))
      };

      footballPrediction.OutcomeProbabilities.Add(Model.Outcome.HomeWin, apiPrediction.ExpectedProbabilities.HomeWinProb);
      footballPrediction.OutcomeProbabilities.Add(Model.Outcome.Draw, apiPrediction.ExpectedProbabilities.DrawProb);
      footballPrediction.OutcomeProbabilities.Add(Model.Outcome.AwayWin, apiPrediction.ExpectedProbabilities.AwayWinProb);

      foreach (var scoreLine in apiPrediction.ScoreProbabilities)
      {
        var key = string.Format("{0}-{1}", scoreLine.HomeGoals.ToString(), scoreLine.AwayGoals.ToString());
        if (!footballPrediction.ScoreLineProbabilities.ContainsKey(key))
          footballPrediction.ScoreLineProbabilities.Add(key, scoreLine.Probability);
      }
      return footballPrediction;
    }
Example #2
0
        private Model.GenericPrediction ConvertAPIToGeneric(APIFootballPrediction apiPrediction, Tournament tournament, DateTime date, Uri predictionURL)
        {
            var tournamentEvent = this.fixtureRepository.GetTournamentEventFromTournamentAndDate(date, tournament.TournamentName);

            var footballPrediction = new Model.FootballPrediction()
            {
                TournamentName      = tournament.TournamentName,
                TournamentEventName = tournamentEvent.EventName,
                TeamOrPlayerA       = apiPrediction.HomeTeam,
                TeamOrPlayerB       = apiPrediction.AwayTeam,
                MatchDate           = date,
                MatchIdentifier     = string.Format("{0}/vs/{1}/{2}/{3}", apiPrediction.HomeTeam, apiPrediction.AwayTeam,
                                                    tournamentEvent.EventName, date.ToShortDateString().Replace("/", "-")),
                PredictionURL = predictionURL
            };

            footballPrediction.OutcomeProbabilities.Add(Model.Outcome.HomeWin, apiPrediction.ExpectedProbabilities.HomeWinProb);
            footballPrediction.OutcomeProbabilities.Add(Model.Outcome.Draw, apiPrediction.ExpectedProbabilities.DrawProb);
            footballPrediction.OutcomeProbabilities.Add(Model.Outcome.AwayWin, apiPrediction.ExpectedProbabilities.AwayWinProb);

            foreach (var scoreLine in apiPrediction.ScoreProbabilities)
            {
                var key = string.Format("{0}-{1}", scoreLine.HomeGoals.ToString(), scoreLine.AwayGoals.ToString());
                if (!footballPrediction.ScoreLineProbabilities.ContainsKey(key))
                {
                    footballPrediction.ScoreLineProbabilities.Add(key, scoreLine.Probability);
                }
            }
            return(footballPrediction);
        }
        private void ReadPredictionData()
        {
            genericPredictions = new List <Model.GenericPrediction>();

            var files = Directory.GetFiles(@"C:\Users\u0158158\Documents\Visual Studio 2010\Projects\ValueSamurai\ValueSamurai.IKTS\bin\Debug")
                        .Where(f => f.IndexOf("IKTS 2011") > 0)
                        .ToList();
            int i = 1;

            foreach (var file in files)
            {
                var connectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\"{0}\"; Extended Properties=\"Excel 12.0; IMEX=1; HDR=NO\";", file);
                var adapter          = new OleDbDataAdapter("SELECT * FROM [DataDump$]", connectionString);
                using (var ds = new DataSet())
                {
                    adapter.Fill(ds, "DataDump");
                    var rowCollection = ds.Tables["DataDump"].AsEnumerable();
                    Predictions.Add(i, rowCollection);
                }
                i++;
            }

            var teams   = new Dictionary <string, TeamPlayer>();
            var matches = new Dictionary <string, Model.FootballPrediction>();

            foreach (var predictionSet in Predictions.Values)
            {
                foreach (var row in predictionSet)
                {
                    if (row.Field <string>(2) == null)
                    {
                        continue;
                    }
                    TeamPlayer teamA = null;
                    TeamPlayer teamB = null;
                    Model.FootballPrediction prediction = null;

                    var teamAName      = row.Field <string>(2);
                    var teamBName      = row.Field <string>(3);
                    var predictionName = string.Format("{0}|{1}", teamAName, teamBName);

                    if (teams.ContainsKey(teamAName))
                    {
                        teamA = teams[teamAName];
                    }
                    else
                    {
                        teamA = this.fixtureRepository.GetTeamOrPlayerFromName(teamAName);
                        teams.Add(teamAName, teamA);
                    }

                    if (teams.ContainsKey(teamBName))
                    {
                        teamB = teams[teamBName];
                    }
                    else
                    {
                        teamB = this.fixtureRepository.GetTeamOrPlayerFromName(teamBName);
                        teams.Add(teamBName, teamB);
                    }

                    if (matches.ContainsKey(predictionName))
                    {
                        prediction = matches[predictionName];
                    }
                    else
                    {
                        prediction = new Model.FootballPrediction()
                        {
                            TournamentName = "Premier League",
                            TeamOrPlayerA  = teamAName,
                            TeamOrPlayerB  = teamBName,
                            MatchDate      = this.FixturesCouponsOdds.First(x => x.Field <string>("HomeTeam") == teamAName && x.Field <string>("AwayTeam") == teamBName).Field <DateTime>("Date"),
                        };
                        prediction.OutcomeProbabilities.Add(Model.Outcome.HomeWin, 0);
                        prediction.OutcomeProbabilities.Add(Model.Outcome.Draw, 0);
                        prediction.OutcomeProbabilities.Add(Model.Outcome.AwayWin, 0);
                        matches.Add(predictionName, prediction);
                    }

                    int scoreA = (int)row.Field <double>(4);
                    int scoreB = (int)row.Field <double>(5);
                    if (!prediction.ScoreLineProbabilities.ContainsKey(string.Format("{0}-{1}", scoreA.ToString(), scoreB.ToString())))
                    {
                        prediction.ScoreLineProbabilities.Add(string.Format("{0}-{1}", scoreA.ToString(), scoreB.ToString()), row.Field <double>(6));
                        if (scoreA == scoreB)
                        {
                            prediction.OutcomeProbabilities[Model.Outcome.Draw] += row.Field <double>(6);
                        }
                        else if (scoreA > scoreB)
                        {
                            prediction.OutcomeProbabilities[Model.Outcome.HomeWin] += row.Field <double>(6);
                        }
                        else if (scoreA < scoreB)
                        {
                            prediction.OutcomeProbabilities[Model.Outcome.AwayWin] += row.Field <double>(6);
                        }
                    }
                }
            }
            genericPredictions.AddRange(matches.Values);
        }
    private void ReadPredictionData()
    {
      genericPredictions = new List<Model.GenericPrediction>();

      var files = Directory.GetFiles(@"C:\Users\u0158158\Documents\Visual Studio 2010\Projects\ValueSamurai\ValueSamurai.IKTS\bin\Debug")
                           .Where(f => f.IndexOf("IKTS 2011") > 0)
                           .ToList();
      int i = 1;
      foreach (var file in files)
      {
        var connectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\"{0}\"; Extended Properties=\"Excel 12.0; IMEX=1; HDR=NO\";", file);
        var adapter = new OleDbDataAdapter("SELECT * FROM [DataDump$]", connectionString);
        using (var ds = new DataSet())
        {
          adapter.Fill(ds, "DataDump");
          var rowCollection = ds.Tables["DataDump"].AsEnumerable();
          Predictions.Add(i, rowCollection);
        }
        i++;
      }

      var teams = new Dictionary<string, TeamPlayer>();
      var matches = new Dictionary<string, Model.FootballPrediction>();

      foreach (var predictionSet in Predictions.Values)
      {
        foreach (var row in predictionSet)
        {
          if (row.Field<string>(2) == null) continue;
          TeamPlayer teamA = null;
          TeamPlayer teamB = null;
          Model.FootballPrediction prediction = null;

          var teamAName = row.Field<string>(2);
          var teamBName = row.Field<string>(3);
          var predictionName = string.Format("{0}|{1}", teamAName, teamBName);

          if (teams.ContainsKey(teamAName))
            teamA = teams[teamAName];
          else
          {
            teamA = this.fixtureRepository.GetTeamOrPlayerFromName(teamAName);
            teams.Add(teamAName, teamA);
          }

          if (teams.ContainsKey(teamBName))
            teamB = teams[teamBName];
          else
          {
            teamB = this.fixtureRepository.GetTeamOrPlayerFromName(teamBName);
            teams.Add(teamBName, teamB);
          }

          if (matches.ContainsKey(predictionName))
            prediction = matches[predictionName];
          else
          {
            prediction = new Model.FootballPrediction()
            {
              TournamentName = "Premier League",
              TeamOrPlayerA = teamAName,
              TeamOrPlayerB = teamBName,
              MatchDate = this.FixturesCouponsOdds.First(x => x.Field<string>("HomeTeam") == teamAName && x.Field<string>("AwayTeam") == teamBName).Field<DateTime>("Date"),

            };
            prediction.OutcomeProbabilities.Add(Model.Outcome.HomeWin, 0);
            prediction.OutcomeProbabilities.Add(Model.Outcome.Draw, 0);
            prediction.OutcomeProbabilities.Add(Model.Outcome.AwayWin, 0);
            matches.Add(predictionName, prediction);
          }

          int scoreA = (int)row.Field<double>(4);
          int scoreB = (int)row.Field<double>(5);
          if (!prediction.ScoreLineProbabilities.ContainsKey(string.Format("{0}-{1}", scoreA.ToString(), scoreB.ToString())))
          {
            prediction.ScoreLineProbabilities.Add(string.Format("{0}-{1}", scoreA.ToString(), scoreB.ToString()), row.Field<double>(6));
            if (scoreA == scoreB)
              prediction.OutcomeProbabilities[Model.Outcome.Draw] += row.Field<double>(6);
            else if (scoreA > scoreB)
              prediction.OutcomeProbabilities[Model.Outcome.HomeWin] += row.Field<double>(6);
            else if (scoreA < scoreB)
              prediction.OutcomeProbabilities[Model.Outcome.AwayWin] += row.Field<double>(6);
          }
        }
      }
      genericPredictions.AddRange(matches.Values);
    }