Beispiel #1
0
        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);
        }
Beispiel #2
0
        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.AwayStarPass == null)
                    {
                        awayEndJammerMap[jam.ID] = playerID;
                    }
                    else if (playerLineup.IsPivot && jsm.AwayStarPass != 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);
        }
        private List <JamScoreModel> TranslateRinxterScoringData(RinxterScoresModel rinxterModel)
        {
            List <JamScoreModel> modelList = new List <JamScoreModel>();

            foreach (RinxterScoreRowModel row in rinxterModel.rows)
            {
                bool     homeSP          = row.data[3].ToString().Contains("*");
                string[] homeScores      = row.data[3].ToString().Split(' ');
                int      homeJammerScore = 0;
                int      homePivotScore  = 0;

                int processLimit = homeScores.Length - 1;
                for (int i = 0; i < processLimit; i++)
                {
                    if (homeScores[i].Contains("*"))
                    {
                        homeScores[i]   = homeScores[i].Substring(0, homeScores[i].Length - 1);
                        homePivotScore += Convert.ToInt16(homeScores[i]);
                    }
                    else
                    {
                        homeJammerScore += Convert.ToInt16(homeScores[i]);
                    }
                }

                bool     awaySP          = row.data[8].ToString().Contains("*");
                string[] awayScores      = row.data[8].ToString().Split(' ');
                int      awayJammerScore = 0;
                int      awayPivotScore  = 0;
                processLimit = awayScores.Length - 1;
                for (int i = 0; i < processLimit; i++)
                {
                    if (awayScores[i].Contains("*"))
                    {
                        awayScores[i]   = awayScores[i].Substring(0, awayScores[i].Length - 1);
                        awayPivotScore += Convert.ToInt16(awayScores[i]);
                    }
                    else
                    {
                        awayJammerScore += Convert.ToInt16(awayScores[i]);
                    }
                }

                JamScoreModel jamScoreModel = new JamScoreModel
                {
                    IsFirstHalf = true,
                    JamNumber   = row.id + 1,
                    AwayJammer  = new ScoreModel
                    {
                        JamTotal = awayJammerScore,
                    },
                    HomeJammer = new ScoreModel
                    {
                        JamTotal = homeJammerScore
                    }
                };
                if (homeSP)
                {
                    jamScoreModel.HomeStarPass = new ScoreModel
                    {
                        JamTotal = homePivotScore
                    };
                }
                if (awaySP)
                {
                    jamScoreModel.AwayStarPass = new ScoreModel
                    {
                        JamTotal = awayPivotScore
                    };
                }
                modelList.Add(jamScoreModel);
            }
            return(modelList);
        }