import logging from utils import measure_execution_time, DATA_DIR, TMP_DIR from profitability import ( analyse_all_traders, label_trades_by_staking, ) import pandas as pd from nr_mech_calls import ( create_unknown_traders_df, compute_daily_mech_calls, transform_to_datetime, ) from markets import check_current_week_data from staking import generate_retention_activity_file logging.basicConfig(level=logging.INFO) @measure_execution_time def prepare_live_metrics( tools_filename="new_tools.parquet", trades_filename="new_fpmmTrades.parquet" ): fpmmTrades = pd.read_parquet(TMP_DIR / trades_filename) tools = pd.read_parquet(TMP_DIR / tools_filename) # TODO if monday data of the week is missing in new_fpmmTrades then take it from the general file try: fpmmTrades["creationTimestamp"] = fpmmTrades["creationTimestamp"].apply( lambda x: transform_to_datetime(x) ) except Exception as e: print(f"Transformation not needed") # check missing data from Monday fpmmTrades = check_current_week_data(fpmmTrades) print("Computing the estimated mech calls dataset") trader_mech_calls = compute_daily_mech_calls(fpmmTrades=fpmmTrades, tools=tools) print("Analysing trades...") all_trades_df = analyse_all_traders(fpmmTrades, trader_mech_calls, daily_info=True) # staking label all_trades_df = label_trades_by_staking(all_trades_df) # create the unknown traders dataset unknown_traders_df, all_trades_df = create_unknown_traders_df( trades_df=all_trades_df ) unknown_traders_df.to_parquet( TMP_DIR / "unknown_daily_traders.parquet", index=False ) # save into a separate file all_trades_df.to_parquet(DATA_DIR / "daily_info.parquet", index=False) # prepare the retention info file generate_retention_activity_file() if __name__ == "__main__": prepare_live_metrics()