Skip to content

Commit

Permalink
Cleaned up logic around network-postfix such that we can use PPSS onc…
Browse files Browse the repository at this point in the history
…e we complete #446
  • Loading branch information
idiom-bytes committed Dec 14, 2023
1 parent 82c79d6 commit a5d7e84
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 36 deletions.
16 changes: 4 additions & 12 deletions pdr_backend/data_eng/gql_data_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
)

from pdr_backend.util.subgraph_predictions import (
get_sapphire_postfix,
get_all_contract_ids_by_owner,
)

Expand All @@ -37,27 +38,18 @@ class GQLDataFactory:
def __init__(self, ppss: PPSS):
self.ppss = ppss

# TO DO: Solve duplicates from subgraph.
# Method 1: Cull anything returned outside st_ut, fin_ut
self.debug_duplicate = False

# TO DO: This code has DRY problems. Reduce.
# get network
if "main" in self.ppss.web3_pp.network:
network = "mainnet"
elif "test" in self.ppss.web3_pp.network:
network = "testnet"
else:
raise ValueError(self.ppss.web3_pp.network)


network = get_sapphire_postfix(ppss.web3_pp.network)

# filter by feed contract address
contract_list = get_all_contract_ids_by_owner(
owner_address=self.ppss.web3_pp.owner_addrs,
network=network,
)
contract_list = [f.lower() for f in contract_list]

# TO-DO: Roll into yaml config
self.record_config = {
"pdr_predictions": {
"fetch_fn": get_pdr_predictions_df,
Expand Down
9 changes: 2 additions & 7 deletions pdr_backend/data_eng/table_pdr_predictions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from polars import Utf8, Int64, Float64, Boolean

from pdr_backend.util.subgraph_predictions import (
get_sapphire_postfix,
fetch_filtered_predictions,
FilterMode,
)
Expand Down Expand Up @@ -59,13 +60,7 @@ def get_pdr_predictions_df(
Update function for graphql query, returns raw data
+ Transforms ts into ms as required for data factory
"""
# TO DO: This code has DRY problems. Reduce.
if "main" in network:
network = "mainnet"
elif "test" in network:
network = "testnet"
else:
raise ValueError(network)
network = get_sapphire_postfix(network)

# fetch predictions
predictions = fetch_filtered_predictions(
Expand Down
11 changes: 2 additions & 9 deletions pdr_backend/util/get_predictions_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pdr_backend.util.csvs import save_analysis_csv
from pdr_backend.util.predictoor_stats import get_cli_statistics
from pdr_backend.util.subgraph_predictions import (
get_sapphire_postfix,
get_all_contract_ids_by_owner,
fetch_filtered_predictions,
FilterMode,
Expand All @@ -21,15 +22,7 @@ def get_predictions_info_main(
end_timestr: str,
pq_dir: str,
):
# get network
# TO DO: This code has DRY problems. Reduce.
if "main" in ppss.web3_pp.network:
network = "mainnet"
elif "test" in ppss.web3_pp.network:
network = "testnet"
else:
raise ValueError(ppss.web3_pp.network)

network = get_sapphire_postfix(ppss.web3_pp.network)
start_ut: int = ms_to_seconds(timestr_to_ut(start_timestr))
end_ut: int = ms_to_seconds(timestr_to_ut(end_timestr))

Expand Down
10 changes: 2 additions & 8 deletions pdr_backend/util/get_predictoors_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pdr_backend.util.csvs import save_prediction_csv
from pdr_backend.util.predictoor_stats import get_cli_statistics
from pdr_backend.util.subgraph_predictions import (
get_sapphire_postfix,
fetch_filtered_predictions,
FilterMode,
)
Expand All @@ -20,14 +21,7 @@ def get_predictoors_info_main(
end_timestr: str,
csv_output_dir: str,
):
# TO DO: This code has DRY problems. Reduce.
if "main" in ppss.web3_pp.network:
network = "mainnet"
elif "test" in ppss.web3_pp.network:
network = "testnet"
else:
raise ValueError(ppss.web3_pp.network)

network = get_sapphire_postfix(ppss.web3_pp.network)
start_ut: int = ms_to_seconds(timestr_to_ut(start_timestr))
end_ut: int = ms_to_seconds(timestr_to_ut(end_timestr))

Expand Down
17 changes: 17 additions & 0 deletions pdr_backend/util/subgraph_predictions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ class FilterMode(Enum):
CONTRACT_TS = 3


@enforce_types
def get_sapphire_postfix(network: str) -> str:
"""
Returns the sapphire postfix based on the network name
Args:
network: the network string from ppss or the full network-string
"""

if "main" in network:
return "mainnet"
elif "test" in network:
return "testnet"
else:
raise ValueError(network, "is not a valid network")


@enforce_types
def fetch_filtered_predictions(
start_ts: int,
Expand Down

0 comments on commit a5d7e84

Please sign in to comment.