private void AddPenaltyServices(Dictionary<string, Player> homePlayerMap, Dictionary<string, Player> awayPlayerMap, IList<Jam> jams, IList<JamLineupModel> lineups, IList<JamScoreModel> scores, PenaltiesModel penalties) { Dictionary<int, Dictionary<int, IList<Models.BoxTimeModel>>> homePlayerBoxTimeMap = new Dictionary<int, Dictionary<int, IList<Models.BoxTimeModel>>>(); Dictionary<int, Dictionary<int, IList<Models.BoxTimeModel>>> awayPlayerBoxTimeMap = new Dictionary<int, Dictionary<int, IList<Models.BoxTimeModel>>>(); Dictionary<int, int> homeEndJammerMap = new Dictionary<int, int>(); Dictionary<int, int> awayEndJammerMap = new Dictionary<int, int>(); foreach (JamLineupModel jamLineup in lineups) { Jam jam = jams.First(j => j.IsFirstHalf == jamLineup.IsFirstHalf && j.JamNumber == jamLineup.JamNumber); JamScoreModel jsm = scores.First(s => s.IsFirstHalf == jam.IsFirstHalf && s.JamNumber == jam.JamNumber); foreach (PlayerLineupModel playerLineup in jamLineup.HomeLineup) { if(playerLineup == null) { continue; } int playerID = homePlayerMap[playerLineup.PlayerNumber].ID; if (playerLineup.IsJammer && jsm.HomeStarPass == null) { homeEndJammerMap[jam.ID] = playerID; } else if(playerLineup.IsPivot && jsm.HomeStarPass != null) { homeEndJammerMap[jam.ID] = playerID; } if (playerLineup.BoxTimes != null && playerLineup.BoxTimes.Any()) { if (!homePlayerBoxTimeMap.ContainsKey(playerID)) { homePlayerBoxTimeMap[playerID] = new Dictionary<int, IList<Models.BoxTimeModel>>(); } homePlayerBoxTimeMap[playerID][jam.ID] = playerLineup.BoxTimes; } } foreach (PlayerLineupModel playerLineup in jamLineup.AwayLineup) { if (playerLineup == null) { continue; } int playerID = awayPlayerMap[playerLineup.PlayerNumber].ID; if (playerLineup.IsJammer && jsm.HomeStarPass == null) { awayEndJammerMap[jam.ID] = playerID; } else if (playerLineup.IsPivot && jsm.HomeStarPass != null) { awayEndJammerMap[jam.ID] = playerID; } if (playerLineup.BoxTimes != null && playerLineup.BoxTimes.Any()) { if (!awayPlayerBoxTimeMap.ContainsKey(playerID)) { awayPlayerBoxTimeMap[playerID] = new Dictionary<int, IList<Models.BoxTimeModel>>(); } awayPlayerBoxTimeMap[playerID][jam.ID] = playerLineup.BoxTimes; } } } Dictionary<int, PlayerPenaltiesModel> homePlayerPenalties = penalties.HomePlayerPenalties.ToDictionary(pp => homePlayerMap[pp.PlayerNumber].ID); Dictionary<int, PlayerPenaltiesModel> awayPlayerPenalties = penalties.AwayPlayerPenalties.ToDictionary(pp => awayPlayerMap[pp.PlayerNumber].ID); PenaltyProcessor processor = new PenaltyProcessor(jams, homePlayerMap, awayPlayerMap); var service = processor.ProcessPenalties(homePlayerBoxTimeMap, homePlayerPenalties, homeEndJammerMap, awayPlayerBoxTimeMap, awayPlayerPenalties, awayEndJammerMap); PenaltyGateway penaltyGateway = new PenaltyGateway(_connection, _transaction); penaltyGateway.AddPenalties(service); }
protected PenaltiesModel ProcessPenalties(ExcelWorksheet fouls) { PenaltiesModel penalties = new PenaltiesModel(); ExcelRange firstHalfFoulRange = fouls.Cells[_cells.HomePenaltyFirstPeriodCell]; ExcelRange secondHalfFoulRange = fouls.Cells[_cells.HomePenaltySecondPeriodCell]; penalties.HomePlayerPenalties = ProcessPenaltySheet(firstHalfFoulRange, secondHalfFoulRange); firstHalfFoulRange = fouls.Cells[_cells.AwayPenaltyFirstPeriodCell]; secondHalfFoulRange = fouls.Cells[_cells.AwayPenaltySecondPeriodCell]; penalties.AwayPlayerPenalties = ProcessPenaltySheet(firstHalfFoulRange, secondHalfFoulRange); return penalties; }
private void AddPenaltyServices(Dictionary<string, Player> homePlayerMap, Dictionary<string, Player> awayPlayerMap, IList<Jam> jams, IList<JamLineupModel> lineups, PenaltiesModel penalties) { Dictionary<int, PlayerPenaltiesModel> homePlayerPenalties = penalties.HomePlayerPenalties.ToDictionary(pp => homePlayerMap[pp.PlayerNumber].ID); Dictionary<int, PlayerPenaltiesModel> awayPlayerPenalties = penalties.AwayPlayerPenalties.ToDictionary(pp => awayPlayerMap[pp.PlayerNumber].ID); AddTeamPenalties(jams, homePlayerMap, homePlayerPenalties); AddTeamPenalties(jams, awayPlayerMap, awayPlayerPenalties); }
private void AddPenaltyServices(Dictionary<string, Player> homePlayerMap, Dictionary<string, Player> awayPlayerMap, IList<Jam> jams, IList<JamLineupModel> lineups, PenaltiesModel penalties) { Dictionary<int, Dictionary<int, IList<Models.BoxTimeModel>>> homePlayerBoxTimeMap = new Dictionary<int, Dictionary<int, IList<Models.BoxTimeModel>>>(); Dictionary<int, Dictionary<int, IList<Models.BoxTimeModel>>> awayPlayerBoxTimeMap = new Dictionary<int, Dictionary<int, IList<Models.BoxTimeModel>>>(); foreach (JamLineupModel jamLineup in lineups) { Jam jam = jams.First(j => j.IsFirstHalf == jamLineup.IsFirstHalf && j.JamNumber == jamLineup.JamNumber); foreach (PlayerLineupModel playerLineup in jamLineup.HomeLineup) { if(playerLineup == null) { continue; } if (playerLineup.BoxTimes != null && playerLineup.BoxTimes.Any()) { int playerID = homePlayerMap[playerLineup.PlayerNumber].ID; if (!homePlayerBoxTimeMap.ContainsKey(playerID)) { homePlayerBoxTimeMap[playerID] = new Dictionary<int, IList<Models.BoxTimeModel>>(); } homePlayerBoxTimeMap[playerID][jam.ID] = playerLineup.BoxTimes; } } foreach (PlayerLineupModel playerLineup in jamLineup.AwayLineup) { if (playerLineup.BoxTimes != null && playerLineup.BoxTimes.Any()) { int playerID = awayPlayerMap[playerLineup.PlayerNumber].ID; if (!awayPlayerBoxTimeMap.ContainsKey(playerID)) { awayPlayerBoxTimeMap[playerID] = new Dictionary<int, IList<Models.BoxTimeModel>>(); } awayPlayerBoxTimeMap[playerID][jam.ID] = playerLineup.BoxTimes; } } } Dictionary<int, PlayerPenaltiesModel> homePlayerPenalties = penalties.HomePlayerPenalties.ToDictionary(pp => homePlayerMap[pp.PlayerNumber].ID); Dictionary<int, PlayerPenaltiesModel> awayPlayerPenalties = penalties.AwayPlayerPenalties.ToDictionary(pp => awayPlayerMap[pp.PlayerNumber].ID); AddTeamPenaltyServices(jams, homePlayerMap, homePlayerBoxTimeMap, homePlayerPenalties); AddTeamPenaltyServices(jams, awayPlayerMap, awayPlayerBoxTimeMap, awayPlayerPenalties); }