It is necessary to implement statistics of user activity (Node.js + MySQL), that is, how many users were online in the game all day.
Actually, the structure of the database is of interest, so that later statistics can be derived using morris .
It is necessary to implement statistics of user activity (Node.js + MySQL), that is, how many users were online in the game all day.
Actually, the structure of the database is of interest, so that later statistics can be derived using morris .
The database in your case should solve two completely different tasks. On the one hand, you need to keep statistics ( write data ), on the other hand, you need to display statistics ( read data ). The hitch is that the data will accumulate and the statistics will be calculated more and more difficult. Hence the need to create different tables (for the first time - see below ) to store time in the game. In one we will store the user ID and the timestamps of the start / end of the session. In the second - a summary of the time in the game by day.
In other words, the point is to keep the facts in one place, and the results of calculations in the other:
-- Сессии пользователей CREATE TABLE `sessions` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, `id_user` INT UNSIGNED NOT NULL, `session_start` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `session_end` TIMESTAMP NULL DEFAULT NULL ) ENGINE = MYISAM; -- Статистика по дням CREATE TABLE `statistics` ( `id_user` INT NOT NULL, `period` DATE NOT NULL, `total` INT(0) NOT NULL, PRIMARY KEY (`id_user`, `period`) ) ENGINE = MYISAM;
An important point. The base will catch the start time of the session itself, but the end time needs to be added. Either store information about the beginning / end of the game session somewhere not in the database, but at the end of the session, immediately write both time stamps. This will do without updates, which is good for performance.
Above, I said about creating tables, but you can immediately attend to the partitions.
CREATE TABLE IF NOT EXISTS `play_time` ( `user_id` INT( 11 ) NOT NULL , `start` DATETIME , `end` DATETIME , KEY `user_id` ( `user_id` ) ) ENGINE = INNODB DEFAULT CHARSET = utf8
Source: https://ru.stackoverflow.com/questions/320665/
All Articles