From 0cf2540b6459ce5f2a5aa63b5b2679d988716b7a Mon Sep 17 00:00:00 2001 From: poka Date: Fri, 8 Nov 2019 04:16:09 +0100 Subject: [PATCH] Ca fait trop longtemps je sais plus ... --- nbr-wallets.sh | 156 +++++++++++++++++++++++++++++++++++++++---------- stats.html | 20 +++++-- 2 files changed, 141 insertions(+), 35 deletions(-) diff --git a/nbr-wallets.sh b/nbr-wallets.sh index bb7c32f..30a8655 100755 --- a/nbr-wallets.sh +++ b/nbr-wallets.sh @@ -6,49 +6,59 @@ 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) ### Variable ### -if [ $de -le 3 ]; then - DUNITER="http://192.168.9.54:45000" -elif [ $de -le 6 ]; then - DUNITER="https://g1.duniter.org" -else - DUNITER="https://duniter.g1.1000i100.fr" -fi +DUNITER="http://192.168.9.54:45000" +DUNITER2="https://g1.duniter.org" +DUNITER3="https://duniter.g1.1000i100.fr" -indexhtml="/var/www/g1-stats/index-$day-$startTime-$id.html" +#indexhtml="/var/www/g1-stats/index-$day-$startTime-$id.html" +indexhtml="/var/www/g1-stats/index.html" ### echo "######" [[ -z $(which jq) || -z $(which bc) ]] && apt update && apt install jq bc echo "Initialisation ..." outFile="/tmp/g1-stats-$day-$startTime_$id" -TXBLOCKS=($(curl -s ${DUNITER}/blockchain/with/tx | jq '.result.blocks[]' | awk '{printf $1" "}')) +TXBLOCKS=$(curl -s ${DUNITER}/blockchain/with/tx | jq '.result.blocks[]') +TXBLOCKS+=$(curl -s ${DUNITER2}/blockchain/with/tx | jq '.result.blocks[]') +TXBLOCKS+=$(curl -s ${DUNITER3}/blockchain/with/tx | jq '.result.blocks[]') +TXBLOCKS=($(echo "$TXBLOCKS" | sort -hu | awk '{printf $1" "}')) +unset 'TXBLOCKS[${#TXBLOCKS[@]}-1]' MEMBERS=($(curl -s ${DUNITER}/wot/members | jq '.results[].pubkey' | tr -d '"')) nbrMembers=${#MEMBERS[@]} lastBloc=${TXBLOCKS[-1]} +#nbrBlocs=${#TXBLOCKS[@]} -for i in ${TXBLOCKS[*]}; do +loopWalletUp() { + for i in ${TXBLOCKS[*]}; do - [[ -z ${TXBLOCKS[$i]} ]] && break - WALLETS=$(curl -s ${DUNITER}/blockchain/block/${TXBLOCKS[$i]} | jq '.transactions[].outputs[]' | tr -d '"' | awk -F '(' '{ print $2 }' | tr -d ')') - bloc=${TXBLOCKS[$i]} - wallets+=$(echo -e "$WALLETS \n" | sed 's/ /\\n/g') + [[ -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') - progress=$(echo "scale=1; $bloc*100/$lastBloc/1" | bc) - sleep 1 - if [[ $1 != "web" ]]; then - clear - echo "Heure de début: $startTime" - echo - echo "Scan en cours: $progress% - $bloc/$lastBloc" - fi + progress=$(echo "scale=1; $bloc*100/$lastBloc/1" | bc) - ((iter++)) -done + if [[ $1 != "web" ]]; then + clear + echo "Heure de début: $startTime" + echo + echo "Scan en cours: $progress% - $bloc/$lastBloc" + fi + ((iter++)) + + done +} +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 @@ -70,6 +80,9 @@ for i in ${MEMBERS[*]}; do ((iter++)) done +} +loopMembers + nbrTotalWallets=$(cat $outFile | wc -l) nbrSimpleWallets=$(echo "$nbrTotalWallets-$nbrMembers" | bc) @@ -83,20 +96,101 @@ web() { sed -i "s/_nbrMembers/$nbrMembers/g" $indexhtml sed -i "s/_pourcentMbrs/$pourcentMbrs/g" $indexhtml sed -i "s/_pourcentWallets/$pourcentWallets/g" $indexhtml - sed -i "s/_node/"$DUNITER"/g" $indexhtml - sed -i "s/_heure/$startTime/g" $indexhtml - +# sed -i "s/_node/$DUNITER/g" $indexhtml + sed -i "s/_heure/$day_$startTime/g" $indexhtml + sed -i "s/_txInSimple/$txInSimple/g" $indexhtml + sed -i "s/_txOutSimple/$txOutSimple/g" $indexhtml + sed -i "s/_soldeSimple/$soldeSimple/g" $indexhtml + 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/_nonConsumedUDT/$nonConsumedUDT/g" $indexhtml chown www-data:www-data $indexhtml 2>/dev/null } -[[ $1 == "web" ]] && web - -echo -e "\n ---" +echo -e "\n ---\n" echo "Noeud: $DUNITER" echo "Nombre total de wallet: $nbrTotalWallets" echo "Nombre de membres: $nbrMembers (${pourcentMbrs}%)" echo "Nombre de simple portefeuille: $nbrSimpleWallets (${pourcentWallets}%)" -echo " ---" +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..." +for i in ${MEMBERS[@]}; do + simpleWallets=$(echo "$simpleWallets" | grep -v "$i") +done + +echo -e "$simpleWallets" > /var/www/g1-stats/wallets-g1-simple.txt + +echo -e "\n ---\n" + +getSolde(){ +solde=0 +txInT=0 +txOutT=0 +nonConsumedUDT=0 +for i in $pubkeys; do +# echo $i + + 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") + + [[ $1 == "mbr" ]] && nonConsumedUD=$(curl -s ${DUNITER}/ud/history/$i | jq '.history.history[].amount' | awk '{s+=$1} END {print s}') || nonConsumedUD=0 + [[ $1 == "mbr" ]] && nonConsumedUDT=$(echo -e "scale=2; ($nonConsumedUD/100)+$nonConsumedUDT" | bc) + + [[ $txInL != "{ }" ]] && txIn=$(echo "$txInL" | jq '.hits.hits[]._source.amount' | awk '{s+=$1} END {print s}') || txIn=0 + [[ $txOutL != "{ }" ]] && txOut=$(echo "$txOutL" | jq '.hits.hits[]._source.amount' | awk '{s+=$1} END {print s}') || txOut=0 + + solde=$(echo -e "scale=2; (($txIn-$txOut+$nonConsumedUD)/100)+$solde" | bc) + + txInT=$(echo -e "scale=2; ($txIn+$nonConsumedUD/100)+$txInT" | bc) + txOutT=$(echo -e "scale=2; ($txOut/100)+$txOutT" | bc) + +done +} + +echo "Récupération du solde des simples wallets..." + +pubkeys=$simpleWallets +getSolde +txInSimple=$txInT +txOutSimple=$txOutT +soldeSimple=$solde +echo -e "Reçus simples wallets:\t $txInSimple" +echo -e "Envoyé simples wallets:\t $txOutSimple" +echo -e "Soldes simples wallets:\t $soldeSimple" + +echo -e "\n ---\n" + +echo "Récupération du solde des membres..." + +pubkeys=${MEMBERS[@]} +getSolde mbr +txInMembers=$txInT +txOutMembers=$txOutT +soldeMembers=$solde +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" + +soldeWalletMembers=$(echo "scale=2; $soldeMembers+$soldeSimple" | bc) +poucentSoldeMembers=$(echo "scale=1; $soldeMembers*100/$soldeWalletMembers/1" | bc) + +echo -e "\n ---\n" +echo -e "Solde Total:\t $soldeWalletMembers" + + +[[ $1 == "web" ]] && web rm $outFile echo "Heure de fin: $(date +'%T')" diff --git a/stats.html b/stats.html index f9c04a5..e65605d 100644 --- a/stats.html +++ b/stats.html @@ -1,16 +1,28 @@ -

La ḡ1 en quelques statistiques

+

La ḡ1 en quelques chiffres

+ +heure: _heure
+noeud scanné: http://192.168.9.54:45000
+ +
---
Nombre total de wallet: _nbrTotalWallets
Nombre de membres: _nbrMembers (_pourcentMbrs%)
Nombre de simple portefeuille: _nbrSimpleWallets (_pourcentWallets%)
-

debug

+
---
-heure: _heure
-noeud scanné: _node
+Reçus simples wallets: _txInSimple
+Envoyé simples wallets: _txOutSimple
+Soldes simples wallets: _soldeSimple (_poucentSoldeMembers%)
+
---
+ +Reçus membres: _txInMembers
+Envoyé membres: _txOutMembers
+Soldes membres: _soldeMembers
+Total DU non consommés: _nonConsumedUDT