fix weekends

This commit is contained in:
olli 2024-09-27 11:51:32 +02:00
parent 335c1ee349
commit 6b9c31bf2b

View File

@ -390,7 +390,6 @@ function convert_ohlcv_1h_to_1d {
f_mytimezone=$(date -d "$_latestdate" +%Z)
local f_today=$(TZ="$f_target_timezone" date "+%Y-%m-%d")
# check if there is a $f_latestdate
grep -A9999 -B24 "^$f_latestdate" "$f_input_file" >"$g_tmp/convert_ohlcv_1h_to_1d_nextlines"
if ! [ -s "$g_tmp/convert_ohlcv_1h_to_1d_nextlines" ]
@ -399,7 +398,7 @@ function convert_ohlcv_1h_to_1d {
f_nextdate=$(date -d "$(head -n1 "$g_tmp/convert_ohlcv_1h_to_1d_nextlines" | cut -d, -f1)" +%Y-%m-%d)
fi
# go through lines
# go through lines and switch to $f_target_timezone
cat "$g_tmp/convert_ohlcv_1h_to_1d_nextlines" | grep ':00:00,' | cut -d, -f1,2,3,4,5,6 | while read f_line
do
g_array "$f_line" g_line_array ,
@ -409,6 +408,22 @@ function convert_ohlcv_1h_to_1d {
echo "${g_line_array[0]},${g_line_array[1]},${g_line_array[2]},${g_line_array[3]},${g_line_array[4]},${g_line_array[5]}"
done >"${f_output_file}.tmp"
# check if $f_nextdate really exists in $f_target_timezone if not add a day until it exists
# useful for weekends
i=1
until grep -q "^$f_nextdate" "${f_output_file}.tmp"
do
echo $f_nextdate
f_nextdate=$(date -d "$f_nextdate +1day" "+%Y-%m-%d")
i=$((i++))
if [ i -gt 10 ]
then
g_echo_warn "${FUNCNAME} $@: no nextdate found after >10 iterations"
return 1
fi
done
# go through converted lines
cat "${f_output_file}.tmp" | while read f_line
do
g_array "$f_line" g_line_array ,