Store day even if no transaction happened
This commit is contained in:
parent
d69b60e362
commit
127c4d5a67
|
@ -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 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
|
||||
else
|
||||
local startIter=0
|
||||
|
@ -23,13 +23,13 @@ scanTxWallets() {
|
|||
|
||||
incExec=1
|
||||
for ((i=$startIter; i<${#TXBLOCKS[@]}; i++)); do
|
||||
startExec=$(($(date +%s%N)/1000000))
|
||||
bloc=${TXBLOCKS[$i]}
|
||||
local startExec=$(($(date +%s%N)/1000000))
|
||||
local bloc=${TXBLOCKS[$i]}
|
||||
[[ -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
|
||||
blocFull=$(curl -s ${DUNITER}/blockchain/block/$bloc)
|
||||
local blocFull=$(curl -s ${DUNITER}/blockchain/block/$bloc)
|
||||
until blocBrut=$(jq -r '.' <<<"$blocFull" 2>/dev/null); do
|
||||
[[ $isWeb != "web" ]] && echo -e "i: $i\n$blocFull"
|
||||
sleep 2
|
||||
|
@ -38,18 +38,18 @@ scanTxWallets() {
|
|||
[[ -z "$blocBrut" ]] && continue
|
||||
|
||||
# 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)
|
||||
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=$(jq -r '.[].date' $jsonFile | tail -n1)
|
||||
local 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 valueReceivedW=$(jq -r '.[].rWallets' $jsonFile | tail -n1 | xargs echo 100* | bc)
|
||||
local valueReceivedM=$(jq -r '.[].rMembers' $jsonFile | tail -n1 | xargs echo 100* | bc)
|
||||
local valueSentW=$(jq -r '.[].sWallets' $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)
|
||||
echo "$recusJson" > $jsonFile
|
||||
|
@ -57,7 +57,6 @@ scanTxWallets() {
|
|||
local recusJson=$(head -n -2 $jsonFile)
|
||||
echo -e "$recusJson\n }," > $jsonFile
|
||||
fi
|
||||
#unset recusJson
|
||||
startBloc=0
|
||||
fi
|
||||
|
||||
|
@ -91,20 +90,20 @@ scanTxWallets() {
|
|||
[[ -z $UDToday ]] && UDToday=0
|
||||
|
||||
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)
|
||||
local jsonTPL=$(sed s/_RMEMBERS/$valueReceivedM/g <<< $jsonTPL)
|
||||
local jsonTPL=$(sed s/_SMEMBERS/$valueSentM/g <<< $jsonTPL)
|
||||
local jsonTPL=$(sed s/_NBRMEMBERS/$nbrMembersToday/g <<< $jsonTPL)
|
||||
local jsonTPL=$(sed s/_NBRWALLETS/$nbrWallets/g <<< $jsonTPL)
|
||||
jsonTPL=$(sed s/_UDTODAY/$UDToday/g <<< $jsonTPL)
|
||||
jsonTPL=$(sed s/_RWALLETS/$valueReceivedW/g <<< $jsonTPL)
|
||||
jsonTPL=$(sed s/_SWALLETS/$valueSentW/g <<< $jsonTPL)
|
||||
jsonTPL=$(sed s/_RMEMBERS/$valueReceivedM/g <<< $jsonTPL)
|
||||
jsonTPL=$(sed s/_SMEMBERS/$valueSentM/g <<< $jsonTPL)
|
||||
jsonTPL=$(sed s/_NBRMEMBERS/$nbrMembersToday/g <<< $jsonTPL)
|
||||
jsonTPL=$(sed s/_NBRWALLETS/$nbrWallets/g <<< $jsonTPL)
|
||||
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
|
||||
applyToday() {
|
||||
[[ -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
|
||||
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
|
||||
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
|
||||
for i in $(ls x*); do
|
||||
local walletToSup=$(cat $i)
|
||||
|
@ -132,7 +131,7 @@ scanTxWallets() {
|
|||
lastUdBloc=$j
|
||||
done
|
||||
[[ -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)
|
||||
|
||||
# Calcul du nombre de nouveaux membres à ce block
|
||||
|
@ -149,7 +148,14 @@ scanTxWallets() {
|
|||
wallets+=$'\n'"$walletsAuj"
|
||||
wallets=$(echo -e "$wallets" | sort -u | grep .)$'\n'
|
||||
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
|
||||
unset recusJson
|
||||
|
||||
|
@ -193,13 +199,13 @@ scanTxWallets() {
|
|||
done
|
||||
|
||||
# Affiche la progression de la boucle si on est pas en mode web
|
||||
progress=$(echo "scale=1; $bloc*100/$lastBloc/1" | bc)
|
||||
endExec=$(($(date +%s%N)/1000000))
|
||||
timeExec=$(echo "scale=3; ($endExec-$startExec)/1000" | bc)
|
||||
local progress=$(echo "scale=1; $bloc*100/$lastBloc/1" | bc)
|
||||
local endExec=$(($(date +%s%N)/1000000))
|
||||
local timeExec=$(echo "scale=3; ($endExec-$startExec)/1000" | bc)
|
||||
#[[ -z $midTimeExec ]] && midTimeExec=$timeExec
|
||||
[[ $incExec9 == 50 || $incExec == 1 ]] && incExec=1 && midTimeExecCum=0
|
||||
midTimeExecCum=$(echo "scale=3; $midTimeExecCum+$timeExec" | bc)
|
||||
midTimeExec=$(echo "scale=3; $midTimeExecCum/$incExec" | bc)
|
||||
local midTimeExecCum=$(echo "scale=3; $midTimeExecCum+$timeExec" | bc)
|
||||
local midTimeExec=$(echo "scale=3; $midTimeExecCum/$incExec" | bc)
|
||||
((incExec++))
|
||||
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
|
||||
|
@ -208,9 +214,10 @@ scanTxWallets() {
|
|||
\rDate: $blockDate
|
||||
\rTemps d'execution: $midTimeExec"
|
||||
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
|
||||
# [[ $i -ge 35949 ]] && break #kopa
|
||||
break
|
||||
done
|
||||
|
||||
[[ $blockDateLast == $blockDate ]] && applyToday
|
||||
|
|
|
@ -3,7 +3,7 @@ source .env
|
|||
|
||||
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')
|
||||
chainMass=$(tail -n1 <<<"$chainData" | xargs -i echo "scale=2; {}/100" | bc)
|
||||
chainMbr=$(head -n1 <<<"$chainData")
|
||||
|
|
Loading…
Reference in New Issue