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 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; }