protected override void ProcessPlayerBoxes(ExcelRange playerRange, PlayerLineupModel player, bool isSP) { int foulCol = 2; // check each foul box for this player in this jam while (foulCol < 5) { object foulMarkObj = playerRange.SubRange(1, foulCol).Value; if (foulMarkObj == null) { break; } string foulMark = foulMarkObj.ToString().Trim(); char? specialKey = null; if (foulMark.Length > 1) { specialKey = foulMark[1]; foulMark = foulMark.Substring(0, 1); } BoxTimeModel boxTime; switch (foulMark.ToString().Trim()) { case "x": case "X": boxTime = new BoxTimeModel { Started = foulCol == 2 ? (bool?) null : false, Exited = true, IsJammer = player.IsJammer, IsPivot = player.IsPivot, IsFullService = foulCol == 2 ? (bool?)null : true, SpecialKey = specialKey }; player.BoxTimes.Add(boxTime); break; case "/": case "\\": boxTime = new BoxTimeModel { Started = false, Exited = false, IsJammer = player.IsJammer, IsPivot = player.IsPivot, IsFullService = false, SpecialKey = specialKey }; player.BoxTimes.Add(boxTime); break; case "s": case "S": case "i": case "I": case "|": case "l": boxTime = new BoxTimeModel { Started = true, Exited = false, IsJammer = player.IsJammer, IsPivot = player.IsPivot, IsFullService = false, SpecialKey = specialKey }; player.BoxTimes.Add(boxTime); break; case "$": boxTime = new BoxTimeModel { Started = true, Exited = true, IsJammer = player.IsJammer, IsPivot = player.IsPivot, IsFullService = true, SpecialKey = specialKey }; player.BoxTimes.Add(boxTime); break; case "3": player.WasInjured = true; break; } foulCol++; } if(isSP) { foulCol = 2; if (player.IsJammer) { foulCol += 4; } else if (player.IsPivot) { foulCol -= 4; } int initialFoulCol = foulCol; int stop = foulCol + 3; BoxTimeModel lastBox = (player.BoxTimes.Count > 0) ? player.BoxTimes[player.BoxTimes.Count - 1] : null; // check each foul box for this player in this jam while (foulCol < stop) { object foulMarkObj = playerRange.SubRange(2, foulCol).Value; if (foulMarkObj == null) { break; } BoxTimeModel boxTime; string foulMark = foulMarkObj.ToString().Trim(); char? specialKey = null; if (foulMark.Length > 1) { specialKey = foulMark[1]; foulMark = foulMark.Substring(0, 1); } switch (foulMark.ToString().Trim()) { case "x": case "X": if (foulCol == initialFoulCol && lastBox != null && !lastBox.Exited) { lastBox.Exited = true; if(lastBox.Started == false) { lastBox.IsFullService = true; } } else { boxTime = new BoxTimeModel { Started = false, Exited = true, IsJammer = player.IsPivot, IsPivot = false, IsFullService = true, SpecialKey = specialKey }; player.BoxTimes.Add(boxTime); } break; case "/": case "\\": boxTime = new BoxTimeModel { Started = false, Exited = false, IsJammer = player.IsPivot, IsPivot = false, IsFullService = false, SpecialKey = specialKey }; player.BoxTimes.Add(boxTime); break; case "s": case "S": Console.WriteLine("s in SP box time"); break; case "$": if(lastBox != null) { lastBox.Exited = true; if(lastBox.Started == false) { lastBox.IsFullService = true; } } else { throw new InvalidOperationException("started in box during star pass?"); } break; case "3": player.WasInjured = true; break; } foulCol++; } } }
protected IList<JamLineupModel> ProcessLineupRows(ExcelRange homeLineupStart, ExcelRange awayLineupStart, bool isFirstHalf) { List<JamLineupModel> list = new List<JamLineupModel>(); int currentRow = 1; while (currentRow < 39) { string jamNumber = homeLineupStart.SubRange(currentRow, 1).Value == null ? null : homeLineupStart.SubRange(currentRow, 1).Value.ToString(); string nextJamNumber = null; if (!string.IsNullOrEmpty(jamNumber)) { // add jam int number = Convert.ToInt32(jamNumber); JamLineupModel jamLineup = new JamLineupModel(); jamLineup.IsFirstHalf = isFirstHalf; jamLineup.JamNumber = number; nextJamNumber = homeLineupStart.SubRange(currentRow + 1, 1).Value == null ? null : homeLineupStart.SubRange(currentRow + 1, 1).Value.ToString(); bool isSP = nextJamNumber == null ? false : nextJamNumber.Trim().ToLowerInvariant() == "sp"; jamLineup.HomeLineup = new List<PlayerLineupModel>(); bool hasPivot = homeLineupStart.SubRange(currentRow, 2).Value == null; _dupePlayerCheck = new HashSet<string>(); // TODO: do error checking here jamLineup.HomeLineup.Add(CreateJamPlayer(homeLineupStart.SubRange(currentRow, 3), true, false, isSP)); jamLineup.HomeLineup.Add(CreateJamPlayer(homeLineupStart.SubRange(currentRow, 7), false, hasPivot, isSP)); jamLineup.HomeLineup.Add(CreateJamPlayer(homeLineupStart.SubRange(currentRow, 11), false, false, isSP)); jamLineup.HomeLineup.Add(CreateJamPlayer(homeLineupStart.SubRange(currentRow, 15), false, false, isSP)); jamLineup.HomeLineup.Add(CreateJamPlayer(homeLineupStart.SubRange(currentRow, 19), false, false, isSP)); nextJamNumber = awayLineupStart.SubRange(currentRow + 1, 1).Value == null ? null : awayLineupStart.SubRange(currentRow + 1, 1).Value.ToString(); isSP = nextJamNumber == null ? false : nextJamNumber.Trim().ToLowerInvariant() == "sp"; jamLineup.AwayLineup = new List<PlayerLineupModel>(); hasPivot = awayLineupStart.SubRange(currentRow, 2).Value == null; _dupePlayerCheck = new HashSet<string>(); // TODO: do error checking here jamLineup.AwayLineup.Add(CreateJamPlayer(awayLineupStart.SubRange(currentRow, 3), true, false, isSP)); jamLineup.AwayLineup.Add(CreateJamPlayer(awayLineupStart.SubRange(currentRow, 7), false, hasPivot, isSP)); jamLineup.AwayLineup.Add(CreateJamPlayer(awayLineupStart.SubRange(currentRow, 11), false, false, isSP)); jamLineup.AwayLineup.Add(CreateJamPlayer(awayLineupStart.SubRange(currentRow, 15), false, false, isSP)); jamLineup.AwayLineup.Add(CreateJamPlayer(awayLineupStart.SubRange(currentRow, 19), false, false, isSP)); list.Add(jamLineup); } currentRow++; while (nextJamNumber != null && (nextJamNumber.ToLower().Trim() == "sp" || nextJamNumber.ToLower().Trim() == "sp*")) { currentRow++; var nextJam = homeLineupStart.SubRange(currentRow, 1).Value; nextJamNumber = nextJam == null ? null : nextJam.ToString(); } } return list; }
private IList<JamScoreModel> ProcessScoreRows(ExcelRange homeScores, ExcelRange awayScores, bool isFirstHalf) { List<JamScoreModel> list = new List<JamScoreModel>(); int currentRow = 1; while (currentRow < 39) { object jamNumber = homeScores.SubRange(currentRow, 1).Value; if (jamNumber != null && !string.IsNullOrEmpty(jamNumber.ToString())) { if (jamNumber.ToString().Trim().ToLower() == "sp*") { currentRow++; continue; } // add jam int number = Convert.ToInt32(jamNumber); JamScoreModel model = new JamScoreModel(); model.JamNumber = number; model.IsFirstHalf = isFirstHalf; model.HomeJammer = CreateScoreModel(homeScores, currentRow); model.AwayJammer = CreateScoreModel(awayScores, currentRow); model.HomeStarPass = model.AwayStarPass = null; currentRow++; // see if the next home row is a star pass object nextJamNumber = homeScores.SubRange(currentRow, 1).Value; if (nextJamNumber != null && nextJamNumber.ToString().Trim().ToLower() == "sp" && homeScores.SubRange(currentRow, 2).Value != null && !string.IsNullOrWhiteSpace(homeScores.SubRange(currentRow, 2).Value.ToString())) { model.HomeStarPass = CreateScoreModel(homeScores, currentRow); } nextJamNumber = awayScores.SubRange(currentRow, 1).Value; if (nextJamNumber != null && nextJamNumber.ToString().Trim().ToLower() == "sp" && awayScores.SubRange(currentRow, 2).Value != null && !string.IsNullOrWhiteSpace(awayScores.SubRange(currentRow, 2).Value.ToString())) { model.AwayStarPass = CreateScoreModel(awayScores, currentRow); } if(model.AwayStarPass != null || model.HomeStarPass != null) { currentRow++; } list.Add(model); } else { break; } } return list; }
private IList<PenaltyModel> ProcessPenaltySheetPlayer(ExcelRange penalties, int rowOffset, bool isFirstHalf) { List<PenaltyModel> list = new List<PenaltyModel>(); int columnOffset = 2; while (columnOffset < 10) { // go through each foul object foulTypeObj = penalties.SubRange(rowOffset, columnOffset).Value; if (foulTypeObj == null || string.IsNullOrWhiteSpace(foulTypeObj.ToString())) { columnOffset++; continue; } string foulType = foulTypeObj.ToString().Trim(); char? specialKey = null; if(foulType.Length > 1) { specialKey = foulType[1]; foulType = foulType.Substring(0, 1); } int jamNumber = Convert.ToInt32(penalties.SubRange(rowOffset + 1, columnOffset).Value); PenaltyModel penalty = new PenaltyModel { IsFirstHalf = isFirstHalf, JamNumber = jamNumber, PenaltyCode = foulType, SpecificKey = specialKey }; list.Add(penalty); columnOffset++; } return list; }
private IList<PlayerPenaltiesModel> ProcessPenaltySheet(ExcelRange firstHalfFouls, ExcelRange secondHalfFouls) { List<PlayerPenaltiesModel> penalties = new List<PlayerPenaltiesModel>(); int rowOffset = 1; while (rowOffset < 40) { object playerObj = firstHalfFouls.SubRange(rowOffset, 1).Value; if (playerObj == null || string.IsNullOrWhiteSpace(playerObj.ToString())) { rowOffset += 2; continue; } PlayerPenaltiesModel model = new PlayerPenaltiesModel(); model.PlayerNumber = playerObj.ToString(); List<PenaltyModel> list = new List<PenaltyModel>(); list.AddRange(ProcessPenaltySheetPlayer(firstHalfFouls, rowOffset, true)); object playerObj2 = secondHalfFouls.SubRange(rowOffset, 1).Value; if (!playerObj2.ToString().Equals(model.PlayerNumber, StringComparison.InvariantCultureIgnoreCase)) { throw new InvalidOperationException("Huh?"); } list.AddRange(ProcessPenaltySheetPlayer(secondHalfFouls, rowOffset, false)); model.Penalties = list; penalties.Add(model); rowOffset += 2; } return penalties; }
private ScoreModel CreateScoreModel(ExcelRange scores, int currentRow) { var scorer = scores.SubRange(currentRow, 2).Value; if(scorer == null || string.IsNullOrEmpty(scorer.ToString())) { return null; } ScoreModel model = new ScoreModel(); model.PlayerNumber = scorer.ToString(); model.JamTotal = Convert.ToInt32(scores.SubRange(currentRow, 17).Value); model.Lost = !string.IsNullOrWhiteSpace((string)scores.SubRange(currentRow, 3).Value); model.Lead = !string.IsNullOrWhiteSpace((string)scores.SubRange(currentRow, 4).Value); model.Called = !string.IsNullOrWhiteSpace((string)scores.SubRange(currentRow, 5).Value); model.NoPass = !string.IsNullOrWhiteSpace((string)scores.SubRange(currentRow, 7).Value); model.Injury = !string.IsNullOrWhiteSpace((string)scores.SubRange(currentRow, 6).Value); return model; }