Store day even if no transaction happened

This commit is contained in:
poka 2020-09-24 03:30:05 +02:00
parent d69b60e362
commit 127c4d5a67
2 changed files with 37 additions and 30 deletions

View File

@ -13,7 +13,7 @@ scanTxWallets() {
local nbrMembersYesterday=$(cat "$startFile" | sed -e '1,/---/d' | sed -e '1,/---/d' | sed '/---/Q' | grep . | cut -d '|' -f 1) 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 blockDateLast=$(cat "$startFile" | sed -e '1,/---/d' | sed -e '1,/---/d' | sed '/---/Q' | grep . | cut -d '|' -f 2)
[[ $lastBloc == $startBloc ]] && return #kopa [[ $lastBloc == $startBloc ]] && return
rm $startFile rm $startFile
else else
local startIter=0 local startIter=0
@ -23,13 +23,13 @@ scanTxWallets() {
incExec=1 incExec=1
for ((i=$startIter; i<${#TXBLOCKS[@]}; i++)); do for ((i=$startIter; i<${#TXBLOCKS[@]}; i++)); do
startExec=$(($(date +%s%N)/1000000)) local startExec=$(($(date +%s%N)/1000000))
bloc=${TXBLOCKS[$i]} local bloc=${TXBLOCKS[$i]}
[[ -z $bloc ]] && break [[ -z $bloc ]] && break
# [[ $i -lt 290 ]] && continue #kopa [[ $i -lt 1193 ]] && continue #kopa
# Récupère la date et l'objet transaction du bloc courant # Récupère la date et l'objet transaction du bloc courant
blocFull=$(curl -s ${DUNITER}/blockchain/block/$bloc) local blocFull=$(curl -s ${DUNITER}/blockchain/block/$bloc)
until blocBrut=$(jq -r '.' <<<"$blocFull" 2>/dev/null); do until blocBrut=$(jq -r '.' <<<"$blocFull" 2>/dev/null); do
[[ $isWeb != "web" ]] && echo -e "i: $i\n$blocFull" [[ $isWeb != "web" ]] && echo -e "i: $i\n$blocFull"
sleep 2 sleep 2
@ -38,18 +38,18 @@ scanTxWallets() {
[[ -z "$blocBrut" ]] && continue [[ -z "$blocBrut" ]] && continue
# Récupération de la date du block # Récupération de la date du block
blockDate=$(jq '.medianTime' <<<"$blocBrut") local blockDate=$(jq '.medianTime' <<<"$blocBrut")
blockDate=$(date -d"@$blockDate" +%d-%m-%y -u) blockDate=$(date -d"@$blockDate" +%d-%m-%y -u)
local walletsReceivedBloc=$(jq '.transactions[]' <<<"$blocBrut") local walletsReceivedBloc=$(jq '.transactions[]' <<<"$blocBrut")
# Si cette itération provient d'un cache, alors on aggrège la dernière date # Si cette itération provient d'un cache, alors on aggrège la dernière date
if [[ $startBloc != 0 ]]; then if [[ $startBloc != 0 ]]; then
lastDate=$(jq -r '.[].date' $jsonFile | tail -n1) local lastDate=$(jq -r '.[].date' $jsonFile | tail -n1)
if [[ "$blockDate" == "$lastDate" || (-n $blockDateLast && $blockDateLast != $blockDate) ]]; then if [[ "$blockDate" == "$lastDate" || (-n $blockDateLast && $blockDateLast != $blockDate) ]]; then
valueReceivedW=$(jq -r '.[].rWallets' $jsonFile | tail -n1 | xargs echo 100* | bc) local valueReceivedW=$(jq -r '.[].rWallets' $jsonFile | tail -n1 | xargs echo 100* | bc)
valueReceivedM=$(jq -r '.[].rMembers' $jsonFile | tail -n1 | xargs echo 100* | bc) local valueReceivedM=$(jq -r '.[].rMembers' $jsonFile | tail -n1 | xargs echo 100* | bc)
valueSentW=$(jq -r '.[].sWallets' $jsonFile | tail -n1 | xargs echo 100* | bc) local valueSentW=$(jq -r '.[].sWallets' $jsonFile | tail -n1 | xargs echo 100* | bc)
valueSentM=$(jq -r '.[].sMembers' $jsonFile | tail -n1 | xargs echo 100* | bc) local valueSentM=$(jq -r '.[].sMembers' $jsonFile | tail -n1 | xargs echo 100* | bc)
local recusJson=$(head -n -11 $jsonFile) local recusJson=$(head -n -11 $jsonFile)
echo "$recusJson" > $jsonFile echo "$recusJson" > $jsonFile
@ -57,7 +57,6 @@ scanTxWallets() {
local recusJson=$(head -n -2 $jsonFile) local recusJson=$(head -n -2 $jsonFile)
echo -e "$recusJson\n }," > $jsonFile echo -e "$recusJson\n }," > $jsonFile
fi fi
#unset recusJson
startBloc=0 startBloc=0
fi fi
@ -91,20 +90,20 @@ scanTxWallets() {
[[ -z $UDToday ]] && UDToday=0 [[ -z $UDToday ]] && UDToday=0
local jsonTPL=$(sed s/_DATE/$blockDateLast/g $SCRIPTPATH/tpl/daily.json) local jsonTPL=$(sed s/_DATE/$blockDateLast/g $SCRIPTPATH/tpl/daily.json)
local jsonTPL=$(sed s/_UDTODAY/$UDToday/g <<< $jsonTPL) jsonTPL=$(sed s/_UDTODAY/$UDToday/g <<< $jsonTPL)
local jsonTPL=$(sed s/_RWALLETS/$valueReceivedW/g <<< $jsonTPL) jsonTPL=$(sed s/_RWALLETS/$valueReceivedW/g <<< $jsonTPL)
local jsonTPL=$(sed s/_SWALLETS/$valueSentW/g <<< $jsonTPL) jsonTPL=$(sed s/_SWALLETS/$valueSentW/g <<< $jsonTPL)
local jsonTPL=$(sed s/_RMEMBERS/$valueReceivedM/g <<< $jsonTPL) jsonTPL=$(sed s/_RMEMBERS/$valueReceivedM/g <<< $jsonTPL)
local jsonTPL=$(sed s/_SMEMBERS/$valueSentM/g <<< $jsonTPL) jsonTPL=$(sed s/_SMEMBERS/$valueSentM/g <<< $jsonTPL)
local jsonTPL=$(sed s/_NBRMEMBERS/$nbrMembersToday/g <<< $jsonTPL) jsonTPL=$(sed s/_NBRMEMBERS/$nbrMembersToday/g <<< $jsonTPL)
local jsonTPL=$(sed s/_NBRWALLETS/$nbrWallets/g <<< $jsonTPL) jsonTPL=$(sed s/_NBRWALLETS/$nbrWallets/g <<< $jsonTPL)
echo -e "$jsonTPL" | tr -d '\\' >> $jsonFile echo -e "$jsonTPL" | tr -d '\\' >> $jsonFile
} }
# Si la 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() { applyToday() {
[[ -z $wallets ]] && wallets="#" [[ -z $wallets ]] && wallets="#"
WALLETS=$(echo -e "$wallets" | grep .) local WALLETS=$(echo -e "$wallets" | grep .)
# On split la listes des wallets pour ne pas saturer grep # On split la listes des wallets pour ne pas saturer grep
local id=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1) local id=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
@ -113,7 +112,7 @@ scanTxWallets() {
pushd $tmpSplit >/dev/null || exit 1 pushd $tmpSplit >/dev/null || exit 1
echo -e "$membresPubkeys\n$WALLETS" | split -d -l 2500 echo -e "$membresPubkeys\n$WALLETS" | split -d -l 2500
walletsAujTmp=$(echo -e "$walletsAuj" | sort -u | awk 'NF') local walletsAujTmp=$(echo -e "$walletsAuj" | sort -u | awk 'NF')
local i local i
for i in $(ls x*); do for i in $(ls x*); do
local walletToSup=$(cat $i) local walletToSup=$(cat $i)
@ -132,7 +131,7 @@ scanTxWallets() {
lastUdBloc=$j lastUdBloc=$j
done done
[[ -z $lastUdBloc ]] && lastUdBloc=$(echo "$udBlocs" | tail -n1) [[ -z $lastUdBloc ]] && lastUdBloc=$(echo "$udBlocs" | tail -n1)
blocUD=$(curl -s ${DUNITER}/blockchain/block/$lastUdBloc | jq '.membersCount,.dividend') local blocUD=$(curl -s ${DUNITER}/blockchain/block/$lastUdBloc | jq '.membersCount,.dividend')
UDToday=$(echo "$blocUD" | tail -n1 | xargs -i echo "scale=2; {}/100" | bc) UDToday=$(echo "$blocUD" | tail -n1 | xargs -i echo "scale=2; {}/100" | bc)
# Calcul du nombre de nouveaux membres à ce block # Calcul du nombre de nouveaux membres à ce block
@ -149,7 +148,14 @@ scanTxWallets() {
wallets+=$'\n'"$walletsAuj" wallets+=$'\n'"$walletsAuj"
wallets=$(echo -e "$wallets" | sort -u | grep .)$'\n' wallets=$(echo -e "$wallets" | sort -u | grep .)$'\n'
nbrMembersYesterday=$nbrMembersTotalToday nbrMembersYesterday=$nbrMembersTotalToday
unset valueReceivedM valueReceivedW valueSentM valueSentW walletsAuj unset valueReceivedM valueReceivedW valueSentM valueSentW walletsAuj nbrMembersToday nbrWallets
# Si il manque un jour sans transaction, on le génère
dateYesterday=$(awk -F '-' '{ print $3"-"$2"-"$1 }' <<<$blockDate | xargs -i date -d "{}-1day" '+%d-%m-%y')
if [[ $dateYesterday != $blockDateLast ]];then
blockDateLast=$dateYesterday
jsonify
fi
fi fi
unset recusJson unset recusJson
@ -193,13 +199,13 @@ scanTxWallets() {
done done
# Affiche la progression de la boucle si on est pas en mode web # Affiche la progression de la boucle si on est pas en mode web
progress=$(echo "scale=1; $bloc*100/$lastBloc/1" | bc) local progress=$(echo "scale=1; $bloc*100/$lastBloc/1" | bc)
endExec=$(($(date +%s%N)/1000000)) local endExec=$(($(date +%s%N)/1000000))
timeExec=$(echo "scale=3; ($endExec-$startExec)/1000" | bc) local timeExec=$(echo "scale=3; ($endExec-$startExec)/1000" | bc)
#[[ -z $midTimeExec ]] && midTimeExec=$timeExec #[[ -z $midTimeExec ]] && midTimeExec=$timeExec
[[ $incExec9 == 50 || $incExec == 1 ]] && incExec=1 && midTimeExecCum=0 [[ $incExec9 == 50 || $incExec == 1 ]] && incExec=1 && midTimeExecCum=0
midTimeExecCum=$(echo "scale=3; $midTimeExecCum+$timeExec" | bc) local midTimeExecCum=$(echo "scale=3; $midTimeExecCum+$timeExec" | bc)
midTimeExec=$(echo "scale=3; $midTimeExecCum/$incExec" | bc) local midTimeExec=$(echo "scale=3; $midTimeExecCum/$incExec" | bc)
((incExec++)) ((incExec++))
if [[ $isWeb != "web" ]]; then if [[ $isWeb != "web" ]]; then
tput cuu1;tput el;tput cuu1;tput el;tput cuu1;tput el;tput cuu1;tput el;tput cuu1;tput el; # Clear the last view tput cuu1;tput el;tput cuu1;tput el;tput cuu1;tput el;tput cuu1;tput el;tput cuu1;tput el; # Clear the last view
@ -208,9 +214,10 @@ scanTxWallets() {
\rDate: $blockDate \rDate: $blockDate
\rTemps d'execution: $midTimeExec" \rTemps d'execution: $midTimeExec"
else else
[[ -z $firstScan ]] && echo "Scan des blocs avec transactions en cours ..." && firstScan=true [[ -z $firstScan ]] && echo "Scan des blocs avec transactions en cours ..." && local firstScan=true
fi fi
# [[ $i -ge 35949 ]] && break #kopa # [[ $i -ge 35949 ]] && break #kopa
break
done done
[[ $blockDateLast == $blockDate ]] && applyToday [[ $blockDateLast == $blockDate ]] && applyToday

View File

@ -3,7 +3,7 @@ source .env
day=$1 day=$1
[[ -z $day ]] && day=1 [[ -z $day ]] && day=1
bloc=$(grep -n . db/udblocs | grep -E "^$day:" | cut -d: -f2) bloc=$(grep -n . db/debug/udblocs | grep -E "^$day:" | cut -d: -f2)
chainData=$(curl -s ${DUNITER}/blockchain/block/$bloc | jq '.membersCount,.monetaryMass') chainData=$(curl -s ${DUNITER}/blockchain/block/$bloc | jq '.membersCount,.monetaryMass')
chainMass=$(tail -n1 <<<"$chainData" | xargs -i echo "scale=2; {}/100" | bc) chainMass=$(tail -n1 <<<"$chainData" | xargs -i echo "scale=2; {}/100" | bc)
chainMbr=$(head -n1 <<<"$chainData") chainMbr=$(head -n1 <<<"$chainData")