reverse array

This commit is contained in:
olli 2024-12-19 21:50:21 +01:00
parent 78f9b15413
commit c728795a9a

View File

@ -85,7 +85,6 @@ function get_values {
done done
# read current levels # read current levels
#v[${f_asset}_price]=${f_tickers_array[$f_asset]}
for f_time in 1w 1d for f_time in 1w 1d
do do
f_levelsfile="asset-histories/${f_asset}.history.${f_time}.csv.levels" f_levelsfile="asset-histories/${f_asset}.history.${f_time}.csv.levels"
@ -93,20 +92,20 @@ function get_values {
then then
# get levels # get levels
read -r -a f_levels <"$f_levelsfile" read -r -a f_levels <"$f_levelsfile"
v[${f_asset}_levels_$f_time]="${f_levels[*]}" vr[${f_asset}_levels_$f_time]="${f_levels[*]}"
# add current price and sort # add current price and sort
f_levels+=("${v[${f_asset}_price]}") f_levels+=("${vr[${f_asset}_price]}")
oldIFS="$IFS" oldIFS="$IFS"
IFS=$'\n' f_levels_sorted=($(sort -n <<<"${f_levels[*]}")) IFS=$'\n' f_levels_sorted=($(sort -n <<<"${f_levels[*]}"))
IFS="$oldIFS" IFS="$oldIFS"
# find current price and +- one for upper lower price # find current price and +- one for upper lower price
for ((i=0; i<${#f_levels_sorted[@]}; i++)); do for ((i=0; i<${#f_levels_sorted[@]}; i++)); do
if [ "${f_levels_sorted[$i]}" = "${v[${f_asset}_price]}" ] if [ "${f_levels_sorted[$i]}" = "${vr[${f_asset}_price]}" ]
then then
v[${f_asset}_levels_${f_time}_next_up]=${f_levels_sorted[i+1]} vr[${f_asset}_levels_${f_time}_next_up]=${f_levels_sorted[i+1]}
v[${f_asset}_levels_${f_time}_next_down]=${f_levels_sorted[i-1]} vr[${f_asset}_levels_${f_time}_next_down]=${f_levels_sorted[i-1]}
break break
fi fi
done done
@ -117,6 +116,11 @@ function get_values {
done done
# use reverse as default to be 0 latest, 1 pre latest,...
unset v
declare -ng v=vr
# write values file for overview
for i in "${!v[@]}" for i in "${!v[@]}"
do do
echo "\${v[$i]}=${v[$i]}" echo "\${v[$i]}=${v[$i]}"