Ejemplo n.º 1
0
        public ChartDataSet GetPlayerDetailsChartData(int id, byte interval, byte dataKind)
        {
            var result = new ChartDataSet();
            var player = _dbContext.Player.SingleOrDefault(p => p.Id == id);

            if (player == null)
            {
                return(result);
            }
            var startDate = ChartDataSet.GetStartDate(interval);

            if (startDate == null)
            {
                return(result);
            }
            var relevantData = _dbContext.PlayerHistory.Where(ph => ph.PlayerId == id && ph.RecordedAt >= startDate)
                               .OrderBy(ph => ph.RecordedAt)
                               .AsEnumerable() // Flesh out the data before client-side grouping
                               .GroupBy(ph => ph.RecordedAt.Date)
                               .Select(g =>
                                       new {
                RecordedAt   = g.Key,
                HistoryEntry = g.OrderByDescending(ph => ph.RecordedAt).First()
            }
                                       );

            switch (dataKind)
            {
            case (byte)ChartDataSet.DataKind.StatsTotal:
                result.AddRange(
                    relevantData.Select(he => new ChartDataPoint {
                    t = he.RecordedAt, y = (double)he.HistoryEntry.StatTotal
                })
                    );
                break;

            case (byte)ChartDataSet.DataKind.Credits:
                result.AddRange(
                    relevantData.Select(he => new ChartDataPoint {
                    t = he.RecordedAt, y = (double)he.HistoryEntry.Bank
                })
                    );
                break;

            case (byte)ChartDataSet.DataKind.Bonds:
                result.AddRange(
                    relevantData.Select(he => new ChartDataPoint {
                    t = he.RecordedAt, y = (double)he.HistoryEntry.Bonds
                })
                    );
                break;

            case (byte)ChartDataSet.DataKind.XP:
                result.AddRange(
                    relevantData.Select(he => new ChartDataPoint {
                    t = he.RecordedAt, y = (double)he.HistoryEntry.Level
                })
                    );
                break;

            default:     // This means invalid input data
                return(result);
            }

            return(result);
        }
Ejemplo n.º 2
0
        public ChartDataSet GetSyndicateHistoricalData(int syndicateId, byte interval, byte dataKind)
        {
            var result    = new ChartDataSet();
            var syndicate = _dbContext.Syndicate.SingleOrDefault(s => s.Id == syndicateId);

            if (syndicate == null)
            {
                return(result);
            }
            var startDate = ChartDataSet.GetStartDate(interval);

            if (startDate == null)
            {
                return(result);
            }
            var relevantData = _dbContext.SyndicateHistory.Where(sh => sh.SyndicateId == syndicateId && sh.RecordedAt >= startDate)
                               .OrderBy(sh => sh.RecordedAt)
                               .AsEnumerable() // Flesh out the data before client-side grouping
                               .GroupBy(sh => sh.RecordedAt.Date)
                               .Select(g =>
                                       new {
                RecordedAt   = g.Key,
                HistoryEntry = g.OrderByDescending(sh => sh.RecordedAt).First()
            }
                                       );

            switch (dataKind)
            {
            case (byte)ChartDataSet.DataKind.MemberCount:
                result.AddRange(
                    relevantData.Select(he => new ChartDataPoint {
                    t = he.RecordedAt, y = (double)he.HistoryEntry.MembersCount
                })
                    );
                break;

            case (byte)ChartDataSet.DataKind.Credits:
                result.AddRange(
                    relevantData.Select(he => new ChartDataPoint {
                    t = he.RecordedAt, y = (double)he.HistoryEntry.Credits
                })
                    );
                break;

            case (byte)ChartDataSet.DataKind.Bonds:
                result.AddRange(
                    relevantData.Select(he => new ChartDataPoint {
                    t = he.RecordedAt, y = (double)he.HistoryEntry.Bonds
                })
                    );
                break;

            case (byte)ChartDataSet.DataKind.XP:
                result.AddRange(
                    relevantData.Select(he => new ChartDataPoint {
                    t = he.RecordedAt, y = (double)he.HistoryEntry.Level
                })
                    );
                break;

            default:     // This means invalid input data
                return(result);
            }

            return(result);
        }