public ImportStat ImportZzzzzz() { string table = "Zzzzz"; var iStat = new ImportStat(_logger, table); if (_seed && _context.Seasons.Count() == 0) { _logger.Write("Importing " + table); iStat.Imported(); ContextSaveChanges(); iStat.Saved(_context.Seasons.Count()); } else { _logger.Write(table + " records exist in context; not importing"); iStat.Imported(); iStat.Saved(0); } iStat.Log(); return iStat; }
public ImportStat ImportGameTeams() { string table = "GameTeams"; var iStat = new ImportStat(_logger, table); if (_seed && _context.GameTeams.Count() == 0) { _logger.Write("Importing " + table); dynamic parsedJson = _jsonFileService.ParseObjectFromJsonFile(_folderPath + "Games.json"); int count = parsedJson.Count; _logger.Write("ImportGameTeams: Access records to process:" + count); int countSaveOrUpdated = 0; for (var d = 0; d < parsedJson.Count; d++) { if (d % 100 == 0) { _logger.Write("ImportGameTeams: Access records processed:" + d); } var json = parsedJson[d]; int gameId = json["GAME_ID"]; int seasonId = json["SEASON_ID"]; int homeTeamId, awayTeamId; homeTeamId = json["HOME_TEAM_ID"]; awayTeamId = json["AWAY_TEAM_ID"]; // FK check //_lo30ContextService.FindGame(gameId, errorIfNotFound: true, errorIfMoreThanOneFound: true, populateFully: false); //_lo30ContextService.FindTeam(homeTeamId, errorIfNotFound: true, errorIfMoreThanOneFound: true, populateFully: false); //_lo30ContextService.FindTeam(awayTeamId, errorIfNotFound: true, errorIfMoreThanOneFound: true, populateFully: false); var gameTeam = new GameTeam(sid: seasonId, gid: gameId, ht: true, tid: homeTeamId, otid: awayTeamId); countSaveOrUpdated = countSaveOrUpdated + _lo30ContextService.SaveOrUpdateGameTeam(gameTeam); gameTeam = new GameTeam(sid: seasonId, gid: gameId, ht: false, tid: awayTeamId, otid: homeTeamId); countSaveOrUpdated = countSaveOrUpdated + _lo30ContextService.SaveOrUpdateGameTeam(gameTeam); } iStat.Imported(); ContextSaveChanges(); iStat.Saved(_context.GameTeams.Count()); } else { _logger.Write(table + " records exist in context; not importing"); iStat.Imported(); iStat.Saved(0); } iStat.Log(); return iStat; }
public ImportStat ImportDivisions() { string table = "Divisions"; var iStat = new ImportStat(_logger, table); if (_seed && _context.Divisions.Count() == 0) { _logger.Write("Importing " + table); var division = new Division(did: 0, dln: "No Division", dsn: "n/a"); int saveOrUpdatedCount = +_lo30ContextService.SaveOrUpdateDivision(division); dynamic parsedJson = _jsonFileService.ParseObjectFromJsonFile(_folderPath + "Teams.json"); int count = parsedJson.Count; _logger.Write("Access records to process:" + count); for (var d = 0; d < parsedJson.Count; d++) { if (d % 100 == 0) { _logger.Write("Access records processed:" + d); } var json = parsedJson[d]; string divName = json["TEAM_DIVISION_NAME"]; if (!string.IsNullOrWhiteSpace(divName)) { var found = _lo30ContextService.FindDivisionByPK2(divName, errorIfNotFound: false, errorIfMoreThanOneFound: true, populateFully: false); if (found == null) { // only add new divisions division = new Division() { DivisionLongName = divName, DivisionShortName = "TBD" }; saveOrUpdatedCount = +_lo30ContextService.SaveOrUpdateDivision(division); } } } iStat.Imported(); ContextSaveChanges(); iStat.Saved(_context.Divisions.Count()); } else { _logger.Write(table + " records exist in context; not importing"); iStat.Imported(); iStat.Saved(0); } iStat.Log(); return iStat; }
public ImportStat ImportPenalties() { string table = "Penalties"; var iStat = new ImportStat(_logger, table); if (_seed && _context.Penalties.Count() == 0) { _logger.Write("Importing " + table); dynamic parsedJson = _jsonFileService.ParseObjectFromJsonFile(Path.Combine(_folderPath, "Penalties.json")); int count = parsedJson.Count; _logger.Write("Access records to process:" + count); for (var d = 0; d < parsedJson.Count; d++) { if (d % 100 == 0) { _logger.Write("Access records processed:" + d); } var json = parsedJson[d]; var penalty = new Penalty() { PenaltyId = json["PENALTY_ID"], PenaltyCode = json["PENALTY_SHORT_DESC"], PenaltyName = json["PENALTY_LONG_DESC"], DefaultPenaltyMinutes = json["DEFAULT_PENALTY_MINUTES"], StickPenalty = json["STICK_PENALTY"] }; _context.Penalties.Add(penalty); } iStat.Imported(); ContextSaveChanges(); iStat.Saved(_context.Penalties.Count()); } else { _logger.Write(table + " records exist in context; not importing"); iStat.Imported(); iStat.Saved(0); } iStat.Log(); return iStat; }
public ImportStat ImportPlayerStatusTypes() { string table = "PlayerStatusTypes"; var iStat = new ImportStat(_logger, table); if (_seed && _context.PlayerStatusTypes.Count() == 0) { _logger.Write("Importing " + table); dynamic parsedJson = _jsonFileService.ParseObjectFromJsonFile(_folderPath + "Statuses.json"); int count = parsedJson.Count; _logger.Write("Access records to process:" + count); for (var d = 0; d < parsedJson.Count; d++) { if (d % 100 == 0) { _logger.Write("Access records processed:" + d); } var json = parsedJson[d]; var playerStatusType = new PlayerStatusType() { PlayerStatusTypeId = json["STATUS_ID"], PlayerStatusTypeName = json["STATUS_DESC"] }; _context.PlayerStatusTypes.Add(playerStatusType); } _lo30ContextService.ContextSaveChanges(); iStat.Imported(); ContextSaveChanges(); iStat.Saved(_context.PlayerStatusTypes.Count()); } else { _logger.Write(table + " records exist in context; not importing"); iStat.Imported(); iStat.Saved(0); } iStat.Log(); return iStat; }
public ImportStat ImportGames() { string table = "Games"; var iStat = new ImportStat(_logger, table); if (_seed && _context.Games.Count() == 0) { _logger.Write("Importing " + table); dynamic parsedJson = _jsonFileService.ParseObjectFromJsonFile(_folderPath + "Games.json"); int count = parsedJson.Count; _logger.Write("SaveOrUpdateGames:Access records to process:" + count); int countSaveOrUpdated = 0; for (var d = 0; d < parsedJson.Count; d++) { if (d % 100 == 0) { _logger.Write("SaveOrUpdateGames:Access records processed:" + d); } var json = parsedJson[d]; int gameId = json["GAME_ID"]; //if (gameId >= startingGameIdToProcess && gameId <= endingGameIdToProcess) //{ int seasonId = json["SEASON_ID"]; DateTime gameDate = json["GAME_DATE"]; DateTime gameTime = json["GAME_TIME"]; bool playoffGame = json["PLAYOFF_GAME_IND"]; var timeSpan = new TimeSpan(gameTime.Hour, gameTime.Minute, gameTime.Second); var gameDateTime = gameDate.Add(timeSpan); var game = new Game( sid: seasonId, gid: gameId, time: gameDateTime, loc: "not set", pfs: playoffGame ); //context.Games.Add(game); // works only if never reprocessing data countSaveOrUpdated = countSaveOrUpdated + _lo30ContextService.SaveOrUpdateGame(game); //} } iStat.Imported(); ContextSaveChanges(); iStat.Saved(_context.Games.Count()); } else { _logger.Write(table + " records exist in context; not importing"); iStat.Imported(); iStat.Saved(0); } iStat.Log(); return iStat; }
public ImportStat ImportPlayerRatings() { string table = "PlayerRatings"; var iStat = new ImportStat(_logger, table); if (_seed && _context.PlayerRatings.Count() == 0) { _logger.Write("Importing " + table); dynamic parsedJson = _jsonFileService.ParseObjectFromJsonFile(_folderPath + "PlayerRatings.json"); int count = parsedJson.Count; int countSaveOrUpdated = 0; _logger.Write("Access records to process:" + count); for (var d = 0; d < parsedJson.Count; d++) { if (d % 100 == 0) { _logger.Write("Access records processed:" + d); } var json = parsedJson[d]; string[] ratingParts = new string[0]; if (json["PLAYER_RATING"] != null) { string rating = json["PLAYER_RATING"]; ratingParts = rating.Split('.'); } int ratingPrimary = -1; int ratingSecondary = -1; if (ratingParts.Length > 0) { ratingPrimary = Convert.ToInt32(ratingParts[0]); ratingSecondary = 0; if (ratingParts.Length > 1) { ratingSecondary = Convert.ToInt32(ratingParts[1]); } } int line = 0; if (json["PLAYER_LINE"] != null) { line = json["PLAYER_LINE"]; } int seasonId = json["SEASON_ID"]; int playerId = json["PLAYER_ID"]; if (playerId == 545 || playerId == 512 || playerId == 426 || playerId == 432 || playerId == 381 || playerId == 282) { // skip these players...they do not exist in the players table } else { var season = _lo30ContextService.FindSeason(seasonId); var playerDraft = _lo30ContextService.FindPlayerDraft(seasonId, playerId); // default the players rating to the start/end of the season var playerRating = new PlayerRating( sid: seasonId, pid: playerId, symd: season.StartYYYYMMDD, eymd: season.EndYYYYMMDD, rp: ratingPrimary, rs: ratingSecondary, line: line ); countSaveOrUpdated = countSaveOrUpdated + _lo30ContextService.SaveOrUpdatePlayerRating(playerRating); } } iStat.Imported(); ContextSaveChanges(); iStat.Saved(_context.PlayerRatings.Count()); // add missing players with default rating (0.0) //var players = _context.Players.ToList(); //foreach (var player in players) //{ // var found = _context.PlayerRatings.Where(x => x.PlayerId == player.PlayerId).ToList(); // if (found == null || found.Count == 0) // { // // TODO, remove hard coding // var season = _lo30ContextService.FindSeason(54); // // default the players rating to the start/end of the season // var playerRating = new PlayerRating( // sid: season.SeasonId, // pid: player.PlayerId, // symd: season.StartYYYYMMDD, // eymd: season.EndYYYYMMDD, // rp: 0, // rs: 0, // line: 0 // ); // countSaveOrUpdated = countSaveOrUpdated + _lo30ContextService.SaveOrUpdatePlayerRating(playerRating); // } //} } else { _logger.Write(table + " records exist in context; not importing"); iStat.Imported(); iStat.Saved(0); } iStat.Log(); return iStat; }
public ImportStat ImportScoreSheetEntryPenalties() { string table = "ScoreSheetEntryPenalty"; var iStat = new ImportStat(_logger, table); if (_seed && _context.ScoreSheetEntryPenalties.Count() == 0) { _logger.Write("Importing " + table); dynamic parsedJson = _jsonFileService.ParseObjectFromJsonFile(_folderPath + "ScoreSheetEntryPenalties.json"); int count = parsedJson.Count; int countSaveOrUpdated = 0; for (var d = 0; d < parsedJson.Count; d++) { if (d % 100 == 0) { _logger.Write("ImportScoreSheetEntryPenalties: Access records processed:" + d + ". Records saved or updated:" + countSaveOrUpdated); } var json = parsedJson[d]; int gameId = json["GAME_ID"]; //if (gameId >= startingGameIdToProcess && gameId <= endingGameIdToProcess) { bool homeTeam = true; string teamJson = json["TEAM"]; string team = teamJson.ToLower(); if (team == "2" || team == "v" || team == "a" || team == "g") { homeTeam = false; } DateTime updatedOn = json["UPDATED_ON"]; var scoreSheetEntryPenalty = new ScoreSheetEntryPenalty() { ScoreSheetEntryPenaltyId = json["SCORE_SHEET_ENTRY_PENALTY_ID"], GameId = json["GAME_ID"], Period = json["PERIOD"], HomeTeam = homeTeam, Player = json["PLAYER"], PenaltyCode = json["PENALTY_CODE"], TimeRemaining = json["TIME_REMAINING"], PenaltyMinutes = json["PENALTY_MINUTES"], UpdatedOn = updatedOn }; countSaveOrUpdated = countSaveOrUpdated + _lo30ContextService.SaveOrUpdateScoreSheetEntryPenalty(scoreSheetEntryPenalty); } } iStat.Imported(); ContextSaveChanges(); iStat.Saved(_context.ScoreSheetEntryGoals.Count()); } else { _logger.Write(table + " records exist in context; not importing"); iStat.Imported(); iStat.Saved(0); } iStat.Log(); return iStat; }
public ImportStat ImportTeamRosters() { string table = "TeamRosters"; var iStat = new ImportStat(_logger, table); if (_seed && _context.TeamRosters.Count() == 0) { _logger.Write("Importing " + table); dynamic parsedJson = _jsonFileService.ParseObjectFromJsonFile(_folderPath + "TeamRosters.json"); int count = parsedJson.Count; _logger.Write("SaveOrUpdateTeamRosters: Access records to process:" + count); int countSaveOrUpdated = 0; for (var d = 0; d < parsedJson.Count; d++) { if (d % 100 == 0) { _logger.Write("SaveOrUpdateTeamRosters: Access records processed:" + d); } var json = parsedJson[d]; int seasonId = json["SEASON_ID"]; bool playoff = json["PLAYOFF_SEASON_IND"]; int teamId = json["TEAM_ID"]; int playerId = json["PLAYER_ID"]; int playerNumber = -1; if (json["PLAYER_NUMBER"] != null) { playerNumber = json["PLAYER_NUMBER"]; } // based on the draft spot, determine team roster line and position var team = _lo30ContextService.FindTeam(teamId); var season = _lo30ContextService.FindSeason(seasonId); PlayerDraft playerDraft; if (team.SeasonId == 54 && playoff == false && playerId == 66) { // HACK FIX for Bill Hamilton rostered sub playerDraft = new PlayerDraft(sid: team.SeasonId, pid: playerId, rnd: 4, ord: -1, pos: "F", line: 1, spcl: false); } else if (team.SeasonId == 54 && playoff == false && playerId == 662) { // HACK FIX for Matt Spease rostered sub playerDraft = new PlayerDraft(sid: team.SeasonId, pid: playerId, rnd: 10, ord: -1, pos: "F", line: 2, spcl: false); } else if (team.SeasonId == 54 && playoff == true && playerId == 674) { // HACK FIX for Bob Hickson rostered sub playerDraft = new PlayerDraft(sid: team.SeasonId, pid: playerId, rnd: -1, ord: -1, pos: "D", line: 1, spcl: false); } else if (team.SeasonId == 54 && playoff == true && playerId == 681) { // HACK FIX for Geoff Cutsy rostered sub playerDraft = new PlayerDraft(sid: team.SeasonId, pid: playerId, rnd: -1, ord: -1, pos: "F", line: 1, spcl: false); } else if (team.SeasonId == 54 && playoff == true && playerId == 757) { // HACK FIX for Gary Zielke rostered sub playerDraft = new PlayerDraft(sid: team.SeasonId, pid: playerId, rnd: -1, ord: -1, pos: "D", line: 1, spcl: false); } else if (team.SeasonId == 54 && playoff == true && playerId == 758) { // HACK FIX for Paul Fretter rostered sub playerDraft = new PlayerDraft(sid: team.SeasonId, pid: playerId, rnd: -1, ord: -1, pos: "F", line: 3, spcl: false); } else if (team.SeasonId == 54 && playoff == true && playerId == 721) { // HACK FIX for Tom Small rostered sub playerDraft = new PlayerDraft(sid: team.SeasonId, pid: playerId, rnd: -1, ord: -1, pos: "D", line: 2, spcl: false); } else if (team.SeasonId == 54 && playoff == true && playerId == 581) { // HACK FIX for Kyle Krupsky rostered sub playerDraft = new PlayerDraft(sid: team.SeasonId, pid: playerId, rnd: -1, ord: -1, pos: "F", line: 2, spcl: false); } else { playerDraft = _lo30ContextService.FindPlayerDraft(team.SeasonId, playerId); } PlayerRating playerRating; if (team.SeasonId == 54 && playoff == false && playerId == 66) { // HACK FIX for Bill Hamilton rostered sub playerRating = new PlayerRating(sid: team.SeasonId, pid: playerId, symd: 20140904, eymd: 20141031, rp: 2, rs: 1, line: 1, pos: "F"); } else if (team.SeasonId == 54 && playoff == false && playerId == 662) { // HACK FIX for Matt Spease rostered sub playerRating = new PlayerRating(sid: team.SeasonId, pid: playerId, symd: 20140904, eymd: 20141031, rp: 6, rs: 2, line: 2, pos: "F"); } else { playerRating = _lo30ContextService.FindPlayerRatingWithYYYYMMDD(playerId, playerDraft.Position, team.SeasonId, season.StartYYYYMMDD); } // default the team roster to the start/end of the season TeamRoster teamRoster; if (team.SeasonId == 54 && playoff == false && playerId == 710) { // HACK FIX for Bill Hamilton rostered sub (Howard) // add billy teamRoster = new TeamRoster(sid: team.SeasonId, tid: team.TeamId, pid: 66, symd: 20140904, eymd: 20141031, pos: "F", rp: 2, rs: 1, line: 1, pn: 15); countSaveOrUpdated = countSaveOrUpdated + _lo30ContextService.SaveOrUpdateTeamRoster(teamRoster); // add howard teamRoster = new TeamRoster(sid: team.SeasonId, tid: team.TeamId, pid: playerId, symd: 20141101, eymd: 20150118, pos: playerDraft.Position, rp: playerRating.RatingPrimary, rs: playerRating.RatingSecondary, line: playerDraft.Line, pn: playerNumber); countSaveOrUpdated = countSaveOrUpdated + _lo30ContextService.SaveOrUpdateTeamRoster(teamRoster); } else if (team.SeasonId == 54 && playoff == false && playerId == 708) { // HACK FIX for Matt Spease rostered sub (Vince) // add matt teamRoster = new TeamRoster(sid: team.SeasonId, tid: team.TeamId, pid: 662, symd: 20140904, eymd: 20141031, pos: "F", rp: 6, rs: 2, line: 2, pn: 17); countSaveOrUpdated = countSaveOrUpdated + _lo30ContextService.SaveOrUpdateTeamRoster(teamRoster); // add vince teamRoster = new TeamRoster(sid: team.SeasonId, tid: team.TeamId, pid: playerId, symd: 20141101, eymd: 20150118, pos: playerDraft.Position, rp: playerRating.RatingPrimary, rs: playerRating.RatingSecondary, line: playerDraft.Line, pn: playerNumber); countSaveOrUpdated = countSaveOrUpdated + _lo30ContextService.SaveOrUpdateTeamRoster(teamRoster); } else { #region else int startYYYYMMDD, endYYYYMMDD; if ( seasonId == 54 && playoff == true && ( playerId == 762 || playerId == 64 || playerId == 594 || playerId == 33 || playerId == 178 || playerId == 674 || playerId == 581 || playerId == 721 || playerId == 757 || playerId == 758 ) ) { // 762 Scott Ranta, 64 Mark Ranta, 594 BJ to LAB // 33 Todd Keller to Zas Ent // 178 Ken Grant, 674 Bob Hickson (708 Vince DeMassa...from regular season) to Bill Brown // 581 Kyle Krupsky (710 Howard Schoenfeldt...from regular season) to D&G // 721 Tom Small to Hunt's Ace // 757 Gary Zielke, 758 Paul Fretter to Glover // 686 Kris Medico, 681 Geoff Cutsy to DPKZ (Joe/Pete still on same team) startYYYYMMDD = 20150122; endYYYYMMDD = 20150322; } else if ( seasonId == 54 && playoff == true && ( playerId == 708 || playerId == 710 ) ) { // (708 Vince DeMassa...from regular season) to Bill Brown // (710 Howard Schoenfeldt...from regular season) to D&G startYYYYMMDD = 20141101; endYYYYMMDD = 20150322; } else if (seasonId == 54 && playoff == false) { // if roster is before playoffs, we don't know if they will be traded // so default to end of regular season date...so if they get traded, don't have to // go back and update the old/initial record startYYYYMMDD = 20140904; endYYYYMMDD = 20150118; } else if (seasonId == 54 && playoff == true) { // if they were not one of the guys who were affected by the trades, // change their end date to the end of the year startYYYYMMDD = 20140904; endYYYYMMDD = 20150322; } else { startYYYYMMDD = season.StartYYYYMMDD; endYYYYMMDD = season.EndYYYYMMDD; } teamRoster = new TeamRoster(sid: team.SeasonId, tid: team.TeamId, pid: playerId, symd: startYYYYMMDD, eymd: endYYYYMMDD, pos: playerDraft.Position, rp: playerRating.RatingPrimary, rs: playerRating.RatingSecondary, line: playerDraft.Line, pn: playerNumber); countSaveOrUpdated = countSaveOrUpdated + _lo30ContextService.SaveOrUpdateTeamRoster(teamRoster); #endregion } } iStat.Imported(); ContextSaveChanges(); iStat.Saved(_context.TeamRosters.Count()); } else { _logger.Write(table + " records exist in context; not importing"); iStat.Imported(); iStat.Saved(0); } iStat.Log(); return iStat; }
public ImportStat ImportPlayers() { string table = "Players"; var iStat = new ImportStat(_logger, table); if (_seed && _context.Players.Count() == 0) { _logger.Write("Importing " + table); var player = new Player() { PlayerId = 0, FirstName = "Unknown", LastName = "Player", Suffix = null, PreferredPosition = "X", Shoots = "X", BirthDate = DateTime.Parse("1/1/1970"), Profession = null, WifesName = null }; _lo30ContextService.SaveOrUpdatePlayer(player); dynamic parsedJson = _jsonFileService.ParseObjectFromJsonFile(_folderPath + "Players.json"); int count = parsedJson.Count; int countSaveOrUpdated = 0; _logger.Write("SaveOrUpdatePlayers: Access records to process:" + count); for (var d = 0; d < parsedJson.Count; d++) { if (d % 100 == 0) { _logger.Write("SaveOrUpdatePlayers: Access records processed:" + d + ". Records saved or updated:" + countSaveOrUpdated); } var json = parsedJson[d]; int playerId = json["PLAYER_ID"]; string firstName = json["PLAYER_FIRST_NAME"]; if (string.IsNullOrWhiteSpace(firstName)) { firstName = "_"; }; string lastName = json["PLAYER_LAST_NAME"]; if (string.IsNullOrWhiteSpace(lastName)) { lastName = "_"; }; string position, positionMapped; position = json["PLAYER_POSITION"]; if (string.IsNullOrWhiteSpace(position)) { position = "X"; } switch (position.ToLower()) { case "f": case "forward": positionMapped = "F"; break; case "d": case "defense": positionMapped = "D"; break; case "g": case "goal": case "goalie": positionMapped = "G"; break; default: positionMapped = "X"; break; } string shoots, shootsMapped; shoots = json["SHOOTS"]; if (string.IsNullOrWhiteSpace(shoots)) { shoots = "X"; } switch (shoots.ToLower()) { case "l": shootsMapped = "L"; break; case "r": shootsMapped = "R"; break; default: shootsMapped = "X"; break; } DateTime? birthDate = null; if (json["BIRTHDATE"] != null) { birthDate = json["BIRTHDATE"]; } player = new Player() { PlayerId = playerId, FirstName = firstName, LastName = lastName, Suffix = json["PLAYER_SUFFIX"], PreferredPosition = positionMapped, Shoots = shootsMapped, BirthDate = birthDate, Profession = json["PROFESSION"], WifesName = json["WIFES_NAME"] }; countSaveOrUpdated = countSaveOrUpdated + _lo30ContextService.SaveOrUpdatePlayer(player); } iStat.Imported(); ContextSaveChanges(); iStat.Saved(_context.Players.Count()); } else { _logger.Write(table + " records exist in context; not importing"); iStat.Imported(); iStat.Saved(0); } iStat.Log(); return iStat; }
public ImportStat ImportGameRosters() { string table = "GameRosters"; var iStat = new ImportStat(_logger, table); if (_seed && _context.GameRosters.Count() == 0) { _logger.Write("Importing " + table); dynamic parsedJsonGR = _jsonFileService.ParseObjectFromJsonFile(_folderPath + "GameRosters.json"); int countGR = parsedJsonGR.Count; int countSaveOrUpdated = 0; _logger.Write("ImportGameRosters: Access records to process:" + countGR); for (var d = 0; d < parsedJsonGR.Count; d++) { if (d % 100 == 0) { _logger.Write("ImportGameRosters: Access records processed:" + d + ". Records saved or updated:" + countSaveOrUpdated); } var json = parsedJsonGR[d]; int seasonId = json["SEASON_ID"]; int gameId = json["GAME_ID"]; //if (gameId >= startingGameIdToProcess && gameId <= endingGameIdToProcess) if ( gameId == 3196 || gameId == 3197 || gameId == 3198 || gameId == 3199 || gameId == 3998 || gameId == 3999 || gameId == 3400 || gameId == 3401 ) { // do nothing, practice games } else { var game = _lo30ContextService.FindGame(gameId); var gameDateYYYYMMDD = ConvertDateTimeIntoYYYYMMDD(game.GameDateTime, ifNullReturnMax: false); //var homeGameTeamId = _lo30ContextService.FindGameTeamByPK2(gameId, homeTeam: true).GameTeamId; //var awayGameTeamId = _lo30ContextService.FindGameTeamByPK2(gameId, homeTeam: false).GameTeamId; int homeTeamId = -1; if (json["HOME_TEAM_ID"] != null) { homeTeamId = json["HOME_TEAM_ID"]; } int homePlayerId = -1; if (json["HOME_PLAYER_ID"] != null) { homePlayerId = json["HOME_PLAYER_ID"]; } int homeSubPlayerId = -1; if (json["HOME_SUB_FOR_PLAYER_ID"] != null) { homeSubPlayerId = json["HOME_SUB_FOR_PLAYER_ID"]; } bool homePlayerSubInd = false; if (json["HOME_PLAYER_SUB_IND"] != null) { homePlayerSubInd = json["HOME_PLAYER_SUB_IND"]; } int homePlayerNumber = -1; if (json["HOME_PLAYER_NUMBER"] != null) { homePlayerNumber = json["HOME_PLAYER_NUMBER"]; } if (homeTeamId == -1) { _logger.Write(string.Format("ImportGameRosters: The homeTeamId is -1, not sure how to process. homeTeamId:{0}, homePlayerId:{1}, homeSubPlayerId:{2}, homePlayerSubInd:{3}, homePlayerNumber:{4}, gameId:{5}", homeTeamId, homePlayerId, homeSubPlayerId, homePlayerSubInd, homePlayerNumber, gameId)); } else if (homePlayerId == -1) { _logger.Write(string.Format("ImportGameRosters: The homePlayerId is -1, not sure how to process. homeTeamId:{0}, homePlayerId:{1}, homeSubPlayerId:{2}, homePlayerSubInd:{3}, homePlayerNumber:{4}, gameId:{5}", homeTeamId, homePlayerId, homeSubPlayerId, homePlayerSubInd, homePlayerNumber, gameId)); } else if (homePlayerNumber == -1) { _logger.Write(string.Format("ImportGameRosters: The homePlayerNumber is -1, not sure how to process. homeTeamId:{0}, homePlayerId:{1}, homeSubPlayerId:{2}, homePlayerSubInd:{3}, homePlayerNumber:{4}, gameId:{5}", homeTeamId, homePlayerId, homeSubPlayerId, homePlayerSubInd, homePlayerNumber, gameId)); } // set the line and position equal to the players drafted / set line position from the team roster var homeTeamRoster = _lo30ContextService.FindTeamRosterWithYYYYMMDD(homeTeamId, homePlayerId, gameDateYYYYMMDD); int homePlayerLine = homeTeamRoster.Line; string homePlayerPosition = homeTeamRoster.Position; int playerId; int? subbingForPlayerId; if (homePlayerSubInd) { playerId = homeSubPlayerId; subbingForPlayerId = homePlayerId; } else { playerId = homePlayerId; subbingForPlayerId = null; } bool isGoalie = false; if (homeTeamRoster.Position == "G") { isGoalie = true; } int ratingPrimary = 0; int ratingSecondary = 0; var playerRating = _lo30ContextService.FindPlayerRatingWithYYYYMMDD(playerId, homePlayerPosition, seasonId, gameDateYYYYMMDD, errorIfNotFound: false); if (playerRating != null) { ratingPrimary = playerRating.RatingPrimary; ratingSecondary = playerRating.RatingSecondary; } var gameRoster = new GameRoster( sid: seasonId, tid: homeTeamId, gid: gameId, pid: playerId, pn: homePlayerNumber.ToString(), pos: homePlayerPosition, rp: ratingPrimary, rs: ratingSecondary, line: homePlayerLine, g: isGoalie, sub: homePlayerSubInd, sfpid: subbingForPlayerId ); countSaveOrUpdated = countSaveOrUpdated + _lo30ContextService.SaveOrUpdateGameRoster(gameRoster); int awayTeamId = -1; if (json["AWAY_TEAM_ID"] != null) { awayTeamId = json["AWAY_TEAM_ID"]; } int awayPlayerId = -1; if (json["AWAY_PLAYER_ID"] != null) { awayPlayerId = json["AWAY_PLAYER_ID"]; } int awaySubPlayerId = -1; if (json["AWAY_SUB_FOR_PLAYER_ID"] != null) { awaySubPlayerId = json["AWAY_SUB_FOR_PLAYER_ID"]; } bool awayPlayerSubInd = false; if (json["AWAY_PLAYER_SUB_IND"] != null) { awayPlayerSubInd = json["AWAY_PLAYER_SUB_IND"]; } int awayPlayerNumber = -1; if (json["AWAY_PLAYER_NUMBER"] != null) { awayPlayerNumber = json["AWAY_PLAYER_NUMBER"]; } if (awayTeamId == -1) { _logger.Write(string.Format("SaveOrUpdateGameRosters: The awayTeamId is -1, not sure how to process. awayTeamId:{0}, awayPlayerId:{1}, awaySubPlayerId:{2}, awayPlayerSubInd:{3}, awayPlayerNumber:{4}, gameId:{5}", awayTeamId, awayPlayerId, awaySubPlayerId, awayPlayerSubInd, awayPlayerNumber, gameId)); } else if (awayPlayerId == -1) { _logger.Write(string.Format("SaveOrUpdateGameRosters: The awayPlayerId is -1, not sure how to process. awayTeamId:{0}, awayPlayerId:{1}, awaySubPlayerId:{2}, awayPlayerSubInd:{3}, awayPlayerNumber:{4}, gameId:{5}", awayTeamId, awayPlayerId, awaySubPlayerId, awayPlayerSubInd, awayPlayerNumber, gameId)); } else if (awayPlayerNumber == -1) { _logger.Write(string.Format("SaveOrUpdateGameRosters: The awayPlayerNumber is -1, not sure how to process. awayTeamId:{0}, awayPlayerId:{1}, awaySubPlayerId:{2}, awayPlayerSubInd:{3}, awayPlayerNumber:{4}, gameId:{5}", awayTeamId, awayPlayerId, awaySubPlayerId, awayPlayerSubInd, awayPlayerNumber, gameId)); } if (awayPlayerSubInd) { playerId = awaySubPlayerId; subbingForPlayerId = awayPlayerId; } else { playerId = awayPlayerId; subbingForPlayerId = null; } // set the line and position equal to the players drafted / set line position from the team roster var awayTeamRoster = _lo30ContextService.FindTeamRosterWithYYYYMMDD(awayTeamId, awayPlayerId, gameDateYYYYMMDD); int awayPlayerLine = awayTeamRoster.Line; string awayPlayerPosition = awayTeamRoster.Position; isGoalie = false; if (awayTeamRoster.Position == "G") { isGoalie = true; } ratingPrimary = 0; ratingSecondary = 0; playerRating = _lo30ContextService.FindPlayerRatingWithYYYYMMDD(playerId, awayPlayerPosition, seasonId, gameDateYYYYMMDD, errorIfNotFound: false); if (playerRating != null) { ratingPrimary = playerRating.RatingPrimary; ratingSecondary = playerRating.RatingSecondary; } gameRoster = new GameRoster( sid: seasonId, tid: awayTeamId, gid: gameId, pid: playerId, pn: awayPlayerNumber.ToString(), pos: awayPlayerPosition, rp: ratingPrimary, rs: ratingSecondary, line: awayPlayerLine, g: isGoalie, sub: awayPlayerSubInd, sfpid: subbingForPlayerId ); countSaveOrUpdated = countSaveOrUpdated + _lo30ContextService.SaveOrUpdateGameRoster(gameRoster); } } iStat.Imported(); ContextSaveChanges(); iStat.Saved(_context.GameRosters.Count()); } else { _logger.Write(table + " records exist in context; not importing"); iStat.Imported(); iStat.Saved(0); } iStat.Log(); return iStat; }
public ImportStat ImportSeasons() { string table = "Seasons"; var iStat = new ImportStat(_logger, table); if (_seed && _context.Seasons.Count() == 0) { _logger.Write("Importing " + table); #region add placeholder season var seasonIdPlaceholder = -1; var season = new Season(sid: seasonIdPlaceholder, sn: "Placeholder", ics: false, stymd: 0, endymd: 0); _context.Seasons.Add(season); #endregion dynamic parsedJson = _jsonFileService.ParseObjectFromJsonFile(_folderPath + "Seasons.json"); int count = parsedJson.Count; _logger.Write("Access records to process:" + count); for (var d = 0; d < parsedJson.Count; d++) { if (d % 100 == 0) { Console.WriteLine("Access records processed:" + d); } var json = parsedJson[d]; DateTime? startDate = null; DateTime? endDate = null; if (json["START_DATE"] != null) { startDate = json["START_DATE"]; } if (json["END_DATE"] != null) { endDate = json["END_DATE"]; } int seasonId = json["SEASON_ID"]; if (seasonId == 54) { startDate = new DateTime(2014, 9, 4); endDate = new DateTime(2015, 3, 29); } season = new Season(sid: seasonId, sn: json["SEASON_NAME"].ToString(), ics: Convert.ToBoolean(json["CURRENT_SEASON_IND"]), stymd: ConvertDateTimeIntoYYYYMMDD(startDate, ifNullReturnMax: false), endymd: ConvertDateTimeIntoYYYYMMDD(endDate, ifNullReturnMax: true)); _context.Seasons.Add(season); } iStat.Imported(); ContextSaveChanges(); iStat.Saved(_context.Seasons.Count()); } else { _logger.Write(table + " records exist in context; not importing"); iStat.Imported(); iStat.Saved(0); } iStat.Log(); return iStat; }
public ImportStat ImportTeams() { string table = "Teams"; var iStat = new ImportStat(_logger, table); if (_seed && _context.Teams.Count() == 0) { _logger.Write("Importing " + table); #region add position night teams var seasonIdPlaceholder = -1; var divisionIdPlaceholder = 1; var team = new Team(sid: seasonIdPlaceholder, tid: -1, tc: "1TH", tns: "1st Place", tnl: "1st Place Team Placeholder", did: divisionIdPlaceholder); _context.Teams.Add(team); team = new Team(sid: seasonIdPlaceholder, tid: -2, tc: "2TH", tns: "2nd Place", tnl: "2nd Place Team Placeholder", did: divisionIdPlaceholder); _context.Teams.Add(team); team = new Team(sid: seasonIdPlaceholder, tid: -3, tc: "3TH", tns: "3rd Place", tnl: "3rd Place Team Placeholder", did: divisionIdPlaceholder); _context.Teams.Add(team); team = new Team(sid: seasonIdPlaceholder, tid: -4, tc: "4TH", tns: "4th Place", tnl: "4th Place Team Placeholder", did: divisionIdPlaceholder); _context.Teams.Add(team); team = new Team(sid: seasonIdPlaceholder, tid: -5, tc: "5TH", tns: "5th Place", tnl: "5th Place Team Placeholder", did: divisionIdPlaceholder); _context.Teams.Add(team); team = new Team(sid: seasonIdPlaceholder, tid: -6, tc: "6TH", tns: "6th Place", tnl: "6th Place Team Placeholder", did: divisionIdPlaceholder); _context.Teams.Add(team); team = new Team(sid: seasonIdPlaceholder, tid: -7, tc: "7TH", tns: "7th Place", tnl: "7th Place Team Placeholder", did: divisionIdPlaceholder); _context.Teams.Add(team); team = new Team(sid: seasonIdPlaceholder, tid: -8, tc: "8TH", tns: "8th Place", tnl: "8th Place Team Placeholder", did: divisionIdPlaceholder); _context.Teams.Add(team); team = new Team(sid: seasonIdPlaceholder, tid: -9, tc: "9TH", tns: "9th Place", tnl: "9th Place Team Placeholder", did: divisionIdPlaceholder); _context.Teams.Add(team); team = new Team(sid: seasonIdPlaceholder, tid: -10, tc: "10TH", tns: "10th Place", tnl: "10th Place Team Placeholder", did: divisionIdPlaceholder); _context.Teams.Add(team); team = new Team(sid: seasonIdPlaceholder, tid: -11, tc: "11TH", tns: "11th Place", tnl: "11th Place Team Placeholder", did: divisionIdPlaceholder); _context.Teams.Add(team); team = new Team(sid: seasonIdPlaceholder, tid: -12, tc: "12TH", tns: "12th Place", tnl: "12th Place Team Placeholder", did: divisionIdPlaceholder); _context.Teams.Add(team); team = new Team(sid: seasonIdPlaceholder, tid: -13, tc: "13TH", tns: "13th Place", tnl: "13th Place Team Placeholder", did: divisionIdPlaceholder); _context.Teams.Add(team); team = new Team(sid: seasonIdPlaceholder, tid: -14, tc: "14TH", tns: "14th Place", tnl: "14th Place Team Placeholder", did: divisionIdPlaceholder); _context.Teams.Add(team); team = new Team(sid: seasonIdPlaceholder, tid: -15, tc: "15TH", tns: "15th Place", tnl: "15th Place Team Placeholder", did: divisionIdPlaceholder); _context.Teams.Add(team); team = new Team(sid: seasonIdPlaceholder, tid: -16, tc: "16TH", tns: "16th Place", tnl: "16th Place Team Placeholder", did: divisionIdPlaceholder); _context.Teams.Add(team); #endregion dynamic parsedJson = _jsonFileService.ParseObjectFromJsonFile(_folderPath + "Teams.json"); int count = parsedJson.Count; _logger.Write("Access records to process:" + count); for (var d = 0; d < parsedJson.Count; d++) { if (d % 100 == 0) { _logger.Write("Access records processed:" + d); } var json = parsedJson[d]; string teamCode = json["TEAM_SHORT_NAME"].ToString(); if (teamCode.Length > 5) { teamCode = teamCode.Substring(0, 5); } team = new Team(sid: Convert.ToInt32(json["SEASON_ID"]), tid: Convert.ToInt32(json["TEAM_ID"]), tc: teamCode, tns: json["TEAM_SHORT_NAME"].ToString(), tnl: json["TEAM_LONG_NAME"].ToString(), did: divisionIdPlaceholder); _context.Teams.Add(team); } iStat.Imported(); ContextSaveChanges(); iStat.Saved(_context.Teams.Count()); } else { _logger.Write(table + " records exist in context; not importing"); iStat.Imported(); iStat.Saved(0); } iStat.Log(); return iStat; }
public ImportStat ImportPlayerStatuses() { string table = "PlayerStatuses"; var iStat = new ImportStat(_logger, table); if (_seed && _context.PlayerStatuses.Count() == 0) { _logger.Write("Importing " + table); dynamic parsedJson = _jsonFileService.ParseObjectFromJsonFile(_folderPath + "PlayerStatuses.json"); int count = parsedJson.Count; _logger.Write("Access records to process:" + count); for (var d = 0; d < parsedJson.Count; d++) { if (d % 100 == 0) { _logger.Write("Access records processed:" + d); } var json = parsedJson[d]; int playerId = json["PLAYER_ID"]; if (playerId == 512 || playerId == 545 || playerId == 571 || playerId == 170 || playerId == 211 || playerId == 213 || playerId == 215 || playerId == 217 || playerId == 282 || playerId == 381 || playerId == 426 || playerId == 432 || playerId == 767) { // do nothing, these guys do not have a player record } else { DateTime? startDate = json["START_DATE"]; DateTime? endDate = json["END_DATE"]; int startYYYYMMDD = ConvertDateTimeIntoYYYYMMDD(startDate, ifNullReturnMax: false); int endYYYYMMDD = ConvertDateTimeIntoYYYYMMDD(endDate, ifNullReturnMax: true); var playerStatus = new PlayerStatus() { PlayerId = playerId, PlayerStatusTypeId = json["STATUS_ID"], StartYYYYMMDD = startYYYYMMDD, EndYYYYMMDD = endYYYYMMDD, CurrentStatus = false }; _context.PlayerStatuses.Add(playerStatus); } } iStat.Imported(); ContextSaveChanges(); iStat.Saved(_context.PlayerStatuses.Count()); // determine the current status var currentPlayerStatus = _context.PlayerStatuses .GroupBy(x => new { x.PlayerId }) .Select(grp => new { PlayerId = grp.Key.PlayerId, EndYYYYMMDD = grp.Max(x => x.EndYYYYMMDD) }) .ToList(); // now update those records foreach (var current in currentPlayerStatus) { var playerStatus = _context.PlayerStatuses.Where(x => x.PlayerId == current.PlayerId && x.EndYYYYMMDD == current.EndYYYYMMDD).FirstOrDefault(); playerStatus.CurrentStatus = true; } int updated = _lo30ContextService.ContextSaveChanges(); _logger.Write("Data Group 3: Updated PlayerStatuses Current " + updated); } else { _logger.Write(table + " records exist in context; not importing"); iStat.Imported(); iStat.Saved(0); } iStat.Log(); return iStat; }
public ImportStat ImportPlayerDrafts() { string table = "PlayerDrafts"; var iStat = new ImportStat(_logger, table); if (_seed && _context.PlayerDrafts.Count() == 0) { _logger.Write("Importing " + table); dynamic parsedJson = _jsonFileService.ParseObjectFromJsonFile(_folderPath + "PlayerRatings.json"); int count = parsedJson.Count; int countSaveOrUpdated = 0; _logger.Write("Access records to process:" + count); for (var d = 0; d < parsedJson.Count; d++) { if (d % 100 == 0) { _logger.Write("Access records processed:" + d); } var json = parsedJson[d]; int seasonId = json["SEASON_ID"]; int playerId = json["PLAYER_ID"]; string draftRound = ""; string position = ""; if (json["PLAYER_DRAFT_ROUND"] != null) { draftRound = json["PLAYER_DRAFT_ROUND"]; } int round = -1; int line = -1; switch (draftRound.ToLower()) { case "g": case "1g": case "2g": case "3g": case "4g": case "5g": case "6g": case "7g": case "8g": position = "G"; line = 1; round = 1; break; case "1d": position = "D"; line = 1; round = 2; break; case "2d": position = "D"; line = 1; round = 5; break; case "3d": position = "D"; line = 2; round = 8; break; case "4d": position = "D"; line = 2; round = 11; break; case "5d": position = "D"; line = 3; break; case "6d": position = "D"; line = 3; round = 14; break; case "1f": position = "F"; line = 1; round = 3; break; case "2f": position = "F"; line = 1; round = 4; break; case "3f": position = "F"; line = 1; round = 6; break; case "4f": position = "F"; line = 2; round = 7; break; case "5f": position = "F"; line = 2; round = 9; break; case "6f": position = "F"; line = 2; round = 10; break; case "7f": position = "F"; line = 3; round = 12; break; case "8f": position = "F"; line = 3; round = 13; break; case "9f": position = "F"; line = 3; round = 15; break; } if (playerId == 545 || playerId == 512 || playerId == 426 || playerId == 432 || playerId == 381 || playerId == 282) { // skip these players...they do not exist in the players table } else { var playerDraft = new PlayerDraft() { SeasonId = seasonId, PlayerId = playerId, Round = round, Order = -1, Position = position, Line = line, Special = false }; countSaveOrUpdated = countSaveOrUpdated + _lo30ContextService.SaveOrUpdatePlayerDraft(playerDraft); } } iStat.Imported(); ContextSaveChanges(); iStat.Saved(_context.PlayerDrafts.Count()); } else { _logger.Write(table + " records exist in context; not importing"); iStat.Imported(); iStat.Saved(0); } iStat.Log(); return iStat; }
public ImportStat ImportScoreSheetEntrySubs() { string table = "ScoreSheetEntrySub"; var iStat = new ImportStat(_logger, table); if (_seed && _context.ScoreSheetEntrySubs.Count() == 0) { _logger.Write("Importing " + table); dynamic parsedJson = _jsonFileService.ParseObjectFromJsonFile(_folderPath + "ScoreSheetEntrySubs.json"); int count = parsedJson.Count; int countSaveOrUpdated = 0; for (var d = 0; d < parsedJson.Count; d++) { if (d % 100 == 0) { _logger.Write("ImportScoreSheetEntrySubs: Access records processed:" + d + ". Records saved or updated:" + countSaveOrUpdated); } var json = parsedJson[d]; int gameId = json["GAME_ID"]; //if (gameId >= startingGameIdToProcess && gameId <= endingGameIdToProcess) { bool homeTeam = true; string teamJson = json["TEAM"]; string team = teamJson.ToLower(); if (team == "2" || team == "v" || team == "a" || team == "g") { homeTeam = false; } int seasonId = json["SEASON_ID"]; string jersey = json["JERSEY"]; int subId = json["SUB_ID"]; int subForId = json["SUB_FOR_ID"]; DateTime updatedOn = json["UPDATED_ON"]; var scoreSheetEntrySub = new ScoreSheetEntrySub() { ScoreSheetEntrySubId = json["SCORE_SHEET_ENTRY_SUB_ID"], GameId = gameId, SubPlayerId = subId, HomeTeam = homeTeam, SubbingForPlayerId = subForId, JerseyNumber = jersey, UpdatedOn = updatedOn }; countSaveOrUpdated = countSaveOrUpdated + _lo30ContextService.SaveOrUpdateScoreSheetEntrySub(scoreSheetEntrySub); } } iStat.Imported(); ContextSaveChanges(); iStat.Saved(_context.ScoreSheetEntryGoals.Count()); } else { _logger.Write(table + " records exist in context; not importing"); iStat.Imported(); iStat.Saved(0); } iStat.Log(); return iStat; }