コード例 #1
0
ファイル: R6Business.cs プロジェクト: G159w/GameStatProject
        public async Task <GenericResponse <IEnumerable <R6LeaderboardResponse> > > GetLeaderboard(string sortBy, string gameMode)
        {
            GenericResponse <IEnumerable <TR6Stat> > leaderboards = await _r6DataAccess.GetLeaderboard(sortBy, gameMode);

            if (leaderboards.Success)
            {
                // Convert to correct model
                IEnumerable <R6LeaderboardResponse> convertedResult = leaderboards.Result.Select(i =>
                {
                    R6StatsResponse baseObject = i.ConvertToR6StatsResponse();
                    return(new R6LeaderboardResponse
                    {
                        GameUsername = i.UserGame.Username,
                        Username = i.UserGame.User.Username,
                        UserId = i.UserGame.UserId,
                        Player = baseObject.Player
                    });
                });
                return(new GenericResponse <IEnumerable <R6LeaderboardResponse> >(convertedResult));
            }
            else
            {
                return(new GenericResponse <IEnumerable <R6LeaderboardResponse> >(leaderboards.ErrorMessage, leaderboards.Exception));
            }
        }
コード例 #2
0
ファイル: R6DataAccess.cs プロジェクト: G159w/GameStatProject
        public async Task <GenericResponse <BooleanResponse> > UpdateCache(R6StatsResponse r6StatsResponse, TUserGame userGame)
        {
            TR6Stat dbStats = _databaseContext.TR6Stat.FirstOrDefault(s => s.UserGame.Username == userGame.Username);

            bool newStats = false;

            if (dbStats == null)
            {
                newStats = true;
                dbStats  = new TR6Stat {
                    UserGameId = userGame.Id
                };
            }

            dbStats.CasualDeaths   = r6StatsResponse.Player.Stats.Casual.Deaths;
            dbStats.CasualKd       = r6StatsResponse.Player.Stats.Casual.Kd;
            dbStats.CasualKills    = r6StatsResponse.Player.Stats.Casual.Kills;
            dbStats.CasualLosses   = r6StatsResponse.Player.Stats.Casual.Losses;
            dbStats.CasualPlaytime = r6StatsResponse.Player.Stats.Casual.Playtime;
            dbStats.CasualWins     = r6StatsResponse.Player.Stats.Casual.Wins;
            dbStats.CasualWlr      = r6StatsResponse.Player.Stats.Casual.Wlr;
            dbStats.PlayerLevel    = r6StatsResponse.Player.Stats.Progression.Level;
            dbStats.RankedDeaths   = r6StatsResponse.Player.Stats.Ranked.Deaths;
            dbStats.RankedKd       = r6StatsResponse.Player.Stats.Ranked.Kd;
            dbStats.RankedKills    = r6StatsResponse.Player.Stats.Ranked.Kills;
            dbStats.RankedLosses   = r6StatsResponse.Player.Stats.Ranked.Losses;
            dbStats.RankedPlaytime = r6StatsResponse.Player.Stats.Ranked.Playtime;
            dbStats.RankedWins     = r6StatsResponse.Player.Stats.Ranked.Wins;
            dbStats.RankedWlr      = r6StatsResponse.Player.Stats.Ranked.Wlr;

            try
            {
                if (newStats)
                {
                    _databaseContext.TR6Stat.Add(dbStats);
                }
                else
                {
                    _databaseContext.TR6Stat.Update(dbStats);
                }
                await _databaseContext.SaveChangesAsync();

                return(new GenericResponse <BooleanResponse>(new BooleanResponse {
                    Success = true
                }));
            }
            catch (DbUpdateException e)
            {
                return(new GenericResponse <BooleanResponse>("Error while saving in cache", e));
            }
        }
コード例 #3
0
ファイル: R6Tools.cs プロジェクト: G159w/GameStatProject
        public static R6StatsResponse ConvertToR6StatsResponse(this R6TrackerResponse r6TrackerResponse)
        {
            if (r6TrackerResponse == null)
            {
                return(null);
            }

            // Convert casual/ranked player time to string
            TimeSpan casualPlaytime = TimeSpan.FromSeconds(r6TrackerResponse.Player.Stats.Casual.Playtime);
            TimeSpan rankedPlaytime = TimeSpan.FromSeconds(r6TrackerResponse.Player.Stats.Ranked.Playtime);

            R6StatsResponse res = new R6StatsResponse
            {
                Player = new R6StatsResponse.R6PlayerStats
                {
                    Stats = new R6StatsResponse.R6InnerStats
                    {
                        Casual = new R6StatsResponse.R6ModeStats
                        {
                            Deaths   = r6TrackerResponse.Player.Stats.Casual.Deaths,
                            Kd       = r6TrackerResponse.Player.Stats.Casual.Kd,
                            Kills    = r6TrackerResponse.Player.Stats.Casual.Kills,
                            Losses   = r6TrackerResponse.Player.Stats.Casual.Losses,
                            Playtime = $"{(long) casualPlaytime.TotalHours} hours",
                            Wins     = r6TrackerResponse.Player.Stats.Casual.Wins,
                            Wlr      = r6TrackerResponse.Player.Stats.Casual.Wlr,
                        },
                        Ranked = new R6StatsResponse.R6ModeStats
                        {
                            Deaths   = r6TrackerResponse.Player.Stats.Ranked.Deaths,
                            Kd       = r6TrackerResponse.Player.Stats.Ranked.Kd,
                            Kills    = r6TrackerResponse.Player.Stats.Ranked.Kills,
                            Losses   = r6TrackerResponse.Player.Stats.Ranked.Losses,
                            Playtime = $"{(long)rankedPlaytime.TotalHours} hours",
                            Wins     = r6TrackerResponse.Player.Stats.Ranked.Wins,
                            Wlr      = r6TrackerResponse.Player.Stats.Ranked.Wlr,
                        },
                        Progression = new R6StatsResponse.R6ProgressionStats
                        {
                            Level = r6TrackerResponse.Player.Stats.Progression.Level
                        }
                    }
                }
            };

            return(res);
        }
コード例 #4
0
ファイル: R6Tools.cs プロジェクト: G159w/GameStatProject
        public static R6StatsResponse ConvertToR6StatsResponse(this TR6Stat r6DbStats)
        {
            if (r6DbStats == null)
            {
                return(null);
            }

            R6StatsResponse res = new R6StatsResponse
            {
                Player = new R6StatsResponse.R6PlayerStats
                {
                    Stats = new R6StatsResponse.R6InnerStats
                    {
                        Casual = new R6StatsResponse.R6ModeStats
                        {
                            Deaths   = r6DbStats.CasualDeaths,
                            Kd       = r6DbStats.CasualKd,
                            Kills    = r6DbStats.CasualKills,
                            Losses   = r6DbStats.CasualLosses,
                            Playtime = r6DbStats.CasualPlaytime,
                            Wins     = r6DbStats.CasualWins,
                            Wlr      = r6DbStats.CasualWlr
                        },
                        Ranked = new R6StatsResponse.R6ModeStats
                        {
                            Deaths   = r6DbStats.RankedDeaths,
                            Kd       = r6DbStats.RankedKd,
                            Kills    = r6DbStats.RankedKills,
                            Losses   = r6DbStats.RankedLosses,
                            Playtime = r6DbStats.RankedPlaytime,
                            Wins     = r6DbStats.RankedWins,
                            Wlr      = r6DbStats.RankedWlr
                        },
                        Progression = new R6StatsResponse.R6ProgressionStats
                        {
                            Level = r6DbStats.PlayerLevel
                        }
                    }
                }
            };

            return(res);
        }