Change explorer mechanic: Add --cumulate option for all functions

This commit is contained in:
poka 2020-10-03 03:49:11 +02:00
parent e04767d59d
commit 8c4618378f
1 changed files with 11 additions and 13 deletions

View File

@ -3,35 +3,33 @@
# Récupération du chemin absolut du répertoir du script actuel
GPATH="$( cd "$(dirname "$0")" ; pwd -P )"
source $GPATH/.env
jsonFile="$GPATH/db/daily.json"
jsonData=$(cat $jsonFile)
# Parse options
for i in $@; do
case "$i" in
-c|--cumulate) echo "On cumule !";;
-h|--help) echo "Demande d'aide";;
-c|--cumulate) jsonData="$(jq -f $GPATH/lib/cumulate.jq $jsonFile)";;
-h|--help) echo "TODO";;
*) isOptions+="$i|";;
esac
done
jsonFile="$GPATH/db/daily.json"
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
[[ -z "$dateRange" ]] && dateRange=$(jq -r '.[].date' <<<$jsonData | tail -n1)
[[ ! $(grep "$dateRange" <<<$jsonData) && $cmd != "select" ]] && echo "La date $dateRange n'existe pas en cache G1Stats" && exit 1
cumulate() {
jsonCum="$(jq -f $GPATH/lib/cumulate.jq $jsonFile)"
jq '.[] | select(.date=="'$dateRange'")' <<<$jsonCum
}
day() {
jq '.[] | select(.date=="'$dateRange'")' $jsonFile
jq '.[] | select(.date=="'$dateRange'")' <<<$jsonData
}
mass() {
jsonDated=$(jq '.[0: map(.date) | index("'$dateRange'")+1]' $jsonFile | jq -f $GPATH/lib/cumulate.jq)
jsonDated=$(jq '.[0: map(.date) | index("'$dateRange'")+1]' <<<$jsonData | jq -f $GPATH/lib/cumulate.jq)
jq '.[] | .UD*.nbrMembers' <<<"$jsonDated" | awk '{ SUM += $1} END { printf "%.2f", SUM }'; echo
}
@ -50,13 +48,13 @@ total() {
}
selectFunc() {
jq '.[] | select('"$args"')' $jsonFile
jq '.[] | select('"$args"')' <<<$jsonData
}
case $cmd in
select) selectFunc;;
'') cumulate;;
'') jsonData="$(jq -f $GPATH/lib/cumulate.jq $jsonFile)"; day;;
*) $cmd;;
esac