From 6cd7368f00be924d4e914d2412e2a67145694e5c Mon Sep 17 00:00:00 2001 From: David Brazda Date: Fri, 24 Nov 2023 21:51:33 +0100 Subject: [PATCH] vyladeni batch header --- v2realbot/controller/services.py | 2 +- v2realbot/static/js/archivetables.js | 106 ++++++++++++++++++++------- v2realbot/static/main.css | 13 +++- 3 files changed, 92 insertions(+), 29 deletions(-) diff --git a/v2realbot/controller/services.py b/v2realbot/controller/services.py index 42959b0..da1b6e2 100644 --- a/v2realbot/controller/services.py +++ b/v2realbot/controller/services.py @@ -809,7 +809,7 @@ def populate_metrics_output_directory(strat: StrategyInstance, inter_batch_param rp_string = "RP" + str(float(np.sum(strat.state.rel_profit_cum))) if len(strat.state.rel_profit_cum) >0 else "noRP" ##summary pro rychle zobrazeni P333L-222 PT9:30 PL10:30 - res["profit"]["sum"]="P"+str(int(sum_wins))+"L"+str(int(sum_losses))+" "+"MCP"+str(int(max_profit))+"MCL(DD)"+str(int(max_loss))+" "+ mpt_string+" " + mlt_string + rp_string + " "+str(strat.state.rel_profit_cum) + res["profit"]["sum"]="P"+str(int(sum_wins))+"L"+str(int(sum_losses))+" "+"MP"+str(int(max_profit))+"ML"+str(int(max_loss))+" "+ mpt_string+" " + mlt_string + rp_string + " "+str(strat.state.rel_profit_cum) #rel_profit zprumerovane res["profit"]["daily_rel_profit_sum"] = float(np.sum(strat.state.rel_profit_cum)) if len(strat.state.rel_profit_cum) > 0 else 0 diff --git a/v2realbot/static/js/archivetables.js b/v2realbot/static/js/archivetables.js index 2ecc6d6..8c615e0 100644 --- a/v2realbot/static/js/archivetables.js +++ b/v2realbot/static/js/archivetables.js @@ -2,6 +2,7 @@ let editor_diff_arch1 let editor_diff_arch2 var archData = null +var batchHeaders = [] function refresh_arch_and_callback(row, callback) { //console.log("entering refresh") @@ -954,7 +955,7 @@ var archiveRecords = {data: 'metrics', visible: true}, {data: 'batch_id', visible: true}, ], - paging: false, + paging: true, processing: true, serverSide: true, columnDefs: [{ @@ -1126,40 +1127,75 @@ var archiveRecords = // Add row grouping based on 'batch_id' rowGroup: { dataSrc: 'batch_id', + //toto je volano pri renderovani groupy startRender: function (rows, group) { var groupId = group ? group : 'no-batch-id'; // Initialize variables for the group var itemCount = 0; - var firstNote = ''; + var period = ''; var profit = ''; + var started = null; + + // // Process each item only once + // archiveRecords.rows({ search: 'applied' }).every(function (rowIdx, tableLoop, rowLoop) { + // var data = this.data(); - // Process each item only once - archiveRecords.rows({ search: 'applied' }).every(function (rowIdx, tableLoop, rowLoop) { - var data = this.data(); - - if ((group && data.batch_id === group)) { - itemCount++; - if (itemCount === 1) { - firstNote = data.note ? data.note.substring(0, 14) : ''; - try { - profit = data.metrics.profit.batch_sum_profit; - } catch (e) { - profit = 'N/A'; - } - } + // if ((group && data.batch_id == group)) { + // itemCount++; + // if (itemCount === 1 ) { + // firstNote = data.note ? data.note.substring(0, 14) : ''; + + // if (data.note) { + // better_counter = extractNumbersFromString(data.note); + // } + // try { + // profit = data.metrics.profit.batch_sum_profit; + // } catch (e) { + // profit = 'N/A'; + // } + // } + // } + // }); + + + //pokud mame batch_id podivame se zda jeho nastaveni uz nema a pokud ano pouzijeme to + //pokud nemame tak si ho loadneme + if (group) { + const existingBatch = batchHeaders.find(batch => batch.batch_id == group); + var firstRowData = rows.data()[0]; + //jeste neni v poli batchu - udelame hlavicku + if (!existingBatch) { + itemCount = extractNumbersFromString(firstRowData.note); + profit = firstRowData.metrics.profit.batch_sum_profit; + period = firstRowData.note ? firstRowData.note.substring(0, 14) : ''; + started = firstRowData.started + var newBatchHeader = {batch_id:group, profit:profit, itemCount:itemCount, period:period, started:started} + batchHeaders.push(newBatchHeader) } - }); - + //uz je v poli, ale mame novejsi (pribyl v ramci backtestu napr.) - updatujeme + else if (new Date(existingBatch.started) < new Date(firstRowData.started)) { + itemCount = extractNumbersFromString(firstRowData.note); + profit = firstRowData.metrics.profit.batch_sum_profit; + period = firstRowData.note ? firstRowData.note.substring(0, 14) : ''; + started = firstRowData.started + existingBatch.itemCount = itemCount; + existingBatch.profit = profit; + existingBatch.period = period; + existingBatch.started = started; + } + //uz je v poli batchu vytahneme + else { + profit = existingBatch.profit + itemCount = existingBatch.itemCount + period = existingBatch.period + started = existingBatch.started + } + } + // Construct the group header var groupHeaderContent = '' + (group ? 'Batch ID: ' + group : 'No Batch') + ''; - groupHeaderContent += (group ? ' (' + itemCount + ')' : ''); - if (firstNote) { - groupHeaderContent += ' ' + firstNote; - } - if (profit) { - groupHeaderContent += ' - Profit: ' + profit + ''; - } + groupHeaderContent += (group ? ' (' + itemCount + ')' + ' ' + period + ' Profit: ' + profit + '' : ''); return $('') .append('' + groupHeaderContent + '') @@ -1171,7 +1207,6 @@ var archiveRecords = var api = this.api(); var rows = api.rows({ page: 'current' }).nodes(); - // Iterate over all rows in the current page api.column(17, { page: 'current' }).data().each(function (group, i) { var groupName = group ? group : 'no-batch-id'; @@ -1191,6 +1226,23 @@ var archiveRecords = } }); +function extractNumbersFromString(str) { + // Regular expression to match the pattern #number1/number2 + const pattern = /#(\d+)\/(\d+)/; + const match = str.match(pattern); + + if (match) { + // Extract number1 and number2 from the match + const number1 = parseInt(match[1], 10); + const number2 = parseInt(match[2], 10); + + //return { number1, number2 }; + return number2; + } else { + return null; + } +} + // Function to generate a unique key for localStorage based on batch_id function generateStorageKey(batchId) { return 'dt-group-state-' + batchId; @@ -1204,7 +1256,7 @@ $('#archiveTable tbody').on('click', 'tr.group-header', function () { archiveRecords.rows().every(function () { var rowGroup = this.data().batch_id ? this.data().batch_id : 'no-batch-id'; - if (rowGroup === name) { + if (rowGroup == name) { if (collapsed) { this.node().style.display = ''; } else { diff --git a/v2realbot/static/main.css b/v2realbot/static/main.css index ce6661a..08f3b76 100644 --- a/v2realbot/static/main.css +++ b/v2realbot/static/main.css @@ -181,11 +181,22 @@ table.dataTable thead>tr>th.sorting_asc:before, table.dataTable thead>tr>th.sort font-weight: bold; } -.group-header .profit-info { +.group-header .batchheader-profit-info { color: #3e999e; /* Highlight profit info */ font-weight: bold; } +.group-header .batchheader-count-info { + color: #a1a1a1; /* Highlight count info */ + font-weight: bold; +} + + +.group-header .batchheader-period-info { + color: #a1a1a1; /* Highlight period info */ + font-weight: bold; +} + .group-header strong { color: #3e999e; /* Distinct color for Batch ID */ }