Esempio n. 1
0
        public ActionResult User(int? id)
        {
            if (id == null)
                return Redirect("~/");

            User user = db.Users.Include("OverallRanks").Include("WeekRanks").Include("TeamPickRecords").Include("TeamPickRecords.Team").Where(u => u.UserID == id).FirstOrDefault();

            if (user == null || user.Rank == null)
                return Redirect("~/");

            List<User> users = db.Users.ToList();
            List<CurveData> curves = new List<CurveData>();
            int totalWins = 0;

            foreach (User u in users)
            {
                int? wins = u.Wins;
                totalWins += (int)wins;

                CurveData cd = curves.Where(c => c.NumWins == wins).FirstOrDefault();

                if (cd == null)
                {
                    cd = new CurveData();
                    cd.NumWins = (int)wins;
                    cd.NumUsers = 1;
                    curves.Add(cd);
                }
                else
                    cd.NumUsers++;
            }

            curves.Fill();
            curves = curves.OrderByDescending(c => c.NumWins).ToList();

            curves.Smooth(1, 3);

            ViewBag.AverageWins = Math.Round(Convert.ToDouble(users.Select(u => u.Wins).Average()), 2);
            ViewBag.CurveData = curves;
            ViewBag.NumUsers = users.Count;

            return View(user);
        }
Esempio n. 2
0
        public static void Fill(this List<CurveData> curves)
        {
            int min = 9999999;
            int max = 0;

            foreach (CurveData cd in curves)
            {
                if (cd.NumWins > max) max = cd.NumWins;
                if (cd.NumWins < min) min = cd.NumWins;
            }

            for (int i = min; i <= max; i++)
            {
                if (curves.Where(cd => cd.NumWins == i).Count() == 0)
                {
                    CurveData newCD = new CurveData();
                    newCD.NumUsers = 0;
                    newCD.NumWins = i;
                    curves.Add(newCD);
                }
            }
        }