//Ranks popular games on the G&H platform using two different critera, associated players and associated events. Players are worth more then events and both are multiplied to scale public ActionResult GetPopularSiteGames() { //Gets all GAME IDs from APIGAMES and counts their occurances this is the base score of the game List <customGame> allAPIGameIDs = (from b in db.APIEventGames group b.GameID by b.GameID into g orderby g.Count() descending select new customGame { id = g.Key, score = (g.Count() + 1) * 1.2 }).ToList(); //Join Events with APIEventGames so we can count the amount of players associated with the game var JoinEventsAPIEvents = (from b in db.Events join product in db.APIEventGames on b.ID equals product.EventID select product); //Using our joined table, count the players for each event, if the event have more then 1 EventPlayer then select it and output it //Contains a list of EventPlayers count, GameID and EventID List <custom> countPlayers = (from b in JoinEventsAPIEvents where b.Event.EventPlayers.Count > 1 select new custom { Score = b.Event.EventPlayers.Count, gameID = b.GameID }).ToList(); //Add the score from allAPIGameIDs to each associated game in our data list //Adds one the the score of each game for each associated EventPlayer and multiplies the overall value by 1.8 for (int i = 0; i != countPlayers.Count(); i++) { customGame current = allAPIGameIDs.Find(d => d.id == countPlayers.ElementAt(i).gameID); current.score += (countPlayers.ElementAt(i).Score + 1) * 1.4; } //Gets the rest of the information required to display the game and details GetGamesFromAPI(allAPIGameIDs); //Sort all elements by their score inplace allAPIGameIDs.Sort((x, y) => y.score.CompareTo(x.score)); ViewBag.Games = allAPIGameIDs; return(View()); }
public customGame GetGame(customGame currentGame) { string cred = System.Web.Configuration.WebConfigurationManager.AppSettings["AtlasKey"]; string URL = "https://www.boardgameatlas.com/api/search?ids=" + currentGame.id + "&client_id=" + System.Web.Configuration.WebConfigurationManager.AppSettings["AtlasKey"]; Debug.WriteLine(URL); string allData = SendRequest(URL); JObject rootObj = JObject.Parse(allData); Debug.WriteLine(allData); List <string> outputIDs = new List <string>(); List <string> outputNames = new List <string>(); List <string> outputThumbUrls = new List <string>(); List <string> min_playersList = new List <string>(); List <string> max_playersList = new List <string>(); List <string> description_previewList = new List <string>(); List <string> reddit_week_countList = new List <string>(); List <string> categoriesList = new List <string>(); List <string> avgUsrRatingList = new List <string>(); for (int i = 0; i < 1; i++) { var getIDs = (string)rootObj.SelectToken("games[" + i + "].id"); outputIDs.Add(getIDs); var getNames = (string)rootObj.SelectToken("games[" + i + "].name"); outputNames.Add(getNames); var getThumbUrls = (string)rootObj.SelectToken("games[" + i + "].thumb_url"); outputThumbUrls.Add(getThumbUrls); var getDescriptionPrev = (string)rootObj.SelectToken("games[" + i + "].description_preview"); description_previewList.Add(getDescriptionPrev); var getCount = (string)rootObj.SelectToken("games[" + i + "].reddit_all_time_count"); reddit_week_countList.Add(getCount); var getCategories = rootObj.SelectToken("games[" + i + "].categories"); if (getCategories != null) { categoriesList.Add(getCategories.ToString()); } var getMinPlayers = (string)rootObj.SelectToken("games[" + i + "].min_players"); min_playersList.Add(getMinPlayers); var getMaxPlayers = (string)rootObj.SelectToken("games[" + i + "].max_players"); max_playersList.Add(getMaxPlayers); var getAvgRating = (string)rootObj.SelectToken("games[" + i + "].average_user_rating"); if (getAvgRating != null) { avgUsrRatingList.Add(getAvgRating.Substring(0, 3)); } currentGame.id = outputIDs.ElementAt(i); currentGame.name = outputNames.ElementAt(i); currentGame.min_players = min_playersList.ElementAt(i); currentGame.max_players = max_playersList.ElementAt(i); currentGame.description_preview = description_previewList.ElementAt(i); currentGame.average_user_rating = avgUsrRatingList.ElementAt(i); currentGame.reddit_all_time_count = reddit_week_countList.ElementAt(i); currentGame.thumb_url = outputThumbUrls.ElementAt(i); } return(currentGame); }