Refactor functions positions; replace membres ans simples wallets loops by grep -v

This commit is contained in:
poka 2020-09-19 01:58:18 +02:00
parent b9ff5a9e04
commit 1376e1621d
10 changed files with 236 additions and 262 deletions

View File

@ -1,9 +0,0 @@
#!/bin/bash
cacheFile=$(ls cache/walletsUp-*)
cacheID=$(echo $cacheFile | awk -F '-' '{ print $NF }')
#rm -f cache/bk-walletsUp-*
cp $cacheFile cache/bk-walletsUp-$cacheID
cp db/recus.json db/bk-recus.json-$cacheID

View File

@ -22,85 +22,36 @@ TXBLOCKS=$(cat $SCRIPTPATH/db/txblocs) #kopa
#TXBLOCKS=$(curl -s ${DUNITER}/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 -r '.results[].pubkey'))
MEMBERS=($(cat db/membresPubkeys)) #kopa
nbrMembers=${#MEMBERS[@]}
#membresPubkeys=$(curl -s ${DUNITER}/wot/members | jq -r '.results[].pubkey')
membresPubkeys=$(cat db/membresPubkeys) #kopa
nbrMembers=$(echo "$membresPubkeys" | wc -l)
lastBloc=${TXBLOCKS[-1]}
isWeb=$1
### On source les fonctions ###
source $SCRIPTPATH/functions.sh
### On source les fonctions
source $SCRIPTPATH/lib/functions.sh
source $SCRIPTPATH/lib/scanTxWallets.sh
### Extraction des adresses Ḡ1 actives ###
loopWalletUp
### Extraction des adresses Ḡ1 actives
scanTxWallets
### Calcul la somme des soldes portefeuilles et membres ###
sumSoldes db/recus.json
### Calcul la somme des soldes portefeuilles et membres
sumSoldes
### Ajout des membres sans transaction
addMembers
#endDate=$(date +'%H:%M')
#echo "Heure de fin: $endDate"
#exit
### Calcul du nombre de wallets
nbrWallets
### Affichage des stats
displayStats
### Ajout des membres sans transaction au fichier tampon ###
loopMembers
### Calcul du nombre de wallets ###
nbrTotalWallets=$(echo "$wallets" | wc -l)
nbrSimpleWallets=$(echo "$nbrTotalWallets-$nbrMembers" | bc)
pourcentMbrs=$(echo "scale=1; $nbrMembers*100/$nbrTotalWallets/1" | bc)
pourcentWallets=$(echo "scale=1; $nbrSimpleWallets*100/$nbrTotalWallets/1" | bc)
### Affichage des stats ###
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 -e "\n ---\n"
echo "Reçus Wallets: $sumRW"
echo "Reçus Membres: $sumRM"
echo "Reçus Total: $sumRT"
echo -e " ---"
echo "Envoyé Wallets: $sumSW"
echo "Envoyé Membres: $sumSM"
echo "Envoyé Total: $sumST"
echo -e " ---"
echo "Solde Wallets: $soldeW"
echo "Solde Membres: $soldeM"
echo -e " ---"
### Isolation des simples portefeuilles ###
simpleWallets="$wallets"
echo "Isolation des simples portefeuilles..."
for i in ${MEMBERS[@]}; do
simpleWallets=$(echo "$simpleWallets" | grep -v "$i")
done
##TODO: Get Solde from JSON Sum for next ... kopa
### Calcul de la masse monétaire et du pourcentage de Ḡ1 sur les simples portefeuilles ###
monetaryMass=$(curl -s ${DUNITER}/blockchain/current | jq .monetaryMass)
monetaryMassBrut=$(echo -e "scale=2; ($monetaryMass/100)/1" | bc)
monetaryMass=$(echo "$monetaryMassBrut" | tr . , | sed ':a;s/\B[0-9]\{3\}\>/ &/;ta')
soldeWalletMembers=$(echo "scale=2; $soldeMBrut+$soldeWBrut" | bc | tr . , | sed ':a;s/\B[0-9]\{3\}\>/ &/;ta')
pourcentSimpleWallet=$(echo "scale=1; $soldeWBrut*100/$monetaryMassBrut/1" | bc)
echo -e " ---"
echo -e "Masse Monétaire:\t $monetaryMass Ḡ1"
# Analyse
echo -e "\n ---\n Analyse\n ---"
sleepyG1=$(echo -e "scale=1; 100-$sumSTBrut*100/$monetaryMassBrut" | bc | tr . ,)
echo -e "$sleepyG1% des Ḡ1 n'ont jamais été utilisés."
### Renseignement de l'index web et indexation de l'historique ###
source $SCRIPTPATH/functions.sh # On source les fonctions de nouveau
### Renseignement de l'index web et indexation de l'historique
# source $SCRIPTPATH/lib/functions.sh # On source les fonctions de nouveau
[[ $isWeb == "web" ]] && web
### Fin de programme ###
### Fin de programme
day=$(date +'%d-%m-%y')
echo -e " ---"
echo "$day - Heure de fin: $(date +'%H:%M')"

125
lib/functions.sh Executable file
View File

@ -0,0 +1,125 @@
#!/bin/bash
addMembers() {
echo -e "\nAjouts des comptes membres sans transaction reçus ..."
wallets="$wallets"'\n'"$membresPubkeys"
wallets=$(echo -e "$wallets" | sort -u)
echo "Isolation des simples portefeuilles..."
simpleWallets=$(echo "$wallets" | grep -v "$membresPubkeys")
}
web() {
[ ! -d $WEBPATH/history/ ] && mkdir -p $WEBPATH/history/
[ ! -d $WEBPATH/graph/ ] && mkdir -p $WEBPATH/graph/
[ ! -d $WEBPATH/css ] && cp -r $SCRIPTPATH/tpl/css $WEBPATH/
[ ! -d $WEBPATH/js ] && cp -r $SCRIPTPATH/tpl/js $WEBPATH/
cp $SCRIPTPATH/tpl/index.html $indexhtml
datePrevious=$(date +'%y-%m-%d' -d "$day -1 day")
[[ -z $(ls -l $WEBPATH/history/ | grep $datePrevious) && -z $(grep '"display:none;" class="previous"' $indexhtml) ]] && sed -i "s/class=\"previous\"/style=\"display:none;\" class=\"previous\"/g" $indexhtml
dateNext=$(date +'%y-%m-%d' -d "$day +1 day")
[[ -z $(ls -l $WEBPATH/history/ | grep $dateNext) && -z $(grep '"display:none;" class="next"' $indexhtml) ]] && sed -i "s/class=\"next\"/style=\"display:none;\" class=\"next\"/g" $indexhtml
sed -i "s/_nbrTotalWallets/$nbrTotalWallets/g" $indexhtml
sed -i "s/_nbrSimpleWallets/$nbrSimpleWallets/g" $indexhtml
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/_day/$dayP/g" $indexhtml
sed -i "s/_sumRW/$sumRW/g" $indexhtml
sed -i "s/_sumSW/$sumSW/g" $indexhtml
sed -i "s/_soldeW/$soldeW/g" $indexhtml
sed -i "s/_sumRM/$sumRM/g" $indexhtml
sed -i "s/_sumSM/$sumSM/g" $indexhtml
sed -i "s/_soldeM/$soldeM/g" $indexhtml
sed -i "s/_pourcentSimpleWallet/$pourcentSimpleWallet/g" $indexhtml
sed -i "s/_nonConsumedUDT/$nonConsumedUDT/g" $indexhtml
sed -i "s/_monetaryMass/$monetaryMass/g" $indexhtml
sed -i "s/_sleepyG1/$sleepyG1/g" $indexhtml
[[ -z $(grep '"display:none;" class="previous"' $indexhtml) ]] && sed -i "s/_datePrevious/$datePrevious/g" $indexhtml && setPrevious="Oui"
[[ -z $(grep '"display:none;" class="next"' $indexhtml) ]] && sed -i "s/_dateNext/$dateNext/g" $indexhtml && setNext="Oui"
echo "$wallets" | grep . > $WEBPATH/wallets-g1.txt
echo -e "$membresPubkeys" | sed 's/ /\n/g' > $WEBPATH/wallets-g1-membres.txt
echo -e "$simpleWallets" > $WEBPATH/wallets-g1-simple.txt
if [[ "$startTime" == "00:00" ]]; then
cp $indexhtml $WEBPATH/history/index_$day.html
sed -i "s/css\/style.css/..\/css\/style.css/g" $WEBPATH/history/index_$day.html
sed -i "s/logo-axiom-team2.svg/..\/logo-axiom-team2.svg/g" $WEBPATH/history/index_$day.html
sed -i "s/_dateNext/$day/g" $WEBPATH/history/index_$datePrevious.html
sed -i "s/style=\"display:none;\" class=\"next\"/class=\"next\"/g" $WEBPATH/history/index_$datePrevious.html
fi
# Export JSON for graph
source $SCRIPTPATH/lib/transform_json.sh
# chown www-data for nginx needs
chown -R www-data:www-data $WEBPATH >/dev/null 2>&1
}
sumSoldes() {
sumRWBrut=$(jq -r '.[].rWallets' db/recus.json | awk '{ SUM += $1} END { printf "%.2f", SUM }')
sumRMBrut=$(jq -r '.[].rMembres' db/recus.json | awk '{ SUM += $1} END { printf "%.2f", SUM }')
sumRTBrut=$(jq -r '.[] | .rWallets, .rMembres' db/recus.json | awk '{ SUM += $1} END { printf "%.2f", SUM }')
sumSWBrut=$(jq -r '.[].sWallets' db/recus.json | awk '{ SUM += $1} END { printf "%.2f", SUM }')
sumSMBrut=$(jq -r '.[].sMembres' db/recus.json | awk '{ SUM += $1} END { printf "%.2f", SUM }')
sumSTBrut=$(jq -r '.[] | .sWallets, .sMembres' db/recus.json | awk '{ SUM += $1} END { printf "%.2f", SUM }')
soldeWBrut=$(echo "$sumRWBrut-$sumSWBrut" | bc)
soldeMBrut=$(echo "$sumRMBrut-$sumSMBrut" | bc)
sumRW=$(echo $sumRWBrut | sed ':a;s/\B[0-9]\{3\}\>/ &/;ta')
sumRM=$(echo $sumRMBrut | sed ':a;s/\B[0-9]\{3\}\>/ &/;ta')
sumRT=$(echo $sumRTBrut | sed ':a;s/\B[0-9]\{3\}\>/ &/;ta')
sumSW=$(echo $sumSWBrut | sed ':a;s/\B[0-9]\{3\}\>/ &/;ta')
sumSM=$(echo $sumSMBrut | sed ':a;s/\B[0-9]\{3\}\>/ &/;ta')
sumST=$(echo $sumSTBrut | sed ':a;s/\B[0-9]\{3\}\>/ &/;ta')
soldeW=$(echo $soldeWBrut | sed ':a;s/\B[0-9]\{3\}\>/ &/;ta')
soldeM=$(echo $soldeMBrut | sed ':a;s/\B[0-9]\{3\}\>/ &/;ta')
### Calcul de la masse monétaire et du pourcentage de Ḡ1 sur les simples portefeuilles ###
monetaryMass=$(curl -s ${DUNITER}/blockchain/current | jq .monetaryMass)
monetaryMassBrut=$(echo "scale=2; ($monetaryMass/100)/1" | bc)
monetaryMass=$(echo "$monetaryMassBrut" | tr . , | sed ':a;s/\B[0-9]\{3\}\>/ &/;ta')
pourcentSimpleWallet=$(echo "$soldeWBrut*100/$monetaryMassBrut/1" | bc -l | xargs printf %.1f)
sleepyG1=$(echo "100-$sumSTBrut*100/$monetaryMassBrut" | bc -l | xargs printf %.1f | tr . ,)
}
nbrWallets() {
nbrTotalWallets=$(echo "$wallets" | wc -l)
nbrSimpleWallets=$(echo "$nbrTotalWallets-$nbrMembers" | bc)
pourcentMbrs=$(echo "$nbrMembers*100/$nbrTotalWallets" | bc -l | xargs printf %.1f)
pourcentWallets=$(echo "$nbrSimpleWallets*100/$nbrTotalWallets" | bc -l | xargs printf %.1f)
}
displayStats() {
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 -e "\n ---\n"
echo "Reçus Wallets: $sumRW"
echo "Reçus Membres: $sumRM"
echo "Reçus Total: $sumRT"
echo -e " ---"
echo "Envoyé Wallets: $sumSW"
echo "Envoyé Membres: $sumSM"
echo "Envoyé Total: $sumST"
echo -e " ---"
echo "Solde Wallets: $soldeW"
echo "Solde Membres: $soldeM"
echo -e " ---"
echo -e "Masse Monétaire:\t $monetaryMass Ḡ1"
echo -e "\n ---\n Analyse\n ---"
echo -e "$sleepyG1% des Ḡ1 n'ont jamais été utilisés."
}

View File

@ -1,6 +1,4 @@
#!/bin/bash
loopWalletUp() {
scanTxWallets() {
local REGEX_PUBKEYS="[a-zA-Z0-9]{42,44}"
# On vérifie le cache existant et on démarre au dernier bloc en cache
@ -19,22 +17,20 @@ loopWalletUp() {
echo "[" > $SCRIPTPATH/db/recus.json
fi
mv debug.log bk-debug.log-$lastBloc 2>/dev/null #kopa
incExec=1 #kopa
incExec=1
for i in ${!TXBLOCKS[*]}; do
set -x # kopa
startExec=$(($(date +%s%N)/1000000))
bloc=${TXBLOCKS[$i]}
[[ -z $bloc ]] && break
[[ $startIter != 0 && $i -le $startIter ]] && continue
# [[ $bloc -lt 5243 ]] && continue #kopa Debug
# [[ $bloc -lt 5243 ]] && continue #kopa
sleep 0.05
# Récupère la date et l'objet transaction du bloc courant
blocFull=$(curl -s ${DUNITER}/blockchain/block/$bloc)
#blocFull=$(cat bloc-267)
until blocBrut=$(echo $blocFull | jq -r '.medianTime, .transactions[]' 2>/dev/null); do
[[ $isWeb != "web" ]] && echo -e "i: $i\n$blocFull" | tee -a debug.log
[[ $isWeb != "web" ]] && echo -e "i: $i\n$blocFull"
sleep 2
blocFull=$(curl -s ${DUNITER}/blockchain/block/$bloc)
done
@ -63,19 +59,15 @@ loopWalletUp() {
unset recusJson
startBloc=0
fi
set +x
# Sélectionne les ligne SIG en retirant les issuers
OIFS="$IFS"
IFS='{'
echo -e "\n-----------------------------------------\nBloc: $bloc" >> debug.log
for j in $walletsReceivedBloc; do
[[ -z $j ]] && continue
local wIssuers=$(echo "{$j" | jq -r '.issuers[0]')
local walletsReceivedTodayTmp+=$(echo "{$j" | jq -r '.outputs[]' | grep -v "$wIssuers" | awk -F: '{print $3 "|" $1}' | sed 's/SIG(//g' | tr -d ')')$'\n'
local sumRBloc=$(echo "{$j" | jq -r '.outputs[]' | grep -v "$wIssuers" | awk -F: '{ print $1 }' | awk '{s+=$1} END {print s}')
[[ $sumRBloc ]] && local walletsSentTodayTmp+=$wIssuers'|'$sumRBloc'\n'
echo -e "R: $walletsReceivedTodayTmp\nS: $walletsSentTodayTmp" | grep . >> debug.log
echo "---" >> debug.log
done
IFS="$OIFS"
local walletsSentToday=$(echo -e "$walletsSentTodayTmp" | head -n -1)
@ -100,9 +92,6 @@ loopWalletUp() {
if [[ -n $blockDateLast && $blockDateLast != $blockDate ]]; then
jsonify
unset valueReceivedM valueReceivedW valueSentM valueSentW
echo -e "Date: $blockDate\n-----------------------------------------\n-----------------------------------------\n" >> debug.log
cp debug/xFullDebug.log debug/xFullDebug-$blockDate.log
echo "" > debug/xFullDebug.log
fi
# Sauvegarde la date de ce bloc pour l'itération suivante
@ -113,7 +102,7 @@ loopWalletUp() {
local pubkey=$(echo $k | awk -F '|' '{ print $1 }')
local value=$(echo $k | awk -F '|' '{ print $2 }')
if [[ $(echo ${MEMBERS[*]} | grep $pubkey) ]]; then
if [[ $(echo "$membresPubkeys" | grep $pubkey) ]]; then
valueReceivedM=$(($valueReceivedM+$value))
pubkeyReceiveM+=${pubkey}\\n
else
@ -127,7 +116,7 @@ loopWalletUp() {
local pubkey=$(echo $k | awk -F '|' '{ print $1 }')
local value=$(echo $k | awk -F '|' '{ print $2 }')
if [[ $(echo ${MEMBERS[*]} | grep $pubkey) ]]; then
if [[ $(echo "$membresPubkeys" | grep $pubkey) ]]; then
valueSentM=$(($valueSentM+$value))
pubkeySentM+=${pubkey}\\n
else
@ -141,7 +130,7 @@ loopWalletUp() {
# 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)) #kopa
endExec=$(($(date +%s%N)/1000000))
timeExec=$(echo "scale=3; ($endExec-$startExec)/1000" | bc)
#[[ -z $midTimeExec ]] && midTimeExec=$timeExec
[[ $incExec9 == 50 || $incExec == 1 ]] && incExec=1 && midTimeExecCum=0
@ -154,12 +143,12 @@ loopWalletUp() {
echo
echo "Scan en cours: $progress% - $bloc/$lastBloc"
echo "Date: $blockDate"
echo "Temps d'execution: $midTimeExec" #kopa
echo "Temps d'execution: $midTimeExec"
else
echo "Scan des blocs avec transactions en cours ..."
fi
# [[ $i -ge 10 ]] && break #kopa Debug
# [[ $i -ge 10 ]] && break #kopa
done
jsonify
@ -175,102 +164,3 @@ loopWalletUp() {
echo -e "$lastBloc\n$wallets" > $SCRIPTPATH/cache/walletsUp-$i
}
loopMembers() {
local iter=0
for i in ${MEMBERS[*]}; do
local progress=$(echo "scale=0; $iter*100/$nbrMembers/1" | bc)
if [[ $progress =~ ^(0|10|20|30|40|50|60|70|80|90|99)$ ]]; then
[[ $progress == 99 ]] && progress=100
if [[ $isWeb != "web" ]]; then
clear
echo "Heure de début: $startTime"
echo
echo "Ajouts des comptes membres sans transaction reçus ... $progress%"
else
echo "Ajouts des comptes membres sans transaction reçus ..."
fi
fi
if [[ -z $(echo "$wallets" | grep "$i") ]]; then
wallets+=$'\n'"$i"
fi
((iter++))
done
}
web() {
[ ! -d $WEBPATH/history/ ] && mkdir -p $WEBPATH/history/
[ ! -d $WEBPATH/graph/ ] && mkdir -p $WEBPATH/graph/
[ ! -d $WEBPATH/css ] && cp -r $SCRIPTPATH/tpl/css $WEBPATH/
[ ! -d $WEBPATH/js ] && cp -r $SCRIPTPATH/tpl/js $WEBPATH/
cp $SCRIPTPATH/tpl/index.html $indexhtml
datePrevious=$(date +'%y-%m-%d' -d "$day -1 day")
[[ -z $(ls -l $WEBPATH/history/ | grep $datePrevious) && -z $(grep '"display:none;" class="previous"' $indexhtml) ]] && sed -i "s/class=\"previous\"/style=\"display:none;\" class=\"previous\"/g" $indexhtml
dateNext=$(date +'%y-%m-%d' -d "$day +1 day")
[[ -z $(ls -l $WEBPATH/history/ | grep $dateNext) && -z $(grep '"display:none;" class="next"' $indexhtml) ]] && sed -i "s/class=\"next\"/style=\"display:none;\" class=\"next\"/g" $indexhtml
sed -i "s/_nbrTotalWallets/$nbrTotalWallets/g" $indexhtml
sed -i "s/_nbrSimpleWallets/$nbrSimpleWallets/g" $indexhtml
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/_day/$dayP/g" $indexhtml
sed -i "s/_sumRW/$sumRW/g" $indexhtml
sed -i "s/_sumSW/$sumSW/g" $indexhtml
sed -i "s/_soldeW/$soldeW/g" $indexhtml
sed -i "s/_sumRM/$sumRM/g" $indexhtml
sed -i "s/_sumSM/$sumSM/g" $indexhtml
sed -i "s/_soldeM/$soldeM/g" $indexhtml
sed -i "s/_pourcentSimpleWallet/$pourcentSimpleWallet/g" $indexhtml
sed -i "s/_nonConsumedUDT/$nonConsumedUDT/g" $indexhtml
sed -i "s/_monetaryMass/$monetaryMass/g" $indexhtml
sed -i "s/_sleepyG1/$sleepyG1/g" $indexhtml
[[ -z $(grep '"display:none;" class="previous"' $indexhtml) ]] && sed -i "s/_datePrevious/$datePrevious/g" $indexhtml && setPrevious="Oui"
[[ -z $(grep '"display:none;" class="next"' $indexhtml) ]] && sed -i "s/_dateNext/$dateNext/g" $indexhtml && setNext="Oui"
echo "$wallets" | grep . > $WEBPATH/wallets-g1.txt
echo -e "${MEMBERS[@]}" | sed 's/ /\n/g' > $WEBPATH/wallets-g1-membres.txt
echo -e "$simpleWallets" > $WEBPATH/wallets-g1-simple.txt
if [[ "$startTime" == "00:00" ]]; then
cp $indexhtml $WEBPATH/history/index_$day.html
sed -i "s/css\/style.css/..\/css\/style.css/g" $WEBPATH/history/index_$day.html
sed -i "s/logo-axiom-team2.svg/..\/logo-axiom-team2.svg/g" $WEBPATH/history/index_$day.html
sed -i "s/_dateNext/$day/g" $WEBPATH/history/index_$datePrevious.html
sed -i "s/style=\"display:none;\" class=\"next\"/class=\"next\"/g" $WEBPATH/history/index_$datePrevious.html
fi
# Export JSON for graph
$SCRIPTPATH/transform_json.sh
# chown www-data for nginx needs
chown -R www-data:www-data $WEBPATH >/dev/null 2>&1
}
sumSoldes() {
sumRWBrut=$(jq -r '.[].rWallets' $1 | awk '{ SUM += $1} END { printf "%.2f", SUM }')
sumRMBrut=$(jq -r '.[].rMembres' $1 | awk '{ SUM += $1} END { printf "%.2f", SUM }')
sumRTBrut=$(jq -r '.[] | .rWallets, .rMembres' $1 | awk '{ SUM += $1} END { printf "%.2f", SUM }')
sumSWBrut=$(jq -r '.[].sWallets' $1 | awk '{ SUM += $1} END { printf "%.2f", SUM }')
sumSMBrut=$(jq -r '.[].sMembres' $1 | awk '{ SUM += $1} END { printf "%.2f", SUM }')
sumSTBrut=$(jq -r '.[] | .sWallets, .sMembres' $1 | awk '{ SUM += $1} END { printf "%.2f", SUM }')
soldeWBrut=$(echo "$sumRWBrut-$sumSWBrut" | bc)
soldeMBrut=$(echo "$sumRMBrut-$sumSMBrut" | bc)
sumRW=$(echo $sumRWBrut | sed ':a;s/\B[0-9]\{3\}\>/ &/;ta')
sumRM=$(echo $sumRMBrut | sed ':a;s/\B[0-9]\{3\}\>/ &/;ta')
sumRT=$(echo $sumRTBrut | sed ':a;s/\B[0-9]\{3\}\>/ &/;ta')
sumSW=$(echo $sumSWBrut | sed ':a;s/\B[0-9]\{3\}\>/ &/;ta')
sumSM=$(echo $sumSMBrut | sed ':a;s/\B[0-9]\{3\}\>/ &/;ta')
sumST=$(echo $sumSTBrut | sed ':a;s/\B[0-9]\{3\}\>/ &/;ta')
soldeW=$(echo $soldeWBrut | sed ':a;s/\B[0-9]\{3\}\>/ &/;ta')
soldeM=$(echo $soldeMBrut | sed ':a;s/\B[0-9]\{3\}\>/ &/;ta')
}

57
lib/transform_json.sh Executable file
View File

@ -0,0 +1,57 @@
#!/bin/bash
# Varialbes
n=2 # Nombre de jours pour les pas en abscisse
#SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
#if [[ -e $SCRIPTPATH/.env ]]; then source $SCRIPTPATH/.env; else echo "Veuillez créer votre fichier .env inspiré de .env.example" && exit 1; fi
## Ḡ1 reçus
rWallets() {
rWallets=$(grep -E "Date:|Reçus simples wallets|Reçus simples portefeuille|Reçus membres" $WEBPATH/history/index_*.html | awk -F '<b>' '{ print $2 }' | awk '{ print $1 }' | tr -d '.' | tr ',' '.')
rWallets=$(sed '/-/i !' <<< $rWallets)
local j=0
local IFS=$'!'
for i in $rWallets; do
((j++))
[[ $j == 1 || ! $(( $j % $n )) == 0 ]] && continue
local dateN=$(sed '2q;d' <<< $i)
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/_RWALLETS/$RW/g <<< $jsonTPL)
local result+=$(sed s/_RMEMBRES/$RM/g <<< $jsonTPL)
done
sed "s/_JSONDATA/$result/g" $SCRIPTPATH/tpl/recus.html > $WEBPATH/graph/recus.html
sed "s/_JSONDATARW/$result/g" $SCRIPTPATH/tpl/mixed.html > $WEBPATH/graph/mixed.html
}
nbrWallets() {
## Nombre de wallets
nbrWallets=$(grep -E "Date:|Nombre de membres|Nombre de simple portefeuille" $WEBPATH/history/index_*.html | awk -F '<b>' '{ print $2 }' | awk -F '</b>' '{ print $1 }' | awk '{ print $1 }')
nbrWallets=$(sed '/-/i !' <<< $nbrWallets)
local j=0
local IFS=$'!'
for i in $nbrWallets; do
((j++))
[[ $j == 1 || ! $(( $j % $n )) == 0 ]] && continue
local dateN=$(sed '2q;d' <<< $i)
local NBRM=$(sed '3q;d' <<< $i)
local NBRW=$(sed '4q;d' <<< $i)
local jsonTPL=$(sed s/_DATE/$dateN/g $SCRIPTPATH/tpl/nbr_wallets.json)
local jsonTPL=$(sed s/_NBRWALLETS/$NBRW/g <<< $jsonTPL)
local result+=$(sed s/_NBRMEMBRES/$NBRM/g <<< $jsonTPL)
done
sed "s/_JSONDATA/$result/g" $SCRIPTPATH/tpl/nbr_wallets.html > $WEBPATH/graph/nbr_wallets.html
sed -i "s/_JSONDATANBRW/$result/g" $WEBPATH/graph/mixed.html
}
rWallets
nbrWallets

View File

@ -1,8 +0,0 @@
#!/bin/bash
cacheFile=$(ls cache/bk-walletsUp-* | tail -n1)
cacheID=$(echo $cacheFile | awk -F '-' '{ print $NF }')
cp $cacheFile cache/walletsUp-$cacheID
cp db/bk-recus.json-$cacheID db/recus.json

11
scripts/backup-actual.sh Executable file
View File

@ -0,0 +1,11 @@
#!/bin/bash
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
cacheFile=$(ls $SCRIPTPATH/../cache/walletsUp-*)
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

5
scripts/export_sommes.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
jq -r '.[] | "---", .date, .rWallets + .rMembres' $SCRIPTPATH/../db/recus.json > $SCRIPTPATH/../db/somme.txt

10
scripts/restore-bk.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/bash
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
cacheFile=$(ls $SCRIPTPATH/../cache/bk-walletsUp-* | tail -n1)
cacheID=$(echo $cacheFile | awk -F '-' '{ print $NF }')
cp $cacheFile $SCRIPTPATH/../cache/walletsUp-$cacheID
cp $SCRIPTPATH/../db/bk-recus.json-$cacheID $SCRIPTPATH/../db/recus.json

View File

@ -1,58 +0,0 @@
#!/bin/bash
# Varialbes
n=2 # Nombre de jours pour les pas en abscisse
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
if [[ -e $SCRIPTPATH/.env ]]; then source $SCRIPTPATH/.env; else echo "Veuillez créer votre fichier .env inspiré de .env.example" && exit 1; fi
## Ḡ1 reçus
rWallets() {
rWallets=$(grep -E "Date:|Reçus simples wallets|Reçus simples portefeuille|Reçus membres" $WEBPATH/history/index_*.html | awk -F '<b>' '{ print $2 }' | awk '{ print $1 }' | tr -d '.' | tr ',' '.')
rWallets=$(sed '/-/i !' <<< $rWallets)
local j=0
local IFS=$'!'
for i in $rWallets; do
((j++))
[[ $j == 1 || ! $(( $j % $n )) == 0 ]] && continue
local dateN=$(sed '2q;d' <<< $i)
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/_RWALLETS/$RW/g <<< $jsonTPL)
local result+=$(sed s/_RMEMBRES/$RM/g <<< $jsonTPL)
done
sed "s/_JSONDATA/$result/g" $SCRIPTPATH/tpl/recus.html > $WEBPATH/graph/recus.html
sed "s/_JSONDATARW/$result/g" $SCRIPTPATH/tpl/mixed.html > $WEBPATH/graph/mixed.html
}
nbrWallets() {
## Nombre de wallets
nbrWallets=$(grep -E "Date:|Nombre de membres|Nombre de simple portefeuille" $WEBPATH/history/index_*.html | awk -F '<b>' '{ print $2 }' | awk -F '</b>' '{ print $1 }' | awk '{ print $1 }')
nbrWallets=$(sed '/-/i !' <<< $nbrWallets)
local j=0
local IFS=$'!'
for i in $nbrWallets; do
((j++))
[[ $j == 1 || ! $(( $j % $n )) == 0 ]] && continue
local dateN=$(sed '2q;d' <<< $i)
local NBRM=$(sed '3q;d' <<< $i)
local NBRW=$(sed '4q;d' <<< $i)
local jsonTPL=$(sed s/_DATE/$dateN/g $SCRIPTPATH/tpl/nbr_wallets.json)
local jsonTPL=$(sed s/_NBRWALLETS/$NBRW/g <<< $jsonTPL)
local result+=$(sed s/_NBRMEMBRES/$NBRM/g <<< $jsonTPL)
done
sed "s/_JSONDATA/$result/g" $SCRIPTPATH/tpl/nbr_wallets.html > $WEBPATH/graph/nbr_wallets.html
sed -i "s/_JSONDATANBRW/$result/g" $WEBPATH/graph/mixed.html
}
rWallets
nbrWallets