dabo/dabo/recalc-times-before-example.sh

86 lines
2.4 KiB
Bash
Raw Normal View History

2023-05-30 11:57:05 +02:00
#!/bin/bash -e
. /etc/bash/gaboshlib.include
g_lockfile
for bashfunc in $(find dabo/functions -type f -name "*.sh")
do
. "$bashfunc"
done
function get_asset {
local rawhistfile=$1
echo "$rawhistfile"
cat "$rawhistfile" | while read f_line
do
local time=""
local timebefore=""
local price30before=""
local price14before=""
local price7before=""
local price1before=""
local change30before=""
local change14before=""
local change7before=""
local change1before=""
local time=$(echo ${f_line} | cut -d, -f1)
if echo $f_line | egrep -q "100,100,100,100$"
then
local time=$(echo ${f_line} | cut -d, -f1)
else
continue
fi
timebefore=$(date "+%Y-%m-%d %H:%M" -d "$time 30 day ago")
#grep "^$timebefore" "$rawhistfile"
#echo "$f_line"
price30before=$(grep "^$timebefore" "$rawhistfile" | cut -d, -f2)
[ -z "$price30before" ] && continue
local price=$(echo ${f_line} | cut -d, -f2)
change30before=$(g_percentage-diff $price30before $price)
#echo "XXXXXXX g_percentage-diff $price30before $price -> $change30before "
timebefore=$(date "+%Y-%m-%d %H:%M" -d "$time 14 day ago")
price14before=$(grep "^$timebefore" "$rawhistfile" | cut -d, -f2)
[ -z "$price14before" ] && continue
change14before=$(g_percentage-diff $price14before $price)
timebefore=$(date "+%Y-%m-%d %H:%M" -d "$time 7 day ago")
price7before=$(grep "^$timebefore" "$rawhistfile" | cut -d, -f2)
[ -z "$price7before" ] && continue
change7before=$(g_percentage-diff $price7before $price)
timebefore=$(date "+%Y-%m-%d %H:%M" -d "$time 1 day ago")
price1before=$(grep "^$timebefore" "$rawhistfile" | cut -d, -f2)
[ -z "$price1before" ] && continue
change1before=$(g_percentage-diff $price1before $price)
#echo "$f_line -- $change1before,$change7before,$change14before,$change30before"
echo "$f_line" | sed "s/^\(${time}.*\)100,100,100,100/\1$change1before,$change7before,$change14before,$change30before/"
2023-05-30 17:48:27 +02:00
sed -i "s/^\(${time}.*\)100,100,100,100/\1$change1before,$change7before,$change14before,$change30before/" $rawhistfile
2023-05-30 11:57:05 +02:00
done
}
find data/botdata/asset-histories -name "*.history.csv" | while read rawhistfile
do
get_asset "${rawhistfile}" || exit 1
done