예제 #1
0
        public ActionResult Ladder()
        {
            var ret = MemCache.GetCached("pwLadder",
                                         () =>
            {
                ZkDataContext db      = new ZkDataContext();
                var gal               = db.Galaxies.First(x => x.IsDefault);
                DateTime minDate      = gal.Started ?? DateTime.UtcNow;
                List <PwLadder> items = db.Accounts.Where(x => x.FactionID != null && x.LastLogin > minDate && x.SpringBattlePlayers.Any(y => y.SpringBattle.StartTime > minDate && !y.IsSpectator && y.SpringBattle.Mode == AutohostMode.Planetwars)).ToList().GroupBy(x => x.Faction)
                                        .Select(
                    x =>
                    new PwLadder
                {
                    Faction = x.Key,
                    Top10   =
                        x.OrderByDescending(y => y.PwAttackPoints)
                        .ThenByDescending(y => y.AccountRatings.Where(r => r.RatingCategory == RatingCategory.Planetwars).Select(r => r.LadderElo).DefaultIfEmpty(WholeHistoryRating.DefaultRating.RealElo).FirstOrDefault())
                        .Take(10)
                        .ToList()
                })
                                        .ToList();
                return(items);
            },
                                         60 * 2);

            return(View("Ladder", ret));
        }
예제 #2
0
        /// <summary>
        /// Go to home page; also updates news read dates
        /// </summary>
        public ActionResult Index()
        {
            // TODO: make two separate pages -- one for logged in users, one for not-logged in users
            // logged in users see their user profile
            // non-logged in users see promotional page

            var db = new ZkDataContext();

            if (!Global.IsAccountAuthorized)
            {
                return(View("Splash"));
            }

            // TODO: randomized backgrounds move here
            var result = new IndexResult
            {
                Spotlight         = SpotlightHandler.GetRandom(),
                Top10Players      = RatingSystems.GetRatingSystem(RatingCategory.MatchMaking).GetTopPlayers(10),
                WikiRecentChanges = MediaWikiRecentChanges.LoadRecentChanges(),
                LobbyStats        = MemCache.GetCached("lobby_stats", GetCurrentLobbyStats, 60 * 2),
                News       = db.News.Where(x => x.Created < DateTime.UtcNow).OrderByDescending(x => x.Created),
                Headlines  = GetHeadlines(db),
                NewThreads = GetNewForumThreads(db)
            };

            return(View("HomeIndex", result));
        }
예제 #3
0
        public ActionResult Index(ChartsModel model)
        {
            model = model ?? new ChartsModel();
            model.PossibleGraphs = GetPossibleProviders().Select(x => new ChartsModel.PossibleGraph()
            {
                Title = x.Title, Name = x.Name
            }).ToList();


            var to       = model.To.Date;
            var from     = model.From.Date;
            var grouping = model.Grouping;

            var providers = GetPossibleProviders().Where(x => model.Graphs.Contains(x.Name));

            var series = new List <GraphSeries>();

            foreach (var prov in providers)
            {
                var data = MemCache.GetCached($"chart_{prov.Title}_{from}_{to}", () => GraphPoint.FillHoles(prov.GetDailyValues(from, to), from, to).ToList(), 3600 * 24);


                if (grouping > 1)
                {
                    data =
                        data.GroupBy(x => (int)x.Day.Subtract(from).TotalDays / grouping)
                        .Select(x => new GraphPoint()
                    {
                        Day = x.First().Day, Value = x.Average(y => y.Value)
                    })
                        .ToList();
                }

                series.Add(new GraphSeries()
                {
                    Title = prov.Title, Data = data
                });
            }


            if (model.Normalize)
            {
                foreach (var s in series)
                {
                    var min = s.Data.Min(x => x.Value);
                    var max = s.Data.Max(x => x.Value);

                    foreach (var d in s.Data)
                    {
                        d.Value = 100.0 * (d.Value - min) / (max - min);
                    }
                }
            }

            model.GraphingData = series;
            return(View("ChartsIndex", model));
        }
예제 #4
0
        public ActionResult GenerateGraph(ChartsModel model)
        {
            model = model ?? new ChartsModel();

            var to       = model.To.Date;
            var from     = model.From.Date;
            var grouping = model.Grouping;

            var providers = GetPossibleProviders().Where(x => model.Graphs.Contains(x.Name));

            var series = new List <GraphSeries>();

            foreach (var prov in providers)
            {
                var data = MemCache.GetCached($"chart_{prov.Title}_{from}_{to}", () => GraphPoint.FillHoles(prov.GetDailyValues(from, to), from, to).ToList(), 3600 * 24);


                if (grouping > 1)
                {
                    data =
                        data.GroupBy(x => (int)x.Day.Subtract(from).TotalDays / grouping)
                        .Select(x => new GraphPoint()
                    {
                        Day = x.First().Day, Value = x.Average(y => y.Value)
                    })
                        .ToList();
                }

                series.Add(new GraphSeries()
                {
                    Title = prov.Title, Data = data
                });
            }


            if (model.Normalize)
            {
                foreach (var s in series)
                {
                    var min = s.Data.Min(x => x.Value);
                    var max = s.Data.Max(x => x.Value);

                    foreach (var d in s.Data)
                    {
                        d.Value = 100.0 * (d.Value - min) / (max - min);
                    }
                }
            }

            // TODO: convert this to System.Web.UI.DataVisualization.Charting  (which this thing is internally using)

            var chart = new Chart(1500, 700, ChartTheme.Blue);

            chart.AddTitle(string.Join(", ", providers.Select(x => x.Name)));
            chart.AddLegend("Daily values", "l");
            var graphType = "Line";

            foreach (var s in series)
            {
                chart.AddSeries(s.Title,
                                graphType,
                                xValue: s.Data.Select(x => x.Day.Date.ToString("d")).ToList(),
                                yValues: s.Data.Select(y => y.Value).ToList(),
                                legend: "l");
            }

            return(File(chart.GetBytes("png"), "image/png"));
        }
예제 #5
0
        /// <summary>
        /// Go to home page; also updates news read dates
        /// </summary>
        public ActionResult Index()
        {
            var db = new ZkDataContext();


            var result = new IndexResult()
            {
                Spotlight         = SpotlightHandler.GetRandom(),
                Top10Players      = RatingSystems.GetRatingSystem(RatingCategory.MatchMaking).GetTopPlayers(10),
                WikiRecentChanges = MediaWikiRecentChanges.LoadRecentChanges()
            };

            result.LobbyStats = MemCache.GetCached("lobby_stats", GetCurrentLobbyStats, 60 * 2);

            result.News = db.News.Where(x => x.Created < DateTime.UtcNow).OrderByDescending(x => x.Created);
            if (Global.Account != null)
            {
                result.Headlines =
                    db.News.Where(
                        x => x.Created <DateTime.UtcNow && x.HeadlineUntil != null && x.HeadlineUntil> DateTime.UtcNow && !x.ForumThread.ForumThreadLastReads.Any(y => y.AccountID == Global.AccountID && y.LastRead != null)).
                    OrderByDescending(x => x.Created).ToList();

                if (result.Headlines.Any())
                {
                    foreach (var h in result.Headlines)
                    {
                        h.ForumThread.UpdateLastRead(Global.AccountID, false);
                    }

                    db.SaveChanges();
                }
            }
            else
            {
                result.Headlines = new List <News>();
            }


            var accessibleThreads = db.ForumThreads.Where(x => x.RestrictedClanID == null || x.RestrictedClanID == Global.ClanID);

            accessibleThreads = accessibleThreads.Where(x => x.ForumCategory.ForumMode != ForumMode.Archive);
            if (!Global.IsAccountAuthorized)
            {
                result.NewThreads = accessibleThreads.OrderByDescending(x => x.LastPost).Take(10).Select(x => new NewThreadEntry()
                {
                    ForumThread = x
                });
            }
            else
            {
                result.NewThreads = (from t in accessibleThreads
                                     let read = t.ForumThreadLastReads.FirstOrDefault(x => x.AccountID == Global.AccountID)
                                                let readForum = t.ForumCategory.ForumLastReads.FirstOrDefault(x => x.AccountID == Global.AccountID)
                                                                where (read == null || t.LastPost > read.LastRead) && (readForum == null || t.LastPost > readForum.LastRead)
                                                                orderby t.LastPost descending
                                                                select new NewThreadEntry {
                    ForumThread = t, WasRead = read != null, WasWritten = read != null && read.LastPosted != null
                }).
                                    Take(10);
            }



            return(View("HomeIndex", result));
        }