diff --git a/explorer.sh b/explorer.sh index 20e7733..657800e 100755 --- a/explorer.sh +++ b/explorer.sh @@ -1,12 +1,14 @@ #!/bin/bash dateRange=$2 -lineNbr=$(grep -n "$dateRange" db/recus.json | cut -d : -f 1) +jsonFile="db/daily.json" +lineNbr=$(grep -n "$dateRange" $jsonFile | cut -d : -f 1) +[[ -z $lineNbr ]] && echo "La date $dateRange n'existe pas en blockchain" && exit 1 cumulate() { - lineNbr=$(($lineNbr+6)) + lineNbr=$(($lineNbr+7)) - jsonDated=$(head -n$lineNbr db/recus.json) + jsonDated=$(head -n$lineNbr $jsonFile) jsonDated=$(echo -e "$jsonDated\n }\n]") sumRWBrut=$(jq -r '.[].rWallets' <<<$jsonDated | awk '{ SUM += $1} END { printf "%.2f", SUM }') @@ -16,23 +18,28 @@ cumulate() { sumSMBrut=$(jq -r '.[].sMembers' <<<$jsonDated | awk '{ SUM += $1} END { printf "%.2f", SUM }') #sumSTBrut=$(jq -r '.[] | .sWallets, .sMembers' <<<$jsonDated | awk '{ SUM += $1} END { printf "%.2f", SUM }') - #echo "$sumRWBrut" + nbrMembers=$(jq -r '.[].nbrMembers' <<<$jsonDated | awk '{ SUM += $1} END { printf "%.2f", SUM }') + nbrWallets=$(jq -r '.[].nbrWallets' <<<$jsonDated | awk '{ SUM += $1} END { printf "%.2f", SUM }') + UD=$(jq -r '.[].UD' <<<$jsonDated | tail -n1) echo "{ \"date\": "\"$dateRange\"", + \"UD\": $UD, \"rWallets\": $sumRWBrut, \"sWallets\": $sumSWBrut, \"rMembers\": $sumRMBrut, - \"sMembers\": $sumSMBrut + \"sMembers\": $sumSMBrut, + \"nbrMembers\": $nbrMembers, + \"nbrWallets\": $nbrWallets } " | jq . } -selectDay() { - lineNbr=$(($lineNbr+7)) +day() { + lineNbr=$(($lineNbr+8)) - jsonDated=$(head -n$lineNbr db/recus.json |tail -n7 | sed 's/},/}/g') - echo "$jsonDated" | jq . + jsonDated=$(head -n$lineNbr $jsonFile | tail -n10 | sed 's/},/}/g') + jq . <<<"$jsonDated" } $1 \ No newline at end of file diff --git a/g1-stats.sh b/g1-stats.sh index 8b1fb0e..571b822 100755 --- a/g1-stats.sh +++ b/g1-stats.sh @@ -31,6 +31,7 @@ nbrMembers=$(echo "$membresPubkeys" | wc -l) lastBloc=${TXBLOCKS[-1]} udBlocs=$(curl -s ${DUNITER}/blockchain/with/ud | jq '.result.blocks[]') isWeb=$1 +jsonFile="$SCRIPTPATH/db/daily.json" ### On source les fonctions source $SCRIPTPATH/lib/functions.sh @@ -38,9 +39,6 @@ source $SCRIPTPATH/lib/scanTxWallets.sh ### Extraction des adresses Ḡ1 actives scanTxWallets $1 #kopa -exit - - ### Calcul la somme des soldes portefeuilles et membres sumSoldes diff --git a/lib/functions.sh b/lib/functions.sh index ad5eed1..672e54c 100755 --- a/lib/functions.sh +++ b/lib/functions.sh @@ -63,13 +63,13 @@ web() { } sumSoldes() { - sumRWBrut=$(jq -r '.[].rWallets' db/recus.json | awk '{ SUM += $1} END { printf "%.2f", SUM }') - sumRMBrut=$(jq -r '.[].rMembers' db/recus.json | awk '{ SUM += $1} END { printf "%.2f", SUM }') - sumRTBrut=$(jq -r '.[] | .rWallets, .rMembers' db/recus.json | awk '{ SUM += $1} END { printf "%.2f", SUM }') - sumSWBrut=$(jq -r '.[].sWallets' db/recus.json | awk '{ SUM += $1} END { printf "%.2f", SUM }') - #sumSWBrut=$(jq -n '[inputs | .[].sWallets] | reduce .[] as $num (0; .+$num)' db/recus.json | xargs printf %.2f | tr ',' '.') - sumSMBrut=$(jq -r '.[].sMembers' db/recus.json | awk '{ SUM += $1} END { printf "%.2f", SUM }') - sumSTBrut=$(jq -r '.[] | .sWallets, .sMembers' db/recus.json | awk '{ SUM += $1} END { printf "%.2f", SUM }') + sumRWBrut=$(jq -r '.[].rWallets' $jsonFile | awk '{ SUM += $1} END { printf "%.2f", SUM }') + sumRMBrut=$(jq -r '.[].rMembers' $jsonFile | awk '{ SUM += $1} END { printf "%.2f", SUM }') + sumRTBrut=$(jq -r '.[] | .rWallets, .rMembers' $jsonFile | awk '{ SUM += $1} END { printf "%.2f", SUM }') + sumSWBrut=$(jq -r '.[].sWallets' $jsonFile | awk '{ SUM += $1} END { printf "%.2f", SUM }') + #sumSWBrut=$(jq -n '[inputs | .[].sWallets] | reduce .[] as $num (0; .+$num)' $jsonFile | xargs printf %.2f | tr ',' '.') + sumSMBrut=$(jq -r '.[].sMembers' $jsonFile | awk '{ SUM += $1} END { printf "%.2f", SUM }') + sumSTBrut=$(jq -r '.[] | .sWallets, .sMembers' $jsonFile | awk '{ SUM += $1} END { printf "%.2f", SUM }') soldeWBrut=$(echo "$sumRWBrut-$sumSWBrut" | bc) soldeMBrut=$(echo "$sumRMBrut-$sumSMBrut" | bc) diff --git a/lib/scanTxWallets.sh b/lib/scanTxWallets.sh index 93ee10b..6de0c91 100755 --- a/lib/scanTxWallets.sh +++ b/lib/scanTxWallets.sh @@ -18,7 +18,7 @@ scanTxWallets() { else local startIter=0 local startBloc=0 - echo "[" > $SCRIPTPATH/db/recus.json + echo "[" > $jsonFile fi incExec=1 @@ -27,12 +27,12 @@ scanTxWallets() { bloc=${TXBLOCKS[$i]} [[ -z $bloc ]] && break [[ $startIter != 0 && $i -le $startIter ]] && continue -# [[ $bloc -lt 5243 ]] && continue #kopa +# [[ $i -lt 290 ]] && continue #kopa sleep 0.05 # Récupère la date et l'objet transaction du bloc courant blocFull=$(curl -s ${DUNITER}/blockchain/block/$bloc) - until blocBrut=$(echo $blocFull | jq -r '.' 2>/dev/null); do + until blocBrut=$(jq -r '.' <<<"$blocFull" 2>/dev/null); do [[ $isWeb != "web" ]] && echo -e "i: $i\n$blocFull" sleep 2 blocFull=$(curl -s ${DUNITER}/blockchain/block/$bloc) @@ -41,24 +41,23 @@ scanTxWallets() { # Récupération de la date du block blockDate=$(jq '.medianTime' <<<"$blocBrut") - blockDate=$(date -d"@$blockDate" +%y-%m-%d -u) + blockDate=$(date -d"@$blockDate" +%d-%m-%y -u) local walletsReceivedBloc=$(jq '.transactions[]' <<<"$blocBrut") # Si cette itération provient d'un cache, alors on aggrège la dernière date if [[ $startBloc != 0 ]]; then - lastDate=$(cat db/recus.json | jq -r '.[].date' | tail -n1) - echo -e "IFCACHE\t - $bloc - $blockDate - $lastDate" >> tata #kopa - if [[ "$blockDate" == "$lastDate" ]]; then - valueReceivedW=$(cat db/recus.json | jq -r '.[].rWallets' | tail -n1 | xargs echo 100* | bc) - valueReceivedM=$(cat db/recus.json | jq -r '.[].rMembers' | tail -n1 | xargs echo 100* | bc) - valueSentW=$(cat db/recus.json | jq -r '.[].sWallets' | tail -n1 | xargs echo 100* | bc) - valueSentM=$(cat db/recus.json | jq -r '.[].sMembers' | tail -n1 | xargs echo 100* | bc) + lastDate=$(jq -r '.[].date' $jsonFile | tail -n1) + if [[ "$blockDate" == "$lastDate" || (-n $blockDateLast && $blockDateLast != $blockDate) ]]; then + valueReceivedW=$(jq -r '.[].rWallets' $jsonFile | tail -n1 | xargs echo 100* | bc) + valueReceivedM=$(jq -r '.[].rMembers' $jsonFile | tail -n1 | xargs echo 100* | bc) + valueSentW=$(jq -r '.[].sWallets' $jsonFile | tail -n1 | xargs echo 100* | bc) + valueSentM=$(jq -r '.[].sMembers' $jsonFile | tail -n1 | xargs echo 100* | bc) - local recusJson=$(head -n -11 db/recus.json) - echo "$recusJson" > $SCRIPTPATH/db/recus.json + local recusJson=$(head -n -11 $jsonFile) + echo "$recusJson" > $jsonFile else - local recusJson=$(head -n -2 db/recus.json) - echo -e "$recusJson\n }," > $SCRIPTPATH/db/recus.json + local recusJson=$(head -n -2 $jsonFile) + echo -e "$recusJson\n }," > $jsonFile fi #unset recusJson startBloc=0 @@ -78,6 +77,10 @@ scanTxWallets() { local walletsSentToday=$(echo -e "$walletsSentTodayTmp" | head -n -1) local walletsReceivedBloc=$(echo -e "$walletsReceivedTodayTmp" | head -n -1) unset walletsReceivedTodayTmp walletsSentTodayTmp + [[ -z $walletsReceivedBloc ]] && continue + + # Stock les clés publiques de ce bloc dans la variable $wallets + walletsAuj+=$(echo "$walletsReceivedBloc" | grep -Eo $REGEX_PUBKEYS)$'\n' # Exporte les valeurs de la journée dans le fichier JSON jsonify() { @@ -89,7 +92,7 @@ scanTxWallets() { [[ -z $nbrWallets ]] && nbrWallets=0 [[ -z $UDToday ]] && UDToday=0 - local jsonTPL=$(sed s/_DATE/$blockDateLast/g $SCRIPTPATH/tpl/recus.json) + local jsonTPL=$(sed s/_DATE/$blockDateLast/g $SCRIPTPATH/tpl/daily.json) local jsonTPL=$(sed s/_UDTODAY/$UDToday/g <<< $jsonTPL) local jsonTPL=$(sed s/_RWALLETS/$valueReceivedW/g <<< $jsonTPL) local jsonTPL=$(sed s/_SWALLETS/$valueSentW/g <<< $jsonTPL) @@ -97,13 +100,10 @@ scanTxWallets() { local jsonTPL=$(sed s/_SMEMBERS/$valueSentM/g <<< $jsonTPL) local jsonTPL=$(sed s/_NBRMEMBERS/$nbrMembersToday/g <<< $jsonTPL) local jsonTPL=$(sed s/_NBRWALLETS/$nbrWallets/g <<< $jsonTPL) - echo -e "$jsonTPL" | tr -d '\\' >> $SCRIPTPATH/db/recus.json + echo -e "$jsonTPL" | tr -d '\\' >> $jsonFile } - # Stock les clés publiques de ce bloc dans la variable $wallets - walletsAuj+=$(echo "$walletsReceivedBloc" | grep -Eo $REGEX_PUBKEYS)$'\n' - - # Si le date du bloc courant est différente du bloc précedent, alors on stock les valeurs journalières + # Si la date du bloc courant est différente du bloc précedent, alors on stock les valeurs journalières applyToday() { [[ -z $wallets ]] && wallets="#" WALLETS=$(echo -e "$wallets" | grep .) @@ -114,13 +114,6 @@ scanTxWallets() { [[ -z $nbrMembersYesterday ]] && nbrMembersYesterday=0 nbrMembersToday=$(($nbrMembersTotalToday-$nbrMembersYesterday)) - # Récupération de la masse monétaire à ce block - #monetaryMassTotalToday=$(jq '.monetaryMass' <<<"$blocBrut") - #monetaryMassTotalToday=$(echo "scale=2; $monetaryMassTotalToday/100" | bc) - #[[ -z $monetaryMassYesterday ]] && monetaryMassYesterday=0 - #monetaryMassToday=$(echo "scale=2; $monetaryMassTotalToday-$monetaryMassYesterday" | bc) - #monetaryMassYesterday=$monetaryMassTotalToday - # Obtention du dividende à ce block udBlock=$(for i in $udBlocs; do [[ $i -ge $bloc ]] && echo $lastBloc && break; lastBloc=$i; done) UDToday=$(curl -s ${DUNITER}/blockchain/block/$udBlock | jq '.dividend') @@ -128,22 +121,14 @@ scanTxWallets() { jsonify } - if [[ -n $blockDateLast && $blockDateLast != $blockDate ]]; then - if [[ -z $recusJson ]]; then - applyToday - else - # Calcul du nombre de nouveaux membres à ce block - nbrMembersTotalToday=$(jq '.membersCount' <<<"$blocBrut") - [[ -z $nbrMembersYesterday ]] && nbrMembersYesterday=0 - nbrMembersToday=$(($nbrMembersTotalToday-$nbrMembersYesterday)) - fi + if [[ -n $blockDateLast && $blockDateLast != $blockDate ]]; then + applyToday [[ $wallets == "#" ]] && unset wallets wallets+=$'\n'"$walletsAuj" wallets=$(echo -e "$wallets" | sort -u | grep .)$'\n' nbrMembersYesterday=$nbrMembersTotalToday unset valueReceivedM valueReceivedW valueSentM valueSentW walletsAuj - echo -e "INLOOP\t - $bloc - $blockDateLast - $nbrMembersYesterday" >> tata #kopa fi unset recusJson @@ -209,11 +194,11 @@ scanTxWallets() { [[ $i -ge $1 ]] && break #kopa done - [[ $blockDateLast == $blockDate ]] && applyToday && echo -e "END\t\t - $bloc - $blockDate - $nbrMembersYesterday" >> tata #kopa + [[ $blockDateLast == $blockDate ]] && applyToday # Retire la dernière virgule et ajoute le crochet de fin de JSON - sed -i '$ s/,//g' $SCRIPTPATH/db/recus.json - echo "]" >> $SCRIPTPATH/db/recus.json + sed -i '$ s/,//g' $jsonFile + echo "]" >> $jsonFile # On supprime les doublons et les lignes vides wallets=$(echo -e "$wallets" | sort -u | awk 'NF') diff --git a/lib/transform_json.sh b/lib/transform_json.sh index 0278849..86fd078 100755 --- a/lib/transform_json.sh +++ b/lib/transform_json.sh @@ -21,7 +21,7 @@ rWallets() { local RW=$(sed '3q;d' <<< $i) local RM=$(sed '4q;d' <<< $i) - local jsonTPL=$(sed s/_DATE/$dateN/g $SCRIPTPATH/tpl/recus.json) + local jsonTPL=$(sed s/_DATE/$dateN/g $SCRIPTPATH/tpl/daily.json) local jsonTPL=$(sed s/_RWALLETS/$RW/g <<< $jsonTPL) local result+=$(sed s/_RMEMBERS/$RM/g <<< $jsonTPL) done diff --git a/scripts/backup-actual.sh b/scripts/backup-actual.sh index a70109b..abb9b72 100755 --- a/scripts/backup-actual.sh +++ b/scripts/backup-actual.sh @@ -7,5 +7,5 @@ cacheID=$(echo $cacheFile | awk -F '-' '{ print $NF }') #rm -f cache/bk-walletsUp-* cp $cacheFile $SCRIPTPATH/../cache/bk-walletsUp-$cacheID -cp $SCRIPTPATH/../db/recus.json $SCRIPTPATH/../db/bk-recus.json-$cacheID +cp $SCRIPTPATH/../db/daily.json $SCRIPTPATH/../db/bk-daily.json-$cacheID diff --git a/scripts/export_sommes.sh b/scripts/export_sommes.sh index e5969c9..ceda966 100755 --- a/scripts/export_sommes.sh +++ b/scripts/export_sommes.sh @@ -2,4 +2,4 @@ SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )" -jq -r '.[] | "---", .date, .rWallets + .rMembers' $SCRIPTPATH/../db/recus.json > $SCRIPTPATH/../db/somme.txt +jq -r '.[] | "---", .date, .rWallets + .rMembers' $SCRIPTPATH/../db/daily.json > $SCRIPTPATH/../db/somme.txt diff --git a/scripts/restore-bk.sh b/scripts/restore-bk.sh index 04370cb..733ec2f 100755 --- a/scripts/restore-bk.sh +++ b/scripts/restore-bk.sh @@ -10,8 +10,8 @@ else cacheID=$(echo $cacheFile | awk -F '-' '{ print $NF }') fi -[[ -f $cacheFile ]] && rm $SCRIPTPATH/../cache/walletsUp-* +[[ -f $cacheFile ]] && rm -f $SCRIPTPATH/../cache/walletsUp-* cp $cacheFile $SCRIPTPATH/../cache/walletsUp-$cacheID -cp $SCRIPTPATH/../db/bk-recus.json-$cacheID $SCRIPTPATH/../db/recus.json +cp $SCRIPTPATH/../db/bk-daily.json-$cacheID $SCRIPTPATH/../db/daily.json diff --git a/tpl/recus.json b/tpl/daily.json similarity index 100% rename from tpl/recus.json rename to tpl/daily.json