Skip to content

Commit

Permalink
v3.2 Top Performing Decks added
Browse files Browse the repository at this point in the history
  • Loading branch information
LiberoHS committed Sep 13, 2019
1 parent e3578cf commit d835e2a
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 45 deletions.
15 changes: 13 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { HomeMenu, PlayerInfo, PlayerList, SearchBar, TournamentInfo, Tournament
import decks from './data/decks.js';
import tournamentList from './data/tournaments.js';
import playerList from './data/players.js';
import topDecks from './data/topDecks.js';

const buttonStyle = {
height: '25px',
Expand Down Expand Up @@ -51,10 +52,14 @@ class App extends React.Component {
tournamentList: tournamentList,
decks: decks,
playerList: playerList,
topDecks: topDecks,

currentTournament: null,
currentPlayer: null,

show: 'home',
data: null,

checkedChallenge: false,
checkedPoints: false,
tracker: 0
Expand Down Expand Up @@ -195,6 +200,11 @@ class App extends React.Component {
playerList.sort(function (a, b) {
return a.name.localeCompare(b.name);
});
topDecks.sort(function (a, b) {
return b.currCP - a.currCP;
});

this.setState({ playerList: playerList, topDecks: topDecks})
// Call our fetch function below once the component mounts
this.callBackendAPI()
.then(res => this.setState({ data: res.express }))
Expand All @@ -214,7 +224,7 @@ class App extends React.Component {

render () {
const { tournamentList, currentTournament, playerList, currentPlayer,
decks, show, checkedChallenge, checkedPoints } = this.state;
decks, topDecks, show, checkedChallenge, checkedPoints } = this.state;

return (
<Grid>
Expand All @@ -241,7 +251,8 @@ class App extends React.Component {
setCurrentTournament={this.setCurrentTournament}
tournaments={tournamentList}
decks={decks}
players={playerList}/>}
players={playerList}
topDecks={topDecks}/>}
</Grid>
<Grid>
{show === 'tournamentList' && <SearchBar onFormSubmit={this.handleChange}/>}
Expand Down
105 changes: 74 additions & 31 deletions src/components/HomeMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const text = {
padding: '10px'
}

const HomeMenu = ({ setCurrentTournament, tournaments, decks, players }) => {
const HomeMenu = ({ setCurrentTournament, tournaments, decks, topDecks, players }) => {
players = players.sort(function (a, b) {
return b.points - a.points;
});
Expand All @@ -20,11 +20,13 @@ const HomeMenu = ({ setCurrentTournament, tournaments, decks, players }) => {

const isDesktop = useMediaQuery({ minWidth: 992 });
const isNotMobile = useMediaQuery({ minWidth: 768 });
const isNotTablet = useMediaQuery({ minWidth: 992 });
let headerStyle = {};
let cellStyle = {};
let tableGrid = {};
let flexContainer = {};

if (isNotMobile) {
if (isNotTablet) {
headerStyle = {
color: 'white',
fontFamily: 'Muli',
Expand All @@ -40,6 +42,10 @@ const HomeMenu = ({ setCurrentTournament, tournaments, decks, players }) => {
height: '80%',
backgroundColor: 'white'
};
flexContainer = {
display: 'flex',
flex: 1
}
} else {
headerStyle = {
color: 'white',
Expand All @@ -48,12 +54,12 @@ const HomeMenu = ({ setCurrentTournament, tournaments, decks, players }) => {
};
cellStyle = {
fontFamily: 'Muli',
fontSize: '10px'
fontSize: '16px'
};
tableGrid = {
margin: '20px',
width: '90%',
height: '85%',
margin: '10px',
width: '95%',
height: '90%',
backgroundColor: 'white'
};
}
Expand All @@ -72,7 +78,7 @@ const HomeMenu = ({ setCurrentTournament, tournaments, decks, players }) => {
width: '100%',
},
tableWrapper: {
maxHeight: 750,
maxHeight: 800,
minWidth: 100,
overflow: 'hidden',
},
Expand Down Expand Up @@ -103,7 +109,7 @@ const HomeMenu = ({ setCurrentTournament, tournaments, decks, players }) => {
</TableRow>
</TableHead>
<TableBody>
{currFormat.map((tournament, key) => {
{currFormat.slice(0,5).map((tournament, key) => {
var search = compareDecks(tournament.standings[0]);
if (search.hasOwnProperty('thumbnails')) {
var sprites = search.thumbnails.map((img, key) => {
Expand Down Expand Up @@ -159,29 +165,66 @@ const HomeMenu = ({ setCurrentTournament, tournaments, decks, players }) => {
</Grid>
</Grid> */}
</Grid>
<Grid item xs={11} style={tableGrid}>
<h3 style={text}>Top Performing Players</h3>
<Paper className={classes.root}>
<div className={classes.tableWrapper}>
<Table>
<TableHead>
<TableRow style={{backgroundColor: '#424242'}}>
<TableCell align="left" style={headerStyle}>Name</TableCell>
<TableCell align="left" style={headerStyle}>Points</TableCell>
</TableRow>
</TableHead>
<TableBody>
{players.map((player, key) => {
return(
<TableRow key={key}>
<TableCell align="left" style={cellStyle}>{player.name}</TableCell>
<TableCell align="left" style={cellStyle}>{player.points}</TableCell>
</TableRow>
)})}
</TableBody>
</Table>
</div>
</Paper>
<Grid style={flexContainer}>
<Grid item xs={11} style={tableGrid}>
<h3 style={text}>Top Performing Decks of the Week</h3>
<Paper className={classes.root}>
<div className={classes.tableWrapper}>
<Table>
<TableHead>
<TableRow style={{backgroundColor: '#424242'}}>
<TableCell align="left" style={headerStyle}>Deck</TableCell>
<TableCell align="left" style={headerStyle}></TableCell>
<TableCell align="left" style={headerStyle}>Points</TableCell>
</TableRow>
</TableHead>
<TableBody>
{topDecks.slice(0,5).map((deck, key) => {
var search = compareDecks(deck);
if (search.hasOwnProperty('thumbnails')) {
var sprites = search.thumbnails.map((img, key) => {
if (isDesktop) {
return <img key={key} src={img} style={{height: '75px', width: '75px'}} alt="rekt" />
} else {
return <img key={key} src={img} style={{height: '50px', width: '50px'}} alt="rekt" />
}
})};
return(
<TableRow key={key}>
<TableCell align="left" style={cellStyle}>{deck.deck}</TableCell>
<TableCell align="left" style={cellStyle}>{sprites}</TableCell>
<TableCell align="left" style={cellStyle}>{deck.currCP}</TableCell>
</TableRow>
)})}
</TableBody>
</Table>
</div>
</Paper>
</Grid>
<Grid item xs={11} style={tableGrid}>
<h3 style={text}>Top Performing Players</h3>
<Paper className={classes.root}>
<div className={classes.tableWrapper}>
<Table>
<TableHead>
<TableRow style={{backgroundColor: '#424242'}}>
<TableCell align="left" style={headerStyle}>Name</TableCell>
<TableCell align="left" style={headerStyle}>Points</TableCell>
</TableRow>
</TableHead>
<TableBody>
{players.slice(0,10).map((player, key) => {
return(
<TableRow key={key}>
<TableCell align="left" style={cellStyle}>{player.name}</TableCell>
<TableCell align="left" style={cellStyle}>{player.points}</TableCell>
</TableRow>
)})}
</TableBody>
</Table>
</div>
</Paper>
</Grid>
</Grid>
</Grid>
)
Expand Down
1 change: 1 addition & 0 deletions src/components/mediaQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const isDesktop = useMediaQuery({ minWidth: 992 });
const isTablet = useMediaQuery({ minWidth: 768, maxWidth: 991 });
const isMobile = useMediaQuery({ maxWidth: 767 });
const isNotMobile = useMediaQuery({ minWidth: 768 });
const isNotTablet = useMediaQuery({ minWidth: 992 });

module.exports = isMobile;

Expand Down
31 changes: 31 additions & 0 deletions src/data/topDecks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const topDecks = [
{ deck: "Pikachu & Zekrom-GX", currCP: 971, totalCP: 1118 },
{ deck: "Ability Reshiram & Charizard-GX", currCP: 1234, totalCP: 1269 },
{ deck: "Blacephalon-GX / Naganadel", currCP: 272, totalCP: 307 },
{ deck: "Malamar / Giratina", currCP: 164, totalCP: 164 },
{ deck: "Malamar / Ultra Necrozma-GX", currCP: 50, totalCP: 135 },
{ deck: "Gardevoir & Sylveon-GX", currCP: 57, totalCP: 57 },
{ deck: "Mew & Mewtwo-GX Toolbox", currCP: 511, totalCP: 519 },
{ deck: "Spiritomb / Froslass", currCP: 32, totalCP: 32 },
{ deck: "Beheeyem", currCP: 50, totalCP: 50 },
{ deck: "Pidgeotto Control", currCP: 40, totalCP: 40 },
{ deck: "Green's Reshiram & Charizard-GX", currCP: 349, totalCP: 398 },
{ deck: "Malamar / Garchomp & Giratina-GX", currCP: 85, totalCP: 85 },
{ deck: "Quagsire / Naganadel", currCP: 160, totalCP: 160 },
{ deck: "Naganadel-GX Checkmate", currCP: 80, totalCP: 80 },
{ deck: "Blastoise / Keldeo-GX", currCP: 60, totalCP: 60 },
{ deck: "Baby Blacephalon", currCP: 60, totalCP: 134 },
{ deck: "Weavile-GX Toolbox", currCP: 10, totalCP: 10 },
{ deck: "Donphan / Florges", currCP: 0, totalCP: 15 },
{ deck: "Zoroark-GX / Greninja & Zoroark-GX", currCP: 0, totalCP: 10 },
{ deck: "Zoroark-GX Checkmate", currCP: 0, totalCP: 12 },
{ deck: "Vileplume Stall", currCP: 0, totalCP: 45 },
{ deck: "Zoroark-GX / Persian", currCP: 0, totalCP: 50 },
{ deck: "Zygarde-GX", currCP: 0, totalCP: 32 },
{ deck: "Zoroark-GX / Silvally-GX", currCP: 0, totalCP: 32 },
{ deck: "Zoroark-GX / Dewgong", currCP: 0, totalCP: 40 },
{ deck: "Beast Box", currCP: 0, totalCP: 15 },
{ deck: "Zapdos / Ultra Beasts", currCP: 0, totalCP: 25 },
];

module.exports = topDecks;
69 changes: 57 additions & 12 deletions src/scripts/init_players.js → src/scripts/init_homeData.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* This script is primarily only used to initialise players into the objects
/* This script is primarily only used to initialise players and decks into the objects
to be exported for data use.
The class initialisation is included and the script will go through the
tournament list to insert any new occurrence of players. */
Expand Down Expand Up @@ -47,6 +47,29 @@ function calcPointPayout(tournament, player) {
return 0;
};

// Class declaration for Deck
class Deck {
constructor(deck) {
this.deck = deck;
this.totalCP = 0; // total CP earnt
this.currCP = 0; // CP earnt in last 10 tournaments
}

get string() {
var string = '';
string += '{ deck: "' + this.deck + '", currCP: ' + this.currCP + ', totalCP: ' + this.totalCP + ' },\n'
return string
}

addCurrCP(value) {
this.currCP += value;
}

addTotalCP(value) {
this.totalCP += value;
}
}

// Class declaration for Player
class Player {
constructor(name) {
Expand Down Expand Up @@ -90,40 +113,62 @@ class Player {
}

// Inputs all the players from all the tournaments into a PlayerList database
var PlayerList = []
var PlayerList = [];
var DeckList = [];

// Iterates through each tournament and the standings
for (let i = 0; i < tournaments.length; i++) {
tournaments[i].standings.map((player, key) => {
var search = PlayerList.some(entry => entry.name === player.name);
var playerSearch = PlayerList.some(entry => entry.name === player.name);
var deckSearch = DeckList.some(entry => entry.deck === player.deck);

// If the player is already in the database
if (search) {
if (playerSearch) {
} else {
PlayerList.push(new Player(player.name));
}

if (deckSearch) {
} else {
DeckList.push(new Deck(player.deck));
}

// Adds the achievement into the database
PlayerList[PlayerList.findIndex(x => x.name === player.name)].addAchievement(tournaments[i].date, tournaments[i].name, tournaments[i].cycle, player.deck, player.placing);
PlayerList[PlayerList.findIndex(x => x.name === player.name)].addPoints(calcPointPayout(tournaments[i], player));
if (i < 10) {
DeckList[DeckList.findIndex(x => x.deck === player.deck)].addCurrCP(calcPointPayout(tournaments[i], player));
}
DeckList[DeckList.findIndex(x => x.deck === player.deck)].addTotalCP(calcPointPayout(tournaments[i], player));
});
}

// Debugging purposes
// for (let j = 0; j < PlayerList.length; j++) {
// if (PlayerList[j].name === 'Brent Tonisson' || PlayerList[j].name === 'Henry Brand')
// console.log(PlayerList[j].achievements);
// for (let j = 0; j < DeckList.length; j++) {
// // if (PlayerList[j].name === 'Brent Tonisson' || PlayerList[j].name === 'Henry Brand')
// console.log(DeckList[j]);
// }
// console.log(PlayerList.length)
// console.log(DeckList.length);

var data = 'const players = [\n';
var playerData = 'const players = [\n';
for (var i = 0; i < PlayerList.length; i++) {
data += '{ name: "' + PlayerList[i].name + '",\nachievements: [' + PlayerList[i].achievementList + '], points: ' + PlayerList[i].points + ' },\n';
playerData += '{ name: "' + PlayerList[i].name + '",\nachievements: [' + PlayerList[i].achievementList + '], points: ' + PlayerList[i].points + ' },\n';
}

playerData += '];\n\nmodule.exports = players;'

var deckData = 'const topDecks = [\n';
for (var i = 0; i < DeckList.length; i++) {
deckData += DeckList[i].string;
}

data += '];\n\nmodule.exports = players;'
deckData += '];\n\nmodule.exports = topDecks;'

var fs = require('fs');
fs.writeFile('../data/players.js', data, function (err, file) {
fs.writeFile('../data/players.js', playerData, function (err, file) {
if (err) throw err;
});

fs.writeFile('../data/topDecks.js', deckData, function (err, file) {
if (err) throw err;
});

0 comments on commit d835e2a

Please sign in to comment.