From f884c16f0785e43d451017d3639e00775be0c4d1 Mon Sep 17 00:00:00 2001 From: David Brazda Date: Mon, 26 Feb 2024 22:42:03 +0700 Subject: [PATCH] #149 --- v2realbot/common/db.py | 7 +++-- v2realbot/common/model.py | 2 ++ v2realbot/controller/services.py | 7 +++-- v2realbot/static/index.html | 6 ++-- .../static/js/tables/archivetable/init.js | 30 +++++++++++-------- 5 files changed, 33 insertions(+), 19 deletions(-) diff --git a/v2realbot/common/db.py b/v2realbot/common/db.py index 8c9ed5a..f8aa176 100644 --- a/v2realbot/common/db.py +++ b/v2realbot/common/db.py @@ -98,7 +98,7 @@ def row_to_runmanager(row: dict) -> RunManagerRecord: #prevede dict radku zpatky na objekt vcetme retypizace def row_to_runarchiveview(row: dict) -> RunArchiveView: - return RunArchive( + a = RunArchiveView( id=row['runner_id'], strat_id=row['strat_id'], batch_id=row['batch_id'], @@ -116,8 +116,11 @@ def row_to_runarchiveview(row: dict) -> RunArchiveView: trade_count=int(row['trade_count']), end_positions=int(row['end_positions']), end_positions_avgp=float(row['end_positions_avgp']), - metrics=orjson.loads(row['metrics']) if row['metrics'] else None + metrics=orjson.loads(row['metrics']) if row['metrics'] else None, + batch_profit=int(row['batch_profit']) if row['batch_profit'] else 0, + batch_count=int(row['batch_count']) if row['batch_count'] else 0, ) + return a #prevede dict radku zpatky na objekt vcetme retypizace def row_to_runarchive(row: dict) -> RunArchive: diff --git a/v2realbot/common/model.py b/v2realbot/common/model.py index f2dc6db..e26a475 100644 --- a/v2realbot/common/model.py +++ b/v2realbot/common/model.py @@ -320,6 +320,8 @@ class RunArchiveView(BaseModel): end_positions: int = 0 end_positions_avgp: float = 0 metrics: Union[dict, str] = None + batch_profit: float = 0 # Total profit for the batch - now calculated during query + batch_count: int = 0 # Count of runs in the batch - now calculated during query #same but with pagination class RunArchiveViewPagination(BaseModel): diff --git a/v2realbot/controller/services.py b/v2realbot/controller/services.py index 3bb197a..b43d0fe 100644 --- a/v2realbot/controller/services.py +++ b/v2realbot/controller/services.py @@ -1126,7 +1126,9 @@ def get_all_archived_runners_p(request: DataTablesRequest) -> Tuple[int, RunArch SELECT runner_id, strat_id, batch_id, symbol, name, note, started, stopped, mode, account, bt_from, bt_to, ilog_save, profit, trade_count, end_positions, end_positions_avgp, metrics, - MAX(stopped) OVER (PARTITION BY batch_id) AS max_stopped + MAX(stopped) OVER (PARTITION BY batch_id) AS max_stopped, + SUM(profit) OVER (PARTITION BY batch_id) AS batch_profit, + COUNT(*) OVER (PARTITION BY batch_id) AS batch_count FROM runner_header WHERE (:search_value = '' OR strat_id LIKE :search_value OR batch_id LIKE :search_value) ), @@ -1140,7 +1142,8 @@ def get_all_archived_runners_p(request: DataTablesRequest) -> Tuple[int, RunArch ) SELECT runner_id, strat_id, batch_id, symbol, name, note, started, stopped, mode, account, bt_from, bt_to, ilog_save, profit, - trade_count, end_positions, end_positions_avgp, metrics + trade_count, end_positions, end_positions_avgp, metrics, + batch_profit, batch_count FROM InterleavedGroups ORDER BY sort_key DESC, diff --git a/v2realbot/static/index.html b/v2realbot/static/index.html index 3521db6..b31df94 100644 --- a/v2realbot/static/index.html +++ b/v2realbot/static/index.html @@ -595,7 +595,9 @@ pos avgp metrics - batchid + batchid + batchprofit + batchcount @@ -1158,7 +1160,7 @@ - + diff --git a/v2realbot/static/js/tables/archivetable/init.js b/v2realbot/static/js/tables/archivetable/init.js index f83e1bc..07d5efd 100644 --- a/v2realbot/static/js/tables/archivetable/init.js +++ b/v2realbot/static/js/tables/archivetable/init.js @@ -42,6 +42,8 @@ function initialize_archiveRecords() { {data: 'end_positions_avgp', visible: true}, {data: 'metrics', visible: true}, {data: 'batch_id', visible: true}, + {data: 'batch_profit', visible: true}, + {data: 'batch_count', visible: true}, ], paging: true, processing: true, @@ -237,6 +239,8 @@ function initialize_archiveRecords() { var groupId = group ? group : 'no-batch-id-' + firstRowData.id; var stateKey = 'dt-group-state-' + groupId; var state = localStorage.getItem(stateKey); + var profit = firstRowData.batch_profit + var itemCount = firstRowData.batch_count // Iterate over each row in the group to set the data attribute // zaroven pro kazdy node nastavime viditelnost podle nastaveni @@ -252,10 +256,10 @@ function initialize_archiveRecords() { }); // Initialize variables for the group - var itemCount = 0; + //var itemCount = 0; var period = ''; var batch_note = ''; - var profit = ''; + //var profit = ''; var started = null; var stratinId = null; var symbol = null; @@ -292,15 +296,15 @@ function initialize_archiveRecords() { const existingBatch = batchHeaders.find(batch => batch.batch_id == group); //jeste neni v poli batchu - udelame hlavicku if (!existingBatch) { - itemCount = extractNumbersFromString(firstRowData.note); - if (!itemCount) { - itemCount="NA" - } + // itemCount = extractNumbersFromString(firstRowData.note); + // if (!itemCount) { + // itemCount="NA" + // } - try { profit = firstRowData.metrics.profit.batch_sum_profit;} - catch (e) {profit = 'NA'} + // try { profit = firstRowData.metrics.profit.batch_sum_profit;} + // catch (e) {profit = 'NA'} - if (!profit) {profit = 'NA'} + // if (!profit) {profit = 'NA'} period = firstRowData.note ? firstRowData.note.substring(0, 14) : ''; try { batch_note = firstRowData.note ? firstRowData.note.split("N:")[1].trim() : '' @@ -316,10 +320,10 @@ function initialize_archiveRecords() { } //uz je v poli, ale mame novejsi (pribyl v ramci backtestu napr.) - updatujeme else if (new Date(existingBatch.started) < new Date(firstRowData.started)) { - try {itemCount = extractNumbersFromString(firstRowData.note);} - catch (e) {itemCount = 'NA'} - try {profit = firstRowData.metrics.profit.batch_sum_profit;} - catch (e) {profit = 'NA'} + // try {itemCount = extractNumbersFromString(firstRowData.note);} + // catch (e) {itemCount = 'NA'} + // try {profit = firstRowData.metrics.profit.batch_sum_profit;} + // catch (e) {profit = 'NA'} period = firstRowData.note ? firstRowData.note.substring(0, 14) : ''; if (period.startsWith("SCHED")) { period = "SCHEDULER";