Skip to content

Instantly share code, notes, and snippets.

@kevinfjbecker
Created July 6, 2016 14:53
Show Gist options
  • Save kevinfjbecker/b1bc6186e57188bf3d3b806a2f0c3993 to your computer and use it in GitHub Desktop.
Save kevinfjbecker/b1bc6186e57188bf3d3b806a2f0c3993 to your computer and use it in GitHub Desktop.
Gather Meta Deck Machups
///////////////////////////////////////////////////////////////////////////////
// get snapshot data -- this might fail, maybe you need to inspect 1st
$bar = $('#deck1').find('.bar-wrap').first();
snapshot = angular.element($bar).scope().snapshot
///////////////////////////////////////////////////////////////////////////////
// inject D3
var script= document.createElement('script');
script.type= 'text/javascript';
script.src= 'https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js';;
document.head.appendChild(script);
///////////////////////////////////////////////////////////////////////////////
function getMachupMatrix(snapshot) {
var d = snapshot.matchupDecks(),
m = snapshot.matchups,
matchupmatrix = [],
i,
j;
for(i = 0; i < d.length; i++) {
matchupmatrix[i] = [];
for(j = 0; j < d.length; j++) {
matchupmatrix[i][j] = getMachupChance(d[i],d[j],m);
}
}
return matchupmatrix;
}
function getMachupChance(forDeck,againstDeck,matchups) {
return matchups
.filter(
m => m.forDeckId === forDeck.deck.id
&& m.againstDeckId === againstDeck.deck.id
||
m.forDeckId === againstDeck.deck.id
&& m.againstDeckId === forDeck.deck.id
)
.map(m => m.forDeckId === forDeck.deck.id ? m.forChance : m.againstChance)[0];
}
function getMatchupDecks(snapshot) {
return snapshot.matchupDecks();
}
///////////////////////////////////////////////////////////////////////////////
console.log(
getMatchupDecks(snapshot).map(d => d.name).join('\t') +
'\n' +
getMachupMatrix(snapshot).map(a => a.join('\t')).join('\r')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment