-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
902 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from datetime import datetime, timedelta | ||
from zoneinfo import ZoneInfo | ||
|
||
import streamlit as st | ||
|
||
from prediction_market_agent_tooling.markets.manifold import get_authenticated_user | ||
from prediction_market_agent_tooling.monitor.markets.manifold import ( | ||
DeployedManifoldAgent, | ||
) | ||
from prediction_market_agent_tooling.monitor.monitor import monitor_agent | ||
|
||
if __name__ == "__main__": | ||
start_time = datetime.now() - timedelta(weeks=1) | ||
agent = DeployedManifoldAgent( | ||
name="foo", | ||
start_time=start_time.astimezone(ZoneInfo("UTC")), | ||
manifold_user_id=get_authenticated_user().id, | ||
) | ||
st.set_page_config(layout="wide") # Best viewed with a wide screen | ||
st.title(f"Monitoring Agent: '{agent.name}'") | ||
monitor_agent(agent) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
prediction_market_agent_tooling/monitor/markets/manifold.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from prediction_market_agent_tooling.markets.data_models import ResolvedBet | ||
from prediction_market_agent_tooling.markets.manifold import ( | ||
get_resolved_manifold_bets, | ||
manifold_to_generic_resolved_bet, | ||
) | ||
from prediction_market_agent_tooling.monitor.monitor import DeployedAgent | ||
|
||
|
||
class DeployedManifoldAgent(DeployedAgent): | ||
manifold_user_id: str | ||
|
||
def get_resolved_bets(self) -> list[ResolvedBet]: | ||
manifold_bets = get_resolved_manifold_bets( | ||
user_id=self.manifold_user_id, | ||
start_time=self.start_time, | ||
end_time=None, | ||
) | ||
return [manifold_to_generic_resolved_bet(b) for b in manifold_bets] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import typing as t | ||
from datetime import datetime | ||
|
||
import altair as alt | ||
import pandas as pd | ||
import streamlit as st | ||
from pydantic import BaseModel | ||
|
||
from prediction_market_agent_tooling.markets.data_models import ResolvedBet | ||
|
||
|
||
class DeployedAgent(BaseModel): | ||
name: str | ||
start_time: datetime = datetime.utcnow() | ||
end_time: t.Optional[datetime] = None | ||
|
||
def get_resolved_bets(self) -> list[ResolvedBet]: | ||
raise NotImplementedError("Subclasses must implement this method.") | ||
|
||
|
||
def monitor_agent(agent: DeployedAgent) -> None: | ||
agent_bets = agent.get_resolved_bets() | ||
bets_info = { | ||
"Market Question": [bet.market_question for bet in agent_bets], | ||
"Bet Amount": [bet.amount.amount for bet in agent_bets], | ||
"Bet Outcome": [bet.outcome for bet in agent_bets], | ||
"Created Time": [bet.created_time for bet in agent_bets], | ||
"Resolved Time": [bet.resolved_time for bet in agent_bets], | ||
"Is Correct": [bet.is_correct for bet in agent_bets], | ||
"Profit": [bet.profit.amount for bet in agent_bets], | ||
} | ||
bets_df = pd.DataFrame(bets_info).sort_values(by="Resolved Time") | ||
|
||
# Metrics | ||
col1, col2 = st.columns(2) | ||
col1.metric(label="Number of bets", value=f"{len(agent_bets)}") | ||
col2.metric(label="% Correct", value=f"{100 * bets_df['Is Correct'].mean():.2f}%") | ||
|
||
# Chart of cumulative profit per day | ||
profit_info = { | ||
"Time": bets_df["Resolved Time"], | ||
"Cumulative Profit": bets_df["Profit"].astype(float), | ||
} | ||
profit_df = pd.DataFrame(profit_info) | ||
profit_df["Date"] = pd.to_datetime(profit_df["Time"].dt.date) | ||
profit_df = ( | ||
profit_df.groupby("Date")["Cumulative Profit"].sum().cumsum().reset_index() | ||
) | ||
profit_df["Cumulative Profit"] = profit_df["Cumulative Profit"].astype(float) | ||
st.empty() | ||
st.altair_chart( | ||
alt.Chart(profit_df) | ||
.mark_line() | ||
.encode( | ||
x=alt.X("Date", axis=alt.Axis(format="%Y-%m-%d"), title=None), | ||
y=alt.Y("Cumulative Profit", axis=alt.Axis(format=".2f")), | ||
) | ||
.interactive(), | ||
use_container_width=True, | ||
) | ||
|
||
# Table of resolved bets | ||
st.empty() | ||
st.subheader("Resolved Bet History") | ||
st.table(bets_df) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters