Skip to content

Commit

Permalink
Move and rename utils (#467)
Browse files Browse the repository at this point in the history
* Move and rename utils
  • Loading branch information
calina-c authored Dec 20, 2023
1 parent 80e9fb6 commit b5496c6
Show file tree
Hide file tree
Showing 136 changed files with 633 additions and 369 deletions.
2 changes: 1 addition & 1 deletion pdr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

from pdr_backend.util import cli_module
from pdr_backend.cli import cli_module

if __name__ == "__main__":
cli_module._do_main()
9 changes: 6 additions & 3 deletions pdr_backend/accuracy/app.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import threading
import json
import threading
from datetime import datetime, timedelta
from typing import Tuple

from enforce_typing import enforce_types
from flask import Flask, jsonify

from pdr_backend.subgraph.subgraph_predictions import get_all_contract_ids_by_owner
from pdr_backend.subgraph.subgraph_predictions import (
fetch_contract_id_and_spe,
get_all_contract_ids_by_owner,
)
from pdr_backend.subgraph.subgraph_slot import calculate_statistics_for_all_assets
from pdr_backend.subgraph.subgraph_predictions import fetch_contract_id_and_spe

app = Flask(__name__)
JSON_FILE_PATH = "pdr_backend/accuracy/output/accuracy_data.json"
Expand Down
2 changes: 1 addition & 1 deletion pdr_backend/aimodel/test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from enforce_typing import enforce_types
import pytest
from enforce_typing import enforce_types

from pdr_backend.aimodel.aimodel_factory import AimodelFactory
from pdr_backend.ppss.aimodel_ss import AimodelSS
Expand Down
18 changes: 9 additions & 9 deletions pdr_backend/aimodel/test/test_aimodel_data_factory.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
from enforce_typing import enforce_types
import numpy as np
import pandas as pd
import polars as pl
import pytest
from enforce_typing import enforce_types

from pdr_backend.aimodel.aimodel_data_factory import AimodelDataFactory
from pdr_backend.lake.merge_df import merge_rawohlcv_dfs
from pdr_backend.lake.test.resources import (
_mergedohlcv_df_ETHUSDT,
_data_pp_ss_1feed,
BINANCE_BTC_DATA,
BINANCE_ETH_DATA,
ETHUSDT_RAWOHLCV_DFS,
KRAKEN_BTC_DATA,
KRAKEN_ETH_DATA,
_data_pp,
_data_pp_ss_1feed,
_data_ss,
_df_from_raw_data,
BINANCE_ETH_DATA,
BINANCE_BTC_DATA,
KRAKEN_ETH_DATA,
KRAKEN_BTC_DATA,
ETHUSDT_RAWOHLCV_DFS,
_mergedohlcv_df_ETHUSDT,
)
from pdr_backend.ppss.data_pp import DataPP
from pdr_backend.ppss.data_ss import DataSS
from pdr_backend.util.mathutil import has_nan, fill_nans
from pdr_backend.util.mathutil import fill_nans, has_nan


@enforce_types
Expand Down
2 changes: 1 addition & 1 deletion pdr_backend/aimodel/test/test_aimodel_factory.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import warnings

from enforce_typing import enforce_types
import numpy as np
from enforce_typing import enforce_types

from pdr_backend.aimodel.aimodel_factory import AimodelFactory
from pdr_backend.ppss.aimodel_ss import APPROACHES, AimodelSS
Expand Down
8 changes: 4 additions & 4 deletions pdr_backend/analytics/check_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@

from enforce_typing import enforce_types

from pdr_backend.models.token import Token
from pdr_backend.contract.token import Token
from pdr_backend.ppss.ppss import PPSS
from pdr_backend.subgraph.core_subgraph import query_subgraph
from pdr_backend.subgraph.subgraph_consume_so_far import get_consume_so_far_per_contract
from pdr_backend.util.constants import S_PER_DAY, S_PER_WEEK
from pdr_backend.util.constants_opf_addrs import get_opf_addresses
from pdr_backend.util.contract import get_address
from pdr_backend.util.mathutil import from_wei
from pdr_backend.util.timeframestr import s_to_timeframe_str
from pdr_backend.util.timeutil import current_ut
from pdr_backend.subgraph.core_subgraph import query_subgraph
from pdr_backend.subgraph.subgraph_consume_so_far import get_consume_so_far_per_contract

_N_FEEDS = 20 # magic number alert. FIX ME, shouldn't be hardcoded

Expand Down Expand Up @@ -128,7 +128,7 @@ def check_network_main(ppss: PPSS, lookback_hours: int):
}
}
secondsPerEpoch
}
}
}
""" % (
cur_ut,
Expand Down
10 changes: 5 additions & 5 deletions pdr_backend/analytics/get_predictions_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

from enforce_typing import enforce_types

from pdr_backend.ppss.ppss import PPSS
from pdr_backend.util.csvs import save_analysis_csv
from pdr_backend.util.networkutil import get_sapphire_postfix
from pdr_backend.analytics.predictoor_stats import get_cli_statistics
from pdr_backend.ppss.ppss import PPSS
from pdr_backend.subgraph.subgraph_predictions import (
get_all_contract_ids_by_owner,
fetch_filtered_predictions,
FilterMode,
fetch_filtered_predictions,
get_all_contract_ids_by_owner,
)
from pdr_backend.util.csvs import save_analysis_csv
from pdr_backend.util.networkutil import get_sapphire_postfix
from pdr_backend.util.timeutil import ms_to_seconds, timestr_to_ut


Expand Down
8 changes: 4 additions & 4 deletions pdr_backend/analytics/get_predictoors_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

from enforce_typing import enforce_types

from pdr_backend.ppss.ppss import PPSS
from pdr_backend.util.csvs import save_prediction_csv
from pdr_backend.util.networkutil import get_sapphire_postfix
from pdr_backend.analytics.predictoor_stats import get_cli_statistics
from pdr_backend.ppss.ppss import PPSS
from pdr_backend.subgraph.subgraph_predictions import (
fetch_filtered_predictions,
FilterMode,
fetch_filtered_predictions,
)
from pdr_backend.util.csvs import save_prediction_csv
from pdr_backend.util.networkutil import get_sapphire_postfix
from pdr_backend.util.timeutil import ms_to_seconds, timestr_to_ut


Expand Down
7 changes: 4 additions & 3 deletions pdr_backend/analytics/get_traction_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
"""

from enforce_typing import enforce_types
from pdr_backend.ppss.ppss import PPSS

from pdr_backend.analytics.predictoor_stats import (
get_traction_statistics,
get_slot_statistics,
get_traction_statistics,
plot_slot_daily_statistics,
plot_traction_cum_sum_statistics,
plot_traction_daily_statistics,
plot_slot_daily_statistics,
)
from pdr_backend.lake.gql_data_factory import GQLDataFactory
from pdr_backend.ppss.ppss import PPSS


@enforce_types
Expand Down
6 changes: 3 additions & 3 deletions pdr_backend/analytics/predictoor_stats.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import os
from typing import List, Dict, Tuple, TypedDict, Set
from enforce_typing import enforce_types
from typing import Dict, List, Set, Tuple, TypedDict

import matplotlib.pyplot as plt
import polars as pl
from enforce_typing import enforce_types

from pdr_backend.models.prediction import Prediction
from pdr_backend.contract.prediction import Prediction
from pdr_backend.util.csvs import get_plots_dir


Expand Down
4 changes: 2 additions & 2 deletions pdr_backend/analytics/test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import pytest

from pdr_backend.models.prediction import (
from pdr_backend.contract.prediction import (
mock_daily_predictions,
mock_first_predictions,
mock_second_predictions,
mock_daily_predictions,
)


Expand Down
5 changes: 2 additions & 3 deletions pdr_backend/analytics/test/test_check_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@

from enforce_typing import enforce_types

from pdr_backend.util.constants import S_PER_DAY, S_PER_WEEK
from pdr_backend.analytics.check_network import (
_N_FEEDS,
check_dfbuyer,
check_network_main,
get_expected_consume,
_N_FEEDS,
)
from pdr_backend.ppss.ppss import mock_ppss
from pdr_backend.ppss.web3_pp import del_network_override
from pdr_backend.util.constants import S_PER_DAY, S_PER_WEEK
from pdr_backend.util.mathutil import to_wei


PATH = "pdr_backend.analytics.check_network"

MOCK_CUR_UT = 1702826080982
Expand Down
2 changes: 1 addition & 1 deletion pdr_backend/analytics/test/test_get_predictions_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from enforce_typing import enforce_types

from pdr_backend.analytics.get_predictions_info import get_predictions_info_main
from pdr_backend.ppss.ppss import mock_ppss
from pdr_backend.ppss.web3_pp import del_network_override
from pdr_backend.analytics.get_predictions_info import get_predictions_info_main
from pdr_backend.subgraph.subgraph_predictions import FilterMode


Expand Down
2 changes: 1 addition & 1 deletion pdr_backend/analytics/test/test_get_predictoors_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from enforce_typing import enforce_types

from pdr_backend.analytics.get_predictoors_info import get_predictoors_info_main
from pdr_backend.ppss.ppss import mock_ppss
from pdr_backend.ppss.web3_pp import del_network_override
from pdr_backend.analytics.get_predictoors_info import get_predictoors_info_main
from pdr_backend.subgraph.subgraph_predictions import FilterMode


Expand Down
4 changes: 2 additions & 2 deletions pdr_backend/analytics/test/test_get_traction_info.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from unittest.mock import Mock, patch

from enforce_typing import enforce_types
import polars as pl
from enforce_typing import enforce_types

from pdr_backend.analytics.get_traction_info import get_traction_info_main
from pdr_backend.ppss.ppss import mock_ppss
from pdr_backend.ppss.web3_pp import del_network_override
from pdr_backend.analytics.get_traction_info import get_traction_info_main
from pdr_backend.subgraph.subgraph_predictions import FilterMode
from pdr_backend.util.timeutil import timestr_to_ut

Expand Down
12 changes: 6 additions & 6 deletions pdr_backend/analytics/test/test_predictoor_stats.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
from typing import List
from unittest.mock import patch

from enforce_typing import enforce_types
import polars as pl
from enforce_typing import enforce_types

from pdr_backend.analytics.predictoor_stats import (
aggregate_prediction_statistics,
get_endpoint_statistics,
calculate_slot_daily_statistics,
get_cli_statistics,
get_traction_statistics,
get_endpoint_statistics,
get_slot_statistics,
calculate_slot_daily_statistics,
plot_traction_daily_statistics,
plot_traction_cum_sum_statistics,
get_traction_statistics,
plot_slot_daily_statistics,
plot_traction_cum_sum_statistics,
plot_traction_daily_statistics,
)


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Utilities for all feeds from binance etc.
Used as inputs for models, and for predicing.
Complementary to models/feed.py which models a prediction feed contract.
Complementary to subgraph/subgraph_feed.py which models a prediction feed contract.
"""

from typing import List, Set
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
from argparse import ArgumentParser as ArgParser
from argparse import Namespace
import sys

from enforce_typing import enforce_types

Expand Down
40 changes: 19 additions & 21 deletions pdr_backend/util/cli_module.py → pdr_backend/cli/cli_module.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,40 @@
import sys

from enforce_typing import enforce_types
from pdr_backend.dfbuyer.dfbuyer_agent import DFBuyerAgent

from pdr_backend.ppss.ppss import PPSS
from pdr_backend.publisher.publish_assets import publish_assets
from pdr_backend.sim.sim_engine import SimEngine
from pdr_backend.payout.payout import do_ocean_payout, do_rose_payout
from pdr_backend.predictoor.approach1.predictoor_agent1 import PredictoorAgent1
from pdr_backend.predictoor.approach3.predictoor_agent3 import PredictoorAgent3
from pdr_backend.trader.approach1.trader_agent1 import TraderAgent1
from pdr_backend.trader.approach2.trader_agent2 import TraderAgent2
from pdr_backend.trueval.trueval_agent import TruevalAgent
from pdr_backend.analytics.check_network import check_network_main
from pdr_backend.util.fund_accounts import fund_accounts_with_OCEAN

from pdr_backend.util.cli_arguments import (
from pdr_backend.analytics.get_predictions_info import get_predictions_info_main
from pdr_backend.analytics.get_predictoors_info import get_predictoors_info_main
from pdr_backend.analytics.get_traction_info import get_traction_info_main
from pdr_backend.cli.cli_arguments import (
CheckNetworkArgParser,
ClaimOceanArgParser,
ClaimRoseArgParser,
CheckNetworkArgParser,
DfbuyerArgParser,
do_help_long,
GetPredictoorsInfoArgParser,
GetPredictionsInfoArgParser,
GetPredictoorsInfoArgParser,
GetTractionInfoArgParser,
PredictoorArgParser,
print_args,
PublisherArgParser,
SimArgParser,
TopupArgParser,
TraderArgParser,
TruevalArgParser,
do_help_long,
print_args,
)

from pdr_backend.dfbuyer.dfbuyer_agent import DFBuyerAgent
from pdr_backend.payout.payout import do_ocean_payout, do_rose_payout
from pdr_backend.ppss.ppss import PPSS
from pdr_backend.predictoor.approach1.predictoor_agent1 import PredictoorAgent1
from pdr_backend.predictoor.approach3.predictoor_agent3 import PredictoorAgent3
from pdr_backend.publisher.publish_assets import publish_assets
from pdr_backend.sim.sim_engine import SimEngine
from pdr_backend.trader.approach1.trader_agent1 import TraderAgent1
from pdr_backend.trader.approach2.trader_agent2 import TraderAgent2
from pdr_backend.trueval.trueval_agent import TruevalAgent
from pdr_backend.util.contract import get_address
from pdr_backend.analytics.get_predictions_info import get_predictions_info_main
from pdr_backend.analytics.get_predictoors_info import get_predictoors_info_main
from pdr_backend.analytics.get_traction_info import get_traction_info_main
from pdr_backend.util.fund_accounts import fund_accounts_with_OCEAN
from pdr_backend.util.topup import topup_main


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from enforce_typing import enforce_types

from pdr_backend.util.feedstr import ArgFeed, ArgFeeds
from pdr_backend.cli.arg_feed import ArgFeed, ArgFeeds


@enforce_types
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from unittest.mock import Mock
import os

from argparse import Namespace
from unittest.mock import Mock

from enforce_typing import enforce_types

from pdr_backend.ppss.ppss import PPSS
from pdr_backend.util.cli_module import (
from pdr_backend.cli.cli_module import (
do_check_network,
do_claim_OCEAN,
do_claim_ROSE,
Expand All @@ -19,6 +18,7 @@
do_trader,
do_trueval,
)
from pdr_backend.ppss.ppss import PPSS


class _APPROACH:
Expand Down Expand Up @@ -125,7 +125,7 @@ def run(self, *args, **kwargs): # pylint: disable=unused-argument
self.__class__.was_run = True


_CLI_PATH = "pdr_backend.util.cli_module"
_CLI_PATH = "pdr_backend.cli.cli_module"


@enforce_types
Expand Down
Loading

0 comments on commit b5496c6

Please sign in to comment.