public override void Run() { var config = GetConfig(); var context = new BasketballDataContext(config); var activeLeagueSeasons = context.LeagueSeasons.Where(x => x.IsActive).ToList(); if (activeLeagueSeasons != null && activeLeagueSeasons.Count > 0) { var countriesDict = context.Countries.ToDictionary(x => x.ApiBasketballCountryId, y => y.CountryId); var statusDict = context.RefGameStatuses .Where(x => !string.IsNullOrEmpty(x.ApiBasketballStatusCode)) .ToDictionary(x => x.ApiBasketballStatusCode, y => y.FullGameStatusId); for (int i = 0; i < activeLeagueSeasons.Count; i++) { var leagueSeason = activeLeagueSeasons[i]; var gamesProcessor = new GamesProcessor(leagueSeason.ApiBasketballLeagueId, leagueSeason.ApiBasketballSeasonKey, countriesDict, statusDict); gamesProcessor.Run(context); context.SaveChanges(); if (i % 10 == 9) { context.Dispose(); context = new BasketballDataContext(config); } } } context.Dispose(); }
public override void Run() { var config = GetConfig(); using (var context = new BasketballDataContext(config)) { // ASSUME ALL GAMES ARE IN DB FROM DAILY TASK // UPDATE RESULTS FOR LIVE/RECENTLY FINAL GAMES // SELECT LEAGUE SEASONS WHERE // 1) A GAME HAS STARTED SINCE THE LAST UNIVERSAL GAME HAS GONE FINAL (PICKUP GAMES AFTER PERIOD WITHOUT RUNNING) // 2) A GAME IS LIVE // 3) THE GAME WILL START IN THE NEXT 4 HOURS DateTime lastFinalGameStart = context.Games.Where(x => liveOrFinalGameStatuses.Contains(x.FullGameStatusId)).Max(x => x.GameTimeUtc); var targetedApiBasketballLeagueSeasonInfos = context.Games.Where(x => x.LeagueSeason.IsActive && x.GameTimeUtc > lastFinalGameStart && liveOrPregameGameStatuses.Contains(x.FullGameStatusId) && x.GameTimeUtc <= DateTime.UtcNow.AddHours(4)) .Select(x => new { x.LeagueSeason.ApiBasketballLeagueId, x.LeagueSeason.ApiBasketballSeasonKey }) .Distinct() .ToList(); if (targetedApiBasketballLeagueSeasonInfos != null && targetedApiBasketballLeagueSeasonInfos.Count > 0) { var countriesDict = context.Countries.ToDictionary(x => x.ApiBasketballCountryId, y => y.CountryId); var statusDict = context.RefGameStatuses .Where(x => !string.IsNullOrEmpty(x.ApiBasketballStatusCode)) .ToDictionary(x => x.ApiBasketballStatusCode, y => y.FullGameStatusId); foreach (var leagueSeasonInfo in targetedApiBasketballLeagueSeasonInfos) { var gamesProcessor = new GamesProcessor(leagueSeasonInfo.ApiBasketballLeagueId, leagueSeasonInfo.ApiBasketballSeasonKey, countriesDict, statusDict); gamesProcessor.Run(context); context.SaveChanges(); } } } }
public override void Run() { Console.WriteLine("Hello World!"); HockeyDataContext context = null; try { var config = GetConfig(); context = new HockeyDataContext(config); //context.Database.EnsureDeleted(); //context.Database.EnsureCreated(); //context.SaveChanges(); //context.RefGameTypes.AddRange(new List<RefGameType> //{ // new RefGameType{ GameTypeId = GameType.Unknown, NhlGameTypeKey = string.Empty, GameTypeDescription = "Unknown"}, // new RefGameType{ GameTypeId = GameType.RegularSeason, NhlGameTypeKey = "R", GameTypeDescription = "Regular Season"}, // new RefGameType{ GameTypeId = GameType.Postseason, NhlGameTypeKey = "P", GameTypeDescription = "Postseason"}, // new RefGameType{ GameTypeId = GameType.Preseason, NhlGameTypeKey = "PR", GameTypeDescription = "Preseason"}, // new RefGameType{ GameTypeId = GameType.AllStarGame, NhlGameTypeKey = "A", GameTypeDescription = "All-Star Game"}, // new RefGameType{ GameTypeId = GameType.AllStarGameWomen, NhlGameTypeKey = "WA", GameTypeDescription = "All-Star Women Game"}, // new RefGameType{ GameTypeId = GameType.Olympics, NhlGameTypeKey = "O", GameTypeDescription = "Olympics Game"}, // new RefGameType{ GameTypeId = GameType.Exhibition, NhlGameTypeKey = "E", GameTypeDescription = "Exhibition"}, // new RefGameType{ GameTypeId = GameType.WorldCupExhibition, NhlGameTypeKey = "WCOH_EXH", GameTypeDescription = "World Cup of Hockey exhibition/preseason games "}, // new RefGameType{ GameTypeId = GameType.WorldCupPrelim, NhlGameTypeKey = "WCOH_PRELIM", GameTypeDescription = "World Cup of Hockey preliminary games"}, // new RefGameType{ GameTypeId = GameType.WorldCupFinal, NhlGameTypeKey = "WCOH_FINAL", GameTypeDescription = "World Cup of Hockey semifinals and finals"}, //}); //context.SaveChanges(); //context.RefGameStatuses.AddRange(new List<RefGameStatus> //{ // new RefGameStatus{ DetailedGameStatusId = DetailedGameStatus.Scheduled, GameStatusId = GameStatus.Pregame, NhlStatusCode = 01, GameStatusName = "Pregame", DetailedGameStatusName = "Scheduled"}, // new RefGameStatus{ DetailedGameStatusId = DetailedGameStatus.Pregame, GameStatusId = GameStatus.Pregame, NhlStatusCode = 02, GameStatusName = "Pregame", DetailedGameStatusName = "Pregame"}, // new RefGameStatus{ DetailedGameStatusId = DetailedGameStatus.InProgress, GameStatusId = GameStatus.Live, NhlStatusCode = 03, GameStatusName = "Live", DetailedGameStatusName = "In-Progress"}, // new RefGameStatus{ DetailedGameStatusId = DetailedGameStatus.InProgressCritical, GameStatusId = GameStatus.Live, NhlStatusCode = 04, GameStatusName = "Live", DetailedGameStatusName = "In-Progress - Critical"}, // new RefGameStatus{ DetailedGameStatusId = DetailedGameStatus.GameOver, GameStatusId = GameStatus.Final, NhlStatusCode = 05, GameStatusName = "Final", DetailedGameStatusName = "Game Over"}, // new RefGameStatus{ DetailedGameStatusId = DetailedGameStatus.Final, GameStatusId = GameStatus.Final, NhlStatusCode = 06, GameStatusName = "Final", DetailedGameStatusName = "Final"}, // new RefGameStatus{ DetailedGameStatusId = DetailedGameStatus.Final2, GameStatusId = GameStatus.Final, NhlStatusCode = 07, GameStatusName = "Final", DetailedGameStatusName = "Final"}, // new RefGameStatus{ DetailedGameStatusId = DetailedGameStatus.ScheduledTbd, GameStatusId = GameStatus.Pregame, NhlStatusCode = 08, GameStatusName = "Pregame", DetailedGameStatusName = "Scheduled (Time TBD)"}, // new RefGameStatus{ DetailedGameStatusId = DetailedGameStatus.Postponed, GameStatusId = GameStatus.Postponed, NhlStatusCode = 09, GameStatusName = "Postponed", DetailedGameStatusName = "Postponed"}, //}); //context.SaveChanges(); //context.RefPlayTypes.AddRange(new List<RefPlayType> //{ // new RefPlayType{ PlayTypeId = PlayType.BlockedShot, NhlCode = "BLOCKED_SHOT", PlayTypeName = "Blocked Shot" }, // new RefPlayType{ PlayTypeId = PlayType.Faceoff, NhlCode = "FACEOFF", PlayTypeName = "Faceoff" }, // new RefPlayType{ PlayTypeId = PlayType.GameEnd, NhlCode = "GAME_END", PlayTypeName = "Game End" }, // new RefPlayType{ PlayTypeId = PlayType.GameScheduled, NhlCode = "GAME_SCHEDULED", PlayTypeName = "Game Scheduled" }, // new RefPlayType{ PlayTypeId = PlayType.Giveaway, NhlCode = "GIVEAWAY", PlayTypeName = "Giveaway" }, // new RefPlayType{ PlayTypeId = PlayType.Goal, NhlCode = "GOAL", PlayTypeName = "Goal" }, // new RefPlayType{ PlayTypeId = PlayType.Hit, NhlCode = "HIT", PlayTypeName = "Hit" }, // new RefPlayType{ PlayTypeId = PlayType.MissedShot, NhlCode = "MISSED_SHOT", PlayTypeName = "Missed Shot" }, // new RefPlayType{ PlayTypeId = PlayType.Penalty, NhlCode = "PENALTY", PlayTypeName = "Penalty" }, // new RefPlayType{ PlayTypeId = PlayType.PeriodEnd, NhlCode = "PERIOD_END", PlayTypeName = "Period End" }, // new RefPlayType{ PlayTypeId = PlayType.PeriodOfficial, NhlCode = "PERIOD_OFFICIAL", PlayTypeName = "Period Official" }, // new RefPlayType{ PlayTypeId = PlayType.PeriodReady, NhlCode = "PERIOD_READY", PlayTypeName = "Period Ready" }, // new RefPlayType{ PlayTypeId = PlayType.PeriodStart, NhlCode = "PERIOD_START", PlayTypeName = "Period Start" }, // new RefPlayType{ PlayTypeId = PlayType.Shot, NhlCode = "SHOT", PlayTypeName = "Shot" }, // new RefPlayType{ PlayTypeId = PlayType.Stoppage, NhlCode = "STOP", PlayTypeName = "Stoppage" }, // new RefPlayType{ PlayTypeId = PlayType.Takeaway, NhlCode = "TAKEAWAY", PlayTypeName = "Takeaway" }, //}); //context.SaveChanges(); //context.RefStoppageTypes.AddRange(new List<RefStoppageType> //{ // new RefStoppageType{ StoppageTypeId = StoppageType.Unknown, NhlDescription = null , StoppageName = "Unknown"}, // new RefStoppageType{ StoppageTypeId = StoppageType.GoalieStopped, NhlDescription = "Goalie Stopped", StoppageName = "Goalie Stopped"}, // new RefStoppageType{ StoppageTypeId = StoppageType.Icing, NhlDescription = "Icing", StoppageName = "Icing"}, // new RefStoppageType{ StoppageTypeId = StoppageType.NetOff, NhlDescription = "Net Off", StoppageName = "Net Off"}, // new RefStoppageType{ StoppageTypeId = StoppageType.Offside, NhlDescription = "Offside", StoppageName = "Offside"}, // new RefStoppageType{ StoppageTypeId = StoppageType.PuckFrozen, NhlDescription = "Puck Frozen", StoppageName = "Puck Frozen"}, // new RefStoppageType{ StoppageTypeId = StoppageType.PuckInBenches, NhlDescription = "Puck In Benches", StoppageName = "Puck in Benches"}, // new RefStoppageType{ StoppageTypeId = StoppageType.PuckInCrowd, NhlDescription = "Puck In Crowd", StoppageName = "Puck in Crowd"}, // new RefStoppageType{ StoppageTypeId = StoppageType.PuckInNetting, NhlDescription = "Puck In Netting", StoppageName = "Puck in Netting"}, // new RefStoppageType{ StoppageTypeId = StoppageType.TVTimeout, NhlDescription = "TV Timeout", StoppageName = "TV timeout"}, //}); //context.SaveChanges(); //context.Leagues.Add(new League { LeagueName = "National Hockey League", LeagueAbbr = "NHL" }); //context.SaveChanges(); //context.Players.Add(new Player { NhlPlayerId = 0, FullName = "Unknown" }); //context.SaveChanges(); var seasonsProcessor = new SeasonsProcessor(); seasonsProcessor.Run(context); //var dbSeasons = context.Seasons.Where(x => x.SeasonId > 100 && x.NhlSeasonKey != "20192020").OrderBy(x => x.SeasonId).ToList(); var dbSeasons = context.Seasons.Where(x => x.NhlSeasonKey == "20192020").OrderBy(x => x.SeasonId).ToList(); //var dbSeasons = context.Seasons.OrderBy(x => x.SeasonId).ToList(); for (int i = 0; i < dbSeasons.Count; i++) { var dbSeason = dbSeasons[i]; var nhlSeasonKey = dbSeason.NhlSeasonKey; Console.WriteLine($"PROCESS TEAMS - {nhlSeasonKey}"); var teamsProcessor = new TeamsProcessor(nhlSeasonKey); teamsProcessor.Run(context); Console.WriteLine($"PROCESS GAMES - {nhlSeasonKey}"); var gamesProcessor = new GamesProcessor(nhlSeasonKey); gamesProcessor.Run(context); var seasonGames = context.Games.Where(x => x.SeasonId == dbSeason.SeasonId).ToList(); for (int j = 0; j < seasonGames.Count; j++) { Console.WriteLine($"PROCESS GAMES - {nhlSeasonKey} - BOXES: {j}/{seasonGames.Count}"); var seasonGame = seasonGames[j]; var gameLiveProcessor = new GameLiveProcessor(seasonGame.NhlGameId, seasonGame.GameDateEst); gameLiveProcessor.Run(context); if (j % 30 == 29) { context.Dispose(); context = new HockeyDataContext(config); } } if (i % 10 == 9) { context.Dispose(); context = new HockeyDataContext(config); } } } finally { if (context != null) { context.Dispose(); } } }
public override void Run() { var config = GetConfig(); using (var context = new BasketballDataContext(config)) { context.Countries.Add( new Country { ApiBasketballCountryId = 0, CountryAbbr = "XX", CountryName = "World", FlagUrl = null }); context.RefGameStatuses.AddRange(new List <RefGameStatus> { new RefGameStatus { FullGameStatusId = FullGameStatus.NotStarted, FullGameStatusName = "Not Started", GameStatusId = GameStatus.Pregame, GameStatusName = "Pregame", ApiBasketballStatusCode = "NS" }, new RefGameStatus { FullGameStatusId = FullGameStatus.Live_Q1, FullGameStatusName = "Live - Q1", GameStatusId = GameStatus.Live, GameStatusName = "Live", ApiBasketballStatusCode = "Q1" }, new RefGameStatus { FullGameStatusId = FullGameStatus.Live_Q2, FullGameStatusName = "Live - Q2", GameStatusId = GameStatus.Live, GameStatusName = "Live", ApiBasketballStatusCode = "Q2" }, new RefGameStatus { FullGameStatusId = FullGameStatus.Live_Q3, FullGameStatusName = "Live - Q3", GameStatusId = GameStatus.Live, GameStatusName = "Live", ApiBasketballStatusCode = "Q3" }, new RefGameStatus { FullGameStatusId = FullGameStatus.Live_Q4, FullGameStatusName = "Live - Q4", GameStatusId = GameStatus.Live, GameStatusName = "Live", ApiBasketballStatusCode = "Q4" }, new RefGameStatus { FullGameStatusId = FullGameStatus.Live_OT, FullGameStatusName = "Live - OT", GameStatusId = GameStatus.Live, GameStatusName = "Live", ApiBasketballStatusCode = "OT" }, new RefGameStatus { FullGameStatusId = FullGameStatus.Live_BK, FullGameStatusName = "Live - Break", GameStatusId = GameStatus.Live, GameStatusName = "Live", ApiBasketballStatusCode = "BT" }, new RefGameStatus { FullGameStatusId = FullGameStatus.Live_HT, FullGameStatusName = "Live - Halftime", GameStatusId = GameStatus.Live, GameStatusName = "Live", ApiBasketballStatusCode = "HT" }, new RefGameStatus { FullGameStatusId = FullGameStatus.Final, FullGameStatusName = "Final", GameStatusId = GameStatus.Final, GameStatusName = "Final", ApiBasketballStatusCode = "FT" }, new RefGameStatus { FullGameStatusId = FullGameStatus.FinalWithOT, FullGameStatusName = "Final (OT)", GameStatusId = GameStatus.Final, GameStatusName = "Final", ApiBasketballStatusCode = "AOT" }, new RefGameStatus { FullGameStatusId = FullGameStatus.Postponed, FullGameStatusName = "Postponed", GameStatusId = GameStatus.Postponed, GameStatusName = "Postponed", ApiBasketballStatusCode = "POST" }, new RefGameStatus { FullGameStatusId = FullGameStatus.Cancelled, FullGameStatusName = "Cancelled", GameStatusId = GameStatus.Cancelled, GameStatusName = "Cancelled", ApiBasketballStatusCode = "CANC" }, new RefGameStatus { FullGameStatusId = FullGameStatus.Unknown, FullGameStatusName = "Unknown", GameStatusId = GameStatus.Unknown, GameStatusName = "Unknown", ApiBasketballStatusCode = null } }); context.SaveChanges(); var bookmakersProcessor = new BookmakersProcessor(); Console.WriteLine("START BOOKMAKERS"); bookmakersProcessor.Run(context); Console.WriteLine("SAVE BOOKMAKERS"); context.SaveChanges(); Console.WriteLine("END BOOKMAKERS"); var betTypesProcessor = new BetTypesProcessor(); Console.WriteLine("START BET TYPES"); betTypesProcessor.Run(context); Console.WriteLine("SAVE BET TYPES"); context.SaveChanges(); Console.WriteLine("END BET TYPES"); var countriesProcessor = new CountriesProcessor(); Console.WriteLine("START COUNTRIES"); countriesProcessor.Run(context); Console.WriteLine("SAVE COUNTRIES"); context.SaveChanges(); Console.WriteLine("END COUNTRIES"); var leaguesProcessor = new LeaguesProcessor(); Console.WriteLine("START LEAGUES"); leaguesProcessor.Run(context); Console.WriteLine("SAVE LEAGUES"); context.SaveChanges(); Console.WriteLine("END LEAGUES"); var leagueSeasons = context.LeagueSeasons .OrderBy(x => x.LeagueSeasonId) .Select(y => new { y.ApiBasketballLeagueId, y.ApiBasketballSeasonKey }) .ToList(); foreach (var leagueSeason in leagueSeasons) { int leagueId = leagueSeason.ApiBasketballLeagueId; string seasonKey = leagueSeason.ApiBasketballSeasonKey; var teamsProcessor = new TeamsProcessor(leagueId, seasonKey); Console.WriteLine($"START TEAMS - {leagueId} {seasonKey}"); teamsProcessor.Run(context); Console.WriteLine($"SAVE TEAMS - {leagueId} {seasonKey}"); context.SaveChanges(); Console.WriteLine($"END TEAMS - {leagueId} {seasonKey}"); } var countriesDict = context.Countries.ToDictionary(x => x.ApiBasketballCountryId, y => y.CountryId); var teamsDict = context.Teams.ToDictionary(x => x.ApiBasketballTeamId, y => y.TeamId); var statusDict = context.RefGameStatuses .Where(x => !string.IsNullOrEmpty(x.ApiBasketballStatusCode)) .ToDictionary(x => x.ApiBasketballStatusCode, y => y.FullGameStatusId); foreach (var leagueSeason in leagueSeasons) { int leagueId = leagueSeason.ApiBasketballLeagueId; string seasonKey = leagueSeason.ApiBasketballSeasonKey; var gamesProcessor = new GamesProcessor(leagueId, seasonKey, countriesDict, statusDict); Console.WriteLine($"START GAMES - {leagueId} {seasonKey}"); gamesProcessor.Run(context); Console.WriteLine($"SAVE GAMES - {leagueId} {seasonKey}"); context.SaveChanges(); Console.WriteLine($"END GAMES - {leagueId} {seasonKey}"); } var bookmakersDict = context.Bookmakers.ToDictionary(x => x.ApiBasketballBookmakerId, y => y.BookmakerId); var betTypesDict = context.BetTypes.ToDictionary(x => x.ApiBasketballBetTypeId, y => y.BetTypeId); var liveAndUpcomingGameStatuses = context.RefGameStatuses .Where(x => x.GameStatusId == GameStatus.Pregame || x.GameStatusId == GameStatus.Live) .Select(x => x.FullGameStatusId) .ToList(); foreach (var leagueSeason in leagueSeasons) { int leagueId = leagueSeason.ApiBasketballLeagueId; string seasonKey = leagueSeason.ApiBasketballSeasonKey; var oddsProcessor = new OddsProcessor(leagueId, seasonKey, betTypesDict, bookmakersDict); Console.WriteLine($"START ODDS - {leagueId} {seasonKey}"); oddsProcessor.Run(context); Console.WriteLine($"SAVE ODDS - {leagueId} {seasonKey}"); context.SaveChanges(); Console.WriteLine($"END ODDS - {leagueId} {seasonKey}"); } } }