File size: 2,770 Bytes
35989d5
 
 
 
 
 
0f3afed
ddd4c40
35989d5
 
 
 
c9eef1d
da9a926
35989d5
df6c9e7
d125423
35989d5
 
a46bb55
 
 
35989d5
 
d125423
 
fe2933b
35989d5
 
 
 
 
 
 
72f2521
 
 
 
c9eef1d
da9a926
72f2521
d125423
72f2521
 
 
 
 
a46bb55
72f2521
 
d125423
 
fe2933b
72f2521
 
 
 
 
 
 
ddd4c40
 
 
 
 
0f3afed
 
ddd4c40
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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,
    )