davidguerreiro / evscalculator

Web application for professional pokemon players
https://evscalculator.com
0 stars 0 forks source link

DB structure #10

Closed jaicab closed 8 years ago

jaicab commented 8 years ago

Training: Training table saves all the data for a single training session.

Field Type Description
id INT(11) NOT_NULL AUTO_INCREMENT Identification number
id_url VARCHAR(255) DEFAULT NULL Url which allows users to load an unfinished training.
id_user INT(11) NOT_NULL DEFAULT 0 User number. This value will be always 0 because the first version doesn't support user creation
hp INT(3) NOT_NULL DEFAULT 0 Hp stat value
attack INT(3) NOT_NULL DEFAULT 0 Attack stat value
defense INT(3) NOT_NULL DEFAULT 0 Defense stat value
spattack INT(3) NOT_NULL DEFAULT 0 Sp Attack stat value
spdefense INT(3) NOT_NULL DEFAULT 0 Sp Defense stat value
speed INT(3) NOT_NULL DEFAULT 0 Speed stat value
version VARCHAR(50) NOT_NULL DEFAULT 'xy' Pokemon 6th gen game version ('xy' -- XY Pokemon games, 'oras' -- Ruby Omega Alpha Sapphire Pokemon Games)
pokerus TINYINT(1) NOT_NULL DEFAULT 0 Pokerus (0 -- disabled, 1 -- enabled)
power_brace TINYINT(1) NOT_NULL DEFAULT 0 Power brace (0 -- unequipped, 1 -- equipped)
sturdy_object TINYINT(1) NOT_NULL DEFAULT 0 Sturdy object (0 -- unequipped, 1 -- equipped)
timestamp TIMESTAMP

Records: Records will provide us with information about how users are using the application, which version of the game is the most used and more

Field Type Description
id INT(11) NOT_NULL AUTO_INCREMENT Identification number
id_training INT(11) NOT_NULL DEFAULT 0 This id related the record with a single training session
stat_name VARCHAR(50) Name of the stat what we are adding or decreasing the value
stat_value INT(3) NOT_NULL DEFAULT 0 Amont of evs that we are adding or subtracting
id_horde INT(11) NOT_NULL DEFAULT 0 The ID of the horde when a horde has been used during the training session
id_vitamin INT(11) NOT_NULL DEFAULT 0 The ID of the vitamin when a vitamin has been used during the training session
version VARCHAR(50) NOT_NULL DEFAULT 'xy' Pokemon 6th gen game version ('xy' -- XY Pokemon games, 'oras' -- Ruby Omega Alpha Sapphire Pokemon Games)
pokerus TINYINT(1) NOT_NULL DEFAULT 0 Pokerus (0 -- disabled, 1 -- enabled)
timestamp TIMESTAMP

User: First approach of the User basic table. Not used in the first version.

Field Type Description
id INT(11) NOT_NULL AUTO_INCREMENT Identification number
name VARCHAR(50) NOT_NULL DEFAULT '' The name of the user
email VARCHAR(255) NOT_NULL DEFAULT '' The email address of the user
timestamp TIMESTAMP

Please check the new database diagram, make and comment any change that you consider relevant ASAP because I'm going to install and test the DB in the server tomorrow in the morning.

Thanks.

jaicab commented 8 years ago

David, can you please break down the DB and move it to text instead of an image and put it at the top? Bear in mind that we need to add vitamins. Also explain what each table and field represents.

davidguerreiro commented 8 years ago

Sure ! About vitamins, they are displayed on the screen in the same way that hordes, so we save only the data about vitamins on the second table (records)

jaicab commented 8 years ago

Ok, you just need to create a list for each table in markdown to replace the image. That way we can all edit it and we have it there, centralised.

jaicab commented 8 years ago

Ok, I'm proposing a few changes. Let me know what you think.

I think this way we not only avoid redundancy, but also improve scalability and our possible studies on the results.

davidguerreiro commented 8 years ago

Ok. let's do it point by point:

I'm updating the tables above with the new changes.

jaicab commented 8 years ago

I like the use of game instead of generation. Nice one.

Regarding the id_horde and id_vitamin, these go on the records table. We can have a static list in PHP or JSON (or both) that lists the hordes and vitamins. What I mean by static is that there are rarely to change, not like records and training which would constantly change. There is no need to have them in a DB because we never are going to change them with a form request or a SQL, and it's us the dev team that is going to change the data in that table.

My point is that when something is internal and it's not going to change or it's unlikely it's going to change often, it should be plain in the code and not in a DB. So, for instance we could have:

$hordes = array();

// These could be abstracted into a function
$horde_magikarp = new stdClass();
$horde_magicarp->name = "Magikarp";
$horde_magikarp->game = 'xy';
array_push($hordes, $horde_magikarp);

// Now we can just use it
echo $hordes[0]->name; // "Magikarp"

// Get the ones for the game 'xy'
function filterByGameXY($var){
    return $var->game === 'xy';
}
// Now $hordes_xy only contain the hordes that are assigned to XY trainings
$hordes_xy = array_filter($hordes, 'filterByGameXY');

All this loads much faster than getting to the DB and doing stuff.

davidguerreiro commented 8 years ago

Got it !! Nice explication !! You'r making magikarp useful for once in life !!

jaicab commented 8 years ago

Glad you got the idea. I also think it should be a JSON file with the hordes and another with the vitamins, and then we process that with PHP so it's easily available. I say JSON because we can cache it and it would be instantaneous, but giving us the flexibility to do other stuff.

jaicab commented 8 years ago

Also, if we feel like it, we can always move the data from the JSON file to tables in the DB and then create the JSON from it. Super scalable!

jaicab commented 8 years ago

I've added timestamp to the user table.

davidguerreiro commented 8 years ago

Thanks ! :D