Add history

This commit is contained in:
poka 2019-11-15 23:33:11 +01:00
parent da76528f96
commit 82ae843307
2 changed files with 76 additions and 55 deletions

View File

@ -1,6 +1,6 @@
#!/bin/bash
startTime=$(date +'%T')
startTime=$(date +'%H:%M')
day=$(date +'%d-%m-%y')
id=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
de=$(cat /dev/urandom | tr -dc '0-9' | fold -w 1 | head -n 1)
@ -14,7 +14,7 @@ indexhtml="/var/www/g1-stats/index.html"
###
echo "######"
echo "$day à startTime"
echo "$day à $startTime"
[[ -z $(which jq) || -z $(which bc) ]] && apt update && apt install jq bc
echo "Initialisation ..."
outFile="/tmp/g1-stats-$day-$startTime_$id"
@ -26,23 +26,29 @@ unset 'TXBLOCKS[${#TXBLOCKS[@]}-1]'
MEMBERS=($(curl -s ${DUNITER}/wot/members | jq '.results[].pubkey' | tr -d '"'))
nbrMembers=${#MEMBERS[@]}
lastBloc=${TXBLOCKS[-1]}
#nbrBlocs=${#TXBLOCKS[@]}
isWeb=$1
echo "Heure de début: $startTime"
loopWalletUp() {
for i in ${TXBLOCKS[*]}; do
[[ -z ${TXBLOCKS[$i]} ]] && break
sleep 0.1
WALLETS=$(curl -s ${DUNITER2}/blockchain/block/${TXBLOCKS[$i]} | jq '.transactions[].outputs[]' | tr -d '"' | awk -F '(' '{ print $2 }' | tr -d ')' || exit)
bloc=${TXBLOCKS[$i]}
[[ $bloc == "153777" ]] && echo "en plein debug ... .." && sleep 10
wallets+=$(echo -e "$WALLETS \n" | sed 's/ /\\n/g')
WALLETS0=$(curl -s ${DUNITER}/blockchain/block/${TXBLOCKS[$i]})
until WALLETS=$(echo $WALLETS0 | jq '.transactions[].outputs[]'); do
echo -e "iter $iter \n$WALLETS0"
sleep 2
WALLETS0=$(curl -s ${DUNITER}/blockchain/block/${TXBLOCKS[$i]})
done
[[ -z "$WALLETS" ]] && echo "Erreur: $RET" && exit 1
WALLETS=$(echo "$WALLETS" | tr -d '"' | awk -F '(' '{ print $2 }' | tr -d ')')
bloc=${TXBLOCKS[$i]}
wallets+=$(echo -e "$WALLETS \n" | sed 's/ /\\n/g')
progress=$(echo "scale=1; $bloc*100/$lastBloc/1" | bc)
if [[ $1 != "web" ]]; then
if [[ $isWeb != "web" ]]; then
clear
echo "Heure de début: $startTime"
echo
@ -56,8 +62,6 @@ loopWalletUp() {
loopWalletUp
echo -e "$(echo -e "$wallets" | sort -u)" > $outFile
#cat /var/www/g1-stats/wallets-g1.txt > $outFile
loopMembers() {
iter=0
for i in ${MEMBERS[*]}; do
@ -65,7 +69,7 @@ for i in ${MEMBERS[*]}; do
progress=$(echo "scale=0; $iter*100/$nbrMembers/1" | bc)
if [[ $progress =~ ^(0|10|20|30|40|50|60|70|80|90|99)$ ]]; then
[[ $progress == 99 ]] && progress=100
if [[ $1 != "web" ]]; then
if [[ $isWeb != "web" ]]; then
clear
echo "Heure de début: $startTime"
echo
@ -105,10 +109,20 @@ web() {
sed -i "s/_txInMembers/$txInMembers/g" $indexhtml
sed -i "s/_txOutMembers/$txOutMembers/g" $indexhtml
sed -i "s/_soldeMembers/$soldeMembers/g" $indexhtml
sed -i "s/_poucentSoldeMembers/$poucentSoldeMembers/g" $indexhtml
sed -i "s/_pourcentSimpleWallet/$pourcentSimpleWallet/g" $indexhtml
sed -i "s/_nonConsumedUDT/$nonConsumedUDT/g" $indexhtml
sed -i "s/_monetaryMass/$monetaryMass/g" $indexhtml
chown www-data:www-data $indexhtml 2>/dev/null
cat "$outFile" | grep . > /var/www/g1-stats/wallets-g1.txt
echo -e "${MEMBERS[@]}" | sed 's/ /\n/g' > /var/www/g1-stats/wallets-g1-membres.txt
echo -e "$simpleWallets" > /var/www/g1-stats/wallets-g1-simple.txt
if [[ "$startTime" == "00:00" ]]; then
cp $indexhtml /var/www/g1-stats/history/index_$day.html
sed -i "s/style.css/..\/style.css/g" /var/www/g1-stats/history/index_$day.html
chown -R www-data:www-data /var/www/g1-stats
fi
}
echo -e "\n ---\n"
@ -120,10 +134,6 @@ echo -e "\n ---\n"
echo "Extraction wallets membres / Simples portefeuille"
cat "$outFile" | grep . > /var/www/g1-stats/wallets-g1.txt
echo -e "${MEMBERS[@]}" | sed 's/ /\n/g' > /var/www/g1-stats/wallets-g1-membres.txt
simpleWallets=$(cat $outFile)
echo "Isolation des simples portefeuilles..."
@ -131,7 +141,9 @@ for i in ${MEMBERS[@]}; do
simpleWallets=$(echo "$simpleWallets" | grep -v "$i")
done
echo -e "$simpleWallets" > /var/www/g1-stats/wallets-g1-simple.txt
#cat "$outFile" | grep . > /var/www/g1-stats/wallets-g1.txt
#echo -e "${MEMBERS[@]}" | sed 's/ /\n/g' > /var/www/g1-stats/wallets-g1-membres.txt
#echo -e "$simpleWallets" > /var/www/g1-stats/wallets-g1-simple.txt
echo -e "\n ---\n"
@ -142,8 +154,14 @@ txOutT=0
nonConsumedUDT=0
nonConsumedUD=0
for i in $pubkeys; do
txInL=$(curl -s "http://g1.data.duniter.fr/g1/movement/_search?filter_path=hits.hits._source&size=10000&q=recipient:$i&pretty")
txOutL=$(curl -s "http://g1.data.duniter.fr/g1/movement/_search?filter_path=hits.hits._source&size=10000&q=issuer:$i&pretty")
until txInL=$(curl -s "http://g1.data.duniter.fr/g1/movement/_search?filter_path=hits.hits._source&size=10000&q=recipient:$i&pretty"); do
echo "Erreur: $i"
sleep 2
done
until txOutL=$(curl -s "http://g1.data.duniter.fr/g1/movement/_search?filter_path=hits.hits._source&size=10000&q=issuer:$i&pretty"); do
echo "Erreur: $i"
sleep 2
done
if [[ $1 == "mbr" ]]; then
nonConsumedUD=$(curl -s ${DUNITER}/ud/history/$i | jq '.history.history[].amount' | awk '{s+=$1} END {print s}') || nonConsumedUD=0
@ -156,7 +174,7 @@ for i in $pubkeys; do
solde=$(echo -e "scale=2; (($txIn-$txOut+$nonConsumedUD)/100)+$solde" | bc)
txInT=$(echo -e "scale=2; ($txIn+$nonConsumedUD/100)+$txInT" | bc)
txInT=$(echo -e "scale=2; (($txIn+$nonConsumedUD)/100)+$txInT" | bc)
txOutT=$(echo -e "scale=2; ($txOut/100)+$txOutT" | bc)
done
@ -166,9 +184,10 @@ echo "Récupération du solde des simples wallets..."
pubkeys=$simpleWallets
getSolde
txInSimple=$txInT
txOutSimple=$txOutT
soldeSimple=$solde
txInSimple=$(echo $txInT | tr . , | sed ':a;s/\B[0-9]\{3\}\>/.&/;ta')
txOutSimple=$(echo $txOutT | tr . , | sed ':a;s/\B[0-9]\{3\}\>/.&/;ta')
soldeSimpleBrut=$(echo $solde)
soldeSimple=$(echo $soldeSimpleBrut | tr . , | sed ':a;s/\B[0-9]\{3\}\>/.&/;ta')
echo -e "Reçus simples wallets:\t $txInSimple"
echo -e "Envoyé simples wallets:\t $txOutSimple"
echo -e "Soldes simples wallets:\t $soldeSimple"
@ -179,25 +198,27 @@ echo "Récupération du solde des membres..."
pubkeys=${MEMBERS[@]}
getSolde
txInMembers=$txInT
txOutMembers=$txOutT
soldeMembers=$solde
txInMembers=$(echo $txInT | tr . , | sed ':a;s/\B[0-9]\{3\}\>/.&/;ta')
txOutMembers=$(echo $txOutT | tr . , | sed ':a;s/\B[0-9]\{3\}\>/.&/;ta')
soldeMembersBrut=$(echo $solde)
soldeMembers=$(echo $soldeMembersBrut | tr . , | sed ':a;s/\B[0-9]\{3\}\>/.&/;ta')
echo -e "Reçus membres:\t $txInMembers"
echo -e "Envoyé membres:\t $txOutMembers"
echo -e "Soldes membres:\t $soldeMembers"
echo -e "Total DU non consumés:\t $nonConsumedUDT"
monetaryMass=$(curl -s ${DUNITER}/blockchain/current | jq .monetaryMass)
monetaryMass=$(echo -e "scale=2; ($monetaryMass/100)/1" | bc)
soldeWalletMembers=$(echo "scale=2; $soldeMembers+$soldeSimple" | bc)
poucentSoldeMembers=$(echo "scale=1; $soldeMembers*100/$monetaryMass/1" | bc)
monetaryMassBrut=$(echo -e "scale=2; ($monetaryMass/100)/1" | bc)
monetaryMass=$(echo "$monetaryMassBrut" | tr . , | sed ':a;s/\B[0-9]\{3\}\>/.&/;ta')
soldeWalletMembers=$(echo "scale=2; $soldeMembersBrut+$soldeSimpleBrut" | bc | tr . , | sed ':a;s/\B[0-9]\{3\}\>/.&/;ta')
pourcentSimpleWallet=$(echo "scale=1; $soldeSimpleBrut*100/$monetaryMassBrut/1" | bc)
echo -e "\n ---\n"
echo -e "Solde des membres (sans DU):\t $soldeWalletMembers"
echo -e "Masse Monétaire:\t $monetaryMass Ḡ1"
[[ $1 == "web" ]] && web
[[ $isWeb == "web" ]] && web
rm $outFile
echo "$day - Heure de fin: $(date +'%T')"
day=$(date +'%d-%m-%y')
echo "$day - Heure de fin: $(date +'%H:%M')"

View File

@ -9,34 +9,34 @@
<center><h1>La Ḡ1 en quelques chiffres</h1></center>
<div id=mainbloc>
Date: <b>_day - _heure</b> <br>
Noeud scanné: <b>https://duniter-g1.p2p.legal</b> <br>
<br>---<br><br>
Nombre total de wallet: <b>_nbrTotalWallets</b> <br>
Nombre de membres: <b>_nbrMembers</b> (_pourcentMbrs%) <br>
Nombre de simple portefeuille: <b>_nbrSimpleWallets</b> (_pourcentWallets%) <br>
<br>---<br><br>
Reçus simples wallets: <b>_txInSimple</b><br>
Envoyé simples wallets: <b>_txOutSimple</b><br>
Soldes simples wallets: <b>_soldeSimple</b> (_poucentSoldeMembers%)<br>
<br>---<br><br>
Reçus membres: <b>_txInMembers</b><br>
Envoyé membres: <b>_txOutMembers</b><br>
Soldes membres: <b>_soldeMembers</b><br>
Masse monétaire: <b>_monetaryMass</b>
<pre>
Date: <b>_day - _heure</b>
Noeud scanné: <b>https://duniter-g1.p2p.legal</b>
---
Nombre total de wallet: <b>_nbrTotalWallets</b>
Nombre de membres: <b>_nbrMembers</b> (_pourcentMbrs%)
Nombre de simple portefeuille: <b>_nbrSimpleWallets</b> (_pourcentWallets%)
---
Reçus simples wallets: <b>_txInSimple Ḡ1</b>
Envoyé simples wallets: <b>_txOutSimple Ḡ1</b>
Soldes simples wallets: <b>_soldeSimple Ḡ1</b> (_pourcentSimpleWallet%)
---
Reçus membres: <b>_txInMembers Ḡ1</b>
Envoyé membres: <b>_txOutMembers Ḡ1</b>
Soldes membres: <b>_soldeMembers Ḡ1</b>
---
Masse monétaire: <b>_monetaryMass Ḡ1</b>
</pre>
</div>
<br>
<center>
| <a href="/wallets-g1.txt">Liste de tous les wallets</a>
| <a href="/wallets-g1-membres.txt">Liste des wallets membres</a>
| <a href="/wallets-g1-simple.txt">Liste des simples portefeuilles</a> |
<br><br>
Ces données sont mises à jours toutes les 3 heures.<br>
<a href="/history/">Consulter l'historique</a>
</center>
</body>