Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Pdr Dashboard] Adds profit metric. #1650

Merged
merged 6 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pdr_backend/pdr_dashboard/dash_components/tooltips.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
5 changes: 3 additions & 2 deletions pdr_backend/pdr_dashboard/test/test_callbacks_predictoors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -65,14 +65,15 @@ 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 = [
"Predictoors",
"Accuracy(avg)",
"Staked",
"Gross Income",
"Profit",
]

for i, metric in enumerate(expected_metrics):
Expand Down
30 changes: 23 additions & 7 deletions pdr_backend/pdr_dashboard/util/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,25 +422,41 @@ 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.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 = (
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)
- (total_predictions or 0) * self.fee_cost * 2
)

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]:
Expand Down
1 change: 1 addition & 0 deletions pdr_backend/pdr_dashboard/util/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}


Expand Down
Loading