Improve speed, remove insane amounts of jq calls and add time selector

This commit is contained in:
Alex 2020-04-15 12:32:55 +02:00
parent 3b0eda764c
commit da28bb12e0
Signed by: caskd
GPG Key ID: F92BA85F61F4C173
2 changed files with 9 additions and 7 deletions

View File

@ -1,11 +1,13 @@
#!/bin/zsh
QUEUE="$(curl -sSL 'https://2b2t.io/api/queue?range=1h')"
PRIO="$(curl -sSL 'https://2b2t.io/api/prioqueue?range=1h')"
PLAY="$(curl -sSL 'https://2b2t.io/api/pingstats?range=1h')"
QUEUE="$(curl -sSL https://2b2t.io/api/queue\?range=$1)"
PRIO="$(curl -sSL https://2b2t.io/api/prioqueue\?range=$1)"
PLAY="$(curl -sSL https://2b2t.io/api/pingstats\?range=$1)"
function gnuplot-parsable {
for ((i=0; i<$(print $1 | jq ".|length");i++)); do
printf "%s\t%s\n" $(print $1 | jq ".[$i][0]") $(print $1 | jq ".[$i][1]");
TIMES=($(print $1 | jq '.[][0]'))
VALUES=($(print $1 | jq '.[][1]'))
for ((i=0; i<${#TIMES[@]};i++)); do
printf "%s\t%s\n" $TIMES[$i] $VALUES[$i];
done
}
gnuplot-parsable "$QUEUE" > queuedata

View File

@ -1,7 +1,7 @@
set xdata time
set timefmt "%s"
set grid
set terminal pngcairo size 1000,1000
set terminal pngcairo size 10000,1000
set output 'graph.png'
f(x)=sprintf("%d", x)
plot "queuedata" u (f($1)):2 w lp title "Queue", "priodata" u (f($1)):2 w lp title "Priority Queue", "playerdata" u (f($1)):2 w lp title "Players"
plot "queuedata" u (f($1)):2 w l title "Queue", "priodata" u (f($1)):2 w l title "Priority Queue", "playerdata" u (f($1)):2 w l title "Players"