added basic charts in webppage

This commit is contained in:
olli 2023-10-06 16:37:55 +02:00
parent 2b74f8de06
commit e0f9e61ea1

View File

@ -1,5 +1,25 @@
function webpage {
function genchart {
local lastmark=0
local mark=""
local file="$1"
local highest=$(sort -n "${file}" | tail -n1 | sed s/^-//)
local lowest=$(sort -n "${file}" | head -n1 | sed s/^-//)
local divideby=$(echo "$highest+$lowest" | bc -l)
local color="green"
tail -n1 "${file}" | grep -q "^-" && color="red"
echo "<div id='${file}'>
<table class='charts-css line show-data-on-hover show-heading'><caption> $file </caption>"
for mark in $(cat "${file}")
do
echo "<tr><td style='--color: $color; --start: calc( ($lastmark + $lowest) / $divideby ); --end: calc( ( $mark + $lowest) / $divideby );'> <span class='tooltip'> ${mark} % </span> </td></tr>"
lastmark=${mark}
done
echo "</table></div>"
}
function webpage {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
# create status webpage
@ -7,7 +27,8 @@ function webpage {
<meta charset="UTF-8">
<meta http-equiv="refresh" content="60" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="/browser.css">' >../index.html.tmp
<link rel="stylesheet" type="text/css" href="/browser.css">
<link rel="stylesheet" type="text/css" href="/charts.min.css">' >../index.html.tmp
echo "<title>Dabo! on ${STOCK_EXCHANGE} - ${URL}</title>
</head><body>" >>../index.html.tmp
echo "<h1>State of Dabo-Bot! on ${STOCK_EXCHANGE} - ${URL} (ReadOnly)</h1>
@ -143,13 +164,15 @@ function webpage {
<td>${CURRENCY} Quantity</td>
<td>${CURRENCY} Price</td>
<td>Commission</td>
<td>Comment</td></tr>" >>../index.html.tmp
<td>Comment</td></tr>
<td>Chart</td>" >>../index.html.tmp
local f_trade_file
for f_trade_file in $(ls -t trade-histories/trade-*-open.history.csv 2>/dev/null)
do
local tradeline=$(tail -n1 ${f_trade_file})
local asset=$(echo ${f_trade_file} | cut -d. -f3 | cut -d- -f1)
local interimfile=$(echo ${f_trade_file} | sed 's/open\.history\.csv/interim\.history\.csv/')
echo "<td>$(echo ${tradeline} | cut -d, -f1)</td>
<td><a href=\"botdata/asset-histories/${asset}.history.csv\">${asset}</a> <a href=\"https://www.coingecko.com/de/munze/$(egrep -i ^$(echo ${asset} | sed "s/${CURRENCY}$//"), COINGECKO_IDS | cut -d, -f2 )\">🔗</a></td>
<td>$(echo ${tradeline} | cut -d, -f2)</td>
@ -157,6 +180,9 @@ function webpage {
<td>$(echo ${tradeline} | cut -d, -f5)</td>
<td>$(echo ${tradeline} | cut -d, -f6)</td>
<td>$(echo ${tradeline} | cut -d, -f7,8,9,10,11,12,13,14,15)</td>
<td width='800'>" >>../index.html.tmp
genchart "$interimfile" >>../index.html.tmp
echo "</td>
</tr>" >>../index.html.tmp
done
echo "</table>" >>../index.html.tmp
@ -170,7 +196,8 @@ function webpage {
<td>${CURRENCY} Quantity</td>
<td>${CURRENCY} Price (result)</td>
<td>Commission</td>
<td>Comment</td></tr>" >>../index.html.tmp
<td>Comment</td>
<td>Chart</td></tr>" >>../index.html.tmp
for f_trade_file in $(ls -t trade-histories/trade-*-closed.history.csv 2>/dev/null | head -n 50)
do
@ -198,6 +225,7 @@ function webpage {
fi
fi
local asset=$(echo ${f_trade_file} | cut -d. -f3 | cut -d- -f1)
interimfile=$(echo ${f_trade_file} | sed 's/closed\.history\.csv/interim\.history\.csv/')
echo "<td>$(echo ${tradeline} | cut -d, -f1)</td>
<td><a href=\"botdata/asset-histories/${asset}.history.csv\">${asset}</a> <a href=\"https://www.coingecko.com/de/munze/$(egrep -i ^$(echo ${asset} | sed "s/${CURRENCY}$//"), COINGECKO_IDS | cut -d, -f2 )\">🔗</a></td>
<td>${f_action}</td>
@ -205,6 +233,9 @@ function webpage {
<td>${f_price}</td>
<td>$(echo ${tradeline} | cut -d, -f6)</td>
<td>$(echo ${tradeline} | cut -d, -f7,8,9,10,11,12,13,14,15)</td>
<td width='800'> ">>../index.html.tmp
echo ${f_action} | grep -q sell && genchart "$interimfile" >>../index.html.tmp
echo "</td>
</tr>" >>../index.html.tmp
done
done
@ -212,48 +243,6 @@ function webpage {
# echo "<table><tr>" >>../index.html.tmp
# echo "<td>Date</td>
# <td>Asset</td>
# <td>Action</td>
# <td>${CURRENCY} Quantity</td>
# <td>${CURRENCY} Price (profit/loss)</td>
# <td>Commission</td>
# <td>Comment</td></tr>" >>../index.html.tmp
# grep ^20 trade-histories/*history.csv | sed 's/\// /; s/\./ /; s/:/ /; s/,/ /g' | sort -r -k3 >${g_tmp}/trade-hist-complete
# local tradeline
# cat ${g_tmp}/trade-hist-complete | while read tradeline
# do
# # use array trade
# local trade=($tradeline)
# local f_trace_price=${trade[8]}
# if [ ${trade[4]} = "sell" ]
# then
# local f_trade_date=${trade[3]}
# local f_trade_currency=${trade[1]}
# local f_trade_sell_for=${trade[6]}
# local f_trade_buy_for=$(grep -B1 "^${f_trade_date},sell," "trade-histories/${f_trade_currency}.history.csv" | grep -i ",buy," | cut -d, -f4 | cut -d" " -f1)
# local f_result=$(echo "scale=2; ${f_trade_sell_for}-$f_trade_buy_for" | bc -l | sed 's/^\./0./; s/^-\./-0./' | xargs printf "%.2f")
# local f_result_percentage=$(g_percentage-diff $f_trade_buy_for ${f_trade_sell_for})
# f_trace_price="$f_trace_price ($f_result( ${f_result_percentage}%))"
# #echo "${trade[1]} $f_trade_buy_for -- ${f_trade_sell_for} == $f_result(${f_result_percentage}%)"
# fi
# echo "<td>${trade[3]}</td>
# <td><a href=\"botdata/asset-histories/${trade[1]}.history.csv\">${trade[1]}</a> <a href=\"https://www.coingecko.com/de/munze/$(egrep -i ^$(echo ${trade[1]} | sed "s/${CURRENCY}$//"), COINGECKO_IDS | cut -d, -f2 )\">🔗</a></td>
# <td>${trade[4]}</td>
# <td>${trade[6]}</td>
# <td>${f_trace_price}</td>
# <td>${trade[9]} ${trade[10]}</td>
# <td>${trade[@]:11:30}</td>
# </tr>" >>../index.html.tmp
#
# done
# echo "</table>" >>../index.html.tmp
echo "<h2>Current config</h2>" >>../index.html.tmp
echo "<pre>$(cat ../../dabo-bot.conf | perl -pe 's/\</&#60;/g; s/\>/&#62;/g;')</pre>" >>../index.html.tmp