Add jo to install for explorer usage; reduce roundit in one line in cumulate.jq; Add several functions in explorer

This commit is contained in:
poka 2020-10-03 03:35:35 +02:00
parent e7686377d2
commit e04767d59d
4 changed files with 42 additions and 9 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ cache
debug.log
bk-debug.log
bk
.gitPushToMaster.sh

View File

@ -4,11 +4,22 @@
GPATH="$( cd "$(dirname "$0")" ; pwd -P )"
source $GPATH/.env
# Parse options
for i in $@; do
case "$i" in
-c|--cumulate) echo "On cumule !";;
-h|--help) echo "Demande d'aide";;
*) isOptions+="$i|";;
esac
done
jsonFile="$GPATH/db/daily.json"
cmd=$1
dateRange=$2
[[ -z $dateRange ]] && dateRange=$(jq -r '.[].date' $jsonFile | tail -n1)
[[ ! $(grep $dateRange $jsonFile) ]] && echo "La date $dateRange n'existe pas en cache G1Stats" && exit 1
cmd=$(cut -d'|' -f1 <<<"$isOptions")
dateRange=$(cut -d'|' -f2 <<<"$isOptions")
args="$(cut -d'|' -f2- <<<"$isOptions" | sed 's/.$//' | tr '|' ' ')"
[[ -z "$dateRange" ]] && dateRange=$(jq -r '.[].date' $jsonFile | tail -n1)
[[ ! $(grep "$dateRange" $jsonFile) && $cmd != "select" ]] && echo "La date $dateRange n'existe pas en cache G1Stats" && exit 1
cumulate() {
jsonCum="$(jq -f $GPATH/lib/cumulate.jq $jsonFile)"
@ -24,6 +35,28 @@ mass() {
jq '.[] | .UD*.nbrMembers' <<<"$jsonDated" | awk '{ SUM += $1} END { printf "%.2f", SUM }'; echo
}
[[ -z $cmd ]] && cmd=cumulate
solde() {
cumDay=$(day)
soldeWallets=$(jq '(.rWallets-.sWallets)*100.0+ 0.5|floor/100.0' <<<$cumDay)
soldeMembers=$(jq '(.rMembers-.sMembers)*100.0+ 0.5|floor/100.0' <<<$cumDay)
jo -p date=$dateRange soldeWallets=$soldeWallets soldeMembers=$soldeMembers | jq .
}
total() {
cumDay=$(day)
totalReceived=$(jq '(.rWallets+.rMembers)*100.0+ 0.5|floor/100.0' <<<$cumDay)
totalSent=$(jq '(.sWallets+.sMembers)*100.0+ 0.5|floor/100.0' <<<$cumDay)
jo -p date=$dateRange totalReceived=$totalReceived totalSent=$totalSent | jq .
}
selectFunc() {
jq '.[] | select('"$args"')' $jsonFile
}
case $cmd in
select) selectFunc;;
'') cumulate;;
*) $cmd;;
esac
$cmd

View File

@ -21,7 +21,7 @@ startTime=$(date +'%H:%M')
day=$(date +'%y-%m-%d')
dayP=$(date +'%d-%m-%y')
echo -e "\n############# $day à $startTime #############\n"
[[ -z $(which jq) || -z $(which bc) || -z $(which curl) ]] && sudo apt update && sudo apt install jq bc curl
[[ -z $(which jq) || -z $(which jo) || -z $(which bc) || -z $(which curl) ]] && sudo apt update && sudo apt install jq jo bc curl
echo "Initialisation ..."
if $debug; then
TXBLOCKS=$(cat $GPATH/db/debug/txblocs)

View File

@ -1,5 +1,4 @@
def round: . + 0.5 | floor;
def roundit: .*100.0|round/100.0;
def roundit: (.*100.0)+ 0.5|floor/100.0;
[foreach .[] as $row (null;
.nbrMembers += $row.nbrMembers |
.nbrWallets += $row.nbrWallets |