// Получение топа дня/недели 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); }
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); }
public async Task <string> SortVideos(string text) { string input = text.Replace("\r", "").Replace("\n[hide]", "[hide]").Replace("[/hide][img]", "[/hide]\n[img]").Replace("[/hide] [img]", "[/hide]\n[img]"); string[] lines = input.Split('\n'); List <Video> videoList = new List <Video>(); int counter = 0; foreach (string line in lines) { ChangeProgress(new Progress(counter++, lines.Length)); string id = Regex.Match(line, "klavogonki.ru/u/#/(\\d+)/\"").Groups[1].ToString(); if (id == "") { continue; } var aj = await quickStatService.GetQuickStat(int.Parse(id), "normal"); int record = aj.Value?.Record ?? 0; var video = new Video() { Text = line, Record = record }; if (aj.Value?.Id == 215625 || aj.Value?.Id == 326740) { video.Record = 800; } else if (aj.Value?.Id == 319684 && record == 0) { video.Record = 600; } videoList.Add(video); } videoList.Sort(); StringBuilder sb = new StringBuilder(500); foreach (Video v in videoList) { sb.Append(v.Text); sb.Append("\r\n"); } ChangeProgress(new Progress(lines.Length, lines.Length)); return(sb.ToString().Replace("[/hide]\r\n[img]", "[/hide][img]")); }
private async Task GetQuickStat() { int counter = 0; var users = Users.Where(x => !x.IsTeamPlayer && !x.IsOldTeamPlayer && x.LeadFriendsCount >= 1 && x.TopStat != null && x.TopStat.AvgErRate <= 0.035).ToList(); foreach (var user in users) { var qs = await quickStatService.GetQuickStat(user.Id); if (qs.UserExists) { user.QuickStat = qs.Value; user.HasTwoThirdEhoughMileage = user.QuickStat.Mileage >= GetMinimumMileage(user.QuickStat.Rank) * 0.666; user.HasEhoughMileage = user.QuickStat.Mileage >= GetMinimumMileage(user.QuickStat.Rank); } ChangeProgress(new Progress(operationCount, operationsCount, ++counter, users.Count)); } }
public async Task <HiddenStat> GetHiddenStat(int userId) { HiddenStat hiddenStat = new HiddenStat(userId); ChangeProgress(new Progress(0)); var qsNormal = await quickStatService.GetQuickStat(userId, "normal"); this.AwardIds = qsNormal.Value.Awards.Select(x => x.ModeId).ToArray(); hiddenStat.TotalMileage = qsNormal.Value.TotalMileage; string json = await NetworkClient.DownloadstringAsync("http://klavogonki.ru/api/profile/get-achieves?q=progress&skip=0&sort=difficulty&userId=" + userId); json = json.Replace("$id", "id"); var achs = JsonHelper.Deserialize <Achievements>(json); List <Tuple <string, double> > userAch = new List <Tuple <string, double> >(32); if (achs.Achieves != null) { foreach (var ach in achs.Achieves) { Achievements.ProgressAchievement a = achs.List.Find(x => x.AchieveId.Id == ach.Key); if (a == null) { continue; } if (ach.Value.Achieve.Name == "Book") { Tuple <string, double> voc = new Tuple <string, double>("voc-" + ach.Value.Achieve.VocId, a.Progress * ach.Value.BookSnippet);// разобраться что это делает userAch.Add(voc); } else if (ach.Value.Achieve.Name == "NumRacesLocal") { Tuple <string, double> voc = new Tuple <string, double> (ach.Value.Achieve.GameType, a.Progress + (a.LevelProgress ?? 0)); userAch.Add(voc); } } } this.AchiveIds = userAch.OrderByDescending(x => x.Item2).Select(x => x.Item1).ToArray(); var modeIds = AwardIds.Union(AchiveIds).ToArray(); for (int i = 0; i < modeIds.Length; i++) { ChangeProgress(new Progress(i, modeIds.Length, hiddenStat.MileageCount, hiddenStat.TotalMileage)); if (!hiddenStat.QuickStats.Exists(x => x.Mode.ModeId == modeIds[i])) { var qs = await quickStatService.GetQuickStat(userId, modeIds[i]); hiddenStat.MileageCount += qs.Value.Mileage; hiddenStat.QuickStats.Add(qs.Value); } if ((i + 1) % 50 == 0) { hiddenStat.QuickStats.Sort(new QuickStat.QuickStartMileageComparer()); PreliminaryHiddenStatUpdated?.Invoke(this, new EventArgs <HiddenStat>(hiddenStat)); } } hiddenStat.QuickStats.Sort(new QuickStat.QuickStartMileageComparer()); ChangeProgress(new Progress(modeIds.Length, modeIds.Length)); return(hiddenStat); }
private async Task <List <HrustPlayer> > GetHrustResults(List <User> users) { List <string> closed = new List <string>(); List <HrustPlayer> results = new List <HrustPlayer>(); int counter = 0; ChangeProgress(new Progress(0, users.Count)); foreach (var user in users) { var os = await openStatService.GetOpenStat(user.Id); HrustPlayer hs; if (os.IsOpen) { string userNick = user.Nick; if (string.IsNullOrEmpty(user.Nick)) { var normalQs = await quickStatService.GetQuickStat(user.Id); userNick = normalQs.Value.Nick; } hs = new HrustPlayer(user.Id, userNick, false); hs.NormalStat.Mileage = os.Value.Gametypes["normal"].Info.NumRaces; hs.NormalStat.Record = os.Value.Gametypes["normal"].Info.BestSpeed.Value; hs.NormalStat.Rank = Rank.GetByRecord(os.Value.Gametypes["normal"].Info.BestSpeed.Value); for (int i = 0; i < HrustConstants.ModeIds.Length; i++) { if (os.Value.Gametypes.ContainsKey(HrustConstants.ModeIds[i])) { hs.ExercisesStat[i].Record = os.Value.Gametypes[HrustConstants.ModeIds[i]].Info.BestSpeed.Value; hs.ExercisesStat[i].Mileage = os.Value.Gametypes[HrustConstants.ModeIds[i]].Info.NumRaces; } } } else { var normalQs = await quickStatService.GetQuickStat(user.Id); hs = new HrustPlayer(user.Id, normalQs.Value.Nick, true); hs.NormalStat.Record = normalQs.Value.Record; hs.NormalStat.Mileage = normalQs.Value.Mileage; hs.NormalStat.Rank = normalQs.Value.Rank; for (int i = 23; i >= 0; i--) { var qs = await quickStatService.GetQuickStat(user.Id, HrustConstants.ModeIds[i]); if (qs.Value.Mileage == 0) { closed.Add(user.Nick); continue; } else { hs.ExercisesStat[i].Record = qs.Value.Record; hs.ExercisesStat[i].Mileage = qs.Value.Mileage; } } } hs.Calculate(); results.Add(hs); ChangeProgress(new Progress(++counter, users.Count)); } results.Sort(); return(results); }
public async Task <List <UserInfoStat> > GetUserInfoStatList(List <int> userIds, bool needFriends) { ChangeProgress(new Progress(0, userIds.Count)); var result = new List <UserInfoStat>(userIds.Count); for (int i = 0; i < userIds.Count; i++) { ChangeProgress(new Progress(i, userIds.Count)); UserInfoStat uis = new UserInfoStat(); uis.UserInfo = (await userInfoService.GetUserInfo(userIds[i])).Value; uis.QuickStat = (await quickStatService.GetQuickStat(userIds[i], "normal")).Value; uis.CalculateRanks(); int sumRating = 0; if (needFriends && userIds[i] != 152219 && userIds[i] != 199825) { var friendlist = await friendsService.GetFriends(userIds[i]); for (int j = 0; j < friendlist.Count; j++) { ChangeProgress(new Progress(i, userIds.Count, j, friendlist.Count)); double pr0 = i * 100.0 / userIds.Count; //количество % в начале расчета игрока 33% double pr1 = 100.0 / userIds.Count; //сколько один игрок занимает процентов double pr2 = j * 100.0 / friendlist.Count; //сколько процентов друзей обработано int index = UserInfoStatDB.FindIndex(x => x.UserInfo.Id == friendlist[j].Id); if (index >= 0) { sumRating += UserInfoStatDB[index].Ranks.Total; } else { UserInfoStat fuis = new UserInfoStat(); fuis.UserInfo = (await userInfoService.GetUserInfo(friendlist[j].Id)).Value; fuis.QuickStat = (await quickStatService.GetQuickStat(friendlist[j].Id, "normal")).Value; fuis.CalculateRanks(); UserInfoStatDB.Add(fuis); sumRating += fuis.Ranks.Total; } } uis.FriendsRating = friendlist.Count == 0 ? 0 : sumRating / friendlist.Count; } result.Add(uis); int ind = UserInfoStatDB.FindIndex(x => x.UserInfo.Id == uis.UserInfo.Id); if (ind >= 0) { UserInfoStatDB[ind] = uis; } else { UserInfoStatDB.Add(uis); } } ChangeProgress(new Progress(userIds.Count, userIds.Count)); dataProvider.Save(UserInfoStatDB); return(result); }