Spaces:
Sleeping
Sleeping
cyberosa commited on
Commit ·
72f2521
1
Parent(s): f497c67
fix typo
Browse files- app.py +8 -3
- tabs/tokens_votes_dist.py +28 -0
app.py
CHANGED
|
@@ -5,7 +5,10 @@ import pandas as pd
|
|
| 5 |
import seaborn as sns
|
| 6 |
import duckdb
|
| 7 |
import logging
|
| 8 |
-
from tabs.tokens_votes_dist import
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
def get_logger():
|
|
@@ -48,10 +51,10 @@ def get_extreme_cases(live_fpmms: pd.DataFrame):
|
|
| 48 |
"""Function to return the id of the best and worst case according to the dist gap metric"""
|
| 49 |
# select markets with more than 1 sample
|
| 50 |
samples_per_market = (
|
| 51 |
-
live_fpmms[["id", "
|
| 52 |
)
|
| 53 |
markets_with_multiple_samples = list(
|
| 54 |
-
samples_per_market.loc[samples_per_market["
|
| 55 |
)
|
| 56 |
selected_markets = live_fpmms.loc[
|
| 57 |
live_fpmms["id"].isin(markets_with_multiple_samples)
|
|
@@ -74,6 +77,7 @@ with demo:
|
|
| 74 |
|
| 75 |
with gr.Row():
|
| 76 |
gr.Markdown("Best case: a market with a low distribution gap metric")
|
|
|
|
| 77 |
with gr.Row():
|
| 78 |
best_market_tokens_dist = get_based_tokens_distribution(
|
| 79 |
best_market_id, markets_data
|
|
@@ -81,6 +85,7 @@ with demo:
|
|
| 81 |
|
| 82 |
with gr.Row():
|
| 83 |
gr.Markdown("Worst case: a market with a high distribution gap metric")
|
|
|
|
| 84 |
|
| 85 |
with gr.Row():
|
| 86 |
worst_market_tokens_dist = get_based_tokens_distribution(
|
|
|
|
| 5 |
import seaborn as sns
|
| 6 |
import duckdb
|
| 7 |
import logging
|
| 8 |
+
from tabs.tokens_votes_dist import (
|
| 9 |
+
get_based_tokens_distribution,
|
| 10 |
+
get_based_votes_distribution,
|
| 11 |
+
)
|
| 12 |
|
| 13 |
|
| 14 |
def get_logger():
|
|
|
|
| 51 |
"""Function to return the id of the best and worst case according to the dist gap metric"""
|
| 52 |
# select markets with more than 1 sample
|
| 53 |
samples_per_market = (
|
| 54 |
+
live_fpmms[["id", "sample_timestamp"]].groupby("id").count().reset_index()
|
| 55 |
)
|
| 56 |
markets_with_multiple_samples = list(
|
| 57 |
+
samples_per_market.loc[samples_per_market["sample_timestamp"] > 1, "id"].values
|
| 58 |
)
|
| 59 |
selected_markets = live_fpmms.loc[
|
| 60 |
live_fpmms["id"].isin(markets_with_multiple_samples)
|
|
|
|
| 77 |
|
| 78 |
with gr.Row():
|
| 79 |
gr.Markdown("Best case: a market with a low distribution gap metric")
|
| 80 |
+
gr.Markdown(f"Market id = {best_market_id}")
|
| 81 |
with gr.Row():
|
| 82 |
best_market_tokens_dist = get_based_tokens_distribution(
|
| 83 |
best_market_id, markets_data
|
|
|
|
| 85 |
|
| 86 |
with gr.Row():
|
| 87 |
gr.Markdown("Worst case: a market with a high distribution gap metric")
|
| 88 |
+
gr.Markdown(f"Market id = {worst_market_id}")
|
| 89 |
|
| 90 |
with gr.Row():
|
| 91 |
worst_market_tokens_dist = get_based_tokens_distribution(
|
tabs/tokens_votes_dist.py
CHANGED
|
@@ -32,3 +32,31 @@ def get_based_tokens_distribution(market_id: str, all_markets: pd.DataFrame):
|
|
| 32 |
labels=[first_outcome, second_outcome],
|
| 33 |
)
|
| 34 |
return gr.Plot(value=ax.figure)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
labels=[first_outcome, second_outcome],
|
| 33 |
)
|
| 34 |
return gr.Plot(value=ax.figure)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def get_based_votes_distribution(market_id: str, all_markets: pd.DataFrame):
|
| 38 |
+
"""Function to paint the evolution of the probability of the outcomes based on the votes distributions over time"""
|
| 39 |
+
selected_market = all_markets.loc[all_markets["id"] == market_id]
|
| 40 |
+
ax = selected_market.plot(
|
| 41 |
+
x="sample_datetime",
|
| 42 |
+
y=["votes_first_outcome_perc", "votes_second_outcome_perc"],
|
| 43 |
+
kind="bar",
|
| 44 |
+
rot=0,
|
| 45 |
+
stacked=True,
|
| 46 |
+
)
|
| 47 |
+
# add overall title
|
| 48 |
+
plt.title(
|
| 49 |
+
"Outcomes probability over time based on votes distributions", fontsize=16
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
# add axis titles
|
| 53 |
+
plt.xlabel("Sample date")
|
| 54 |
+
plt.ylabel("Percentage")
|
| 55 |
+
first_outcome = selected_market.iloc[0].first_outcome
|
| 56 |
+
second_outcome = selected_market.iloc[0].second_outcome
|
| 57 |
+
ax.legend(
|
| 58 |
+
bbox_to_anchor=(1, 1.02),
|
| 59 |
+
loc="upper left",
|
| 60 |
+
labels=[first_outcome, second_outcome],
|
| 61 |
+
)
|
| 62 |
+
return gr.Plot(value=ax.figure)
|