Пример #1
0
        /// <summary>
        /// Updates the player profile with a specific gs tournament id
        /// </summary>
        public static void UpdatePlayerProfiles(long gsTournamentId)
        {
            using DBContext c = new DBContext();
            GSTournament tournament = c.GSTournament.FirstOrDefault(t => t.Id == gsTournamentId);

            if (tournament == null)
            {
                return;
            }

            List <GSTeam>       teams   = c.GSTeam.Where(t => t.GSTournamentId == tournament.Id).ToList();
            List <GSTeamMember> members = new List <GSTeamMember>();

            for (int i = 0; i < teams.Count; i++)
            {
                foreach (GSTeamMember member in c.GSTeamMember.Where(t => t.GSTeamId == teams[i].Id))
                {
                    try
                    {
                        PlayerProfile p = c.PlayerProfile.FirstOrDefault(p => p.OsuId == member.OsuUserId);

                        if (p == null)
                        {
                            p = c.PlayerProfile.Add(new PlayerProfile()
                            {
                                OsuId         = member.OsuUserId,
                                Username      = "",
                                LastPlacement = "",
                                LastUpdated   = DateTime.UtcNow
                            }).Entity;

                            c.SaveChanges();
                        }

                        p.LastPlacement = teams[i].Placement.ToString(CultureInfo.CurrentCulture);
                        p.TournamentsPlayed++;

                        if (teams[i].Placement == 1)
                        {
                            p.TournamentWins++;
                        }

                        (int, string)rankAndUsername = GetRankAndUsername(member.OsuUserId);

                        p.BadgeCount  = GetBadgeCount(member.OsuUserId);
                        p.BWSRank     = CalculateBWS(rankAndUsername.Item1, p.BadgeCount);
                        p.Username    = rankAndUsername.Item2;
                        p.LastUpdated = DateTime.UtcNow;

                        c.PlayerProfile.Update(p);
                        c.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        Logger.Log($"Error building player profile, skipping: {ex}");
                        continue;
                    }
                }
            }
        }
Пример #2
0
            public IHttpContext Submit(IHttpContext c)
            {
                try
                {
                    if (!CheckApiKey(c))
                    {
                        return(c);
                    }
                    else if (GetApiKeyAccess(c) <= AccessLevel.Host)
                    {
                        Respond(HttpStatusCode.Forbidden, "Not Enough permissions", c);
                        return(c);
                    }

                    List <long> userIds = new List <long>();

                    BinaryAPIReader       reader       = new BinaryAPIReader(((HttpRequest)c.Request).Advanced.InputStream);
                    GlobalStatsTournament tourneystats = new GlobalStatsTournament();
                    tourneystats.Deserialize(reader);

                    using DBContext dbc = new DBContext();

                    GSTournament tourney = dbc.GSTournament.Add(new GSTournament(tourneystats.HostOsuId, tourneystats.Name, tourneystats.Acronym, tourneystats.Thread, tourneystats.CountryCode, tourneystats.Start, tourneystats.End, tourneystats.RankMin, tourneystats.RankMax)).Entity;
                    dbc.SaveChanges();

                    foreach (var teamstats in tourneystats.Teams)
                    {
                        GSTeam team = dbc.GSTeam.Add(new GSTeam(tourney.Id, teamstats.Placement, teamstats.Name)).Entity;
                        dbc.SaveChanges();

                        foreach (long userId in teamstats.OsuUserIds)
                        {
                            GSTeamMember member = new GSTeamMember(team.Id, userId);
                            dbc.GSTeamMember.Add(member);
                            userIds.Add(userId);
                        }
                    }

                    dbc.SaveChanges();

                    Task.Run(() => SkyBot.GlobalStatistics.GSStatisticHandler.UpdatePlayerProfiles(tourney.Id)).ConfigureAwait(false);

                    Respond(HttpStatusCode.Ok, "Submitted and updated", c);
                    return(c);
                }
                catch (Exception ex)
                {
                    Logger.Log(ex, LogLevel.Error);
                    Respond(HttpStatusCode.InternalServerError, ex.ToString(), c);
                    return(c);
                }
            }