diff --git a/nbr-wallets.sh b/nbr-wallets.sh
index b9e6197..c290730 100755
--- a/nbr-wallets.sh
+++ b/nbr-wallets.sh
@@ -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')"
diff --git a/stats.html b/stats.html
index 7594693..354a6fe 100644
--- a/stats.html
+++ b/stats.html
@@ -9,34 +9,34 @@
La Ḡ1 en quelques chiffres
-Date:
_day - _heure
-Noeud scanné:
https://duniter-g1.p2p.legal
-
-
---
-
-Nombre total de wallet:
_nbrTotalWallets
-Nombre de membres:
_nbrMembers (_pourcentMbrs%)
-Nombre de simple portefeuille:
_nbrSimpleWallets (_pourcentWallets%)
-
-
---
-
-Reçus simples wallets:
_txInSimple
-Envoyé simples wallets:
_txOutSimple
-Soldes simples wallets:
_soldeSimple (_poucentSoldeMembers%)
-
-
---
-
-Reçus membres:
_txInMembers
-Envoyé membres:
_txOutMembers
-Soldes membres:
_soldeMembers
-Masse monétaire:
_monetaryMass
+
+Date: _day - _heure
+Noeud scanné: https://duniter-g1.p2p.legal
+---
+Nombre total de wallet: _nbrTotalWallets
+Nombre de membres: _nbrMembers (_pourcentMbrs%)
+Nombre de simple portefeuille: _nbrSimpleWallets (_pourcentWallets%)
+---
+Reçus simples wallets: _txInSimple Ḡ1
+Envoyé simples wallets: _txOutSimple Ḡ1
+Soldes simples wallets: _soldeSimple Ḡ1 (_pourcentSimpleWallet%)
+---
+Reçus membres: _txInMembers Ḡ1
+Envoyé membres: _txOutMembers Ḡ1
+Soldes membres: _soldeMembers Ḡ1
+---
+Masse monétaire: _monetaryMass Ḡ1
+
-
| Liste de tous les wallets
| Liste des wallets membres
| Liste des simples portefeuilles |
+
+
+Ces données sont mises à jours toutes les 3 heures.
+Consulter l'historique