From f159857e13f0db49c88944f70fa8cd13cb2aa2fa Mon Sep 17 00:00:00 2001 From: poka Date: Thu, 18 Jun 2020 03:28:09 +0200 Subject: [PATCH] Add json transform and graph view --- g1-stats.sh | 2 +- tpl/graph.html | 48 ++++++++++++++++++++++++++++++ tpl/graph.json | 1 + index-stats.html => tpl/index.html | 0 transform_json.sh | 19 ++++++++++++ 5 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 tpl/graph.html create mode 100644 tpl/graph.json rename index-stats.html => tpl/index.html (100%) create mode 100755 transform_json.sh diff --git a/g1-stats.sh b/g1-stats.sh index 7b0a565..fccd775 100755 --- a/g1-stats.sh +++ b/g1-stats.sh @@ -104,7 +104,7 @@ web() { [ ! -d $WEBPATH/history/ ] && mkdir -p $WEBPATH/history/ [ ! -d $WEBPATH/css ] && cp -r $SCRIPTPATH/css $WEBPATH/ - cp $SCRIPTPATH/index-stats.html $indexhtml + 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 diff --git a/tpl/graph.html b/tpl/graph.html new file mode 100644 index 0000000..3f50559 --- /dev/null +++ b/tpl/graph.html @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + diff --git a/tpl/graph.json b/tpl/graph.json new file mode 100644 index 0000000..ea6c0ca --- /dev/null +++ b/tpl/graph.json @@ -0,0 +1 @@ + {\n \"date\": \"_DATE\",\n \"rWallet\": \"_RWALLET\"\n }, diff --git a/index-stats.html b/tpl/index.html similarity index 100% rename from index-stats.html rename to tpl/index.html diff --git a/transform_json.sh b/transform_json.sh new file mode 100755 index 0000000..f0005c3 --- /dev/null +++ b/transform_json.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +rWallets=$(cat /home/axiom/apps/g1-stats/history/index_*.html | grep -E "Date:|Reçus simples wallets|Reçus simples portefeuille" | awk -F '' '{ print $2 }' | awk '{ print $1 }' | tr -d '.' | tr ',' '.') + +j=0 +for i in $rWallets; do + if [[ $j == 0 ]]; then + dateN=$i + cp tpl/graph.json rWallets-$i.json + sed -i s/_DATE/$i/g rWallets-$i.json + j=1 + else + result+=$(sed s/_RWALLET/$i/g rWallets-$dateN.json) + j=0 + rm rWallets-$dateN.json + fi +done + +sed "s/_JSONDATA/$result/g" tpl/graph.html > graph.html