IngRRD/lib/get_next_level
2015-02-06 17:10:02 +01:00

125 lines
3.2 KiB
Bash

#!/bin/bash
# IngRRD (https://forge.riquer.fr/p/ingrrd/)
# Copyright (C) 2014-2015 Vincent Riquer
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
get_next_level() {
local level
next=()
for (( level = curlevel + 1; level <= 16; level++))
do
if (( lvl[level] > last["AP"] ))
then
next+=(
CDEF:nextcross$level=pred,${lvl[level]},GE,pred,UNKN,IF
VDEF:nexttime$level=nextcross$level,FIRST
"PRINT:nexttime$level:$level %s:strftime"
)
fi
done
{
read
while read level timestamp
do
nextlevels[level]=$timestamp
done
} < <(
rrdtool graph /dev/null -s -$prevperiod -e +5y \
DEF:data=$rrdfile:AP:AVERAGE:step=3600 \
VDEF:intercept=data,LSLINT \
VDEF:growth=data,LSLSLOPE \
CDEF:trend=data,POP,COUNT,growth,*,intercept,+ \
CDEF:pred=TIME,NOW,GE,trend,UNKN,IF \
"${next[@]}"
)
for stat in ${medals[@]}
do
next=()
if ! (( hasbronze[$stat] ))
then
next+=(
CDEF:nextcrossbronze=pred,${bronze[$stat]},GE,pred,UNKN,IF
VDEF:nexttimebronze=nextcrossbronze,FIRST
"PRINT:nexttimebronze:bronze %s:strftime"
)
fi
if ! (( hassilver[$stat] ))
then
next+=(
CDEF:nextcrosssilver=pred,${silver[$stat]},GE,pred,UNKN,IF
VDEF:nexttimesilver=nextcrosssilver,FIRST
"PRINT:nexttimesilver:silver %s:strftime"
)
fi
if ! (( hasgold[$stat] ))
then
next+=(
CDEF:nextcrossgold=pred,${gold[$stat]},GE,pred,UNKN,IF
VDEF:nexttimegold=nextcrossgold,FIRST
"PRINT:nexttimegold:gold %s:strftime"
)
fi
if ! (( hasplatinum[$stat] ))
then
next+=(
CDEF:nextcrossplatinum=pred,${platinum[$stat]},GE,pred,UNKN,IF
VDEF:nexttimeplatinum=nextcrossplatinum,FIRST
"PRINT:nexttimeplatinum:platinum %s:strftime"
)
fi
if ! (( hasblack[$stat] ))
then
next+=(
CDEF:nextcrossblack=pred,${black[$stat]},GE,pred,UNKN,IF
VDEF:nexttimeblack=nextcrossblack,FIRST
"PRINT:nexttimeblack:black %s:strftime"
)
fi
{
read
while read matter timestamp
do
case $matter in
bronze)
nextbronze[timestamp]+="$stat "
;;
silver)
nextsilver[timestamp]+="$stat "
;;
gold)
nextgold[timestamp]+="$stat "
;;
platinum)
nextplatinum[timestamp]+="$stat "
;;
black)
nextblack[timestamp]+="$stat "
;;
esac
done
} < <(
rrdtool graph /dev/null -s -$prevperiod -e +5y \
DEF:data=$rrdfile:$stat:AVERAGE:step=600 \
VDEF:intercept=data,LSLINT \
VDEF:growth=data,LSLSLOPE \
CDEF:trend=data,POP,COUNT,growth,*,intercept,+ \
CDEF:pred=TIME,NOW,GE,trend,UNKN,IF \
"${next[@]}"
)
done
}