diff --git a/README.md b/README.md index 3056de2..b960c81 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,58 @@ -# twister-stat -Statistic tools for twister network +# twister-stat ⠀ +Statistic tools for twister network ⠀ + +## Blockchain crawler ⠀ + +Script written in python v2, that scans the blockchain and dump the data to the MySQL database. ⠀ + +Index contain: ⠀ + +- block number ⠀ +- block hash ⠀ +- time created ⠀ +- usernames ⠀ + +### Configuration ⠀ + +line 5 - MySQL database ⠀ +line 13 - blocks per step ⠀ +line 31 - twister API ⠀ + +### Requirements ⠀ + +`apt install python2 php-mysql mysql-server` ⠀ +`pip install mysqlclient` ⠀ + +### Running ⠀ + +`python2 crawler/blockchain.py` ⠀ + +## Charts ⠀ + +Tools for the data dumped visualization written in PHP ⠀ + +### Configuration ⠀ + +line 8 - MySQL database ⠀ + +### Requirements ⠀ + +`php-fpm` +`php-curl`⠀ + +### Running ⠀ + +create new server instance ⠀ + +`cd chart` ⠀ +`php -S localhost:8081` ⠀ + +open in browser ⠀ + +`http://localhost:8081/index.php` ⠀ + +todo: ⠀ + +## Static dumps directory ⠀ + +`dump` \ No newline at end of file diff --git a/chart/index.php b/chart/index.php new file mode 100644 index 0000000..bbc7771 --- /dev/null +++ b/chart/index.php @@ -0,0 +1,126 @@ + 'SET NAMES utf8']); + $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); +} catch(PDOException $e) { + trigger_error($e->getMessage()); +} + +// Get total blocks +$query = $db->query('SELECT COUNT(*) AS `total` FROM `block`'); +$blocksTotal = $query->fetch()['total']; + +// Get total users +$query = $db->query('SELECT COUNT(*) AS `total` FROM `user`'); +$usersTotal = $query->fetch()['total']; + +// Get stats +$query = $db->query('SELECT YEAR(FROM_UNIXTIME(`time`)) AS `year`, + MONTH(FROM_UNIXTIME(`time`)) AS `month`, + COUNT(`block`.`blockId`) AS `blocks`, + + SUM((SELECT COUNT(`user`.`userId`) FROM `user` + WHERE `user`.`blockId` = `block`.`blockId` + GROUP BY `user`.`blockId`)) AS `users` + + FROM `block` + + GROUP BY `year`, `month` + ORDER BY `year`, `month` +'); + +$stats = $query->fetchAll(); + +?> + + + +
+ + +