Add json transform and graph view

This commit is contained in:
poka 2020-06-18 03:28:09 +02:00
parent d0c9475e57
commit f159857e13
5 changed files with 69 additions and 1 deletions

View File

@ -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

48
tpl/graph.html Normal file
View File

@ -0,0 +1,48 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="js/Chart.js"></script>
<script type="text/javascript" src="js/require.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<canvas id="myChart" width="1000" height="500"></canvas>
<script>
var jsonfile = {
"jsonarray": [
_JSONDATA
]
};
var date = jsonfile.jsonarray.map(function(e) {
return e.date;
});
var rwallet = jsonfile.jsonarray.map(function(e) {
return e.rWallet;
});;
var ctx = document.getElementById("myChart");
var config = {
type: 'line',
data: {
labels: date,
datasets: [{
label: 'Ḡ1 reçus sur les simples portefeuilles',
data: rwallet,
backgroundColor: 'rgba(0, 119, 204, 0.3)'
}]
},
options: {
maintainAspectRatio: false
}
};
var myChart = new Chart(ctx, config);
</script>
</body>
</html>

1
tpl/graph.json Normal file
View File

@ -0,0 +1 @@
{\n \"date\": \"_DATE\",\n \"rWallet\": \"_RWALLET\"\n },

19
transform_json.sh Executable file
View File

@ -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 '<b>' '{ 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