From 19b7cb156f3c65b8f9e3a1800d085790fcbcfac5 Mon Sep 17 00:00:00 2001 From: poka Date: Fri, 15 Oct 2021 00:23:17 +0200 Subject: [PATCH] Cache every day; Catch 1006 ucode --- g1-stats.sh | 3 ++- lib/functions.sh | 18 ++++++++++++++++++ lib/scanTxWallets.sh | 31 +++++++++++++++++++++++++++++-- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/g1-stats.sh b/g1-stats.sh index e8acfcd..322bea9 100755 --- a/g1-stats.sh +++ b/g1-stats.sh @@ -29,7 +29,8 @@ if $debug; then udBlocs=$(cat $GPATH/db/debug/udblocs) echo # To clean next progress view else - TXBLOCKS=$(curl -s ${DUNITER}/blockchain/with/tx | jq '.result.blocks[]') +# TXBLOCKS=$(curl -s ${DUNITER}/blockchain/with/tx | jq '.result.blocks[]') + TXBLOCKS=$(cat $GPATH/tx.json | jq '.result.blocks[]') echo "TXBLOCKS OK" membresPubkeys=$(curl -s ${DUNITER}/wot/members | jq -r '.results[].pubkey') tput cuu1;tput el; diff --git a/lib/functions.sh b/lib/functions.sh index 8e53a90..8740fc1 100755 --- a/lib/functions.sh +++ b/lib/functions.sh @@ -132,3 +132,21 @@ Analyse --- $sleepyG1% des Ḡ1 n'ont jamais été utilisés." } + +rmOldCache() { + keepCache=20 + listCache=$(ls -l $GPATH/db/bk-* | awk '{ print $9 }') + listID=$(echo "$listCache" | awk -F '-' '{ print $NF }') + + nbrID=$(echo "$listID" | wc -l) + nbrToSup=$((nbrID-$keepCache)) + + if [[ $nbrToSup -ge 0 ]]; then + cacheIDToSup=$(echo "$listID" | head -n$nbrToSup) + + for i in $cacheIDToSup; do + rm $GPATH/db/bk-daily.json-$i + rm $GPATH/cache/bk-walletsUp-$i + done + fi +} diff --git a/lib/scanTxWallets.sh b/lib/scanTxWallets.sh index 71a9d96..8452906 100755 --- a/lib/scanTxWallets.sh +++ b/lib/scanTxWallets.sh @@ -13,8 +13,8 @@ scanTxWallets() { local nbrMembersYesterday=$(cat "$startFile" | sed -e '1,/---/d' | sed -e '1,/---/d' | sed '/---/Q' | grep . | cut -d '|' -f 1) local blockDateLast=$(cat "$startFile" | sed -e '1,/---/d' | sed -e '1,/---/d' | sed '/---/Q' | grep . | cut -d '|' -f 2) local nbrDays=$(cat "$startFile" | sed -e '1,/---/d' | sed -e '1,/---/d' | sed '/---/Q' | grep . | cut -d '|' -f 3) - #! ($debug) && - [[ $lastBloc -le $startBloc || $startIter -ge ${#TXBLOCKS[@]} ]] && return + #! ($debug) && + [[ $lastBloc -le $startBloc || $startIter -ge ${#TXBLOCKS[@]} ]] && echo "$lastBloc -le $startBloc || $startIter -ge ${#TXBLOCKS[@]}" && return rm $startFile else local startIter=0 @@ -24,6 +24,7 @@ scanTxWallets() { fi incExec=1 for ((i=$startIter; i<${#TXBLOCKS[@]}; i++)); do + local nbrIteration=$i local startExec=$(($(date +%s%N)/1000000)) local bloc=${TXBLOCKS[$i]} [[ -z $bloc ]] && break @@ -31,6 +32,11 @@ scanTxWallets() { # Récupération du bloc courant local blocFull=$(curl -s ${DUNITER}/blockchain/block/$bloc) + while [[ $(jq -r '.ucode' <<<"$blocFull") == 1006 ]]; do + [[ $isWeb != "web" ]] && echo -e "i: $i\n$blocFull" + sleep 2 + blocFull=$(curl -s ${DUNITER}/blockchain/block/$bloc) + done until blocBrut=$(jq -r '.' <<<"$blocFull" 2>/dev/null); do [[ $isWeb != "web" ]] && echo -e "i: $i\n$blocFull" sleep 2 @@ -38,6 +44,10 @@ scanTxWallets() { done [[ -z "$blocBrut" ]] && continue + echo "$blocFull" > debugTmp.txt + echo "-----------------------------------" >> debugTmp.txt + echo "$blocBrut" >> debugTmp.txt + # Récupération de la date du block local blockDate=$(jq '.medianTime' <<<"$blocBrut") #kopa echo "$blocBrut" @@ -141,6 +151,23 @@ scanTxWallets() { nbrMembersToday=$(($nbrMembersTotalToday-$nbrMembersYesterday)) jsonify + + # Mise en cache périodique + + ## On supprime les doublons et les lignes vides + wallets=$(echo -e "$wallets" | sort -u | awk 'NF') + +# if ((i % 50 == 0)); then #kopaa + echo -e "$bloc\n$wallets\n---\n$walletsAuj\n---\n$nbrMembersYesterday|$blockDateLast|$nbrDays" > $GPATH/cache/bk-walletsUp-$nbrIteration + cp $GPATH/db/daily.json $GPATH/db/bk-daily.json-$nbrIteration + + ## Retire la dernière virgule et ajoute le crochet de fin de JSON + sed -i '$ s/,//g' $GPATH/db/bk-daily.json-$nbrIteration + echo "]" >> $GPATH/db/bk-daily.json-$nbrIteration + + ## On supprime le vieux cache + rmOldCache +# fi } if [[ -n $blockDateLast && $blockDateLast != $blockDate ]]; then