import pandas as pd import gradio as gr import matplotlib.pyplot as plt import seaborn as sns from seaborn import FacetGrid import plotly.express as px from datetime import datetime, UTC, date from typing import Tuple def get_based_tokens_distribution(market_id: str, all_markets: pd.DataFrame): """Function to paint the evolution of the probability of the outcomes based on the tokens distributions over time""" sns.set_style("darkgrid") plt.rcParams["figure.figsize"] = (10, 5) selected_market = all_markets.loc[all_markets["id"] == market_id] ax = selected_market.plot.barh( x="sample_datetime", y=["first_token_perc", "second_token_perc"], stacked=True ) # add overall title # plt.title( # "Outcomes probability over time based on tokens distributions", fontsize=8 # ) # add axis titles plt.xlabel("Probability percentage(%)") plt.ylabel("Sample date") plt.yticks(fontsize=8) first_outcome = selected_market.iloc[0].first_outcome second_outcome = selected_market.iloc[0].second_outcome ax.legend( loc="upper left", labels=[first_outcome, second_outcome], ) return gr.Plot(value=ax.figure) def get_based_votes_distribution(market_id: str, all_markets: pd.DataFrame): """Function to paint the evolution of the probability of the outcomes based on the votes distributions over time""" sns.set_style("darkgrid") plt.rcParams["figure.figsize"] = (10, 5) selected_market = all_markets.loc[all_markets["id"] == market_id] ax = selected_market.plot.barh( x="sample_datetime", y=["votes_first_outcome_perc", "votes_second_outcome_perc"], stacked=True, ) # add overall title # plt.title("Outcomes probability over time based on votes distributions", fontsize=8) # add axis titles plt.xlabel("Probability percentage(%)") plt.ylabel("Sample date") plt.yticks(fontsize=8) first_outcome = selected_market.iloc[0].first_outcome second_outcome = selected_market.iloc[0].second_outcome ax.legend( loc="upper left", labels=[first_outcome, second_outcome], ) return gr.Plot(value=ax.figure) def get_extreme_cases(live_fpmms: pd.DataFrame) -> Tuple: """Function to return the id of the best and worst case according to the dist gap metric""" # select markets with some trades selected_markets = live_fpmms.loc[(live_fpmms["total_trades"] > 0)] print(selected_markets.head()) selected_markets.sort_values(by="dist_gap_perc", ascending=False, inplace=True) return ( selected_markets.iloc[-1].id, selected_markets.iloc[-1].dist_gap_perc, selected_markets.iloc[0].id, selected_markets.iloc[0].dist_gap_perc, )