Esempio n. 1
0
        public void Import(string connectionString, StatbookModel statbook, bool assumeATeams)
        {
            _connection = new SqlConnection(connectionString);
            try
            {
                _connection.Open();
                _transaction = _connection.BeginTransaction();

                // insert leagues
                LeagueGateway leagueGateway = new LeagueGateway(_connection, _transaction);
                var leagues = leagueGateway.GetAllLeagues();
                League homeLeague = leagues.FirstOrDefault(l => l.Name.ToLower() == statbook.HomeTeam.LeagueName.ToLower());
                League awayLeague = leagues.FirstOrDefault(l => l.Name.ToLower() == statbook.AwayTeam.LeagueName.ToLower());
                int maxID = leagues.Select(l => l.ID).Max();
                if(homeLeague == null)
                {
                    homeLeague = leagueGateway.GetLeague(maxID + 1, statbook.HomeTeam.LeagueName, statbook.Date, false);
                    maxID++;
                }
                if(awayLeague == null)
                {
                    awayLeague = leagueGateway.GetLeague(maxID + 1, statbook.AwayTeam.LeagueName, statbook.Date, false);
                    maxID++;
                }

                // insert teams
                TeamGateway teamGateway = new TeamGateway(_connection, _transaction);
                Team homeTeam, awayTeam;
                if (assumeATeams)
                {
                    homeTeam = teamGateway.GetATeam(homeLeague.ID);
                    awayTeam = teamGateway.GetATeam(awayLeague.ID);

                }
                else
                {
                    homeTeam = teamGateway.GetTeam(statbook.HomeTeam.Name, homeLeague.ID, "A", false);
                    awayTeam = teamGateway.GetTeam(statbook.AwayTeam.Name, awayLeague.ID, "A", false);
                }

                // insert bout
                BoutGateway boutGateway = new BoutGateway(_connection, _transaction);
                if(!boutGateway.DoesBoutExist(homeTeam.ID, awayTeam.ID, statbook.Date))
                {
                    Bout bout = boutGateway.GetBout(homeTeam.ID, awayTeam.ID, statbook.Date);
                    BoutDataImport(statbook, bout, homeTeam, awayTeam);
                }
                else
                {
                    // bout already exists
                    Console.WriteLine(string.Format("Bout between {0} and {1} on {2} already exists.", homeTeam.Name, awayTeam.Name, statbook.Date));
                }

                _transaction.Commit();
            }
            finally
            {
                _connection.Close();
            }
        }
Esempio n. 2
0
        protected StatbookModel ProcessIrgf(ExcelWorksheet irgf)
        {
            StatbookModel statbook = new StatbookModel();
            statbook.HomeTeam = new TeamModel();
            statbook.AwayTeam = new TeamModel();

            statbook.HomeTeam.LeagueName = irgf.Cells[_cells.HomeLeagueCell].Value.ToString().Trim();
            statbook.HomeTeam.Name = irgf.Cells[_cells.HomeTeamNameCell].Value.ToString().Trim();

            statbook.AwayTeam.LeagueName = irgf.Cells[_cells.AwayLeagueCell].Value.ToString().Trim();
            statbook.AwayTeam.Name = irgf.Cells[_cells.AwayTeamNameCell].Value.ToString().Trim();

            string dateString = irgf.Cells[_cells.BoutDateCell].Value.ToString().Trim();// +" " + irgf.Cells["H5"].Value.ToString();
            if (dateString.Contains("/") || dateString.Contains("-"))
            {
                statbook.Date = Convert.ToDateTime(dateString);
            }
            else
            {
                statbook.Date = DateTime.FromOADate(Convert.ToDouble(dateString));
            }

            ExcelRange homeStart = irgf.Cells[_cells.HomeRosterCell];
            ExcelRange awayStart = irgf.Cells[_cells.AwayRosterCell];
            statbook.HomeTeam.Players = new List<PlayerModel>();
            statbook.AwayTeam.Players = new List<PlayerModel>();

            for (int i = 0; i < 20; i++)
            {
                object numberCell = homeStart.Offset(i, 0).Value;
                if (numberCell != null && !string.IsNullOrWhiteSpace(numberCell.ToString()))
                {
                    PlayerModel player = new PlayerModel();

                    player.Number = numberCell.ToString().Trim();
                    player.Name = homeStart.Offset(i, 1).Value.ToString();
                    statbook.HomeTeam.Players.Add(player);
                }

                numberCell = awayStart.Offset(i, 0).Value;
                if (numberCell != null && !string.IsNullOrWhiteSpace(numberCell.ToString()))
                {
                    PlayerModel player = new PlayerModel();
                    player.Number = numberCell.ToString().Trim();
                    player.Name = awayStart.Offset(i, 1).Value.ToString();
                    statbook.AwayTeam.Players.Add(player);
                }
            }
            return statbook;
        }
Esempio n. 3
0
        public void Import(string connectionString, StatbookModel statbook)
        {
            _connection = new SqlConnection(connectionString);
            try
            {
                _connection.Open();
                _transaction = _connection.BeginTransaction();

                // insert leagues
                LeagueGateway leagueGateway = new LeagueGateway(_connection, _transaction);
                var leagues = leagueGateway.GetAllLeagues();
                League homeLeague = leagues.FirstOrDefault(l => l.Name.ToLower() == statbook.HomeTeam.LeagueName.ToLower());
                League awayLeague = leagues.FirstOrDefault(l => l.Name.ToLower() == statbook.AwayTeam.LeagueName.ToLower());
                int maxID = leagues.Select(l => l.ID).Max();
                if(homeLeague == null || awayLeague == null)
                {
                    throw new InvalidOperationException("Bad league name");
                }

                // for the basic importer, we'll just take whatever A team this league has, rather than worrying about validating the team name
                TeamGateway teamGateway = new TeamGateway(_connection, _transaction);
                Team homeTeam = teamGateway.GetATeam(homeLeague.ID);
                Team awayTeam = teamGateway.GetATeam(awayLeague.ID);

                // insert bout
                BoutGateway boutGateway = new BoutGateway(_connection, _transaction);
                if(!boutGateway.DoesBoutExist(homeTeam.ID, awayTeam.ID, statbook.Date))
                {
                    Bout bout = boutGateway.GetBout(homeTeam.ID, awayTeam.ID, statbook.Date);
                    BoutDataImport(statbook, bout, homeTeam, awayTeam);
                }
                else
                {
                    // bout already exists
                    Console.WriteLine(string.Format("Bout between {0} and {1} on {2} already exists.", homeTeam.Name, awayTeam.Name, statbook.Date));
                }

                _transaction.Commit();
            }
            finally
            {
                _connection.Close();
            }
        }
Esempio n. 4
0
        private void BoutDataImport(StatbookModel statbook, Bout bout, Team homeTeam, Team awayTeam)
        {
            // import players
            Dictionary<string, Player> homePlayerMap = CreatePlayerMap(homeTeam, statbook.HomeTeam.Players);
            Dictionary<string, Player> awayPlayerMap = CreatePlayerMap(awayTeam, statbook.AwayTeam.Players);

            // import jams
            List<Jam> jamList = CreateJamList(bout, statbook.Lineups);

            // import player jams
            Dictionary<int, List<JamPlayer>> jamPlayerMap = CreateJamPlayerMap(homePlayerMap, awayPlayerMap, jamList, statbook.Lineups);

            // import scores
            AddScores(homePlayerMap, awayPlayerMap, jamList, statbook.Scores);

            // import penalties/box times
            AddPenaltyServices(homePlayerMap, awayPlayerMap, jamList, statbook.Lineups, statbook.Scores, statbook.Penalties);
        }
Esempio n. 5
0
 private void IntegrateStarPasses(StatbookModel statbookModel, List<JamScoreModel> jamScoreModelList)
 {
     if(statbookModel.Scores.Count != jamScoreModelList.Count)
     {
         // this is unexpected
         throw new FormatException("score list length mismatch");
     }
     for(int i = 0; i < jamScoreModelList.Count; i++)
     {
         if(jamScoreModelList[i].AwayStarPass != null)
         {
             jamScoreModelList[i].AwayStarPass.PlayerNumber =
                 statbookModel.Lineups[i].AwayLineup.First(l => l.IsPivot).PlayerNumber;
             statbookModel.Scores[i].AwayJammer.JamTotal = jamScoreModelList[i].AwayJammer.JamTotal;
             statbookModel.Scores[i].AwayStarPass = jamScoreModelList[i].AwayStarPass;
         }
         if (jamScoreModelList[i].HomeStarPass != null)
         {
             jamScoreModelList[i].HomeStarPass.PlayerNumber =
                 statbookModel.Lineups[i].HomeLineup.First(l => l.IsPivot).PlayerNumber;
             statbookModel.Scores[i].HomeJammer.JamTotal = jamScoreModelList[i].HomeJammer.JamTotal;
             statbookModel.Scores[i].HomeStarPass = jamScoreModelList[i].HomeStarPass;
         }
     }
 }