Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Usage: Go to https://www.metacritic.com/feature/best-videogames-released-in-2018 and open the console
- // Type in "var temp1 = <<paste Data here>>" and hit enter
- // Copy and paste this entire file into the console and run it to see the updated chart
- (function () {
- const TARGET_YEAR = 2019;
- const PLATFORMS = temp1
- const SCORE_BREAKDOWN_ELEMENT = $('.listtable:first-of-type');
- function calculateTotals() {
- console.log("Updating Table");
- // Create exclusives list
- const systemCountForGames = {}
- for (let platform of PLATFORMS) {
- for (let game of platform.data) {
- if (typeof systemCountForGames[game.title] === "undefined")
- systemCountForGames[game.title] = new Set([platform.key])
- else
- systemCountForGames[game.title].add(platform.key)
- }
- }
- // Update title
- let newTitle = $('caption', SCORE_BREAKDOWN_ELEMENT).text().replace(/20[0-2]\d/, TARGET_YEAR);
- $('caption', SCORE_BREAKDOWN_ELEMENT).text(newTitle)
- var v_post_string = "";
- // Update table
- for (let platform of PLATFORMS) {
- // Update table
- let tableRow = $(`tr:contains("${platform.title}")`, SCORE_BREAKDOWN_ELEMENT);
- let columns = $('td', tableRow);
- let thisYearsGames = platform.data.filter(x=>x.year === TARGET_YEAR && x.score !== null);
- // Total
- $(columns[2]).text(thisYearsGames.length)
- // Pie
- let red = thisYearsGames.filter(x=> x.score <= 49).length;
- let yellow = thisYearsGames.filter(x => 50 <= x.score && x.score <= 74).length;
- let games75Higher = thisYearsGames.filter(x => 75 <= x.score);
- let green = games75Higher.length;
- $(columns[3]).html(`<span class="sparkpie">${green},${yellow},${red}</span>`);
- $('.sparkpie', columns[3]).sparkline('html', { type: 'pie', height: '30px', offset: -90, sliceColors: ['#66cc33', '#ffcc33', '#ff0000'] });
- // Average Metascore
- let average = thisYearsGames.map(x => x.score).reduce((x, y) => x + y) / thisYearsGames.length;
- let rounded = Math.round((average + Number.EPSILON) * 100) / 100
- $(columns[4]).text(rounded.toFixed(1))
- // Great Games** (90 or higher)
- $(columns[5]).text(thisYearsGames.filter(x => x.score >= 90).length)
- //Good Exclusives** (75 or higher)
- let goodExclusives = games75Higher.map(game =>{return {game:game , systems:systemCountForGames[game.title]}})
- .filter(x => x.systems.size === 1 && x.systems.has(platform.key));
- $(columns[6]).text(goodExclusives.length);
- var exclusivesString = `\n\n ${platform.title} Good Exclusives:` + "\n> "+goodExclusives.map(x=>x.game.title).join("\n> ");
- v_post_string+= exclusivesString
- }
- console.log("Platform data:", PLATFORMS);
- console.log(v_post_string);
- }
- calculateTotals()
- })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement