-
Notifications
You must be signed in to change notification settings - Fork 25
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
Fix #1384: Improve Predictoors Table #1398
Changes from 6 commits
ea92251
4726743
2373150
59d6617
4791c44
147b619
24a4118
d1f2c7b
55cf9f4
4d9a946
04abc7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
PREDICTOOR_TABLE_COLUMNS = [ | ||
{"name": "User Addr", "id": "user_address"}, | ||
{"name": "Profit", "id": "total_profit"}, | ||
{"name": "AVG Accuracy", "id": "avg_accuracy"}, | ||
{"name": "AVG Stake", "id": "avg_stake"}, | ||
{"name": "User", "id": "user"}, | ||
] | ||
|
||
PREDICTOOR_TABLE_HIDDEN_COLUMNS = ["user"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
get_feeds_data_from_db, | ||
get_predictoors_data_from_db, | ||
get_payouts_from_db, | ||
get_user_payouts_stats_from_db, | ||
filter_objects_by_field, | ||
get_feed_ids_based_on_predictoors_from_db, | ||
) | ||
|
@@ -16,6 +17,10 @@ | |
from pdr_backend.analytics.predictoor_dashboard.dash_components.util import ( | ||
select_or_clear_all_by_table, | ||
) | ||
from pdr_backend.analytics.predictoor_dashboard.dash_components.app_constants import ( | ||
PREDICTOOR_TABLE_COLUMNS, | ||
PREDICTOOR_TABLE_HIDDEN_COLUMNS, | ||
) | ||
from pdr_backend.cli.arg_feeds import ArgFeeds | ||
|
||
|
||
|
@@ -24,16 +29,18 @@ def get_callbacks(app): | |
@app.callback( | ||
Output("feeds-data", "data"), | ||
Output("predictoors-data", "data"), | ||
Output("user-payout-stats", "data"), | ||
Output("error-message", "children"), | ||
Input("data-folder", "data"), | ||
) | ||
def get_input_data_from_db(files_dir): | ||
try: | ||
feeds_data = get_feeds_data_from_db(files_dir) | ||
predictoors_data = get_predictoors_data_from_db(files_dir) | ||
return feeds_data, predictoors_data, None | ||
user_payout_stats = get_user_payouts_stats_from_db(files_dir) | ||
return feeds_data, predictoors_data, user_payout_stats, None | ||
except Exception as e: | ||
return None, None, dash.html.H3(str(e)) | ||
return None, None, None, dash.html.H3(str(e)) | ||
|
||
@app.callback( | ||
Output("accuracy_chart", "children"), | ||
|
@@ -109,31 +116,27 @@ def create_feeds_table(feeds_data): | |
columns = [{"name": col, "id": col} for col in feeds_data[0].keys()] | ||
return columns | ||
|
||
@app.callback( | ||
Output("predictoors_table", "columns"), | ||
Input("predictoors-data", "data"), | ||
) | ||
def create_predictoors_table(predictoors_data): | ||
if not predictoors_data: | ||
return dash.no_update | ||
columns = [{"name": col, "id": col} for col in predictoors_data[0].keys()] | ||
return columns | ||
|
||
@app.callback( | ||
Output("predictoors_table", "data"), | ||
Output("predictoors_table", "selected_rows"), | ||
Output("predictoors_table", "columns"), | ||
Output("predictoors_table", "hidden_columns"), | ||
[ | ||
Input("search-input-Predictoors", "value"), | ||
Input("predictoors_table", "selected_rows"), | ||
Input("predictoors_table", "data"), | ||
Input("predictoors-data", "data"), | ||
Input("user-payout-stats", "data"), | ||
], | ||
) | ||
def update_predictoors_table_on_search( | ||
search_value, selected_rows, predictoors_table, predictoors_data | ||
search_value, | ||
selected_rows, | ||
predictoors_table, | ||
predictoors_data, | ||
user_payout_stats, | ||
): | ||
selected_predictoors = [predictoors_table[i] for i in selected_rows] | ||
|
||
if not search_value: | ||
filtered_data = predictoors_data | ||
else: | ||
|
@@ -142,13 +145,49 @@ def update_predictoors_table_on_search( | |
predictoors_data, "user", search_value, selected_predictoors | ||
) | ||
|
||
if user_payout_stats: | ||
# Her bir data elemanı için, eşleşen user_payout_stat bulunur ve güncellenir. | ||
# Eşleşme yoksa, orijinal data elemanı korunur. | ||
filtered_data = [ | ||
{ | ||
**data, | ||
**next( | ||
( | ||
user_payout_stat | ||
for user_payout_stat in user_payout_stats | ||
if user_payout_stat["user"] == data["user"] | ||
), | ||
{}, | ||
), | ||
} | ||
for data in filtered_data | ||
] | ||
|
||
# shorten the user address | ||
for data in filtered_data: | ||
new_data = { | ||
"user_address": data["user"][:5] + "..." + data["user"][-5:], | ||
"total_profit": round(data["total_profit"], 2), | ||
"avg_accuracy": round(data["avg_accuracy"], 2), | ||
"avg_stake": round(data["avg_stake"], 2), | ||
"user": data["user"], | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we save this values directly on the predictoor_data state inside |
||
|
||
data.clear() | ||
data.update(new_data) | ||
|
||
selected_predictoor_indices = [ | ||
i | ||
for i, predictoor in enumerate(filtered_data) | ||
if predictoor in selected_predictoors | ||
] | ||
|
||
return filtered_data, selected_predictoor_indices | ||
return ( | ||
filtered_data, | ||
selected_predictoor_indices, | ||
PREDICTOOR_TABLE_COLUMNS, | ||
PREDICTOOR_TABLE_HIDDEN_COLUMNS, | ||
) | ||
|
||
@app.callback( | ||
Output("feeds_table", "data"), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,23 @@ def get_predictoors_data_from_db(lake_dir: str): | |
|
||
|
||
@enforce_types | ||
def get_user_payouts_stats_from_db(lake_dir: str): | ||
return _query_db( | ||
lake_dir, | ||
f""" | ||
SELECT | ||
"user", | ||
SUM(payout - stake) AS total_profit, | ||
SUM(CASE WHEN payout > 0 THEN 1 ELSE 0 END) * 100.0 / COUNT(*) AS avg_accuracy, | ||
AVG(stake) AS avg_stake | ||
FROM | ||
{Payout.get_lake_table_name()} | ||
GROUP BY | ||
"user" | ||
""", | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good job with the query, the data comes in very fast! |
||
|
||
|
||
def get_feed_ids_based_on_predictoors_from_db( | ||
lake_dir: str, predictoor_addrs: List[str] | ||
): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should translate this to english 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry my fault :D