Пример #1
0
        // Получение топа дня/недели
        public async Task <ModeStatList> GetBulkTop(ModeStatSettings input, Period period)
        {
            ChangeProgress(new Progress(0));

            var statType = new StatType()
            {
                HasQuickStat     = input.NeedQuickStat,
                HasPeriod        = input.NeedPeriodStat,
                HasDayTopResult  = period == Period.Day,
                HasWeekTopResult = period == Period.Week
            };
            ModeStatList results = new ModeStatList(statType);


            foreach (var modeId in input.ModeIds)
            {
                int top_maxpages  = (int)Math.Round(input.MaxUsers / 30.0, 0);
                int progressTotal = top_maxpages * 30;

                List <TopStat> topResults = await GetTop(modeId, input.MaxUsers, period);

                ModeStat modeStat = new ModeStat(new Mode(modeId));
                foreach (var player in topResults)
                {
                    modeStat.Add(new Stat(player.Id)
                    {
                        TopResult = player.Result
                    });
                }
                results.Add(modeStat);
                ChangeProgress(new Progress(input.ModeIds.Count, input.ModeIds.Count, progressTotal, progressTotal));
            }

            foreach (var modeStat in results)
            {
                foreach (var stat in modeStat)
                {
                    if (input.NeedQuickStat)
                    {
                        stat.QuickStat = (await quickStatService.GetQuickStat(stat.UserId, modeStat.Mode.ModeId)).Value;
                    }

                    if (input.NeedPeriodStat && input.DateFrom != null && input.DateTo != null)
                    {
                        //http://klavogonki.ru/api/profile/get-stats-details-data?userId=231371&gametype=normal&fromDate=2016-01-08&toDate=2016-02-07&grouping=day

                        var daysStat = await periodStatService.GetDaysStat(stat.UserId, modeStat.Mode.ModeId);

                        var periodStat = periodStatService.GetPeriodStat(daysStat.Value, from: input.DateFrom.Value, to: input.DateTo.Value);

                        stat.PeriodStat = periodStat;
                    }
                }
            }
            return(results);
        }
Пример #2
0
        public async Task <ModeStatList> GetStatsByUsersAndModes(ModeStatSettings input)
        {
            ChangeProgress(new Progress(0));

            bool needPeriod   = input.NeedPeriodStat && input.DateFrom != null && input.DateTo != null;
            var  modeStatList = new ModeStatList(new StatType {
                HasPeriod = needPeriod
            });

            int progressCounter = 0;
            int progressTotal   = input.ModeIds.Count * input.UserIds.Count;

            foreach (var modeId in input.ModeIds)
            {
                var mode = new Mode(modeId);
                var list = new ModeStat(mode);
                foreach (var userId in input.UserIds)
                {
                    ChangeProgress(new Progress(progressCounter++, progressTotal));

                    var qs = await quickStatService.GetQuickStat(userId, modeId);

                    if (string.IsNullOrEmpty(mode.Name) && qs.Value != null)
                    {
                        mode.SetName(qs.Value.Mode.Name);
                    }

                    var s = await detailedStatService.GetDayStat(userId, modeId, DateTime.Today);

                    Stat stat = new Stat(qs.Value)
                    {
                        HasPremium = s.Value?.HasPremium
                    };

                    if (needPeriod)
                    {
                        var daysStat = await periodStatService.GetDaysStat(userId, modeId);

                        if (daysStat.IsOpen)
                        {
                            var periodStat = periodStatService.GetPeriodStat(daysStat.Value, from: input.DateFrom.Value, to: input.DateTo.Value, maxSpeed: qs.Value.Record);
                            stat.PeriodStat = periodStat;
                        }
                    }

                    list.Add(stat);
                }
                modeStatList.Add(list);
            }
            ChangeProgress(new Progress(progressCounter, progressTotal));
            return(modeStatList);
        }