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