Advertisement
Guest User

Metacritic calculator

a guest
Feb 23rd, 2020
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Usage: Go to https://www.metacritic.com/feature/best-videogames-released-in-2018 and open the console
  2. // Type in "var temp1 = <<paste Data here>>" and hit enter
  3. // Copy and paste this entire file into the console and run it to see the updated chart
  4.  
  5.    
  6. (function () {
  7.  
  8.  
  9.     const TARGET_YEAR = 2019;
  10.     const PLATFORMS = temp1
  11.     const SCORE_BREAKDOWN_ELEMENT = $('.listtable:first-of-type');
  12.  
  13.     function calculateTotals() {
  14.  
  15.         console.log("Updating Table");
  16.  
  17.         // Create exclusives list
  18.         const systemCountForGames = {}
  19.         for (let platform of PLATFORMS) {
  20.             for (let game of platform.data) {
  21.                     if (typeof systemCountForGames[game.title] === "undefined")
  22.                         systemCountForGames[game.title] = new Set([platform.key])
  23.                     else
  24.                         systemCountForGames[game.title].add(platform.key)
  25.             }
  26.         }
  27.  
  28.         // Update title
  29.         let newTitle = $('caption', SCORE_BREAKDOWN_ELEMENT).text().replace(/20[0-2]\d/, TARGET_YEAR);
  30.         $('caption', SCORE_BREAKDOWN_ELEMENT).text(newTitle)
  31.        
  32.         var v_post_string = "";
  33.         // Update table
  34.         for (let platform of PLATFORMS) {
  35.             // Update table
  36.             let tableRow = $(`tr:contains("${platform.title}")`, SCORE_BREAKDOWN_ELEMENT);
  37.             let columns = $('td', tableRow);
  38.  
  39.             let thisYearsGames = platform.data.filter(x=>x.year === TARGET_YEAR && x.score !== null);
  40.  
  41.             // Total
  42.             $(columns[2]).text(thisYearsGames.length)
  43.  
  44.             // Pie
  45.             let red = thisYearsGames.filter(x=> x.score <= 49).length;
  46.             let yellow = thisYearsGames.filter(x => 50 <= x.score && x.score <= 74).length;
  47.             let games75Higher = thisYearsGames.filter(x => 75 <= x.score);
  48.             let green = games75Higher.length;
  49.             $(columns[3]).html(`<span class="sparkpie">${green},${yellow},${red}</span>`);
  50.             $('.sparkpie', columns[3]).sparkline('html', { type: 'pie', height: '30px', offset: -90, sliceColors: ['#66cc33', '#ffcc33', '#ff0000'] });
  51.  
  52.             // Average Metascore
  53.             let average = thisYearsGames.map(x => x.score).reduce((x, y) => x + y) / thisYearsGames.length;
  54.             let rounded = Math.round((average + Number.EPSILON) * 100) / 100
  55.             $(columns[4]).text(rounded.toFixed(1))
  56.  
  57.             // Great Games** (90 or higher)
  58.             $(columns[5]).text(thisYearsGames.filter(x => x.score >= 90).length)
  59.  
  60.             //Good Exclusives** (75 or higher)
  61.             let goodExclusives = games75Higher.map(game =>{return {game:game , systems:systemCountForGames[game.title]}})
  62.             .filter(x => x.systems.size === 1 && x.systems.has(platform.key));
  63.             $(columns[6]).text(goodExclusives.length);
  64.             var exclusivesString = `\n\n ${platform.title} Good Exclusives:` + "\n> "+goodExclusives.map(x=>x.game.title).join("\n> ");
  65.             v_post_string+= exclusivesString
  66.         }
  67.         console.log("Platform data:", PLATFORMS);
  68.         console.log(v_post_string);
  69.     }
  70.  
  71.     calculateTotals()
  72.  
  73. })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement