private void AssignPenaltyCosts(Dictionary<int, IGrouping<int, JamTeamData>> jamDataMap, Dictionary<int, JamTimeEstimate> jamTimeMap, Dictionary<int, List<JamPlayerEffectiveness>> pjeMap, Dictionary<int, List<PenaltyGroup>> jamBoxTimeMap, Dictionary<int, int> boxTimeEstimates, int jamID, JamTeamEffectiveness jte) { List<PenaltyGroup> jamPenaltyGroups = jamBoxTimeMap[jamID]; JamTeamData thisJamData = jamDataMap[jamID].First(jd => jd.TeamID == jte.TeamID); foreach (PenaltyGroup group in jamPenaltyGroups) { int penaltyPlayerID = group.Penalties[0].PlayerID; foreach (BoxTime boxTime in group.BoxTimes) { if (boxTime.JamID == jamID) { // determine how big the swing would be if there had been no box time served double qualityDifference = DetermineQualityWithoutPenalty(thisJamData, boxTime.IsJammer) - jte.Percentile; // the cost of the box time is how bad that player would have to be in that jam to have an equivalent effect // we estimate this based on how important the player is in the jam, by position double penaltyCost = boxTime.IsJammer ? qualityDifference * 2 : qualityDifference * 8; double totalPenaltyTime = boxTime.IsJammer ? thisJamData.JammerBoxTime : thisJamData.BlockerBoxTime; // modify this by how much of the total penalty time this player contributed // doing the rough estimate version for now double penaltyPortion = boxTimeEstimates[boxTime.BoxTimeID] / totalPenaltyTime; // a portion of that cost goes to each penalty that factors into this box time int penaltyCount = group.Penalties.Count; foreach (Penalty penalty in group.Penalties) { var penaltyPJE = pjeMap[penalty.JamID].First(pje => pje.PlayerID == penalty.PlayerID); penaltyPJE.PenaltyCost += penaltyPortion * penaltyCost / penaltyCount; if(double.IsNaN(penaltyPJE.PenaltyCost)) { throw new Exception(penalty.JamID + ": bad penalty data"); } } // for a given penalty group, there should only ever be // a single box time in a given jam break; } } } }
private static void ProcessJamPlayer(Dictionary<int, List<PenaltyGroup>> pgMap, Dictionary<int, List<PenaltyGroup>> jamBoxTimeMap, Dictionary<int, int> boxTimeEstimates, int jamID, JamTeamEffectiveness jte1, List<JamPlayerEffectiveness> pjeList, int jamTime, JamPlayer player) { // handle penalties var playerPenaltyGroups = pgMap.ContainsKey(player.PlayerID) ? pgMap[player.PlayerID] : null; ProcessPlayerJamPenalties(jamBoxTimeMap, jamID, playerPenaltyGroups); // try to estimate what portion of a jam someone missed via time in the box double share = player.IsJammer ? 0.5 : 0.125; int timeInBox = 0; if (jamBoxTimeMap.ContainsKey(jamID)) { foreach (PenaltyGroup group in jamBoxTimeMap[jamID]) { foreach (BoxTime bt in group.BoxTimes) { if (bt.PlayerID == player.PlayerID && bt.JamID == jamID) { // factor in estimated box time timeInBox += boxTimeEstimates[bt.BoxTimeID]; } } } } JamPlayerEffectiveness pje = new JamPlayerEffectiveness { PlayerID = player.PlayerID, TeamID = player.TeamID, JamPortion = ((double)jamTime - timeInBox) / jamTime, BaseQuality = jte1.Percentile, JamID = jamID, IsJammer = player.IsJammer, PenaltyCost = 0 }; pjeList.Add(pje); }