public static List <MainCalculator.PositionGoals> GetTeamScorersByPosition(sakilaEntities4 db, int teamId, int competitionId,
                                                                                   int gamesToTake = 50)
        {
            var returnVal     = new List <MainCalculator.PositionGoals>();
            var latestMatches = MainCalculator.GetTeamLatesMatches(db, teamId, competitionId, gamesToTake);
            var matchesIds    = latestMatches.Select(x => x.CompetitionMatchID);

            var teamGoalsConceded = db.matchgoal
                                    .Where(x => matchesIds.Contains(x.MatchID) && x.TeamID == teamId)
                                    .ToList();

            var groupByPosition = teamGoalsConceded
                                  .GroupBy(x => x.player.PositionID)
                                  .OrderByDescending(x => x.Count())
                                  .ToList();


            foreach (var g in groupByPosition)
            {
                var position = db.playerposition.First(x => x.PlayerPositionID == g.Key).PlayerPositionName;
                var cnt      = g.Count();
                var newItem  = new MainCalculator.PositionGoals
                {
                    Goals    = cnt,
                    Position = position
                };
                returnVal.Add(newItem);
            }

            return(returnVal);
        }
        public static void GetAllStdDevForEvent(int eventTyepId, string eventName, int competitionId)
        {
            var l = new List <MainCalculator.TeamStdDevAndAverage>();

            using (var db = new sakilaEntities4())
            {
                var teams = db.team.Where(x => x.TeamTypeID == 1 && x.TeamName != "NA").ToList();
                foreach (var team in teams)
                {
                    var allValues =
                        db.matchevent.Where(
                            x =>
                            x.EventTypeID == eventTyepId &&
                            x.TeamID == team.TeamID &&
                            x.competitionmatch.CompetitionID == competitionId &&
                            x.eventvalue != null)
                        .Select(x => x.eventvalue).ToList();
                    if (!allValues.Any())
                    {
                        continue;
                    }

                    var avg    = (double)allValues.Average();
                    var result = MainCalculator.CalculateStdDev(allValues.Select(x => x.Value).ToList());
                    l.Add(new MainCalculator.TeamStdDevAndAverage {
                        StdDev = result, TeamName = team.TeamName, Average = avg
                    });
                }
            }

            var path = @"C:\Users\user\Desktop\DataProjects\AverageAndStdDev" + eventName + ".tsv";

            File.WriteAllLines(path, l.OrderByDescending(x => x.Average).Select(x => x.TeamName + "\t" + Math.Round(x.Average, 2) + "\t" + Math.Round(x.StdDev, 2)));
        }
 public static decimal GetAverageGoalForCompetition(int competitionId)
 {
     using (var db = new sakilaEntities4())
     {
         var matches      = MainCalculator.GetAllMatchesForCompetition(competitionId, db);
         var sumHomeGoals = matches.Sum(x => x.HomeGoals);
         var sumAwayGoals = matches.Sum(x => x.AwayGoals);
         return((decimal)(sumAwayGoals + sumHomeGoals) / matches.Count);
     }
 }
        public static List <string> GetTeamLetterSequence(sakilaEntities4 db, int teamId, int competitionId,
                                                          int gamesToTake = 50)
        {
            var latestMatchesLetters = MainCalculator.GetTeamLatesMatches(db, teamId, competitionId, gamesToTake)
                                       .OrderBy(x => x.MatchDate)
                                       .Select(x => GetCompetitionMatchResultLetter(x, teamId))
                                       .ToList();

            return(latestMatchesLetters);
        }
        public static MainCalculator.TeamStdDevAndAverage GetGoalsStdDevForTeam(team team)
        {
            var allValues = GetTeamGoals(team.TeamID);
            var avg       = (double)allValues.Average();
            var result    = MainCalculator.CalculateStdDev(allValues.ToList());

            return(new MainCalculator.TeamStdDevAndAverage {
                StdDev = result, TeamName = team.TeamName, Average = avg
            });
        }
        public void CalculateExpectedWinnerByStrength()
        {
            var homeTeamStengthDiff = MainCalculator.StrengthDiffCaculator(HomeTeamStats.TeamStrength, AwayTeamStats.TeamStrength);
            var awayTeamStengthDiff = MainCalculator.StrengthDiffCaculator(AwayTeamStats.TeamStrength, HomeTeamStats.TeamStrength);

            var homeCalculatedGoals = Math.Round(HomeExpectedGoals.Average + homeTeamStengthDiff, 2);
            var awayCalculatedGoals = Math.Round(AwayExpectedGoals.Average + awayTeamStengthDiff, 2);

            StrengthExpectedWinner = MainCalculator.GetExpectedWinner(homeCalculatedGoals, awayCalculatedGoals);
        }
示例#7
0
        public static decimal GetTeamFormInLatestMatches(sakilaEntities4 db, int teamId, int competitionId, int matchesToTake = 50, DateTime?endDate = null)
        {
            if (!endDate.HasValue)
            {
                endDate = DateTime.Now;
            }

            var latestMatches    = MainCalculator.GetTeamLatesMatches(db, teamId, competitionId, matchesToTake, endDate);
            var pointsAggregated = CalculatePointsForTeamInMatches(latestMatches, teamId);

            return(Math.Round((decimal)pointsAggregated / latestMatches.Count, 2));
        }
        public static MainCalculator.TeamStdDevAndAverage GetGoalsConcededAverageAtAway(List <competitionmatch> relevantMatches, int teamId,
                                                                                        int competitionId, int matchesToTake = 50)
        {
            //var relevantMatches = MainCalculator.GetTeamLatesMatches(db, teamId, competitionId, matchesToTake);
            var awayGoalsValues = relevantMatches.Where(x => x.AwayTeamID == teamId).Select(x => x.HomeGoals).ToList();
            var avg             = Math.Round(awayGoalsValues.Average(), 2);
            var result          = Math.Round(MainCalculator.CalculateStdDev(awayGoalsValues.ToList()), 2);

            return(new MainCalculator.TeamStdDevAndAverage {
                StdDev = result, Average = avg
            });
        }
        public static void PrintReportForNextDays(int daysToGet)
        {
            var matches              = PremierLeagueMainProject.GetNextMatches(daysToGet);
            var combinedLetterDict   = LettersSequenceCalculator.GetCombinedLettersDictionary();
            var attributeDict        = SecondaryStatsCalculator.BuildAttributesDictionary(3);
            var attributeClashingMap = MainCalculator.BuildAttributeMatchMap();

            foreach (var match in matches)
            {
                Console.WriteLine(match.HomeTeam + " Vs. " + match.AwayTeam);
                CreateMatchReport(combinedLetterDict, attributeDict, attributeClashingMap, match.HomeTeam, match.AwayTeam, 3);
            }
        }
        public static MainCalculator.TeamStdDevAndAverage GetGoalsScoringAverageAtAway(List <competitionmatch> allMatches, int teamId,
                                                                                       int competitionId, int matchesToTake = 50)
        {
            var relevantMatches = allMatches.Where(x => x.AwayTeamID == teamId).ToList();
            var homeGoalsValues = relevantMatches.Where(x => x.HomeTeamID == teamId).Select(x => x.HomeGoals).ToList();
            var awayGoalsValues = relevantMatches.Where(x => x.AwayTeamID == teamId).Select(x => x.AwayGoals).ToList();
            var allValues       = homeGoalsValues.Concat(awayGoalsValues).ToList();
            var avg             = Math.Round(allValues.Average(), 2);
            var result          = Math.Round(MainCalculator.CalculateStdDev(allValues.ToList()), 2);

            return(new MainCalculator.TeamStdDevAndAverage {
                StdDev = result, Average = avg
            });
        }
        public static void PrintReportForNextDaysNewVersion(int daysToGet, int competitionId, bool withAttr = false)
        {
            Console.WriteLine($"Started: {DateTime.Now.Hour}:{DateTime.Now.Minute}");
            var matches = PremierLeagueMainProject.GetNextMatches(daysToGet);

            Console.WriteLine($"Got {matches.Count} new matches");
            var combinedLetterDict   = LettersSequenceCalculator.GetCombinedLettersDictionary();
            var attributeClashingMap = new List <MainCalculator.AttributesMatch>();
            var attributeDict        = new Dictionary <int, List <DataObjects.AttributeType> >();

            if (withAttr)
            {
                Console.WriteLine("Starting building attributes dictionary");
                attributeDict = SecondaryStatsCalculator.BuildAttributesDictionary(competitionId);
                Console.WriteLine("Finished building attributes dictionary");
                attributeClashingMap = MainCalculator.BuildAttributeMatchMap();
                Console.WriteLine($"Ended build: {DateTime.Now.Hour}:{DateTime.Now.Minute}");
            }

            var recs     = new List <MainCalculator.Recommendation>();
            var recsPath = @"C:\Users\user\Desktop\DataProjects\2018\RecommendationsFile.tsv";

            foreach (var match in matches)
            {
                var path = @"C:\Users\user\Desktop\DataProjects\2018\" + match.HomeTeam + "VS" + match.AwayTeam + ".tsv";
                Console.WriteLine(match.HomeTeam + " Vs. " + match.AwayTeam);
                var reportObj = new ReportObject();
                reportObj.Init(combinedLetterDict, attributeDict, attributeClashingMap, competitionId);
                reportObj.Build(match.HomeTeam, match.AwayTeam);

                reportObj.CalculateExpectedWinnerByStrength();
                reportObj.CalculateExpectedWinnerByLetters();
                //reportObj.CalculateAttributesExpectedWinner();

                reportObj.FindRecommendations();
                recs.AddRange(reportObj.MatchRecommendations);

                var linesToWrite = reportObj.GetLinesToWrite();
                File.WriteAllLines(path, linesToWrite);
            }

            var recsToWrite = recs.Where(x => x.Result != null)
                              .Where(x => x.Confidence >= 60m)
                              .OrderByDescending(x => x.Confidence)
                              .Select(x => $"{x.HomeTeam} VS. {x.AwayTeam} ({x.Type}): {x.Result} ({x.Confidence}%) (Ratio: {Math.Round(100/x.Confidence, 2)})");

            File.WriteAllLines(recsPath, recsToWrite);
        }
示例#12
0
        public static TeamBalance GetTeamBalanceHome(sakilaEntities4 db, int teamId, int competitionId, int gamesToTake = 50, DateTime?endDate = null)
        {
            var latestMatches = MainCalculator.GetTeamLatesMatches(db, teamId, competitionId, gamesToTake, endDate)
                                .Where(x => x.HomeTeamID == teamId)
                                .ToList();
            var wins  = latestMatches.Count(x => x.WinnerTeamID == teamId);
            var losts = latestMatches.Count(x => x.WinnerTeamID != null && x.WinnerTeamID != teamId);
            var draws = latestMatches.Count(x => x.WinnerTeamID == null);

            return(new TeamBalance
            {
                Win = wins,
                Draw = draws,
                Lost = losts
            });
        }
        public static decimal GetTeamFormInLatestMatchesHomeAway(sakilaEntities4 db, int teamId, int competitionId, string homeOrAway, int matchesToTake = 50)
        {
            var latestMatches = MainCalculator.GetTeamLatesMatches(db, teamId, competitionId, matchesToTake);

            if (homeOrAway == "Home")
            {
                latestMatches = latestMatches.Where(x => x.HomeTeamID == teamId).ToList();
            }
            if (homeOrAway == "Away")
            {
                latestMatches = latestMatches.Where(x => x.AwayTeamID == teamId).ToList();
            }
            var pointsAggregated = PointsCalculator.CalculatePointsForTeamInMatches(latestMatches, teamId);

            return(Math.Round((decimal)pointsAggregated / latestMatches.Count, 2));
        }
        public static double GetStdValueForTeamInEvent(sakilaEntities4 db, int teamId, int competitionId, int eventTypeId,
                                                       int gamesToTake = 50)
        {
            var values =
                db.matchevent.Where(
                    x =>
                    x.EventTypeID == eventTypeId &&
                    x.TeamID == teamId &&
                    x.competitionmatch.CompetitionID == competitionId &&
                    x.eventvalue != null)
                .OrderByDescending(x => x.competitionmatch.MatchDate)
                .Take(gamesToTake)
                .Select(x => (int)x.eventvalue)
                .ToList();

            return(MainCalculator.CalculateStdDev(values));
        }
        public static MainCalculator.TeamStdDevAndAverage GetGoalsConcededAverage(List <competitionmatch> relevantMatches, int teamId,
                                                                                  int competitionId, int matchesToTake = 50, DateTime?endDate = null)
        {
            if (!endDate.HasValue)
            {
                endDate = DateTime.Now;
            }
            relevantMatches = relevantMatches.Take(matchesToTake).ToList();
            var homeGoalsValues = relevantMatches.Where(x => x.HomeTeamID == teamId).Select(x => x.AwayGoals).ToList();
            var awayGoalsValues = relevantMatches.Where(x => x.AwayTeamID == teamId).Select(x => x.HomeGoals).ToList();
            var allValues       = homeGoalsValues.Concat(awayGoalsValues).ToList();
            var avg             = Math.Round(allValues.Average(), 2);
            var result          = Math.Round(MainCalculator.CalculateStdDev(allValues.ToList()), 2);

            return(new MainCalculator.TeamStdDevAndAverage {
                StdDev = result, Average = avg
            });
        }
        public TeamReportStats(Dictionary <string, List <Helper.LetterDistribution> > lettersDict,
                               Dictionary <int, List <DataObjects.AttributeType> > attributesDict,
                               int competitionId, string teamName, sakilaEntities4 db, bool isHomeTeam)
        {
            Team = db.team.First(x => x.TeamName == teamName);
            var relevantMatches = MainCalculator.GetTeamLatesMatches(db, Team.TeamID, competitionId);

            TeamForm             = LettersSequenceCalculator.GetTeamLatestSequence(db, Team.TeamID, competitionId);
            TeamOverallBalance   = new TeamOverallBalance(Team, competitionId, isHomeTeam, relevantMatches);
            TeamGoalsStats       = new TeamGoalsStats(Team, competitionId, isHomeTeam, db, relevantMatches);
            TeamAttributes       = Helper.GetTeamAttributeFromDict(Team.TeamID, attributesDict);
            TeamAttributesString = Helper.GetTeamAttributesList((int)Team.TeamID, attributesDict);
            string homeTeamSeq;

            LettersDistribution = LettersSequenceCalculator.BuildSequenceStringExpectation(db, Team.TeamID,
                                                                                           competitionId, lettersDict, out homeTeamSeq);
            TeamLastThreeResults = homeTeamSeq;
        }
        public static MainCalculator.TeamStdDevAndAverage GetGoalsScoringAverage(sakilaEntities4 db, int teamId,
                                                                                 int competitionId, int matchesToTake = 50, DateTime?endDate = null)
        {
            if (!endDate.HasValue)
            {
                endDate = DateTime.Now;
            }

            var relevantMatches = MainCalculator.GetTeamLatesMatches(db, teamId, competitionId, matchesToTake, endDate);
            var homeGoalsValues = relevantMatches.Where(x => x.HomeTeamID == teamId).Select(x => x.HomeGoals).ToList();
            var awayGoalsValues = relevantMatches.Where(x => x.AwayTeamID == teamId).Select(x => x.AwayGoals).ToList();
            var allValues       = homeGoalsValues.Concat(awayGoalsValues).ToList();
            var avg             = Math.Round(allValues.Average(), 2);
            var result          = Math.Round(MainCalculator.CalculateStdDev(allValues.ToList()), 2);

            return(new MainCalculator.TeamStdDevAndAverage {
                StdDev = result, Average = avg
            });
        }
        public static double GetStdEventValuePerTeamMatches(sakilaEntities4 db, int teamId, int competitionId, int eventTypeId, int gamesToTake = 50)
        {
            var matchesIds = MainCalculator.GetTeamLatesMatches(db, teamId, competitionId, gamesToTake)
                             .Select(x => x.CompetitionMatchID)
                             .ToList();

            var values =
                db.matchevent.Where(
                    x =>
                    x.EventTypeID == eventTypeId &&
                    matchesIds.Contains(x.MatchID) &&
                    x.competitionmatch.CompetitionID == competitionId &&
                    x.eventvalue != null)
                .OrderByDescending(x => x.competitionmatch.MatchDate)
                .Take(gamesToTake)
                .Select(x => (int)x.eventvalue)
                .ToList();

            return(Math.Round(MainCalculator.CalculateStdDev(values), 2));
        }
        public static string GetTeamLatestSequence(sakilaEntities4 db, int teamId, int competitionId, int gamesToTake = 50)
        {
            var latestMatches = MainCalculator.GetTeamLatesMatches(db, teamId, competitionId, gamesToTake)
                                .OrderBy(x => x.MatchDate)
                                .Reverse()
                                .Select(x => GetCompetitionMatchResultLetter(x, teamId))
                                .ToList();
            var firstLetter = latestMatches.First();
            var sequence    = firstLetter;
            var curLetter   = latestMatches[1];
            var i           = 1;

            while (curLetter == firstLetter && i < latestMatches.Count - 1)
            {
                sequence += " " + curLetter;
                i++;
                curLetter = latestMatches[i];
            }

            return(sequence);
        }
        public static string GetTeamTopScorersAgainsePosition(sakilaEntities4 db, int teamId, int competitionId,
                                                              int gamesToTake = 50)
        {
            var latestMatches = MainCalculator.GetTeamLatesMatches(db, teamId, competitionId, gamesToTake);
            var matchesIds    = latestMatches.Select(x => x.CompetitionMatchID);

            var teamGoalsConceded = db.matchgoal
                                    .Where(x => matchesIds.Contains(x.MatchID) && x.TeamID != teamId)
                                    .ToList();

            var groupByPosition = teamGoalsConceded
                                  .GroupBy(x => x.player.PositionID)
                                  .OrderByDescending(x => x.Count())
                                  .Select(x => x.First().player.PositionID)
                                  .First();

            var positionName = db.playerposition.First(x => x.PlayerPositionID == groupByPosition).PlayerPositionName;
            var percent      = (decimal)teamGoalsConceded.Where(x => x.player.PositionID == groupByPosition).Count() /
                               teamGoalsConceded.Count;

            return(positionName + " (" + Math.Round(percent * 100, 2) + ")");
        }
        public static double?GetAverageEventValuePerTeamMatches(sakilaEntities4 db, int teamId, int competitionId, int eventTypeId, int gamesToTake = 50)
        {
            var matchesIds = MainCalculator.GetTeamLatesMatches(db, teamId, competitionId, gamesToTake)
                             .Select(x => x.CompetitionMatchID)
                             .ToList();



            var average =
                db.matchevent.Where(
                    x =>
                    x.EventTypeID == eventTypeId &&
                    matchesIds.Contains(x.MatchID) &&
                    x.competitionmatch.CompetitionID == competitionId &&
                    x.eventvalue != null)
                .OrderByDescending(x => x.competitionmatch.MatchDate)
                .Take(gamesToTake)
                .Select(x => x.eventvalue)
                .Average() * 2;

            return(average);
        }
        public static TopScorer GetTeamTopScorer(sakilaEntities4 db, int teamId, int competitionId, int gamesToTake = 50)
        {
            var latestMatches = MainCalculator.GetTeamLatesMatches(db, teamId, competitionId, gamesToTake);
            var matchesIds    = latestMatches.Select(x => x.CompetitionMatchID);

            var teamGoals = db.matchgoal
                            .Where(x => matchesIds.Contains(x.MatchID) && x.TeamID == teamId)
                            .ToList();

            if (!teamGoals.Any())
            {
                return(new TopScorer
                {
                    Name = "NA",
                    Goals = 0,
                    Position = "NA"
                });
            }

            var mostGoals = teamGoals
                            .GroupBy(x => x.ScorerID)
                            .OrderByDescending(x => x.Count());

            var topScorerID = mostGoals
                              .Select(x => x.First().ScorerID)
                              .First();

            var player = db.player.First(x => x.PlayerID == topScorerID);

            var positionName = db.playerposition.First(x => x.PlayerPositionID == player.PositionID).PlayerPositionName;

            return(new TopScorer
            {
                Name = player.PlayerName,
                Goals = mostGoals.First().Count(),
                Position = positionName
            });
        }
示例#23
0
            public bool AggregateStats(sakilaEntities4 db, bool isTest = false)
            {
                var homeTeam = db.team.First(x => x.TeamID == HomeTeamID);
                var awayTeam = db.team.First(x => x.TeamID == AwayTeamID);

                HomeTeamValue = homeTeam.MarketValue.Value;
                AwayTeamValue = awayTeam.MarketValue.Value;
                HomeTeam      = homeTeam.TeamName;
                AwayTeam      = awayTeam.TeamName;

                HomeTeamMatches = MainCalculator.GetTeamLatesMatches(db, HomeTeamID, CompetitionID, 50, Date);
                AwayTeamMatches = MainCalculator.GetTeamLatesMatches(db, AwayTeamID, CompetitionID, 50, Date);

                if (HomeTeamMatches.Count < 4 || HomeTeamMatches.Count > 34 || AwayTeamMatches.Count < 4 || AwayTeamMatches.Count > 34)
                {
                    return(false);
                }

                HomeTotalShotsAvg = SecondaryStatsCalculator.GetAverageEventValue(db, HomeTeamID, CompetitionID, (int)DataObjects.EventType.TotalShots).Value;
                AwayTotalShotsAvg = SecondaryStatsCalculator.GetAverageEventValue(db, AwayTeamID, CompetitionID, (int)DataObjects.EventType.TotalShots).Value;

                HomeShotsOnTargetAvg = SecondaryStatsCalculator.GetAverageEventValue(db, HomeTeamID, CompetitionID, (int)DataObjects.EventType.ShotsOnTarget).Value;
                AwayShotsOnTargetAvg = SecondaryStatsCalculator.GetAverageEventValue(db, AwayTeamID, CompetitionID, (int)DataObjects.EventType.ShotsOnTarget).Value;

                HomeTotalShotsAgainstAvg = SecondaryStatsCalculator.GetAverageEventValueAgainstTeam(db, HomeTeamID, CompetitionID, (int)DataObjects.EventType.TotalShots).Value;
                AwayTotalShotsAgainstAvg = SecondaryStatsCalculator.GetAverageEventValueAgainstTeam(db, AwayTeamID, CompetitionID, (int)DataObjects.EventType.TotalShots).Value;

                HomeShotsOnTargetAgainstAvg = SecondaryStatsCalculator.GetAverageEventValueAgainstTeam(db, HomeTeamID, CompetitionID, (int)DataObjects.EventType.ShotsOnTarget).Value;
                AwayShotsOnTargetAgainstAvg = SecondaryStatsCalculator.GetAverageEventValueAgainstTeam(db, AwayTeamID, CompetitionID, (int)DataObjects.EventType.ShotsOnTarget).Value;

                HomeTotalShotsExpectedVsTeam = (HomeTotalShotsAvg + AwayTotalShotsAgainstAvg) / 2;
                AwayTotalShotsExpectedVsTeam = (AwayTotalShotsAvg + HomeTotalShotsAgainstAvg) / 2;

                HomeShotsOnTargetExpectedVsTeam = (HomeShotsOnTargetAvg + AwayShotsOnTargetAgainstAvg) / 2;
                AwayShotsOnTargetExpectedVsTeam = (AwayShotsOnTargetAvg + HomeShotsOnTargetAgainstAvg) / 2;

                HomePossessionAvg = SecondaryStatsCalculator.GetAverageEventValue(db, HomeTeamID, CompetitionID, (int)DataObjects.EventType.Possession).Value;
                AwayPossessionAvg = SecondaryStatsCalculator.GetAverageEventValue(db, AwayTeamID, CompetitionID, (int)DataObjects.EventType.Possession).Value;

                HomeFoulsAvg = SecondaryStatsCalculator.GetAverageEventValue(db, HomeTeamID, CompetitionID, (int)DataObjects.EventType.Fouls).Value;
                AwayFoulsAvg = SecondaryStatsCalculator.GetAverageEventValue(db, AwayTeamID, CompetitionID, (int)DataObjects.EventType.Fouls).Value;

                HomePointsSeasonal = PointsCalculator.CalculatePointPace(PointsCalculator.GetTeamBalance(HomeTeamMatches, HomeTeamID, CompetitionID));
                AwayPointsSeasonal = PointsCalculator.CalculatePointPace(PointsCalculator.GetTeamBalance(AwayTeamMatches, AwayTeamID, CompetitionID));

                HomePointsLast3 = PointsCalculator.CalculatePointPace(PointsCalculator.GetTeamBalance(HomeTeamMatches, HomeTeamID, CompetitionID, 3));
                AwayPointsLast3 = PointsCalculator.CalculatePointPace(PointsCalculator.GetTeamBalance(AwayTeamMatches, AwayTeamID, CompetitionID, 3));

                HomePointsAtHome = PointsCalculator.CalculatePointPace(PointsCalculator.GetTeamBalanceHome(HomeTeamMatches, HomeTeamID, CompetitionID));
                AwayPointsAtAway = PointsCalculator.CalculatePointPace(PointsCalculator.GetTeamBalanceAway(AwayTeamMatches, AwayTeamID, CompetitionID));

                HomeGoalsAvgSeasonal = GoalsCalculator.GetGoalsScoringAverage(HomeTeamMatches, HomeTeamID, CompetitionID).Average;
                AwayGoalsAvgSeasonal = GoalsCalculator.GetGoalsScoringAverage(AwayTeamMatches, AwayTeamID, CompetitionID).Average;

                HomeGoalsAvgLast3 = GoalsCalculator.GetGoalsScoringAverage(HomeTeamMatches, HomeTeamID, CompetitionID, 3).Average;
                AwayGoalsAvgLast3 = GoalsCalculator.GetGoalsScoringAverage(AwayTeamMatches, AwayTeamID, CompetitionID, 3).Average;

                HomeGoalsAvgAtHome = GoalsCalculator.GetGoalsScoringAverageAtHome(HomeTeamMatches, HomeTeamID, CompetitionID).Average;
                AwayGoalsAvgAtAway = GoalsCalculator.GetGoalsScoringAverageAtAway(AwayTeamMatches, AwayTeamID, CompetitionID).Average;

                HomeGoalsExpected = (HomeGoalsAvgSeasonal + HomeGoalsAvgLast3 + HomeGoalsAvgAtHome) / 3;
                AwayGoalsExpected = (AwayGoalsAvgSeasonal + AwayGoalsAvgLast3 + AwayGoalsAvgAtAway) / 3;

                HomeGoalsConcededAvgSeasonal = GoalsCalculator.GetGoalsConcededAverage(HomeTeamMatches, HomeTeamID, CompetitionID).Average;
                AwayGoalsConcededAvgSeasonal = GoalsCalculator.GetGoalsConcededAverage(AwayTeamMatches, AwayTeamID, CompetitionID).Average;

                HomeGoalsConcededAvgLast3 = GoalsCalculator.GetGoalsConcededAverage(HomeTeamMatches, HomeTeamID, CompetitionID, 3).Average;
                AwayGoalsConcededAvgLast3 = GoalsCalculator.GetGoalsConcededAverage(AwayTeamMatches, AwayTeamID, CompetitionID, 3).Average;

                HomeGoalsConcededAvgAtHome = GoalsCalculator.GetGoalsConcededAverageAtHome(HomeTeamMatches, HomeTeamID, CompetitionID).Average;
                AwayGoalsConcededAvgAtAway = GoalsCalculator.GetGoalsConcededAverageAtAway(AwayTeamMatches, AwayTeamID, CompetitionID).Average;

                HomeGoalsExpectedConcede = (HomeGoalsConcededAvgSeasonal + HomeGoalsConcededAvgLast3 + HomeGoalsConcededAvgAtHome) / 3;
                AwayGoalsExpectedConcede = (AwayGoalsConcededAvgSeasonal + AwayGoalsConcededAvgLast3 + AwayGoalsConcededAvgAtAway) / 3;

                HomeGoalsExpectedVsTeam = (HomeGoalsExpected + AwayGoalsExpectedConcede) / 2;
                AwayGoalsExpectedVsTeam = (AwayGoalsExpected + HomeGoalsExpectedConcede) / 2;

                HomeTrend = LettersSequenceCalculator.GetTeamLetterScore(HomeTeamMatches, HomeTeamID, CompetitionID);
                AwayTrend = LettersSequenceCalculator.GetTeamLetterScore(AwayTeamMatches, AwayTeamID, CompetitionID);

                HomePointsWeightedSeasonal = PointsCalculator.GetWeightedBalance(db, HomeTeamMatches, HomeTeamID, CompetitionID);
                AwayPointsWeightedSeasonal = (PointsCalculator.GetWeightedBalance(db, AwayTeamMatches, AwayTeamID, CompetitionID));

                ChanceCreationHome = HomePossessionAvg / HomeTotalShotsAvg;
                ChanceCreationAway = AwayPossessionAvg / AwayTotalShotsAvg;

                ShotsAccuracyHome = HomeTotalShotsAvg == 0 || HomeShotsOnTargetAvg == 0 ? 0 : HomeTotalShotsAvg / HomeShotsOnTargetAvg;
                ShotsAccuracyAway = AwayTotalShotsAvg == 0 || AwayShotsOnTargetAvg == 0 ? 0 : AwayTotalShotsAvg / AwayShotsOnTargetAvg;

                ScoringRateHome = HomeShotsOnTargetAvg == 0 || HomeGoalsAvgSeasonal == 0 ? 0 : HomeShotsOnTargetAvg / HomeGoalsAvgSeasonal;
                ScoringRateAway = AwayShotsOnTargetAvg == 0 || AwayGoalsAvgSeasonal == 0 ? 0 : AwayShotsOnTargetAvg / AwayGoalsAvgSeasonal;

                KeeperStrengthHome = HomeShotsOnTargetAgainstAvg == 0 || HomeGoalsConcededAvgSeasonal == 0 ? 0 : HomeShotsOnTargetAgainstAvg / HomeGoalsConcededAvgSeasonal;
                KeeperStrengthAway = AwayShotsOnTargetAgainstAvg == 0 || AwayGoalsConcededAvgSeasonal == 0 ? 0 : AwayShotsOnTargetAgainstAvg / AwayGoalsConcededAvgSeasonal;

                if (!isTest)
                {
                    var relevantMatchOdds = db.matchodds.FirstOrDefault(x => x.MatchID == CompetitionMatchId);
                    if (relevantMatchOdds != null)
                    {
                        HomeOddsRatio  = relevantMatchOdds.HomeTeamOdds;
                        DrawOddsRatio  = relevantMatchOdds.DrawOdds;
                        AwayOddsRatio  = relevantMatchOdds.AwayTeamOdds;
                        IsHomeFavorite = 0;
                        if (HomeOddsRatio < AwayOddsRatio)
                        {
                            IsHomeFavorite = 1;
                        }
                    }

                    else
                    {
                        Console.WriteLine("Failed to fing odds for match: " + HomeTeamID + " VS. " + AwayTeamID);
                        HomeOddsRatio  = 0.00M;
                        DrawOddsRatio  = 0.00M;
                        AwayOddsRatio  = 0.00M;
                        IsHomeFavorite = 0;
                    }
                }

                else
                {
                    HomeOddsRatio  = 0.00M;
                    DrawOddsRatio  = 0.00M;
                    AwayOddsRatio  = 0.00M;
                    IsHomeFavorite = 0;
                }


                var homeTeamSeq      = LettersSequenceCalculator.GetTeamLetterSequence(db, HomeTeamID, CompetitionID, 3);
                var homeSeqString    = string.Join("", homeTeamSeq);
                var homeTeamExpected = LettersDict.First(x => x.Key.Equals(homeSeqString)).Value;

                HomeExpectedWin = Math.Round(homeTeamExpected.First(x => x.Letter == "W").Percent, 2);

                var awayTeamSeq      = LettersSequenceCalculator.GetTeamLetterSequence(db, AwayTeamID, CompetitionID, 3);
                var awaySeqString    = string.Join("", awayTeamSeq);
                var awayTeamExpected = LettersDict.First(x => x.Key.Equals(awaySeqString)).Value;

                AwayExpectedWin = Math.Round(awayTeamExpected.First(x => x.Letter == "W").Percent, 2);

                Round = (decimal)(HomeTeamMatches.Count + AwayTeamMatches.Count) / 2;

                if (AwayPossessionAvg == 0.0 || HomePossessionAvg == 0.0)
                {
                    return(false);
                }

                return(true);
            }
 public void CalculateExpectedWinnerByLetters()
 {
     LettersExpectedWinner = MainCalculator.GetLettersExpectedWinner(HomeTeamStats.LettersDistribution,
                                                                     AwayTeamStats.LettersDistribution);
 }
 public void CalculateAttributesExpectedWinner()
 {
     ClashingAttributesExpectedWinner = MainCalculator.GetAttributeAdventageWinner(HomeTeamStats.TeamAttributes,
                                                                                   AwayTeamStats.TeamAttributes, AttributeClashingMap);
 }
        public static void CreateMatchReport(Dictionary <string, List <Helper.LetterDistribution> > lettersDict,
                                             Dictionary <int, List <DataObjects.AttributeType> > attributesDict,
                                             List <MainCalculator.AttributesMatch> attributeClashingMap,
                                             string homeTeam, string awayTeam, int competitionId)
        {
            var linesToWrite = new List <string>
            {
                "Home Team: " + homeTeam,
                "Away Team: " + awayTeam + "\n"
            };
            var path = @"C:\Users\user\Desktop\DataProjects\" + homeTeam + "VS" + awayTeam + ".tsv";

            using (var db = new sakilaEntities4())
            {
                var homeTeamObj = db.team.First(x => x.TeamName == homeTeam);
                var awayTeamObj = db.team.First(x => x.TeamName == awayTeam);

                linesToWrite.Add(homeTeam + " Market Value: " + homeTeamObj.MarketValue);
                linesToWrite.Add(awayTeam + " Market Value: " + awayTeamObj.MarketValue + "\n");

                var homeTeamBalance = PointsCalculator.GetTeamBalance(db, homeTeamObj.TeamID, competitionId);
                var awayTeamBalance = PointsCalculator.GetTeamBalance(db, awayTeamObj.TeamID, competitionId);

                var homeTeamBalanceLast3 = PointsCalculator.GetTeamBalance(db, homeTeamObj.TeamID, competitionId, 3);
                var awayTeamBalanceLast3 = PointsCalculator.GetTeamBalance(db, awayTeamObj.TeamID, competitionId, 3);

                var teamBalanceAtHome       = PointsCalculator.GetTeamBalanceHome(db, homeTeamObj.TeamID, competitionId);
                var teamBalanceAwayFromHome = PointsCalculator.GetTeamBalanceAway(db, awayTeamObj.TeamID, competitionId);

                var homeTeamSeasonForm = PointsCalculator.CalculatePointPace(homeTeamBalance);
                var awayTeamSeasonForm = PointsCalculator.CalculatePointPace(awayTeamBalance);

                var homeTeamLatest3Form = PointsCalculator.CalculatePointPace(homeTeamBalanceLast3);
                var awayTeamLatest3Form = PointsCalculator.CalculatePointPace(awayTeamBalanceLast3);

                var homeTeamSeasonFormAtHome = PointsCalculator.CalculatePointPace(teamBalanceAtHome);
                var awayTeamSeasonFormAway   = PointsCalculator.CalculatePointPace(teamBalanceAwayFromHome);

                var foulsAverageHome = SecondaryStatsCalculator.GetAverageFoulsPerTeam(db, homeTeamObj.TeamID, competitionId);
                var foulsAverageAway = SecondaryStatsCalculator.GetAverageFoulsPerTeam(db, awayTeamObj.TeamID, competitionId);

                var cornersAverageHome = SecondaryStatsCalculator.GetAverageCornersPerTeam(db, homeTeamObj.TeamID, competitionId);
                var cornersAverageAway = SecondaryStatsCalculator.GetAverageCornersPerTeam(db, awayTeamObj.TeamID, competitionId);
                var cornersAverageOnHomeTeamMatches = SecondaryStatsCalculator.AverageCornersOnTeamsMatches(db, homeTeamObj.TeamID,
                                                                                                            competitionId);
                var cornersAverageOnAwayTeamMatches = SecondaryStatsCalculator.AverageCornersOnTeamsMatches(db, awayTeamObj.TeamID,
                                                                                                            competitionId);
                var cornersStdOnHomeTeamMatches = SecondaryStatsCalculator.GetStdCornersPerTeamsMatches(db, homeTeamObj.TeamID,
                                                                                                        competitionId);
                var cornersStdOnAwayTeamMatches = SecondaryStatsCalculator.GetStdCornersPerTeamsMatches(db, awayTeamObj.TeamID,
                                                                                                        competitionId);

                var shotsOnTargetAverageHome = SecondaryStatsCalculator.GetAverageTotalShotsPerTeam(db, homeTeamObj.TeamID, competitionId);
                var shotsOnTargetAverageAway = SecondaryStatsCalculator.GetAverageTotalShotsPerTeam(db, awayTeamObj.TeamID, competitionId);

                var shotsOnTargetAverageAgainstHome = SecondaryStatsCalculator.GetAverageShotsOnTargetAgainstTeam(db, homeTeamObj.TeamID, competitionId);
                var shotsOnTargetAverageAgainstAway = SecondaryStatsCalculator.GetAverageShotsOnTargetAgainstTeam(db, awayTeamObj.TeamID, competitionId);

                var possessionAverageHome = SecondaryStatsCalculator.GetAveragePossessionPerTeam(db, homeTeamObj.TeamID, competitionId);
                var possessionAverageAway = SecondaryStatsCalculator.GetAveragePossessionPerTeam(db, awayTeamObj.TeamID, competitionId);

                var possessionAverageAgainstHome = SecondaryStatsCalculator.GetAveragePossessionAgainstTeam(db, homeTeamObj.TeamID, competitionId);
                var possessionAverageAgainstAway = SecondaryStatsCalculator.GetAveragePossessionAgainstTeam(db, awayTeamObj.TeamID, competitionId);

                var possToShotsRateHome = Math.Round((double)(possessionAverageHome / shotsOnTargetAverageHome), 2);
                var possToShotsRateAway = Math.Round((double)(possessionAverageAway / shotsOnTargetAverageAway), 2);

                var possToShotsRateAgainstHome = Math.Round((double)(possessionAverageAgainstHome / shotsOnTargetAverageAgainstHome), 2);
                var possToShotsRateAgainstAway = Math.Round((double)(possessionAverageAgainstAway / shotsOnTargetAverageAgainstAway), 2);

                var goalScoredHomeSeasonal = GoalsCalculator.GetGoalsScoringAverage(db, homeTeamObj.TeamID, competitionId);
                var goalScoredHomeLatest3  = GoalsCalculator.GetGoalsScoringAverage(db, homeTeamObj.TeamID, competitionId, 3);
                var goalScoredHomeAtHome   = GoalsCalculator.GetGoalsScoringAverageAtHome(db, homeTeamObj.TeamID,
                                                                                          competitionId);

                var goalScoredAwaySeasonal = GoalsCalculator.GetGoalsScoringAverage(db, awayTeamObj.TeamID, competitionId);
                var goalScoredAwayLatest3  = GoalsCalculator.GetGoalsScoringAverage(db, awayTeamObj.TeamID, competitionId, 3);
                var goalScoredAwayAtAway   = GoalsCalculator.GetGoalsScoringAverageAtAway(db, awayTeamObj.TeamID,
                                                                                          competitionId);

                var shotsToGoalsRateHome = Math.Round((double)(shotsOnTargetAverageHome / goalScoredHomeSeasonal.Average), 2);
                var shotsToGoalRateAway  = Math.Round((double)(shotsOnTargetAverageAway / goalScoredAwaySeasonal.Average), 2);

                var homeTeamTopScorer = GoalsCalculator.GetTeamTopScorer(db, homeTeamObj.TeamID, competitionId);
                var awayTeamTopScorer = GoalsCalculator.GetTeamTopScorer(db, awayTeamObj.TeamID, competitionId);

                var goalConcededHomeSeasonal = GoalsCalculator.GetGoalsConcededAverage(db, homeTeamObj.TeamID, competitionId);
                var goalConcededHomeLatest3  = GoalsCalculator.GetGoalsConcededAverage(db, homeTeamObj.TeamID, competitionId, 3);
                var goalConcededHomeAtHome   = GoalsCalculator.GetGoalsConcededAverageAtHome(db, homeTeamObj.TeamID, competitionId);

                var goalConcededAwaySeasonal = GoalsCalculator.GetGoalsConcededAverage(db, awayTeamObj.TeamID, competitionId);
                var goalConcededAwayLatest3  = GoalsCalculator.GetGoalsConcededAverage(db, awayTeamObj.TeamID, competitionId, 3);
                var goalConcededAwayAtAway   = GoalsCalculator.GetGoalsConcededAverageAtAway(db, awayTeamObj.TeamID, competitionId);

                var shotsToGoalsRateAgainstHome = Math.Round((double)(shotsOnTargetAverageAgainstHome / goalConcededHomeSeasonal.Average), 2);
                var shotsToGoalRateAgainstAway  = Math.Round((double)(shotsOnTargetAverageAgainstAway / goalConcededAwaySeasonal.Average), 2);

                var expectShotsHome   = Math.Round((double)(shotsOnTargetAverageAgainstAway + shotsOnTargetAverageHome) / 2, 2);
                var expectedShotsAway = Math.Round((double)(shotsOnTargetAverageAgainstHome + shotsOnTargetAverageAway) / 2, 2);

                var homeExpectedConversionRate = Math.Round((decimal)(shotsToGoalRateAgainstAway + shotsToGoalsRateHome) / 2, 2);
                var awayExpectedConversionRate = Math.Round((decimal)(shotsToGoalRateAway + shotsToGoalsRateAgainstHome) / 2, 2);

                var homeExpectedGoalsByConversionRate = expectShotsHome / (double)homeExpectedConversionRate;
                var awayExpectedGoalsByConversionRate = expectedShotsAway / (double)awayExpectedConversionRate;

                var expectedWinnerByConversion = MainCalculator.GetExpectedWinner(homeExpectedGoalsByConversionRate, awayExpectedGoalsByConversionRate, 1, 0.5d);

                var conversionExpectedWinner = MainCalculator.CalculateConversionWinner(homeExpectedConversionRate,
                                                                                        awayExpectedConversionRate);

                var goalHomeConcededPosition = GoalsCalculator.GetTeamTopScorersAgainsePosition(db, homeTeamObj.TeamID,
                                                                                                competitionId);

                var goalAwayConcededPosition = GoalsCalculator.GetTeamTopScorersAgainsePosition(db, awayTeamObj.TeamID,
                                                                                                competitionId);

                var homeTeamFormLetters = LettersSequenceCalculator.GetTeamLatestSequence(db, homeTeamObj.TeamID, competitionId);
                var awayTeamFormLetters = LettersSequenceCalculator.GetTeamLatestSequence(db, awayTeamObj.TeamID, competitionId);

                var homeTeamStrength = MainCalculator.CalculateTeamStrength((int)homeTeamObj.MarketValue, homeTeamSeasonForm, homeTeamLatest3Form, homeTeamSeasonFormAtHome);
                var awayTeamStrength = MainCalculator.CalculateTeamStrength((int)awayTeamObj.MarketValue, awayTeamSeasonForm, awayTeamLatest3Form, awayTeamSeasonFormAway);

                var homeTeamExpectedGoals = GoalsCalculator.CalculateExpectedGoals(goalScoredHomeSeasonal,
                                                                                   goalScoredHomeLatest3, goalConcededAwaySeasonal, goalConcededAwayLatest3,
                                                                                   goalScoredHomeAtHome, goalConcededAwayAtAway);

                var awayTeamExpectedGoals = GoalsCalculator.CalculateExpectedGoals(goalScoredAwaySeasonal,
                                                                                   goalScoredAwayLatest3, goalConcededHomeSeasonal, goalConcededHomeLatest3,
                                                                                   goalScoredAwayAtAway, goalConcededHomeAtHome);

                var homeTeamStengthDiff = MainCalculator.StrengthDiffCaculator(homeTeamStrength, awayTeamStrength);
                var awayTeamStengthDiff = MainCalculator.StrengthDiffCaculator(awayTeamStrength, homeTeamStrength);

                string homeTeamSeq;
                var    homeSequenceExpectation = LettersSequenceCalculator.BuildSequenceStringExpectation(db, homeTeamObj.TeamID,
                                                                                                          competitionId, lettersDict, out homeTeamSeq);

                var homeSequenceStringExpectation =
                    LettersSequenceCalculator.BuildSequenceStringExpectation(homeSequenceExpectation, homeTeamSeq);

                string awayTeanSeq;
                var    awaySequenceExpectation = LettersSequenceCalculator.BuildSequenceStringExpectation(db, awayTeamObj.TeamID,
                                                                                                          competitionId, lettersDict, out awayTeanSeq);

                var awaySequenceStringExpectation =
                    LettersSequenceCalculator.BuildSequenceStringExpectation(awaySequenceExpectation, awayTeanSeq);

                var homeCalculatedGoals   = Math.Round(homeTeamExpectedGoals.Average + homeTeamStengthDiff, 2);
                var awayCalculatedGoals   = Math.Round(awayTeamExpectedGoals.Average + awayTeamStengthDiff, 2);
                var expectedWinner        = MainCalculator.GetExpectedWinner(homeCalculatedGoals, awayCalculatedGoals);
                var lettersExpectedWinner = MainCalculator.GetLettersExpectedWinners(homeSequenceExpectation,
                                                                                     awaySequenceExpectation);

                var homeTeamAttributes = Helper.GetTeamAttributesList((int)homeTeamObj.TeamID, attributesDict);
                var awayTeamAttributes = Helper.GetTeamAttributesList((int)awayTeamObj.TeamID, attributesDict);

                linesToWrite.Add(homeTeam + " Strength: " + homeTeamStrength);
                linesToWrite.Add(awayTeam + " Strength: " + awayTeamStrength + "\n");

                linesToWrite.Add("Strength Expected Winner: " + expectedWinner.Winner + " (" + Math.Min(expectedWinner.Confidence * 100, 100) + "%)");
                linesToWrite.Add("Expected Goals: " + Math.Round(homeTeamExpectedGoals.Average + awayTeamExpectedGoals.Average, 2) + " (Average Std: " + Math.Round((homeTeamExpectedGoals.StdDev + awayTeamExpectedGoals.StdDev) / 2, 1) + ")");
                linesToWrite.Add("Expected Result: " + homeCalculatedGoals + ":" + awayCalculatedGoals + "\n");

                linesToWrite.Add(homeTeam + " Expected Result According to Form: " + homeSequenceStringExpectation);
                linesToWrite.Add(awayTeam + " Expected Result According to Form: " + awaySequenceStringExpectation + "\n" + "\n");
                linesToWrite.Add("Letters Expected Results: " + lettersExpectedWinner);

                if (homeTeamAttributes.Any() || awayTeamAttributes.Any())

                {
                    linesToWrite.Add("---------Tips---------");

                    if (homeTeamAttributes.Any())
                    {
                        linesToWrite.Add(homeTeam + ":");
                        linesToWrite.AddRange(homeTeamAttributes);
                        linesToWrite.Add("");
                    }

                    if (awayTeamAttributes.Any())
                    {
                        linesToWrite.Add(awayTeam + ":");
                        linesToWrite.AddRange(awayTeamAttributes);
                        linesToWrite.Add("");
                    }
                    linesToWrite.Add("");

                    var homeTeamAttrs      = Helper.GetTeamAttributeFromDict(homeTeamObj.TeamID, attributesDict);
                    var awayTeamAttrs      = Helper.GetTeamAttributeFromDict(awayTeamObj.TeamID, attributesDict);
                    var attributeAdventage = MainCalculator.GetAttributeAdventageList(homeTeamAttrs,
                                                                                      awayTeamAttrs, attributeClashingMap);
                    if (attributeAdventage.Any())
                    {
                        linesToWrite.Add("Atributes Adventages: ");
                        linesToWrite.Add("");
                    }
                    linesToWrite.AddRange(attributeAdventage);
                    linesToWrite.Add("");
                }

                linesToWrite.Add("---------Balance & Points---------");
                linesToWrite.Add(homeTeam + " Balance: " + homeTeamBalance.Win + "-" + homeTeamBalance.Draw + "-" + homeTeamBalance.Lost + "(Pace: " + homeTeamSeasonForm + ")");
                linesToWrite.Add(homeTeam + " Balance at Home: " + teamBalanceAtHome.Win + "-" + teamBalanceAtHome.Draw + "-" + teamBalanceAtHome.Lost + "(Pace: " + homeTeamSeasonFormAtHome + ")");
                linesToWrite.Add(homeTeam + " Balance Latest 3: " + homeTeamBalanceLast3.Win + "-" + homeTeamBalanceLast3.Draw + "-" + homeTeamBalanceLast3.Lost + "(Pace: " + homeTeamLatest3Form + ")");
                linesToWrite.Add(homeTeam + " Form: " + homeTeamFormLetters + "\n");

                linesToWrite.Add(awayTeam + " Balance: " + awayTeamBalance.Win + "-" + awayTeamBalance.Draw + "-" + awayTeamBalance.Lost + "(Pace:" + awayTeamSeasonForm + ")");
                linesToWrite.Add(awayTeam + " Balance Away: " + teamBalanceAwayFromHome.Win + "-" + teamBalanceAwayFromHome.Draw + "-" + teamBalanceAwayFromHome.Lost + "(Pace: " + awayTeamSeasonFormAway + ")");
                linesToWrite.Add(awayTeam + " Balance Latest 3: " + awayTeamBalanceLast3.Win + "-" + awayTeamBalanceLast3.Draw + "-" + awayTeamBalanceLast3.Lost + "(Pace:" + awayTeamLatest3Form + ")");
                linesToWrite.Add(awayTeam + " Form: " + awayTeamFormLetters + "\n");

                linesToWrite.Add("---------Goals---------");
                linesToWrite.Add(homeTeam + " Goal Scored Average: " + goalScoredHomeSeasonal.Average + "(Std: " + goalScoredHomeSeasonal.StdDev + ")");
                linesToWrite.Add(homeTeam + " Goal Scored Latest 3 Average: " + goalScoredHomeLatest3.Average + "(Std: " + goalScoredHomeLatest3.StdDev + ")");
                linesToWrite.Add(homeTeam + " Goal Scored At Home Matchs: " + goalScoredHomeAtHome.Average + "(Std: " + goalScoredHomeAtHome.StdDev + ")" + "\n");


                linesToWrite.Add(awayTeam + " Goal Scored Average: " + goalScoredAwaySeasonal.Average + "(Std: " + goalScoredAwaySeasonal.StdDev + ")");
                linesToWrite.Add(awayTeam + " Goal Scored Latest 3 Average: " + goalScoredAwayLatest3.Average + "(Std: " + goalScoredAwayLatest3.StdDev + ")");
                linesToWrite.Add(awayTeam + " Goal Scored At Away Matches: " + goalScoredAwayAtAway.Average + "(Std: " + goalScoredAwayAtAway.StdDev + ")" + "\n");

                linesToWrite.Add(homeTeam + " Top Scorer: " + homeTeamTopScorer.Name + " (" + homeTeamTopScorer.Goals + ")");
                linesToWrite.Add(awayTeam + " Top Scorer: " + awayTeamTopScorer.Name + " (" + awayTeamTopScorer.Goals + ")" + "\n");

                linesToWrite.Add(homeTeam + " Goal Conceded Average: " + goalConcededHomeSeasonal.Average + "(Std: " + goalConcededHomeSeasonal.StdDev + ")");
                linesToWrite.Add(homeTeam + " Goal Conceded Latest 3 Average: " + goalConcededHomeLatest3.Average + "(Std: " + goalConcededHomeLatest3.StdDev + ")");
                linesToWrite.Add(homeTeam + " Goal Conceded At Home Matches: " + goalConcededHomeAtHome.Average + "(Std: " + goalConcededHomeAtHome.StdDev + ")" + "\n");

                linesToWrite.Add(awayTeam + " Goal Conceded Average: " + goalConcededAwaySeasonal.Average + "(Std: " + goalConcededAwaySeasonal.StdDev + ")");
                linesToWrite.Add(awayTeam + " Goal Conceded Latest 3 Average: " + goalConcededAwayLatest3.Average + "(Std: " + goalConcededAwayLatest3.StdDev + ")");
                linesToWrite.Add(awayTeam + " Goal Conceded At Away Matches: " + goalConcededAwayAtAway.Average + "(Std: " + goalConcededAwayAtAway.StdDev + ")" + "\n");

                linesToWrite.Add(homeTeam + " Conceded Mostly from: " + goalHomeConcededPosition);
                linesToWrite.Add(awayTeam + " Conceded Mostly from: " + goalAwayConcededPosition + "\n" + "\n");

                linesToWrite.Add("---------Corners---------");
                linesToWrite.Add(homeTeam + " Corners Average: " + cornersAverageHome);
                linesToWrite.Add("Average Corners on " + homeTeam + " Matches: " + cornersAverageOnHomeTeamMatches + "(Std:" + cornersStdOnHomeTeamMatches + ")" + "\n");
                linesToWrite.Add(awayTeam + " Corners Average: " + cornersAverageAway);
                linesToWrite.Add("Average Corners on " + awayTeam + " Matches: " + cornersAverageOnAwayTeamMatches + "(Std:" + cornersStdOnAwayTeamMatches + ")" + "\n" + "\n");

                linesToWrite.Add("---------Other Stats---------");
                linesToWrite.Add(homeTeam + " Fouls Average: " + foulsAverageHome);
                linesToWrite.Add(awayTeam + " Fouls Average: " + foulsAverageAway + "\n");

                linesToWrite.Add(homeTeam + " Possession Average: " + possessionAverageHome + "%");
                linesToWrite.Add(awayTeam + " Possession Average: " + possessionAverageAway + "%" + "\n");

                linesToWrite.Add(homeTeam + " Shots on Goal Average: " + shotsOnTargetAverageHome);
                linesToWrite.Add(awayTeam + " Shots on Goal Average: " + shotsOnTargetAverageAway + "\n");

                linesToWrite.Add("---------Funnels (Possession:Shots:Goals)---------");
                linesToWrite.Add(homeTeam + " Funnel: (" + ((double)possessionAverageHome) + ") : (" + ((double)shotsOnTargetAverageHome) + ") : (" + (goalScoredHomeSeasonal.Average) + ")");
                linesToWrite.Add(homeTeam + " Possession to Shots Conversion: " + possToShotsRateHome);
                linesToWrite.Add(homeTeam + " Shots to Goals Conversion: " + shotsToGoalsRateHome + "\n");

                linesToWrite.Add(homeTeam + " Opponents Funnel: (" + ((double)possessionAverageAgainstHome) + ") : (" + ((double)shotsOnTargetAverageAgainstHome) + ") : (" + (goalConcededHomeSeasonal.Average) + ")");
                linesToWrite.Add(homeTeam + " Possession to Shots Conversion Against " + homeTeam + ": " + possToShotsRateAgainstHome);
                linesToWrite.Add(homeTeam + " Shots to Goals Conversion Against " + homeTeam + ": " + shotsToGoalsRateAgainstHome + "\n");

                linesToWrite.Add(awayTeam + " Funnel: (" + ((double)possessionAverageAway) + ") : (" + ((double)shotsOnTargetAverageAway) + ") : (" + (goalScoredAwaySeasonal.Average) + ")");
                linesToWrite.Add(awayTeam + " Possession to Shots Conversion: " + possToShotsRateAway);
                linesToWrite.Add(awayTeam + " Shots to Goals Conversion: " + shotsToGoalRateAway + "\n");

                linesToWrite.Add(awayTeam + " Oponents Funnel: (" + ((double)possessionAverageAgainstAway) + ") : (" + ((double)shotsOnTargetAverageAgainstAway) + ") : (" + (goalConcededAwaySeasonal.Average) + ")");
                linesToWrite.Add(awayTeam + " Possession to Shots Conversion Against " + awayTeam + ": " + possToShotsRateAgainstAway);
                linesToWrite.Add(awayTeam + " Shots to Goals Conversion Against " + awayTeam + ": " + shotsToGoalRateAgainstAway);
                linesToWrite.Add("");
                linesToWrite.Add(homeTeam + " Expected Conversion: " + homeExpectedConversionRate);
                linesToWrite.Add(awayTeam + " Expected Conversion: " + awayExpectedConversionRate + "\n");
                linesToWrite.Add("Expected Average Conversion: " + Math.Round((awayExpectedConversionRate + homeExpectedConversionRate) / 2, 2));
                linesToWrite.Add("");
                linesToWrite.Add(conversionExpectedWinner);
                linesToWrite.Add("Shots Conversion Winner: " + expectedWinnerByConversion.Winner + " (" + Math.Min(expectedWinnerByConversion.Confidence * 100, 100) + "%)");
            }

            File.WriteAllLines(path, linesToWrite);
        }