Пример #1
0
        private EstimatedRankings[] SaveEstimatedRanking(Rankings[] points)
        {
            EstimatedRankings[] estimatedRanking = new EstimatedRankings[7];
            for (int i = 0; i < points.Length; i++)
            {
                estimatedRanking[i] = new EstimatedRankings()
                {
                    Anderson_Packers    = points[i].Anderson_Packers, Atlanta_Hawks = points[i].Atlanta_Hawks, Baltimore_Bullets = points[i].Baltimore_Bullets, Boston_Celtics = points[i].Boston_Celtics,
                    Brooklyn_Nets       = points[i].Brooklyn_Nets, Charlotte_Hornets = points[i].Charlotte_Hornets, Chicago_Stags = points[i].Chicago_Stags, Chicago_Bulls = points[i].Chicago_Bulls,
                    Cleveland_Cavaliers = points[i].Cleveland_Cavaliers, Cleveland_Rebels = points[i].Cleveland_Rebels, Dallas_Mavericks = points[i].Dallas_Mavericks, Denver_Nuggets = points[i].Denver_Nuggets,
                    Detroit_Pistons     = points[i].Detroit_Pistons, Detroit_Falcons = points[i].Detroit_Falcons, Golden_State_Warriors = points[i].Golden_State_Warriors, Houston_Rockets = points[i].Houston_Rockets,
                    ID = points[i].ID, Indianapolis_Jets = points[i].Indianapolis_Jets, Indianapolis_Olympians = points[i].Indianapolis_Olympians, Indiana_Pacers = points[i].Indiana_Pacers, LA_Clipers = points[i].LA_Clipers,
                    Los_Angeles_Lakers     = points[i].Los_Angeles_Lakers, Memphis_Grizzlies = points[i].Memphis_Grizzlies, Miami_Heat = points[i].Miami_Heat, Milwaukee_Bucks = points[i].Milwaukee_Bucks,
                    Minnesota_Timberwolves = points[i].Minnesota_Timberwolves, New_Orleans_Pelicans = points[i].New_Orleans_Pelicans, New_York_Knicks = points[i].New_York_Knicks, Oklahoma_City_Thunder = points[i].Oklahoma_City_Thunder,
                    Orlando_Magic          = points[i].Orlando_Magic, Philadelphia_76ers = points[i].Philadelphia_76ers, Phoenix_Suns = points[i].Phoenix_Suns, Pittsburgh_Ironmen = points[i].Pittsburgh_Ironmen,
                    Portland_Trail_Blazers = points[i].Portland_Trail_Blazers, Providence_Steam_Rollers = points[i].Providence_Steam_Rollers, Sacramento_Kings = points[i].Sacramento_Kings, San_Antonio_Spurs = points[i].San_Antonio_Spurs,
                    Sheboygan_Red_Skins    = points[i].Sheboygan_Red_Skins, St__Louis_Bombers = points[i].St__Louis_Bombers, Toronto_Huskies = points[i].Toronto_Huskies, Toronto_Raptors = points[i].Toronto_Raptors,
                    Utah_Jazz = points[i].Utah_Jazz, Washington_Capitols = points[i].Washington_Capitols, Washington_Wizards = points[i].Washington_Wizards, Waterloo_Hawks = points[i].Waterloo_Hawks
                };
            }

            foreach (var rnk in estimatedRanking)
            {
                _estimatedRankingRepository.Add(rnk);
            }
            _estimatedRankingRepository.SaveChanges();
            return(estimatedRanking);
        }
Пример #2
0
        public int[] GetSeasonRanking(PropertyInfo propInfo, Season season)
        {
            if (propInfo == null)
            {
                propInfo = new EstimatedRankings().GetType().GetProperty(_team.Name.Replace(' ', '_').Replace('.', '_'));
            }
            int[] rankings = new int[7] {
                0, 0, 0, 0, 0, 0, 0
            };
            string novId = string.Format("{0} {1}", season, Month.November);
            string decId = string.Format("{0} {1}", season, Month.December);
            string janId = string.Format("{0} {1}", season, Month.January);
            string febId = string.Format("{0} {1}", season, Month.February);
            string marId = string.Format("{0} {1}", season, Month.March);
            string aprId = string.Format("{0} {1}", season, Month.April);
            string poId  = string.Format("{0} {1}", season, Month.PlayOffs);

            try
            {
                rankings[0] = Convert.ToInt32(propInfo.GetValue(_estimatedRankingRepository.First(x => x.ID == novId)));
                rankings[1] = Convert.ToInt32(propInfo.GetValue(_estimatedRankingRepository.First(x => x.ID == decId)));
                rankings[2] = Convert.ToInt32(propInfo.GetValue(_estimatedRankingRepository.First(x => x.ID == janId)));
                rankings[3] = Convert.ToInt32(propInfo.GetValue(_estimatedRankingRepository.First(x => x.ID == febId)));
                rankings[4] = Convert.ToInt32(propInfo.GetValue(_estimatedRankingRepository.First(x => x.ID == marId)));
                rankings[5] = Convert.ToInt32(propInfo.GetValue(_estimatedRankingRepository.First(x => x.ID == aprId)));
                rankings[6] = Convert.ToInt32(propInfo.GetValue(_estimatedRankingRepository.First(x => x.ID == poId)));
            }
            catch { }
            return(rankings);
        }
Пример #3
0
        public static EstimatedRankings ConvertPositionsToRanking(Positions positions)
        {
            EstimatedRankings ranking = new EstimatedRankings()
            {
                Anderson_Packers      = positions.Anderson_Packers,
                Atlanta_Hawks         = positions.Atlanta_Hawks,
                Baltimore_Bullets     = positions.Baltimore_Bullets,
                Boston_Celtics        = positions.Boston_Celtics,
                Brooklyn_Nets         = positions.Brooklyn_Nets,
                Charlotte_Hornets     = positions.Charlotte_Hornets,
                Chicago_Stags         = positions.Chicago_Stags,
                Chicago_Bulls         = positions.Chicago_Bulls,
                Cleveland_Cavaliers   = positions.Cleveland_Cavaliers,
                Cleveland_Rebels      = positions.Cleveland_Rebels,
                Dallas_Mavericks      = positions.Dallas_Mavericks,
                Denver_Nuggets        = positions.Denver_Nuggets,
                Detroit_Pistons       = positions.Detroit_Pistons,
                Detroit_Falcons       = positions.Detroit_Falcons,
                Golden_State_Warriors = positions.Golden_State_Warriors,
                Houston_Rockets       = positions.Houston_Rockets,
                ID = positions.ID,
                Indianapolis_Jets        = positions.Indianapolis_Jets,
                Indianapolis_Olympians   = positions.Indianapolis_Olympians,
                Indiana_Pacers           = positions.Indiana_Pacers,
                LA_Clipers               = positions.LA_Clipers,
                Los_Angeles_Lakers       = positions.Los_Angeles_Lakers,
                Memphis_Grizzlies        = positions.Memphis_Grizzlies,
                Miami_Heat               = positions.Miami_Heat,
                Milwaukee_Bucks          = positions.Milwaukee_Bucks,
                Minnesota_Timberwolves   = positions.Minnesota_Timberwolves,
                New_Orleans_Pelicans     = positions.New_Orleans_Pelicans,
                New_York_Knicks          = positions.New_York_Knicks,
                Oklahoma_City_Thunder    = positions.Oklahoma_City_Thunder,
                Orlando_Magic            = positions.Orlando_Magic,
                Philadelphia_76ers       = positions.Philadelphia_76ers,
                Phoenix_Suns             = positions.Phoenix_Suns,
                Portland_Trail_Blazers   = positions.Portland_Trail_Blazers,
                Providence_Steam_Rollers = positions.Providence_Steam_Rollers,
                Sacramento_Kings         = positions.Sacramento_Kings,
                San_Antonio_Spurs        = positions.San_Antonio_Spurs,
                Sheboygan_Red_Skins      = positions.Sheboygan_Red_Skins,
                St__Louis_Bombers        = positions.St__Louis_Bombers,
                Toronto_Huskies          = positions.Toronto_Huskies,
                Toronto_Raptors          = positions.Toronto_Raptors,
                Utah_Jazz           = positions.Utah_Jazz,
                Washington_Capitols = positions.Washington_Capitols,
                Washington_Wizards  = positions.Washington_Wizards,
                Waterloo_Hawks      = positions.Waterloo_Hawks,
                Pittsburgh_Ironmen  = positions.Pittsburgh_Ironmen
            };

            return(ranking);
        }
Пример #4
0
        // GET: Calculation
        public ActionResult Index(int id = 1)
        {
            SeasonCalculations calc = new SeasonCalculations((Season)id, _teamsRepository, _activityRepository,
                                                             _rankingRepository, _positionsRepository, _estimatedRankingRepository);
            Activity isActive;

            EstimatedRankings[] points;
            calc.GetRanking(out points, out isActive);
            List <CalculationsViewModel> viewModel      = new List <CalculationsViewModel>();
            EstimatedRankings            currentRanking = ConvertHelper.ConvertPositionsToRanking(calc.GetPosition((Season)id));
            Positions         previousRanking           = calc.GetPosition((Season)id - 1);
            EstimatedRankings prevRanking = null;

            if (previousRanking != null)
            {
                prevRanking = ConvertHelper.ConvertPositionsToRanking(previousRanking);
            }
            foreach (Teams team in allTeams)
            {
                PropertyInfo propInfo = isActive.GetType().GetProperty(team.Name.Replace(' ', '_').Replace('.', '_'));
                if (Convert.ToBoolean(propInfo.GetValue(isActive)))
                {
                    propInfo = points[0].GetType().GetProperty(team.Name.Replace(' ', '_').Replace('.', '_'));
                    int   prevRank = prevRanking == null ? 0 : Convert.ToInt32(propInfo.GetValue(prevRanking));
                    int[] res      = new int[7];
                    viewModel.Add(new CalculationsViewModel(team, new int[] { Convert.ToInt32(propInfo.GetValue(points[0])), Convert.ToInt32(propInfo.GetValue(points[1])),
                                                                              Convert.ToInt32(propInfo.GetValue(points[2])), Convert.ToInt32(propInfo.GetValue(points[3])), Convert.ToInt32(propInfo.GetValue(points[4])),
                                                                              Convert.ToInt32(propInfo.GetValue(points[5])), Convert.ToInt32(propInfo.GetValue(points[6])) }, Convert.ToInt32(propInfo.GetValue(currentRanking)), prevRank));
                }
            }
            viewModel = viewModel.OrderByDescending(x => x.Points[6]).ToList();
            List <Teams> drawTeams  = new List <Teams>();
            List <int[]> drawPoints = new List <int[]>();

            foreach (CalculationsViewModel vm in viewModel.Take(5))
            {
                drawTeams.Add(vm.Team);
                drawPoints.Add(vm.Points);
            }
            DrawChart drawChart = new DrawChart();
            string    path      = drawChart.GenerateChart(drawTeams, drawPoints, (Season)id);

            ViewBag.Season            = (Season)id;
            ViewBag.SeasonDisplayName = Helpers.Helper.GetSeasonDisplayName((Season)id);
            ViewBag.Path = path;
            return(View(viewModel));
        }
Пример #5
0
        private Dictionary <Season, int> EstimateAllTimeRanking()
        {
            PropertyInfo             propInfo         = new EstimatedRankings().GetType().GetProperty(_team.Name.Replace(' ', '_').Replace('.', '_'));
            Dictionary <Season, int> estimatedRanking = new Dictionary <Season, int>();

            foreach (Season season in Enum.GetValues(typeof(Season)))
            {
                string poId  = string.Format("{0} {1}", season, Month.PlayOffs);
                int    score = 0;
                try
                {
                    score = Convert.ToInt32(propInfo.GetValue(_estimatedRankingRepository.First(x => x.ID == poId)));
                }
                catch { }
                estimatedRanking.Add(season, score);
            }
            return(estimatedRanking);
        }
Пример #6
0
        private EstimatedRankings[] GetEstimatedRanking()
        {
            EstimatedRankings[] rankings = new EstimatedRankings[7];
            string nov = string.Format("{0} {1}", _currentSeason, Month.November);
            string dec = string.Format("{0} {1}", _currentSeason, Month.December);
            string jan = string.Format("{0} {1}", _currentSeason, Month.January);
            string feb = string.Format("{0} {1}", _currentSeason, Month.February);
            string mar = string.Format("{0} {1}", _currentSeason, Month.March);
            string apr = string.Format("{0} {1}", _currentSeason, Month.April);
            string po  = string.Format("{0} {1}", _currentSeason, Month.PlayOffs);

            rankings[0] = _estimatedRankingRepository.First(x => x.ID == nov);
            rankings[1] = _estimatedRankingRepository.First(x => x.ID == dec);
            rankings[2] = _estimatedRankingRepository.First(x => x.ID == jan);
            rankings[3] = _estimatedRankingRepository.First(x => x.ID == feb);
            rankings[4] = _estimatedRankingRepository.First(x => x.ID == mar);
            rankings[5] = _estimatedRankingRepository.First(x => x.ID == apr);
            rankings[6] = _estimatedRankingRepository.First(x => x.ID == po);
            return(rankings);
        }
Пример #7
0
 private void SavePositions(EstimatedRankings points, Activity isActive)
 {
     if (!_positionsRepository.AsQueryable().Where(x => x.ID == _currentSeason.ToString()).Any())
     {
         KeyValuePair <Teams, int?>[] teamPoints = new KeyValuePair <Teams, int?> [44];
         for (int i = 0; i < 44; i++)
         {
             PropertyInfo propInfo = points.GetType().GetProperty(allTeams[i].Name.Replace(' ', '_').Replace('.', '_'));
             teamPoints[i] = new KeyValuePair <Teams, int?>(allTeams[i], Convert.ToInt32(propInfo.GetValue(points)));
         }
         teamPoints = teamPoints.OrderByDescending(m => m.Value).ToArray();
         for (int i = 0; i < teamPoints.Length; i++)
         {
             if (teamPoints[i].Value == 0)
             {
                 teamPoints[i] = new KeyValuePair <Teams, int?>(teamPoints[i].Key, null);
             }
             else
             {
                 teamPoints[i] = new KeyValuePair <Teams, int?>(teamPoints[i].Key, i + 1);
             }
         }
         Positions positions = new Positions();
         positions.ID = _currentSeason.ToString();
         for (int i = 0; i < allTeams.Length; i++)
         {
             int?         pkt      = teamPoints.Where(m => m.Key == allTeams[i]).First().Value;
             PropertyInfo propInfo = new Positions().GetType().GetProperty(allTeams[i].Name.Replace(' ', '_').Replace('.', '_'));
             if (pkt != null && pkt != 0)
             {
                 propInfo.SetValue(positions, Convert.ToInt32(teamPoints.Where(m => m.Key == allTeams[i]).First().Value));
             }
             else
             {
                 propInfo.SetValue(positions, null);
             }
         }
         _positionsRepository.Add(positions);
         _positionsRepository.SaveChanges();
     }
 }