Example #1
0
        public string GetScoresCsv(DateTime date)
        {
            try
            {
                using (var client = new WebClient())
                {
                    string dir    = AppDomain.CurrentDomain.BaseDirectory;
                    string path   = dir + Constants.CSV_CURRENT_FILE_NAME;
                    string season = SeasonHelper.GetCurrentSeasonShort(date);

                    if (File.Exists(Constants.CSV_CURRENT_FILE_NAME))
                    {
                        logger.InfoFormat("File {0} will be overwritten", Constants.CSV_CURRENT_FILE_NAME);
                        File.Delete(Constants.CSV_CURRENT_FILE_NAME);
                    }

                    client.DownloadFile(@"http://www.football-data.co.uk/mmz4281/" + season + @"/E0.csv", path);
                    logger.InfoFormat("Downloading csv file succeeded. File location is: ", path);

                    return(path);
                }
            }
            catch (Exception e)
            {
                logger.Error("Error while downloading csv file.", e);
                return("");
            }
        }
Example #2
0
        public List <MatchModel> ParseJsonMatches(JObject o)
        {
            var matches = new List <MatchModel>();

            var jsonMatches = o["fixtures"].Children();

            foreach (var m in jsonMatches)
            {
                try
                {
                    var match = new MatchModel();
                    match.Date      = (DateTime)m["date"];
                    match.HomeTeam  = (String)m["homeTeamName"];
                    match.AwayTeam  = (String)m["awayTeamName"];
                    match.Season    = SeasonHelper.GetCurrentSeason(match.Date);
                    match.Matchweek = (int)m["matchday"];
                    matches.Add(match);
                    logger.InfoFormat("Match: {0} - {1}, date: {2} parsed successfully", match.HomeTeam, match.AwayTeam, match.Date);
                }
                catch (Exception e)
                {
                    logger.Error("Error while parsing match", e);
                }
            }
            logger.InfoFormat("{0}/{1} matches parsed successfully", matches.Count, jsonMatches.ToList().Count);
            return(matches);
        }
        public List <ScoreModel> ParseCsvScores(string csvFilePath, DateTime startDate)
        {
            var scores = new List <ScoreModel>();

            using (TextReader reader = File.OpenText(@csvFilePath))
            {
                using (CsvReader csv = new CsvReader(reader))
                {
                    try
                    {
                        while (csv.Read())
                        {
                            var dateStr = csv.GetField <string>("Date");
                            var date    = DateTime.ParseExact(dateStr, "dd/MM/yy", CultureInfo.InvariantCulture);
                            var season  = SeasonHelper.GetCurrentSeason(date);

                            if (date >= startDate)
                            {
                                var score = new ScoreModel();
                                score.HomeTeam          = csv.GetField <string>("HomeTeam");
                                score.AwayTeam          = csv.GetField <string>("AwayTeam");
                                score.HomeGoals         = csv.GetField <int>("FTHG");
                                score.AwayGoals         = csv.GetField <int>("FTAG");
                                score.HomeShots         = csv.GetField <int>("HS");
                                score.AwayShots         = csv.GetField <int>("AS");
                                score.HomeShotsOnTarget = csv.GetField <int>("HST");
                                score.AwayShotsOnTarget = csv.GetField <int>("AST");
                                score.HalfTimeHomeGoals = csv.GetField <int>("HTHG");
                                score.HalfTimeAwayGoals = csv.GetField <int>("HTAG");
                                score.HomeCorners       = csv.GetField <int>("HC");
                                score.AwayCorners       = csv.GetField <int>("AC");
                                score.HomeFouls         = csv.GetField <int>("HF");
                                score.AwayFouls         = csv.GetField <int>("AF");
                                score.HomeYellowCards   = csv.GetField <int>("HY");
                                score.AwayYellowCards   = csv.GetField <int>("AY");
                                score.HomeRedCards      = csv.GetField <int>("HR");
                                score.AwayRedCards      = csv.GetField <int>("AR");
                                score.Referee           = csv.GetField <string>("Referee");
                                score.Season            = season;
                                score.Date = date;

                                scores.Add(score);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        logger.Warn("Error while parsing csv file.", e);
                    }
                }
            }
            logger.InfoFormat("{0} scores have been parsed successfully. Scores after {1} were being processed", scores.Count, startDate);
            return(scores);
        }
        public List <ScoreModel> ParseCsvScores(DateTime startDate)
        {
            var scores = new List <ScoreModel>();

            //using (TextReader reader = File.OpenText(dir + "\\" + "App_Data\\" + Constants.CSV_FILE_NAME))
            using (TextReader reader = File.OpenText(dir + "\\" + Constants.CSV_FILE_NAME))
            {
                using (CsvReader csv = new CsvReader(reader))
                {
                    while (csv.Read())
                    {
                        var date   = csv.GetField <DateTime>("Date");
                        var season = SeasonHelper.GetCurrentSeason(date);

                        if (date >= startDate)
                        {
                            var score = new ScoreModel();
                            score.HomeTeam          = csv.GetField <string>("HomeTeam");
                            score.AwayTeam          = csv.GetField <string>("AwayTeam");
                            score.HomeGoals         = csv.GetField <int>("FTHG");
                            score.AwayGoals         = csv.GetField <int>("FTAG");
                            score.HomeShots         = csv.GetField <int>("HS");
                            score.AwayShots         = csv.GetField <int>("AS");
                            score.HomeShotsOnTarget = csv.GetField <int>("HST");
                            score.AwayShotsOnTarget = csv.GetField <int>("AST");
                            score.HalfTimeHomeGoals = csv.GetField <int>("HTHG");
                            score.HalfTimeAwayGoals = csv.GetField <int>("HTAG");
                            score.HomeCorners       = csv.GetField <int>("HC");
                            score.AwayCorners       = csv.GetField <int>("AC");
                            score.HomeFouls         = csv.GetField <int>("HF");
                            score.AwayFouls         = csv.GetField <int>("AF");
                            score.HomeYellowCards   = csv.GetField <int>("HY");
                            score.AwayYellowCards   = csv.GetField <int>("AY");
                            score.HomeRedCards      = csv.GetField <int>("HR");
                            score.AwayRedCards      = csv.GetField <int>("AR");
                            score.Referee           = csv.GetField <string>("Referee");
                            score.Season            = season;

                            scores.Add(score);
                        }
                    }
                }
            }
            return(scores);
        }
        public List <MatchModel> GetMatches(int matchday)
        {
            var matches = new List <MatchModel>();

            var o = JObject.Parse(_api.GetMatchdayJson(matchday));

            var jsonMatches = o["fixtures"].Children();

            foreach (var m in jsonMatches)
            {
                if ((String)m["status"] == "SCHEDULED")
                {
                    var match = new MatchModel();
                    match.Date      = (DateTime)m["date"];
                    match.HomeTeam  = (String)m["homeTeamName"];
                    match.AwayTeam  = (String)m["awayTeamName"];
                    match.Season    = SeasonHelper.GetCurrentSeason(match.Date);
                    match.Matchweek = (int)m["matchday"];
                    matches.Add(match);
                }
            }
            return(matches);
        }
        public List <MatchModel> ParseCsvMatches(string csvFilePath)
        {
            List <MatchModel> matches = new List <MatchModel>();

            using (TextReader reader = File.OpenText(@csvFilePath))
            {
                using (CsvReader csv = new CsvReader(reader))
                {
                    int matchOfSeason = 0;

                    try
                    {
                        while (csv.Read())
                        {
                            var date = csv.GetField <DateTime>("Date");

                            MatchModel match = new MatchModel
                            {
                                HomeTeam  = csv.GetField <string>("HomeTeam"),
                                AwayTeam  = csv.GetField <string>("AwayTeam"),
                                Date      = date,
                                Season    = SeasonHelper.GetCurrentSeason(date),
                                Matchweek = (int)(matchOfSeason / 10) + 1
                            };
                            matchOfSeason++;
                            matches.Add(match);
                        }
                    }
                    catch (Exception e)
                    {
                        logger.Warn("Error while processing matches.", e);
                    }
                }
            }
            logger.InfoFormat("{0} matches have been parsed successfully.", matches.Count);
            return(matches);
        }