From 6a88d251240eeec5aa34ce5a0576cb913563d30d Mon Sep 17 00:00:00 2001 From: Norbert Date: Thu, 29 Aug 2024 14:37:11 +0300 Subject: [PATCH 1/8] use one query for predictoor data and removed unnecesary queries --- pdr_backend/pdr_dashboard/pages/home.py | 4 +- .../pdr_dashboard/pages/predictoors.py | 4 +- pdr_backend/pdr_dashboard/predictoor_dash.py | 5 +- .../pdr_dashboard/test/test_util_data.py | 4 +- .../pdr_dashboard/test/test_util_db.py | 47 ------------------- pdr_backend/pdr_dashboard/util/data.py | 8 ++-- pdr_backend/pdr_dashboard/util/db.py | 25 ---------- 7 files changed, 12 insertions(+), 85 deletions(-) diff --git a/pdr_backend/pdr_dashboard/pages/home.py b/pdr_backend/pdr_dashboard/pages/home.py index 187dae0ce..27f325db6 100644 --- a/pdr_backend/pdr_dashboard/pages/home.py +++ b/pdr_backend/pdr_dashboard/pages/home.py @@ -3,6 +3,7 @@ from pdr_backend.pdr_dashboard.util.data import ( col_to_human, + get_predictoors_home_page_table_data, ) from pdr_backend.pdr_dashboard.dash_components.view_elements import ( get_date_period_selection_component, @@ -79,7 +80,8 @@ def get_feeds_cols_data(self): return (columns, hidden_columns), data def get_predictoors_cols_data(self): - data = self.app.predictoors_data + predictoor_data = self.app.predictoors_data + data = get_predictoors_home_page_table_data(predictoor_data) columns = [{"name": col_to_human(col), "id": col} for col in data[0].keys()] hidden_columns = ["user"] diff --git a/pdr_backend/pdr_dashboard/pages/predictoors.py b/pdr_backend/pdr_dashboard/pages/predictoors.py index 78f7162a7..5092fb1b8 100644 --- a/pdr_backend/pdr_dashboard/pages/predictoors.py +++ b/pdr_backend/pdr_dashboard/pages/predictoors.py @@ -87,10 +87,8 @@ def get_search_bar_row(self): ) def get_main_container(self): - predictoor_stats = self.app.db_getter.predictoor_payouts_stats() - predictoor_cols, predictoor_data, raw_predictoor_data = ( - self.get_data_for_predictoors_table(predictoor_stats) + self.get_data_for_predictoors_table(self.app.predictoors_data) ) self.app.predictoor_table_data = raw_predictoor_data diff --git a/pdr_backend/pdr_dashboard/predictoor_dash.py b/pdr_backend/pdr_dashboard/predictoor_dash.py index 16633627c..f7e4cf74c 100644 --- a/pdr_backend/pdr_dashboard/predictoor_dash.py +++ b/pdr_backend/pdr_dashboard/predictoor_dash.py @@ -11,7 +11,6 @@ get_callbacks_predictoors, ) from pdr_backend.pdr_dashboard.dash_components.view_elements import get_layout -from pdr_backend.pdr_dashboard.util.data import get_predictoors_data_from_payouts from pdr_backend.pdr_dashboard.util.db import DBGetter from pdr_backend.pdr_dashboard.util.prices import ( calculate_tx_gas_fee_cost_in_OCEAN, @@ -48,9 +47,7 @@ def setup_app(app, ppss: PPSS): app.network_name = ppss.web3_pp.network app.feeds_data = app.db_getter.feeds_data() - app.predictoors_data = get_predictoors_data_from_payouts( - app.db_getter.payouts_stats() - ) + app.predictoors_data = app.db_getter.predictoor_payouts_stats() valid_addresses = [p["user"].lower() for p in app.predictoors_data] app.favourite_addresses = [ diff --git a/pdr_backend/pdr_dashboard/test/test_util_data.py b/pdr_backend/pdr_dashboard/test/test_util_data.py index 4861fec30..2e3afd810 100644 --- a/pdr_backend/pdr_dashboard/test/test_util_data.py +++ b/pdr_backend/pdr_dashboard/test/test_util_data.py @@ -2,7 +2,7 @@ import dash from pdr_backend.pdr_dashboard.util.data import ( - get_predictoors_data_from_payouts, + get_predictoors_home_page_table_data, select_or_clear_all_by_table, ) @@ -59,7 +59,7 @@ def test_get_predictoors_data_from_payouts(): }, ] - result = get_predictoors_data_from_payouts(user_payout_stats) + result = get_predictoors_home_page_table_data(user_payout_stats) assert isinstance(result, list) assert len(result) == 2 diff --git a/pdr_backend/pdr_dashboard/test/test_util_db.py b/pdr_backend/pdr_dashboard/test/test_util_db.py index 062f4f300..7d580ace7 100644 --- a/pdr_backend/pdr_dashboard/test/test_util_db.py +++ b/pdr_backend/pdr_dashboard/test/test_util_db.py @@ -42,26 +42,6 @@ def test_get_feeds_data( _clear_test_db(ppss.lake_ss.lake_dir) -@enforce_types -def test_get_predictoors_data( - tmpdir, - _sample_first_predictions, -): - ppss, sample_data_df = _prepare_test_db( - tmpdir, _sample_first_predictions, Prediction.get_lake_table_name() - ) - - db_getter = DBGetter(ppss.lake_ss.lake_dir) - result = db_getter.predictoors_data() - - grouped_sample = sample_data_df.unique("user") - - assert isinstance(result, list) - assert len(result) == len(grouped_sample) - - _clear_test_db(ppss.lake_ss.lake_dir) - - @enforce_types def test_get_payouts( tmpdir, @@ -102,33 +82,6 @@ def test_get_payouts( _clear_test_db(ppss.lake_ss.lake_dir) -def test_get_user_payouts_stats( - tmpdir, - _sample_payouts, -): - ppss, _ = _prepare_test_db( - tmpdir, _sample_payouts, table_name=Payout.get_lake_table_name() - ) - - db_getter = DBGetter(ppss.lake_ss.lake_dir) - result = db_getter.payouts_stats() - - assert isinstance(result, list) - assert len(result) == 5 - - test_row = [ - row - for row in result - if row["user"] == "0x02e9d2eede4c5347e55346860c8a8988117bde9e" - ][0] - - assert test_row["user"] == "0x02e9d2eede4c5347e55346860c8a8988117bde9e" - assert test_row["avg_accuracy"] == 100.0 - assert test_row["avg_stake"] == 1.9908170679122585 - - _clear_test_db(ppss.lake_ss.lake_dir) - - def test_get_feed_daily_subscriptions_by_feed_id(tmpdir, _sample_subscriptions): ppss, _ = _prepare_test_db( tmpdir, _sample_subscriptions, table_name=Subscription.get_lake_table_name() diff --git a/pdr_backend/pdr_dashboard/util/data.py b/pdr_backend/pdr_dashboard/util/data.py index 60779b939..1cd02997f 100644 --- a/pdr_backend/pdr_dashboard/util/data.py +++ b/pdr_backend/pdr_dashboard/util/data.py @@ -1,5 +1,6 @@ import logging +from copy import deepcopy from datetime import datetime, timedelta from typing import Union, List, Dict, Any, Optional from enforce_typing import enforce_types @@ -60,7 +61,7 @@ def select_or_clear_all_by_table( @enforce_types -def get_predictoors_data_from_payouts( +def get_predictoors_home_page_table_data( user_payout_stats: List[Dict[str, Any]], ) -> List[Dict[str, Any]]: """ @@ -71,7 +72,8 @@ def get_predictoors_data_from_payouts( list: List of processed user payouts stats data. """ - for data in user_payout_stats: + payout_stats = deepcopy(user_payout_stats) + for data in payout_stats: formatted_data = format_dict( pick_from_dict( data=data, keys=["user", "total_profit", "avg_accuracy", "avg_stake"] @@ -89,7 +91,7 @@ def get_predictoors_data_from_payouts( data.clear() data.update(new_data) - return user_payout_stats + return payout_stats def get_start_date_from_period(number_days: int): diff --git a/pdr_backend/pdr_dashboard/util/db.py b/pdr_backend/pdr_dashboard/util/db.py index e8c2b542d..136d696b7 100644 --- a/pdr_backend/pdr_dashboard/util/db.py +++ b/pdr_backend/pdr_dashboard/util/db.py @@ -49,31 +49,6 @@ def feeds_data(self): """, ) - @enforce_types - def predictoors_data(self): - return self._query_db( - f""" - SELECT user FROM {Prediction.get_lake_table_name()} - GROUP BY user - """, - ) - - @enforce_types - def payouts_stats(self): - return self._query_db( - 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" - """, - ) - @enforce_types def feed_payouts_stats(self): return self._query_db( From 97908b27659686182163e4e90755e28732f3f420 Mon Sep 17 00:00:00 2001 From: Norbert Date: Thu, 29 Aug 2024 16:58:40 +0300 Subject: [PATCH 2/8] feeds table cleanup and make column names consistent --- .../callbacks/callbacks_feeds.py | 16 +-- pdr_backend/pdr_dashboard/pages/feeds.py | 109 +----------------- pdr_backend/pdr_dashboard/predictoor_dash.py | 3 + .../expected_feeds_table_data.json | 80 ++++++------- .../filtered_accuracy_min_55.json | 4 +- .../filtered_base_token_ada.json | 8 +- .../filtered_base_token_eth.json | 8 +- .../filtered_base_token_eth_5m.json | 4 +- .../test/json_fixtures/search_6f3bc.json | 4 +- .../test/json_fixtures/search_ada.json | 8 +- .../test/json_fixtures/search_eth.json | 8 +- .../sorted_feeds_table_asc_by_volume.json | 80 ++++++------- .../test/test_callbacks_feeds.py | 12 +- pdr_backend/pdr_dashboard/util/data.py | 103 ++++++++++++++++- 14 files changed, 223 insertions(+), 224 deletions(-) diff --git a/pdr_backend/pdr_dashboard/callbacks/callbacks_feeds.py b/pdr_backend/pdr_dashboard/callbacks/callbacks_feeds.py index b1b1bbaab..1ea8c701a 100644 --- a/pdr_backend/pdr_dashboard/callbacks/callbacks_feeds.py +++ b/pdr_backend/pdr_dashboard/callbacks/callbacks_feeds.py @@ -17,8 +17,8 @@ def get_callbacks_feeds(app): [ Input("base_token", "value"), Input("quote_token", "value"), - Input("exchange", "value"), - Input("time", "value"), + Input("source", "value"), + Input("timeframe", "value"), Input("sales_button", "n_clicks"), Input("revenue_button", "n_clicks"), Input("accuracy_button", "n_clicks"), @@ -39,8 +39,8 @@ def get_callbacks_feeds(app): def filter_table( base_token, quote_token, - exchange, - time, + source, + timeframe, _n_clicks_sales, _n_clicks_revenue, _n_clicks_accuracy, @@ -63,8 +63,8 @@ def filter_table( conditions = [ ("filter", "base_token", base_token), ("filter", "quote_token", quote_token), - ("filter", "exchange", exchange), - ("filter", "time", time), + ("filter", "source", source), + ("filter", "timeframe", timeframe), ("range", "sales_raw", sales_min, sales_max), ("range", "sales_revenue_(OCEAN)", revenue_min, revenue_max), ("range", "avg_accuracy", accuracy_min, accuracy_max), @@ -145,8 +145,8 @@ def filter_table_by_volume_range( @app.callback( Output("base_token", "value"), Output("quote_token", "value"), - Output("exchange", "value"), - Output("time", "value"), + Output("source", "value"), + Output("timeframe", "value"), Output("sales_min", "value"), Output("sales_max", "value"), Output("revenue_min", "value"), diff --git a/pdr_backend/pdr_dashboard/pages/feeds.py b/pdr_backend/pdr_dashboard/pages/feeds.py index ded66548d..e6acbcc17 100644 --- a/pdr_backend/pdr_dashboard/pages/feeds.py +++ b/pdr_backend/pdr_dashboard/pages/feeds.py @@ -1,23 +1,17 @@ -from typing import List, Dict, Any, Tuple, Union - from dash import html, dcc, dash_table -from pdr_backend.pdr_dashboard.util.data import ( - get_feed_column_ids, - find_with_key_value, -) from pdr_backend.pdr_dashboard.dash_components.view_elements import ( get_metric, get_search_bar, ) -from pdr_backend.pdr_dashboard.util.format import format_table +from pdr_backend.pdr_dashboard.util.data import get_feeds_data_for_feeds_table from pdr_backend.pdr_dashboard.pages.common import TabularPage, Filter, add_to_filter from pdr_backend.pdr_dashboard.dash_components.modal import get_modal filters = [ {"name": "base_token", "placeholder": "Base Token", "options": []}, {"name": "quote_token", "placeholder": "Quote Token", "options": []}, - {"name": "exchange", "placeholder": "Exchange", "options": []}, - {"name": "time", "placeholder": "Time", "options": []}, + {"name": "source", "placeholder": "Source", "options": []}, + {"name": "timeframe", "placeholder": "Timeframe", "options": []}, ] filters_objects = [Filter(**item) for item in filters] @@ -120,8 +114,8 @@ def get_main_container(self): self.app.network_name ) - feed_cols, feed_data, raw_feed_data = self.get_feeds_data_for_feeds_table( - feed_stats, feed_subscriptions + feed_cols, feed_data, raw_feed_data = get_feeds_data_for_feeds_table( + self.app.feeds_data, feed_stats, feed_subscriptions ) self.app.feeds_table_data = raw_feed_data @@ -153,96 +147,3 @@ def get_feeds_table_area( ], style={"width": "100%", "overflow": "scroll"}, ) - - def get_feeds_stat_with_contract( - self, contract: str, feed_stats: List[Dict[str, Any]] - ) -> Dict[str, Union[float, int]]: - result = find_with_key_value(feed_stats, "contract", contract) - - if result: - return { - "avg_accuracy": float(result["avg_accuracy"]), - "avg_stake_per_epoch_(OCEAN)": float(result["avg_stake"]), - "volume_(OCEAN)": float(result["volume"]), - } - - return { - "avg_accuracy": 0, - "avg_stake_per_epoch_(OCEAN)": 0, - "volume_(OCEAN)": 0, - } - - def get_feeds_subscription_stat_with_contract( - self, contract: str, feed_subcription_stats: List[Dict[str, Any]] - ) -> Dict[str, Union[float, int, str]]: - result = find_with_key_value(feed_subcription_stats, "contract", contract) - - if result: - sales_str = f"{result['sales']}" - - df_buy_count_str = ( - f"{result['df_buy_count']}-DF" if result["df_buy_count"] > 0 else "" - ) - ws_buy_count_str = ( - f"{result['ws_buy_count']}-WS" if result["ws_buy_count"] > 0 else "" - ) - - if df_buy_count_str or ws_buy_count_str: - counts_str = "_".join( - filter(None, [df_buy_count_str, ws_buy_count_str]) - ) - - if counts_str: - sales_str += f"_{counts_str}" - - return { - "price_(OCEAN)": result["price"], - "sales": sales_str, - "sales_raw": result["sales"], - "sales_revenue_(OCEAN)": result["sales_revenue"], - } - - return { - "price_(OCEAN)": 0, - "sales": 0, - "sales_raw": 0, - "sales_revenue_(OCEAN)": 0, - } - - def get_feeds_data_for_feeds_table( - self, - feed_stats: List[Dict[str, Any]], - feed_subcription_stats: List[Dict[str, Any]], - ) -> Tuple[List[Dict[str, str]], List[Dict[str, Any]], List[Dict[str, Any]]]: - - temp_data = self.app.feeds_data - - new_feed_data = [] - ## split the pair column into two columns - for feed in temp_data: - split_pair = feed["pair"].split("/") - feed_item = {} - feed_item["addr"] = feed["contract"] - feed_item["base_token"] = split_pair[0] - feed_item["quote_token"] = split_pair[1] - feed_item["exchange"] = feed["source"].capitalize() - feed_item["time"] = feed["timeframe"] - feed_item["full_addr"] = feed["contract"] - - result = self.get_feeds_stat_with_contract(feed["contract"], feed_stats) - - feed_item.update(result) - - subscription_result = self.get_feeds_subscription_stat_with_contract( - feed["contract"], feed_subcription_stats - ) - - feed_item.update(subscription_result) - - new_feed_data.append(feed_item) - - columns = get_feed_column_ids(new_feed_data[0]) - - formatted_data = format_table(new_feed_data, columns) - - return columns, formatted_data, new_feed_data diff --git a/pdr_backend/pdr_dashboard/predictoor_dash.py b/pdr_backend/pdr_dashboard/predictoor_dash.py index f7e4cf74c..af5a17286 100644 --- a/pdr_backend/pdr_dashboard/predictoor_dash.py +++ b/pdr_backend/pdr_dashboard/predictoor_dash.py @@ -46,7 +46,10 @@ def setup_app(app, ppss: PPSS): app.db_getter = DBGetter(ppss.lake_ss.lake_dir) app.network_name = ppss.web3_pp.network + app.feed_stats = app.db_getter.feed_payouts_stats() + app.feed_subscriptions = app.db_getter.feed_subscription_stats(app.network_name) app.feeds_data = app.db_getter.feeds_data() + app.predictoors_data = app.db_getter.predictoor_payouts_stats() valid_addresses = [p["user"].lower() for p in app.predictoors_data] diff --git a/pdr_backend/pdr_dashboard/test/json_fixtures/expected_feeds_table_data.json b/pdr_backend/pdr_dashboard/test/json_fixtures/expected_feeds_table_data.json index 9a1a8968b..2257bfb34 100644 --- a/pdr_backend/pdr_dashboard/test/json_fixtures/expected_feeds_table_data.json +++ b/pdr_backend/pdr_dashboard/test/json_fixtures/expected_feeds_table_data.json @@ -4,8 +4,8 @@ "Addr": "0xf28...70b30", "Base Token": "TRX", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "5m", + "Source": "Binance", + "Timeframe": "5m", "Avg Accuracy": "65.09%", "Avg Stake Per Epoch (Ocean)": "193.28", "Volume (Ocean)": "40.98K", @@ -18,8 +18,8 @@ "Addr": "0xd41...90065", "Base Token": "BNB", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "1h", + "Source": "Binance", + "Timeframe": "1h", "Avg Accuracy": "50.0%", "Avg Stake Per Epoch (Ocean)": "975.06", "Volume (Ocean)": "15.6K", @@ -32,8 +32,8 @@ "Addr": "0x2d8...a3152", "Base Token": "XRP", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "1h", + "Source": "Binance", + "Timeframe": "1h", "Avg Accuracy": "50.0%", "Avg Stake Per Epoch (Ocean)": "1.02K", "Volume (Ocean)": "16.27K", @@ -46,8 +46,8 @@ "Addr": "0x3fb...6f3bc", "Base Token": "SOL", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "5m", + "Source": "Binance", + "Timeframe": "5m", "Avg Accuracy": "49.06%", "Avg Stake Per Epoch (Ocean)": "182.83", "Volume (Ocean)": "38.76K", @@ -60,8 +60,8 @@ "Addr": "0x74a...c06dd", "Base Token": "SOL", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "1h", + "Source": "Binance", + "Timeframe": "1h", "Avg Accuracy": "50.0%", "Avg Stake Per Epoch (Ocean)": "948.45", "Volume (Ocean)": "15.18K", @@ -74,8 +74,8 @@ "Addr": "0xfa6...b08dd", "Base Token": "LTC", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "1h", + "Source": "Binance", + "Timeframe": "1h", "Avg Accuracy": "50.0%", "Avg Stake Per Epoch (Ocean)": "998.29", "Volume (Ocean)": "15.97K", @@ -88,8 +88,8 @@ "Addr": "0x31f...ebfbd", "Base Token": "BNB", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "5m", + "Source": "Binance", + "Timeframe": "5m", "Avg Accuracy": "51.89%", "Avg Stake Per Epoch (Ocean)": "207.1", "Volume (Ocean)": "43.91K", @@ -102,8 +102,8 @@ "Addr": "0xbe0...2d434", "Base Token": "DOGE", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "5m", + "Source": "Binance", + "Timeframe": "5m", "Avg Accuracy": "48.58%", "Avg Stake Per Epoch (Ocean)": "187.3", "Volume (Ocean)": "39.71K", @@ -116,8 +116,8 @@ "Addr": "0x816...b2553", "Base Token": "BTC", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "1h", + "Source": "Binance", + "Timeframe": "1h", "Avg Accuracy": "50.0%", "Avg Stake Per Epoch (Ocean)": "870.51", "Volume (Ocean)": "13.93K", @@ -130,8 +130,8 @@ "Addr": "0xd49...e0a80", "Base Token": "TRX", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "1h", + "Source": "Binance", + "Timeframe": "1h", "Avg Accuracy": "50.0%", "Avg Stake Per Epoch (Ocean)": "994.48", "Volume (Ocean)": "15.91K", @@ -144,8 +144,8 @@ "Addr": "0x30f...77695", "Base Token": "ETH", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "5m", + "Source": "Binance", + "Timeframe": "5m", "Avg Accuracy": "48.94%", "Avg Stake Per Epoch (Ocean)": "159.64", "Volume (Ocean)": "37.51K", @@ -158,8 +158,8 @@ "Addr": "0x9c4...07e1f", "Base Token": "DOT", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "5m", + "Source": "Binance", + "Timeframe": "5m", "Avg Accuracy": "52.36%", "Avg Stake Per Epoch (Ocean)": "195.97", "Volume (Ocean)": "41.54K", @@ -172,8 +172,8 @@ "Addr": "0xb1c...23766", "Base Token": "LTC", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "5m", + "Source": "Binance", + "Timeframe": "5m", "Avg Accuracy": "49.06%", "Avg Stake Per Epoch (Ocean)": "192.51", "Volume (Ocean)": "40.81K", @@ -186,8 +186,8 @@ "Addr": "0x18f...e3151", "Base Token": "ADA", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "5m", + "Source": "Binance", + "Timeframe": "5m", "Avg Accuracy": "50.47%", "Avg Stake Per Epoch (Ocean)": "207.16", "Volume (Ocean)": "43.92K", @@ -200,8 +200,8 @@ "Addr": "0x93f...8b48f", "Base Token": "DOT", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "1h", + "Source": "Binance", + "Timeframe": "1h", "Avg Accuracy": "50.0%", "Avg Stake Per Epoch (Ocean)": "982.41", "Volume (Ocean)": "15.72K", @@ -214,8 +214,8 @@ "Addr": "0xf8c...c3fb3", "Base Token": "DOGE", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "1h", + "Source": "Binance", + "Timeframe": "1h", "Avg Accuracy": "50.0%", "Avg Stake Per Epoch (Ocean)": "951.39", "Volume (Ocean)": "15.22K", @@ -228,8 +228,8 @@ "Addr": "0xe66...69690", "Base Token": "BTC", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "5m", + "Source": "Binance", + "Timeframe": "5m", "Avg Accuracy": "48.09%", "Avg Stake Per Epoch (Ocean)": "168.41", "Volume (Ocean)": "39.58K", @@ -242,8 +242,8 @@ "Addr": "0xa2d...a0cf0", "Base Token": "ADA", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "1h", + "Source": "Binance", + "Timeframe": "1h", "Avg Accuracy": "50.0%", "Avg Stake Per Epoch (Ocean)": "1.03K", "Volume (Ocean)": "16.49K", @@ -256,8 +256,8 @@ "Addr": "0x55c...2cedb", "Base Token": "XRP", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "5m", + "Source": "Binance", + "Timeframe": "5m", "Avg Accuracy": "49.79%", "Avg Stake Per Epoch (Ocean)": "143.39", "Volume (Ocean)": "33.7K", @@ -270,8 +270,8 @@ "Addr": "0xaa6...710c5", "Base Token": "ETH", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "1h", + "Source": "Binance", + "Timeframe": "1h", "Avg Accuracy": "50.0%", "Avg Stake Per Epoch (Ocean)": "931.99", "Volume (Ocean)": "14.91K", diff --git a/pdr_backend/pdr_dashboard/test/json_fixtures/filtered_accuracy_min_55.json b/pdr_backend/pdr_dashboard/test/json_fixtures/filtered_accuracy_min_55.json index 6884cbcd1..78054d15b 100644 --- a/pdr_backend/pdr_dashboard/test/json_fixtures/filtered_accuracy_min_55.json +++ b/pdr_backend/pdr_dashboard/test/json_fixtures/filtered_accuracy_min_55.json @@ -4,8 +4,8 @@ "Addr": "0xf28...70b30", "Base Token": "TRX", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "5m", + "Source": "Binance", + "Timeframe": "5m", "Avg Accuracy": "65.09%", "Avg Stake Per Epoch (Ocean)": "193.28", "Volume (Ocean)": "40.98K", diff --git a/pdr_backend/pdr_dashboard/test/json_fixtures/filtered_base_token_ada.json b/pdr_backend/pdr_dashboard/test/json_fixtures/filtered_base_token_ada.json index f1820926b..3bd57c7c9 100644 --- a/pdr_backend/pdr_dashboard/test/json_fixtures/filtered_base_token_ada.json +++ b/pdr_backend/pdr_dashboard/test/json_fixtures/filtered_base_token_ada.json @@ -4,8 +4,8 @@ "Addr": "0xa2d...a0cf0", "Base Token": "ADA", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "1h", + "Source": "Binance", + "Timeframe": "1h", "Avg Accuracy": "50.0%", "Avg Stake Per Epoch (Ocean)": "1.03K", "Volume (Ocean)": "16.49K", @@ -18,8 +18,8 @@ "Addr": "0x18f...e3151", "Base Token": "ADA", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "5m", + "Source": "Binance", + "Timeframe": "5m", "Avg Accuracy": "50.47%", "Avg Stake Per Epoch (Ocean)": "207.16", "Volume (Ocean)": "43.92K", diff --git a/pdr_backend/pdr_dashboard/test/json_fixtures/filtered_base_token_eth.json b/pdr_backend/pdr_dashboard/test/json_fixtures/filtered_base_token_eth.json index ff65643db..3e511359d 100644 --- a/pdr_backend/pdr_dashboard/test/json_fixtures/filtered_base_token_eth.json +++ b/pdr_backend/pdr_dashboard/test/json_fixtures/filtered_base_token_eth.json @@ -4,8 +4,8 @@ "Addr": "0x30f...77695", "Base Token": "ETH", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "5m", + "Source": "Binance", + "Timeframe": "5m", "Avg Accuracy": "48.94%", "Avg Stake Per Epoch (Ocean)": "159.64", "Volume (Ocean)": "37.51K", @@ -18,8 +18,8 @@ "Addr": "0xaa6...710c5", "Base Token": "ETH", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "1h", + "Source": "Binance", + "Timeframe": "1h", "Avg Accuracy": "50.0%", "Avg Stake Per Epoch (Ocean)": "931.99", "Volume (Ocean)": "14.91K", diff --git a/pdr_backend/pdr_dashboard/test/json_fixtures/filtered_base_token_eth_5m.json b/pdr_backend/pdr_dashboard/test/json_fixtures/filtered_base_token_eth_5m.json index d21fc7b06..e52317871 100644 --- a/pdr_backend/pdr_dashboard/test/json_fixtures/filtered_base_token_eth_5m.json +++ b/pdr_backend/pdr_dashboard/test/json_fixtures/filtered_base_token_eth_5m.json @@ -4,8 +4,8 @@ "Addr": "0x30f...77695", "Base Token": "ETH", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "5m", + "Source": "Binance", + "Timeframe": "5m", "Avg Accuracy": "48.94%", "Avg Stake Per Epoch (Ocean)": "159.64", "Volume (Ocean)": "37.51K", diff --git a/pdr_backend/pdr_dashboard/test/json_fixtures/search_6f3bc.json b/pdr_backend/pdr_dashboard/test/json_fixtures/search_6f3bc.json index 4e3d3e0b8..247ca934b 100644 --- a/pdr_backend/pdr_dashboard/test/json_fixtures/search_6f3bc.json +++ b/pdr_backend/pdr_dashboard/test/json_fixtures/search_6f3bc.json @@ -4,8 +4,8 @@ "Addr": "0x3fb...6f3bc", "Base Token": "SOL", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "5m", + "Source": "Binance", + "Timeframe": "5m", "Avg Accuracy": "49.06%", "Avg Stake Per Epoch (Ocean)": "182.83", "Volume (Ocean)": "38.76K", diff --git a/pdr_backend/pdr_dashboard/test/json_fixtures/search_ada.json b/pdr_backend/pdr_dashboard/test/json_fixtures/search_ada.json index f1820926b..3bd57c7c9 100644 --- a/pdr_backend/pdr_dashboard/test/json_fixtures/search_ada.json +++ b/pdr_backend/pdr_dashboard/test/json_fixtures/search_ada.json @@ -4,8 +4,8 @@ "Addr": "0xa2d...a0cf0", "Base Token": "ADA", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "1h", + "Source": "Binance", + "Timeframe": "1h", "Avg Accuracy": "50.0%", "Avg Stake Per Epoch (Ocean)": "1.03K", "Volume (Ocean)": "16.49K", @@ -18,8 +18,8 @@ "Addr": "0x18f...e3151", "Base Token": "ADA", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "5m", + "Source": "Binance", + "Timeframe": "5m", "Avg Accuracy": "50.47%", "Avg Stake Per Epoch (Ocean)": "207.16", "Volume (Ocean)": "43.92K", diff --git a/pdr_backend/pdr_dashboard/test/json_fixtures/search_eth.json b/pdr_backend/pdr_dashboard/test/json_fixtures/search_eth.json index 3dda8b15c..b4d3a5b16 100644 --- a/pdr_backend/pdr_dashboard/test/json_fixtures/search_eth.json +++ b/pdr_backend/pdr_dashboard/test/json_fixtures/search_eth.json @@ -4,8 +4,8 @@ "Addr": "0xaa6...710c5", "Base Token": "ETH", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "1h", + "Source": "Binance", + "Timeframe": "1h", "Avg Accuracy": "50.0%", "Avg Stake Per Epoch (Ocean)": "931.99", "Volume (Ocean)": "14.91K", @@ -18,8 +18,8 @@ "Addr": "0x30f...77695", "Base Token": "ETH", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "5m", + "Source": "Binance", + "Timeframe": "5m", "Avg Accuracy": "48.94%", "Avg Stake Per Epoch (Ocean)": "159.64", "Volume (Ocean)": "37.51K", diff --git a/pdr_backend/pdr_dashboard/test/json_fixtures/sorted_feeds_table_asc_by_volume.json b/pdr_backend/pdr_dashboard/test/json_fixtures/sorted_feeds_table_asc_by_volume.json index 3d92e375b..7bae425d5 100644 --- a/pdr_backend/pdr_dashboard/test/json_fixtures/sorted_feeds_table_asc_by_volume.json +++ b/pdr_backend/pdr_dashboard/test/json_fixtures/sorted_feeds_table_asc_by_volume.json @@ -4,8 +4,8 @@ "Addr": "0x816...b2553", "Base Token": "BTC", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "1h", + "Source": "Binance", + "Timeframe": "1h", "Avg Accuracy": "50.0%", "Avg Stake Per Epoch (Ocean)": "870.51", "Volume (Ocean)": "13.93K", @@ -18,8 +18,8 @@ "Addr": "0xaa6...710c5", "Base Token": "ETH", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "1h", + "Source": "Binance", + "Timeframe": "1h", "Avg Accuracy": "50.0%", "Avg Stake Per Epoch (Ocean)": "931.99", "Volume (Ocean)": "14.91K", @@ -32,8 +32,8 @@ "Addr": "0x74a...c06dd", "Base Token": "SOL", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "1h", + "Source": "Binance", + "Timeframe": "1h", "Avg Accuracy": "50.0%", "Avg Stake Per Epoch (Ocean)": "948.45", "Volume (Ocean)": "15.18K", @@ -46,8 +46,8 @@ "Addr": "0xf8c...c3fb3", "Base Token": "DOGE", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "1h", + "Source": "Binance", + "Timeframe": "1h", "Avg Accuracy": "50.0%", "Avg Stake Per Epoch (Ocean)": "951.39", "Volume (Ocean)": "15.22K", @@ -60,8 +60,8 @@ "Addr": "0xd41...90065", "Base Token": "BNB", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "1h", + "Source": "Binance", + "Timeframe": "1h", "Avg Accuracy": "50.0%", "Avg Stake Per Epoch (Ocean)": "975.06", "Volume (Ocean)": "15.6K", @@ -74,8 +74,8 @@ "Addr": "0x93f...8b48f", "Base Token": "DOT", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "1h", + "Source": "Binance", + "Timeframe": "1h", "Avg Accuracy": "50.0%", "Avg Stake Per Epoch (Ocean)": "982.41", "Volume (Ocean)": "15.72K", @@ -88,8 +88,8 @@ "Addr": "0xd49...e0a80", "Base Token": "TRX", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "1h", + "Source": "Binance", + "Timeframe": "1h", "Avg Accuracy": "50.0%", "Avg Stake Per Epoch (Ocean)": "994.48", "Volume (Ocean)": "15.91K", @@ -102,8 +102,8 @@ "Addr": "0xfa6...b08dd", "Base Token": "LTC", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "1h", + "Source": "Binance", + "Timeframe": "1h", "Avg Accuracy": "50.0%", "Avg Stake Per Epoch (Ocean)": "998.29", "Volume (Ocean)": "15.97K", @@ -116,8 +116,8 @@ "Addr": "0x2d8...a3152", "Base Token": "XRP", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "1h", + "Source": "Binance", + "Timeframe": "1h", "Avg Accuracy": "50.0%", "Avg Stake Per Epoch (Ocean)": "1.02K", "Volume (Ocean)": "16.27K", @@ -130,8 +130,8 @@ "Addr": "0xa2d...a0cf0", "Base Token": "ADA", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "1h", + "Source": "Binance", + "Timeframe": "1h", "Avg Accuracy": "50.0%", "Avg Stake Per Epoch (Ocean)": "1.03K", "Volume (Ocean)": "16.49K", @@ -144,8 +144,8 @@ "Addr": "0x55c...2cedb", "Base Token": "XRP", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "5m", + "Source": "Binance", + "Timeframe": "5m", "Avg Accuracy": "49.79%", "Avg Stake Per Epoch (Ocean)": "143.39", "Volume (Ocean)": "33.7K", @@ -158,8 +158,8 @@ "Addr": "0x30f...77695", "Base Token": "ETH", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "5m", + "Source": "Binance", + "Timeframe": "5m", "Avg Accuracy": "48.94%", "Avg Stake Per Epoch (Ocean)": "159.64", "Volume (Ocean)": "37.51K", @@ -172,8 +172,8 @@ "Addr": "0x3fb...6f3bc", "Base Token": "SOL", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "5m", + "Source": "Binance", + "Timeframe": "5m", "Avg Accuracy": "49.06%", "Avg Stake Per Epoch (Ocean)": "182.83", "Volume (Ocean)": "38.76K", @@ -186,8 +186,8 @@ "Addr": "0xe66...69690", "Base Token": "BTC", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "5m", + "Source": "Binance", + "Timeframe": "5m", "Avg Accuracy": "48.09%", "Avg Stake Per Epoch (Ocean)": "168.41", "Volume (Ocean)": "39.58K", @@ -200,8 +200,8 @@ "Addr": "0xbe0...2d434", "Base Token": "DOGE", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "5m", + "Source": "Binance", + "Timeframe": "5m", "Avg Accuracy": "48.58%", "Avg Stake Per Epoch (Ocean)": "187.3", "Volume (Ocean)": "39.71K", @@ -214,8 +214,8 @@ "Addr": "0xb1c...23766", "Base Token": "LTC", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "5m", + "Source": "Binance", + "Timeframe": "5m", "Avg Accuracy": "49.06%", "Avg Stake Per Epoch (Ocean)": "192.51", "Volume (Ocean)": "40.81K", @@ -228,8 +228,8 @@ "Addr": "0xf28...70b30", "Base Token": "TRX", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "5m", + "Source": "Binance", + "Timeframe": "5m", "Avg Accuracy": "65.09%", "Avg Stake Per Epoch (Ocean)": "193.28", "Volume (Ocean)": "40.98K", @@ -242,8 +242,8 @@ "Addr": "0x9c4...07e1f", "Base Token": "DOT", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "5m", + "Source": "Binance", + "Timeframe": "5m", "Avg Accuracy": "52.36%", "Avg Stake Per Epoch (Ocean)": "195.97", "Volume (Ocean)": "41.54K", @@ -256,8 +256,8 @@ "Addr": "0x31f...ebfbd", "Base Token": "BNB", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "5m", + "Source": "Binance", + "Timeframe": "5m", "Avg Accuracy": "51.89%", "Avg Stake Per Epoch (Ocean)": "207.1", "Volume (Ocean)": "43.91K", @@ -270,8 +270,8 @@ "Addr": "0x18f...e3151", "Base Token": "ADA", "Quote Token": "USDT", - "Exchange": "Binance", - "Time": "5m", + "Source": "Binance", + "Timeframe": "5m", "Avg Accuracy": "50.47%", "Avg Stake Per Epoch (Ocean)": "207.16", "Volume (Ocean)": "43.92K", diff --git a/pdr_backend/pdr_dashboard/test/test_callbacks_feeds.py b/pdr_backend/pdr_dashboard/test/test_callbacks_feeds.py index c03f1f4cd..6ecbe4fbf 100644 --- a/pdr_backend/pdr_dashboard/test/test_callbacks_feeds.py +++ b/pdr_backend/pdr_dashboard/test/test_callbacks_feeds.py @@ -74,8 +74,8 @@ def test_feeds_table(_sample_app, dash_duo): "Addr", "Base Token", "Quote Token", - "Exchange", - "Time", + "Source", + "Timeframe", "Avg Accuracy", "Avg Stake Per Epoch (Ocean)", "Volume (Ocean)", @@ -129,8 +129,8 @@ def test_feeds_table_filters(_sample_app, dash_duo): _set_dropdown_and_verify_row_count(dash_duo, "#base_token", "ETH", 3) _verify_table_data(table, "filtered_base_token_eth.json") - # Test filtering with time - _set_dropdown_and_verify_row_count(dash_duo, "#time", "5m", 2) + # Test filtering with timeframe + _set_dropdown_and_verify_row_count(dash_duo, "#timeframe", "5m", 2) _verify_table_data(table, "filtered_base_token_eth_5m.json") _clear_feeds_filters(dash_duo) @@ -183,7 +183,7 @@ def test_feeds_table_modal(_sample_app, dash_duo): base_token = table.find_element(By.XPATH, "//tr[2]//td[3]//div").text quote_token = table.find_element(By.XPATH, "//tr[2]//td[4]//div").text timeframe = table.find_element(By.XPATH, "//tr[2]//td[6]//div").text - exchange = table.find_element(By.XPATH, "//tr[2]//td[5]//div").text + source = table.find_element(By.XPATH, "//tr[2]//td[5]//div").text dash_duo.wait_for_element("#feeds_modal", timeout=4) @@ -192,7 +192,7 @@ def test_feeds_table_modal(_sample_app, dash_duo): header_text = modal.find_element( By.XPATH, "//div[@id='feeds_modal-header']//span" ).text - assert header_text == f"{base_token}-{quote_token} {timeframe} {exchange}" + assert header_text == f"{base_token}-{quote_token} {timeframe} {source}" number_of_plots = len( modal.find_element(By.ID, "feeds_modal-body").find_elements( diff --git a/pdr_backend/pdr_dashboard/util/data.py b/pdr_backend/pdr_dashboard/util/data.py index 1cd02997f..51d09090f 100644 --- a/pdr_backend/pdr_dashboard/util/data.py +++ b/pdr_backend/pdr_dashboard/util/data.py @@ -1,11 +1,14 @@ import logging - from copy import deepcopy from datetime import datetime, timedelta -from typing import Union, List, Dict, Any, Optional -from enforce_typing import enforce_types +from typing import Union, List, Dict, Any, Optional, Tuple import dash -from pdr_backend.pdr_dashboard.util.format import pick_from_dict, format_dict +from enforce_typing import enforce_types +from pdr_backend.pdr_dashboard.util.format import ( + format_table, + pick_from_dict, + format_dict, +) logger = logging.getLogger("predictoor_dashboard_utils") @@ -128,3 +131,95 @@ def find_with_key_value( return obj return None + + +def get_feeds_stat_with_contract( + contract: str, feed_stats: List[Dict[str, Any]] +) -> Dict[str, Union[float, int]]: + result = find_with_key_value(feed_stats, "contract", contract) + + if result: + return { + "avg_accuracy": float(result["avg_accuracy"]), + "avg_stake_per_epoch_(OCEAN)": float(result["avg_stake"]), + "volume_(OCEAN)": float(result["volume"]), + } + + return { + "avg_accuracy": 0, + "avg_stake_per_epoch_(OCEAN)": 0, + "volume_(OCEAN)": 0, + } + + +def get_feeds_subscription_stat_with_contract( + contract: str, feed_subcription_stats: List[Dict[str, Any]] +) -> Dict[str, Union[float, int, str]]: + result = find_with_key_value(feed_subcription_stats, "contract", contract) + + if result: + sales_str = f"{result['sales']}" + + df_buy_count_str = ( + f"{result['df_buy_count']}-DF" if result["df_buy_count"] > 0 else "" + ) + ws_buy_count_str = ( + f"{result['ws_buy_count']}-WS" if result["ws_buy_count"] > 0 else "" + ) + + if df_buy_count_str or ws_buy_count_str: + counts_str = "_".join(filter(None, [df_buy_count_str, ws_buy_count_str])) + + if counts_str: + sales_str += f"_{counts_str}" + + return { + "price_(OCEAN)": result["price"], + "sales": sales_str, + "sales_raw": result["sales"], + "sales_revenue_(OCEAN)": result["sales_revenue"], + } + + return { + "price_(OCEAN)": 0, + "sales": 0, + "sales_raw": 0, + "sales_revenue_(OCEAN)": 0, + } + + +def get_feeds_data_for_feeds_table( + feeds_data: List[Dict[str, Any]], + feed_stats: List[Dict[str, Any]], + feed_subcription_stats: List[Dict[str, Any]], +) -> Tuple[List[Dict[str, str]], List[Dict[str, Any]], List[Dict[str, Any]]]: + + new_feed_data = [] + ## split the pair column into two columns + for feed in feeds_data: + split_pair = feed["pair"].split("/") + feed_item = {} + feed_item["addr"] = feed["contract"] + feed_item["base_token"] = split_pair[0] + feed_item["quote_token"] = split_pair[1] + feed_item["source"] = feed["source"].capitalize() + feed_item["timeframe"] = feed["timeframe"] + feed_item["full_addr"] = feed["contract"] + + result = get_feeds_stat_with_contract(feed["contract"], feed_stats) + + feed_item.update(result) + + subscription_result = get_feeds_subscription_stat_with_contract( + feed["contract"], feed_subcription_stats + ) + + feed_item.update(subscription_result) + + new_feed_data.append(feed_item) + + columns = get_feed_column_ids(new_feed_data[0]) + + formatted_data = format_table(new_feed_data, columns) + + return columns, formatted_data, new_feed_data From 02f9e088f56242292334ec55c82d6d8f1846aa46 Mon Sep 17 00:00:00 2001 From: Norbert Date: Thu, 29 Aug 2024 17:38:56 +0300 Subject: [PATCH 3/8] fix home page predictoors table filtered data --- pdr_backend/pdr_dashboard/callbacks/callbacks_home.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pdr_backend/pdr_dashboard/callbacks/callbacks_home.py b/pdr_backend/pdr_dashboard/callbacks/callbacks_home.py index 62c1d6633..e62afac73 100644 --- a/pdr_backend/pdr_dashboard/callbacks/callbacks_home.py +++ b/pdr_backend/pdr_dashboard/callbacks/callbacks_home.py @@ -9,6 +9,7 @@ get_date_period_text, get_start_date_from_period, select_or_clear_all_by_table, + get_predictoors_home_page_table_data, ) from pdr_backend.pdr_dashboard.util.format import format_value @@ -113,7 +114,7 @@ def update_predictoors_table_on_search( show_favourite_addresses, ): selected_predictoors = [predictoors_table[i] for i in selected_rows] - filtered_data = app.predictoors_data + filtered_data = get_predictoors_home_page_table_data(app.predictoors_data) if "show-favourite-addresses.value" in dash.callback_context.triggered_prop_ids: custom_predictoors = [ From 0b30f5d11d8a3eefee03e97e4150fab677b2d0d9 Mon Sep 17 00:00:00 2001 From: Norbert Date: Fri, 30 Aug 2024 13:00:31 +0300 Subject: [PATCH 4/8] fix deselect configured pdr addrs on stitch disable --- pdr_backend/pdr_dashboard/callbacks/callbacks_home.py | 7 +++++-- setup.py | 1 - 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pdr_backend/pdr_dashboard/callbacks/callbacks_home.py b/pdr_backend/pdr_dashboard/callbacks/callbacks_home.py index e62afac73..fd79b4ab0 100644 --- a/pdr_backend/pdr_dashboard/callbacks/callbacks_home.py +++ b/pdr_backend/pdr_dashboard/callbacks/callbacks_home.py @@ -113,13 +113,16 @@ def update_predictoors_table_on_search( predictoors_table, show_favourite_addresses, ): + formatted_predictoors_data = get_predictoors_home_page_table_data( + app.predictoors_data + ) selected_predictoors = [predictoors_table[i] for i in selected_rows] - filtered_data = get_predictoors_home_page_table_data(app.predictoors_data) + filtered_data = formatted_predictoors_data if "show-favourite-addresses.value" in dash.callback_context.triggered_prop_ids: custom_predictoors = [ predictoor - for predictoor in app.predictoors_data + for predictoor in formatted_predictoors_data if predictoor["user"] in app.favourite_addresses ] diff --git a/setup.py b/setup.py index 6abe7879d..e26f0fe9d 100644 --- a/setup.py +++ b/setup.py @@ -44,7 +44,6 @@ "time_machine==2.15.0", "typeguard==4.3.0", "xgboost==2.1.1", - "dash_bootstrap_components==1.6.0", "web3==6.20.2", "sapphire.py==0.2.3", "stopit==1.1.2", From 5422ab37bee80f534d18ccda64130e142245c4a1 Mon Sep 17 00:00:00 2001 From: Norbert Date: Fri, 30 Aug 2024 13:46:17 +0300 Subject: [PATCH 5/8] fix feeds modal to use new table column names --- pdr_backend/pdr_dashboard/dash_components/modal.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pdr_backend/pdr_dashboard/dash_components/modal.py b/pdr_backend/pdr_dashboard/dash_components/modal.py index 5fc0fc0a1..64b9d8b2a 100644 --- a/pdr_backend/pdr_dashboard/dash_components/modal.py +++ b/pdr_backend/pdr_dashboard/dash_components/modal.py @@ -42,7 +42,7 @@ def get_header(self) -> html.Div: elif self.modal_id == "feeds_modal": sr = self.selected_row modal_header_title = f"""{sr["base_token"]}-{sr["quote_token"]} - {sr["time"]} {sr["exchange"]} + {sr["timeframe"]} {sr["source"]} """ header = html.Div( @@ -85,10 +85,10 @@ def create_figures(self): if self.modal_id == "feeds_modal": feed = ArgFeed( - exchange=selected_row["exchange"].lower(), + exchange=selected_row["source"].lower(), signal=None, pair=f'{selected_row["base_token"]}-{selected_row["quote_token"]}', - timeframe=selected_row["time"], + timeframe=selected_row["timeframe"], contract=selected_row["full_addr"], ) From eb778543a185dfbdd0a127f391ca3eaee06783c8 Mon Sep 17 00:00:00 2001 From: Norbert Date: Fri, 30 Aug 2024 16:12:39 +0300 Subject: [PATCH 6/8] fix avg stake metric wrong format --- pdr_backend/pdr_dashboard/test/conftest.py | 2 +- pdr_backend/pdr_dashboard/test/test_util_db.py | 12 +----------- pdr_backend/pdr_dashboard/util/format.py | 3 +-- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/pdr_backend/pdr_dashboard/test/conftest.py b/pdr_backend/pdr_dashboard/test/conftest.py index 3d9415472..496ad8914 100644 --- a/pdr_backend/pdr_dashboard/test/conftest.py +++ b/pdr_backend/pdr_dashboard/test/conftest.py @@ -54,7 +54,7 @@ def sample_table_rows(): def pytest_setup_options(): options = Options() - options.add_argument("--headless") + # options.add_argument("--headless") options.add_argument("--disable-gpu") options.add_argument("--disable-search-engine-choice-screen") options.add_argument("--window-size=1920,1080") diff --git a/pdr_backend/pdr_dashboard/test/test_util_db.py b/pdr_backend/pdr_dashboard/test/test_util_db.py index ede725c2d..b6b3726a0 100644 --- a/pdr_backend/pdr_dashboard/test/test_util_db.py +++ b/pdr_backend/pdr_dashboard/test/test_util_db.py @@ -28,16 +28,6 @@ def test_get_feeds_data(_sample_app): assert len(result) == 20 -@enforce_types -def test_get_predictoors_data(_sample_app): - db_getter = _sample_app.db_getter - - result = db_getter.predictoors_data() - - assert isinstance(result, list) - assert len(result) == 57 - - def test_get_payouts( _sample_app, ): @@ -75,7 +65,7 @@ def test_get_user_payouts_stats( _sample_app, ): db_getter = _sample_app.db_getter - result = db_getter.payouts_stats() + result = db_getter.predictoor_payouts_stats() assert isinstance(result, list) assert len(result) == 57 diff --git a/pdr_backend/pdr_dashboard/util/format.py b/pdr_backend/pdr_dashboard/util/format.py index b2649c0f2..91c249ba7 100644 --- a/pdr_backend/pdr_dashboard/util/format.py +++ b/pdr_backend/pdr_dashboard/util/format.py @@ -3,7 +3,6 @@ from enforce_typing import enforce_types from numerize import numerize - FORMAT_CONFIG = { "feeds_page_Accuracy_metric": "percentage", "accuracy_metric": "percentage", @@ -11,7 +10,7 @@ "feeds_page_Revenue_metric": "currency", "feeds_page_Sales_metric": "currency_without_decimal", "profit_metric": "currency_without_decimal_with_suffix", - "stake_metric": "currency_with_decimal_and_suffix", + "stake_metric": "currency_without_decimal_with_suffix", "costs_metric": "approximate_currency_with_decimal", "addr": "eth_address", "user": "eth_address", From 35e59111ec036cd494e403b06b0000f1697bf0aa Mon Sep 17 00:00:00 2001 From: Norbert Date: Fri, 30 Aug 2024 16:47:23 +0300 Subject: [PATCH 7/8] fix format value test stake metric --- pdr_backend/pdr_dashboard/test/test_util_format.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pdr_backend/pdr_dashboard/test/test_util_format.py b/pdr_backend/pdr_dashboard/test/test_util_format.py index 5487d0059..f4cf01486 100644 --- a/pdr_backend/pdr_dashboard/test/test_util_format.py +++ b/pdr_backend/pdr_dashboard/test/test_util_format.py @@ -70,7 +70,7 @@ def test_format_value(): assert format_value(12, "feeds_page_Volume_metric") == "12 OCEAN" assert format_value(12, "feeds_page_Revenue_metric") == "12 OCEAN" assert format_value(9876.12, "profit_metric") == "9.88K OCEAN" - assert format_value(9876.12, "stake_metric") == "9876.12 OCEAN" + assert format_value(9876.12, "stake_metric") == "9.88K OCEAN" assert format_value(9876, "costs_metric") == "~9876" assert ( format_value("0x1234567890123456789012345678901234567890", "addr") From 28a2bc645fc0fc2a2c57280c0e3b1ceabe080bda Mon Sep 17 00:00:00 2001 From: Norbert Date: Mon, 2 Sep 2024 10:16:41 +0300 Subject: [PATCH 8/8] review fixes --- .../pdr_dashboard/pages/predictoors.py | 5 +- pdr_backend/pdr_dashboard/test/conftest.py | 2 +- pdr_backend/pdr_dashboard/util/data.py | 50 +++++++++---------- pdr_backend/pdr_dashboard/util/format.py | 6 ++- 4 files changed, 31 insertions(+), 32 deletions(-) diff --git a/pdr_backend/pdr_dashboard/pages/predictoors.py b/pdr_backend/pdr_dashboard/pages/predictoors.py index 5092fb1b8..d2d167372 100644 --- a/pdr_backend/pdr_dashboard/pages/predictoors.py +++ b/pdr_backend/pdr_dashboard/pages/predictoors.py @@ -88,7 +88,7 @@ def get_search_bar_row(self): def get_main_container(self): predictoor_cols, predictoor_data, raw_predictoor_data = ( - self.get_data_for_predictoors_table(self.app.predictoors_data) + self.get_data_for_predictoors_table() ) self.app.predictoor_table_data = raw_predictoor_data @@ -123,10 +123,9 @@ def get_predictoor_table_area( def get_data_for_predictoors_table( self, - predictoor_stats: List[Dict[str, Any]], ) -> Tuple[List[Dict[str, str]], List[Dict[str, Any]], List[Dict[str, Any]]]: - temp_data = predictoor_stats + temp_data = self.app.predictoors_data new_predictoor_data = [] diff --git a/pdr_backend/pdr_dashboard/test/conftest.py b/pdr_backend/pdr_dashboard/test/conftest.py index 496ad8914..3d9415472 100644 --- a/pdr_backend/pdr_dashboard/test/conftest.py +++ b/pdr_backend/pdr_dashboard/test/conftest.py @@ -54,7 +54,7 @@ def sample_table_rows(): def pytest_setup_options(): options = Options() - # options.add_argument("--headless") + options.add_argument("--headless") options.add_argument("--disable-gpu") options.add_argument("--disable-search-engine-choice-screen") options.add_argument("--window-size=1920,1080") diff --git a/pdr_backend/pdr_dashboard/util/data.py b/pdr_backend/pdr_dashboard/util/data.py index 51d09090f..a3df1fc2b 100644 --- a/pdr_backend/pdr_dashboard/util/data.py +++ b/pdr_backend/pdr_dashboard/util/data.py @@ -6,7 +6,6 @@ from enforce_typing import enforce_types from pdr_backend.pdr_dashboard.util.format import ( format_table, - pick_from_dict, format_dict, ) @@ -78,9 +77,8 @@ def get_predictoors_home_page_table_data( payout_stats = deepcopy(user_payout_stats) for data in payout_stats: formatted_data = format_dict( - pick_from_dict( - data=data, keys=["user", "total_profit", "avg_accuracy", "avg_stake"] - ) + data=data, + only_include_keys=["user", "total_profit", "avg_accuracy", "avg_stake"], ) new_data = { @@ -157,34 +155,34 @@ def get_feeds_subscription_stat_with_contract( ) -> Dict[str, Union[float, int, str]]: result = find_with_key_value(feed_subcription_stats, "contract", contract) - if result: - sales_str = f"{result['sales']}" + if not result: + return { + "price_(OCEAN)": 0, + "sales": 0, + "sales_raw": 0, + "sales_revenue_(OCEAN)": 0, + } - df_buy_count_str = ( - f"{result['df_buy_count']}-DF" if result["df_buy_count"] > 0 else "" - ) - ws_buy_count_str = ( - f"{result['ws_buy_count']}-WS" if result["ws_buy_count"] > 0 else "" - ) + sales_str = f"{result['sales']}" - if df_buy_count_str or ws_buy_count_str: - counts_str = "_".join(filter(None, [df_buy_count_str, ws_buy_count_str])) + df_buy_count_str = ( + f"{result['df_buy_count']}-DF" if result["df_buy_count"] > 0 else "" + ) + ws_buy_count_str = ( + f"{result['ws_buy_count']}-WS" if result["ws_buy_count"] > 0 else "" + ) - if counts_str: - sales_str += f"_{counts_str}" + if df_buy_count_str or ws_buy_count_str: + counts_str = "_".join(filter(None, [df_buy_count_str, ws_buy_count_str])) - return { - "price_(OCEAN)": result["price"], - "sales": sales_str, - "sales_raw": result["sales"], - "sales_revenue_(OCEAN)": result["sales_revenue"], - } + if counts_str: + sales_str += f"_{counts_str}" return { - "price_(OCEAN)": 0, - "sales": 0, - "sales_raw": 0, - "sales_revenue_(OCEAN)": 0, + "price_(OCEAN)": result["price"], + "sales": sales_str, + "sales_raw": result["sales"], + "sales_revenue_(OCEAN)": result["sales_revenue"], } diff --git a/pdr_backend/pdr_dashboard/util/format.py b/pdr_backend/pdr_dashboard/util/format.py index 91c249ba7..7d6fb065e 100644 --- a/pdr_backend/pdr_dashboard/util/format.py +++ b/pdr_backend/pdr_dashboard/util/format.py @@ -48,7 +48,9 @@ def pick_from_dict(data: Dict[str, Any], keys: List[str]) -> Dict[str, Any]: @enforce_types -def format_dict(data: Dict[str, Union[int, float, str]]) -> dict[str, str]: +def format_dict( + data: Dict[str, Union[int, float, str]], only_include_keys: List[str] +) -> dict[str, str]: """ Format dictionary. Args: @@ -60,7 +62,7 @@ def format_dict(data: Dict[str, Union[int, float, str]]) -> dict[str, str]: key: format_value( data[key] if isinstance(data[key], str) else float(data[key]), key ) - for key in data.keys() + for key in only_include_keys }