g1-stats/g1-stats.sh

75 lines
2.2 KiB
Bash
Raw Normal View History

2019-10-29 04:55:50 +01:00
#!/bin/bash
2020-06-01 02:36:19 +02:00
################################################################################
# Author: Poka (poka@p2p.legal)
2020-06-24 21:18:23 +02:00
# Version: 0.2.0
2020-06-01 02:36:19 +02:00
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
# Git: https://git.p2p.legal/axiom-team/g1-stats
################################################################################
[[ -z $debug ]] && debug=false
2020-09-21 04:57:13 +02:00
# Exit script if error
set -e
2020-09-21 04:57:13 +02:00
# Récupération du chemin absolut du répertoir du script actuel
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
if [[ -e $SCRIPTPATH/.env ]]; then source $SCRIPTPATH/.env; else echo "Veuillez créer votre fichier .env inspiré de .env.example" && exit 1; fi
2019-10-29 04:55:50 +01:00
2019-11-19 16:03:22 +01:00
### Initialisation des données ###
startTime=$(date +'%H:%M')
day=$(date +'%y-%m-%d')
dayP=$(date +'%d-%m-%y')
2019-11-19 16:03:22 +01:00
echo -e "\n############# $day à $startTime #############\n"
2020-09-21 04:57:13 +02:00
[[ -z $(which jq) || -z $(which bc) || -z $(which curl) ]] && sudo apt update && sudo apt install jq bc curl
2019-10-29 04:55:50 +01:00
echo "Initialisation ..."
if $debug; then
2020-09-24 01:04:11 +02:00
TXBLOCKS=$(cat $SCRIPTPATH/db/debug/txblocs)
membresPubkeys=$(cat $SCRIPTPATH/db/debug/membresPubkeys)
udBlocs=$(cat $SCRIPTPATH/db/debug/udblocs)
echo # To clean next progress view
else
TXBLOCKS=$(curl -s ${DUNITER}/blockchain/with/tx | jq '.result.blocks[]')
2020-09-24 01:04:11 +02:00
echo "TXBLOCKS OK"
membresPubkeys=$(curl -s ${DUNITER}/wot/members | jq -r '.results[].pubkey')
tput cuu1;tput el;
2020-09-24 01:04:11 +02:00
echo "membresPubkeys OK"
udBlocs=$(curl -s ${DUNITER}/blockchain/with/ud | jq '.result.blocks[]')
tput cuu1;tput el;
2020-09-24 01:04:11 +02:00
echo "udBlocs OK"
fi
2020-09-21 02:11:23 +02:00
TXBLOCKS=($(echo "$TXBLOCKS" | sort -hu | awk '{printf $1" "}'))
unset 'TXBLOCKS[${#TXBLOCKS[@]}-1]'
nbrMembers=$(echo "$membresPubkeys" | wc -l)
2019-10-29 04:55:50 +01:00
lastBloc=${TXBLOCKS[-1]}
2019-11-15 23:33:11 +01:00
isWeb=$1
jsonFile="$SCRIPTPATH/db/daily.json"
2019-10-29 04:55:50 +01:00
### On source les fonctions
source $SCRIPTPATH/lib/functions.sh
source $SCRIPTPATH/lib/scanTxWallets.sh
2020-09-15 16:50:15 +02:00
### Extraction des adresses Ḡ1 actives
2020-09-21 06:39:45 +02:00
scanTxWallets
2020-06-24 21:18:23 +02:00
### Calcul la somme des soldes portefeuilles et membres
sumSoldes
2020-09-15 04:05:07 +02:00
### Ajout des membres sans transaction
addMembers
2020-06-24 21:18:23 +02:00
### Calcul du nombre de wallets
nbrWallets
2019-11-19 16:03:22 +01:00
### Affichage des stats
displayStats
2019-10-29 04:55:50 +01:00
### Renseignement de l'index web et indexation de l'historique
2020-09-18 15:47:09 +02:00
[[ $isWeb == "web" ]] && web
### Fin de programme
2019-11-15 23:33:11 +01:00
day=$(date +'%d-%m-%y')
echo "
---
$day - Heure de fin: $(date +'%H:%M')"