forked from axiom-team/g1-stats
Ca fait trop longtemps je sais plus ...
This commit is contained in:
parent
d8be294803
commit
0cf2540b64
136
nbr-wallets.sh
136
nbr-wallets.sh
|
@ -6,35 +6,41 @@ 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 ')')
|
||||
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
|
||||
|
@ -45,10 +51,14 @@ for i in ${TXBLOCKS[*]}; do
|
|||
|
||||
((iter++))
|
||||
|
||||
done
|
||||
|
||||
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')"
|
||||
|
|
20
stats.html
20
stats.html
|
@ -1,16 +1,28 @@
|
|||
<html>
|
||||
<meta charset="UTF-8">
|
||||
|
||||
<center><h1>La ḡ1 en quelques statistiques</h1></center>
|
||||
<center><h1>La ḡ1 en quelques chiffres</h1></center>
|
||||
|
||||
heure: <b>_heure</b> <br>
|
||||
noeud scanné: <b>http://192.168.9.54:45000</b> <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>
|
||||
|
||||
<h4>debug</h4>
|
||||
<br>---<br>
|
||||
|
||||
heure: <b>_heure</b> <br>
|
||||
noeud scanné: <b>_node</b> <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>
|
||||
|
||||
Reçus membres: <b>_txInMembers</b><br>
|
||||
Envoyé membres: <b>_txOutMembers</b><br>
|
||||
Soldes membres: <b>_soldeMembers</b><br>
|
||||
Total DU non consommés: <b>_nonConsumedUDT</b><br>
|
||||
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue