public async Task FindTotalGameWorth() { ApiHelper api = ApiHelper.Instance; api.SetKey(API_KEY); var data = await api.GetGamesForUser(TEST_OLD_ACC_URL, true); var appIds = data.Select(sgm => sgm.appid).ToList(); var detailedData = await api.GetDetailedGameInfos(appIds); double worth = DataAnalyzer.CalculateTotalGameWorth(detailedData); Assert.AreEqual(150.98, worth); }
// GET: PlayerModels/Create public async Task <IActionResult> DetailedGames(string id) { if (id == null) { return(NotFound()); } GameViewModel info = new GameViewModel(); try { // Retrieve all raw data ApiHelper.Instance.SetKey(Constants.API_KEY); var userGames = await ApiHelper.Instance.GetGamesForUser(id, true); var ids = userGames.Select(sgm => sgm.appid).ToList(); var detailedGames = await _context.GetDetailedGameDatas(ids); // Compile into something easier to work with var overview = userGames.ToDictionary( sgm => sgm.appid, sgm => new GameValue() { simpleGame = sgm } ); foreach (DetailedGameData dgd in detailedGames) { overview[dgd.steam_appid].detailedGame = dgd; } // Calculate necessary values var count = userGames.Count; var totalTime = DataAnalyzer.CalculateTotalTimePlayed(userGames); var totalWorth = DataAnalyzer.CalculateTotalGameWorth(detailedGames); var mostExpensive = DataAnalyzer.FindMostExpensiveGame(detailedGames); var leastExpensive = DataAnalyzer.FindLeastExpensiveGame(detailedGames); var mostWorth = DataAnalyzer.FindMostWorthGame(userGames, detailedGames); var leastWorth = DataAnalyzer.FindMostWorthGame(userGames, detailedGames); // Construct view model info.RequestId = System.Diagnostics.Activity.Current?.Id ?? HttpContext.TraceIdentifier; info.GameCount = count; info.TotalTimePlayed = totalTime + " minutes"; info.TotalWorth = "$" + totalWorth; info.MostExpensiveGame = overview[mostExpensive.steam_appid]; info.LeastExpensiveGame = overview[leastExpensive.steam_appid]; info.MostWorthGame = mostWorth; info.LeastWorthGame = leastWorth; info.Games = overview.Select(o => o.Value).ToList(); } catch (MissingSteamIDException ex) { return(NotFound()); } catch (InvalidSteamIDException ex) { return(NotFound()); } if (info == null) { return(NotFound()); } return(View(info)); }