From 496dda9510c0e68c4ff1ba6a5c2afed39c2686b8 Mon Sep 17 00:00:00 2001 From: Calina Cenan Date: Thu, 3 Oct 2024 13:14:05 +0100 Subject: [PATCH 1/4] Adds profit metric. --- pdr_backend/pdr_dashboard/test/test_callbacks_predictoors.py | 5 +++-- pdr_backend/pdr_dashboard/util/db.py | 3 +++ pdr_backend/pdr_dashboard/util/format.py | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pdr_backend/pdr_dashboard/test/test_callbacks_predictoors.py b/pdr_backend/pdr_dashboard/test/test_callbacks_predictoors.py index b30ea3bc4..953f7b786 100644 --- a/pdr_backend/pdr_dashboard/test/test_callbacks_predictoors.py +++ b/pdr_backend/pdr_dashboard/test/test_callbacks_predictoors.py @@ -53,7 +53,7 @@ def test_predictoors_table(_sample_app, dash_duo): _verify_table_data(table, "expected_predictoors_table_data.json") -def test_feeds_page_metrics_row(_sample_app, dash_duo): +def test_predictoors_page_metrics_row(_sample_app, dash_duo): app = _sample_app start_server_and_wait(dash_duo, app) @@ -65,7 +65,7 @@ def test_feeds_page_metrics_row(_sample_app, dash_duo): # Validate metrics # select first level divs metrics = metrics_row.find_elements(By.XPATH, "./div") - assert len(metrics) == 4 + assert len(metrics) == 5 metric_texts = [_remove_tags(m.text) for m in metrics] expected_metrics = [ @@ -73,6 +73,7 @@ def test_feeds_page_metrics_row(_sample_app, dash_duo): "Accuracy(avg)", "Staked", "Gross Income", + "Profit", ] for i, metric in enumerate(expected_metrics): diff --git a/pdr_backend/pdr_dashboard/util/db.py b/pdr_backend/pdr_dashboard/util/db.py index c447fb85c..5b163aa47 100644 --- a/pdr_backend/pdr_dashboard/util/db.py +++ b/pdr_backend/pdr_dashboard/util/db.py @@ -436,11 +436,14 @@ def predictoors_metrics(self) -> dict[str, Union[int, float]]: ) ) + profit = tot_gross_income - (tot_stake * 2 * self.fee_cost if tot_stake else 0) + return { "Predictoors": predictoors, "Accuracy(avg)": avg_accuracy, "Staked": tot_stake, "Gross Income": tot_gross_income, + "Profit": profit, } def get_first_and_last_slot_timestamp(self) -> Tuple[UnixTimeS, UnixTimeS]: diff --git a/pdr_backend/pdr_dashboard/util/format.py b/pdr_backend/pdr_dashboard/util/format.py index 1d867ab87..954057d1a 100644 --- a/pdr_backend/pdr_dashboard/util/format.py +++ b/pdr_backend/pdr_dashboard/util/format.py @@ -82,6 +82,7 @@ "predictoors_page_accuracy_metric": "percentage", "predictoors_page_staked_metric": "currency", "predictoors_page_gross_income_metric": "currency", + "predictoors_page_profit_metric": "currency", } From 215210adad5359fb98a0c691487ad456d7d061fb Mon Sep 17 00:00:00 2001 From: Calina Cenan Date: Thu, 3 Oct 2024 14:50:00 +0100 Subject: [PATCH 2/4] Adds tooltip and subtract stake loss. --- .../pdr_dashboard/dash_components/tooltips.yaml | 1 + pdr_backend/pdr_dashboard/util/db.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pdr_backend/pdr_dashboard/dash_components/tooltips.yaml b/pdr_backend/pdr_dashboard/dash_components/tooltips.yaml index e8188b56b..bd23912f8 100644 --- a/pdr_backend/pdr_dashboard/dash_components/tooltips.yaml +++ b/pdr_backend/pdr_dashboard/dash_components/tooltips.yaml @@ -32,3 +32,4 @@ tooltip-predictoors_page_accuracy_metric: "Average accuracy of predictions" tooltip-predictoors_page_staked_metric: "Total stake placed by predictoors" tooltip-predictoors_page_gross_income_metric: "Total profit generated by correct predictions" + tooltip-predictoors_page_profit_metric: "Profit generated by correct predictions, excluding fees" diff --git a/pdr_backend/pdr_dashboard/util/db.py b/pdr_backend/pdr_dashboard/util/db.py index 5b163aa47..921aa227d 100644 --- a/pdr_backend/pdr_dashboard/util/db.py +++ b/pdr_backend/pdr_dashboard/util/db.py @@ -422,13 +422,14 @@ def predictoors_metrics(self) -> dict[str, Union[int, float]]: SUM( CASE WHEN p.payout > p.stake THEN p.payout - p.stake ELSE 0 END - ) AS tot_gross_income + ) AS tot_gross_income, + SUM(CASE WHEN p.payout = 0 THEN p.stake ELSE 0 END) AS stake_loss, FROM {tbl_parquet_path(self.lake_dir, BronzePrediction)} p """ if self.start_date_ms: query_predictoors_metrics += f" WHERE timestamp > {self.start_date_ms}" - predictoors, avg_accuracy, tot_stake, tot_gross_income = ( + predictoors, avg_accuracy, tot_stake, tot_gross_income, stake_loss = ( self.file_reader._query_db( query_predictoors_metrics, scalar=True, @@ -436,7 +437,11 @@ def predictoors_metrics(self) -> dict[str, Union[int, float]]: ) ) - profit = tot_gross_income - (tot_stake * 2 * self.fee_cost if tot_stake else 0) + profit = ( + tot_gross_income + - (tot_stake * 2 * self.fee_cost if tot_stake else 0) + - (stake_loss if stake_loss else 0) + ) return { "Predictoors": predictoors, From 61e95e5478508bd9c3d20977dd1e564a0d58d602 Mon Sep 17 00:00:00 2001 From: Calina Cenan Date: Fri, 4 Oct 2024 10:29:35 +0100 Subject: [PATCH 3/4] New formula. --- pdr_backend/pdr_dashboard/util/db.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/pdr_backend/pdr_dashboard/util/db.py b/pdr_backend/pdr_dashboard/util/db.py index 921aa227d..78643c011 100644 --- a/pdr_backend/pdr_dashboard/util/db.py +++ b/pdr_backend/pdr_dashboard/util/db.py @@ -423,13 +423,13 @@ def predictoors_metrics(self) -> dict[str, Union[int, float]]: CASE WHEN p.payout > p.stake THEN p.payout - p.stake ELSE 0 END ) AS tot_gross_income, - SUM(CASE WHEN p.payout = 0 THEN p.stake ELSE 0 END) AS stake_loss, + SUM(CASE WHEN p.payout > 0 THEN p.payout ELSE 0 END) AS clipped_payout FROM {tbl_parquet_path(self.lake_dir, BronzePrediction)} p """ if self.start_date_ms: query_predictoors_metrics += f" WHERE timestamp > {self.start_date_ms}" - predictoors, avg_accuracy, tot_stake, tot_gross_income, stake_loss = ( + predictoors, avg_accuracy, tot_stake, tot_gross_income, clipped_payout = ( self.file_reader._query_db( query_predictoors_metrics, scalar=True, @@ -437,11 +437,7 @@ def predictoors_metrics(self) -> dict[str, Union[int, float]]: ) ) - profit = ( - tot_gross_income - - (tot_stake * 2 * self.fee_cost if tot_stake else 0) - - (stake_loss if stake_loss else 0) - ) + profit = (clipped_payout or 0) - (tot_stake or 0) return { "Predictoors": predictoors, From a729354b52d63c820ebbeca6257d22798edb0bb8 Mon Sep 17 00:00:00 2001 From: Calina Cenan Date: Fri, 4 Oct 2024 11:02:48 +0100 Subject: [PATCH 4/4] Adjust formula to subtract costs. --- pdr_backend/pdr_dashboard/util/db.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/pdr_backend/pdr_dashboard/util/db.py b/pdr_backend/pdr_dashboard/util/db.py index 78643c011..92f12fb49 100644 --- a/pdr_backend/pdr_dashboard/util/db.py +++ b/pdr_backend/pdr_dashboard/util/db.py @@ -423,21 +423,33 @@ def predictoors_metrics(self) -> dict[str, Union[int, float]]: CASE WHEN p.payout > p.stake THEN p.payout - p.stake ELSE 0 END ) AS tot_gross_income, - SUM(CASE WHEN p.payout > 0 THEN p.payout ELSE 0 END) AS clipped_payout + SUM(CASE WHEN p.payout > 0 THEN p.payout ELSE 0 END) AS clipped_payout, + COUNT(p.ID) AS total_predictions FROM {tbl_parquet_path(self.lake_dir, BronzePrediction)} p """ + if self.start_date_ms: query_predictoors_metrics += f" WHERE timestamp > {self.start_date_ms}" - predictoors, avg_accuracy, tot_stake, tot_gross_income, clipped_payout = ( - self.file_reader._query_db( - query_predictoors_metrics, - scalar=True, - cache_file_name="predictoor_metrics_predictoors", - ) + + ( + predictoors, + avg_accuracy, + tot_stake, + tot_gross_income, + clipped_payout, + total_predictions, + ) = self.file_reader._query_db( + query_predictoors_metrics, + scalar=True, + cache_file_name="predictoor_metrics_predictoors", ) - profit = (clipped_payout or 0) - (tot_stake or 0) + profit = ( + (clipped_payout or 0) + - (tot_stake or 0) + - (total_predictions or 0) * self.fee_cost * 2 + ) return { "Predictoors": predictoors,