Skip to content

Commit

Permalink
chore: script
Browse files Browse the repository at this point in the history
  • Loading branch information
jmoreira-valory committed May 6, 2024
1 parent cafa91e commit 05974c1
Showing 1 changed file with 59 additions and 9 deletions.
68 changes: 59 additions & 9 deletions scripts/list_finalizing_markets.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,54 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#!/usr/bin/env python3\n",
"# -*- coding: utf-8 -*-\n",
"# ------------------------------------------------------------------------------\n",
"#\n",
"# Copyright 2024 Valory AG\n",
"#\n",
"# Licensed under the Apache License, Version 2.0 (the \"License\");\n",
"# you may not use this file except in compliance with the License.\n",
"# You may obtain a copy of the License at\n",
"#\n",
"# http://www.apache.org/licenses/LICENSE-2.0\n",
"#\n",
"# Unless required by applicable law or agreed to in writing, software\n",
"# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
"# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
"# See the License for the specific language governing permissions and\n",
"# limitations under the License.\n",
"#\n",
"# ------------------------------------------------------------------------------\n",
"\n",
"\"\"\"Script for analyzing market creator markets.\"\"\"\n",
"\n",
"from collections import defaultdict\n",
"from datetime import datetime, timedelta\n",
"from enum import Enum\n",
"from mech_request_utils import get_mech_requests, IPFS_ADDRESS\n",
"from scipy import stats\n",
"from string import Template\n",
"from typing import Any, Dict, Optional\n",
"from IPython.display import display, HTML\n",
"\n",
"import seaborn as sns\n",
"import dateutil.parser\n",
"import json\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import pandas as pd\n",
"import pytz\n",
"import requests\n",
"\n",
"MARKET_CREATOR_ADDRESS = \"0x89c5cc945dd550BcFfb72Fe42BfF002429F46Fec\""
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -54,8 +103,10 @@
"# Filter out outliers\n",
"mean = deliver_delay_blocks_stats[2]\n",
"std = np.sqrt(deliver_delay_blocks_stats[3])\n",
"alpha = 1\n",
"alpha = 5\n",
"deliver_delay_blocks = [td for td in deliver_delay_blocks if np.abs(td - mean) <= alpha * std]\n",
"#deliver_delay_blocks = [td for td in deliver_delay_blocks]\n",
"\n",
"\n",
"# Create histogram\n",
"plt.hist(deliver_delay_blocks, bins=100, color='blue', edgecolor='black')\n",
Expand Down Expand Up @@ -165,8 +216,8 @@
"display_latest_requests(mech_requests)\n",
"plot_latest_mech_requests_count(mech_requests)\n",
"\n",
"from_date = \"2024-01-01T00:00:00Z\"\n",
"to_date = \"2024-12-31T23:59:59Z\"\n",
"from_date = \"2024-04-01T00:00:00Z\"\n",
"to_date = \"2024-04-25T23:59:59Z\"\n",
"\n",
"from_timestamp = int(dateutil.parser.isoparse(from_date).replace(tzinfo=pytz.utc).timestamp())\n",
"to_timestamp = int(dateutil.parser.isoparse(to_date).replace(tzinfo=pytz.utc).timestamp())\n",
Expand All @@ -193,7 +244,7 @@
"from_date = \"2024-02-19T00:00:00Z\"\n",
"from_timestamp = int(dateutil.parser.isoparse(from_date).replace(tzinfo=pytz.utc).timestamp())\n",
"\n",
"plot_delivers_evolution_over_time(mech_requests, from_timestamp, weeks=9) # Plot evolution for 4 weeks\n"
"plot_delivers_evolution_over_time(mech_requests, from_timestamp, weeks=12) # Plot evolution for 4 weeks\n"
]
},
{
Expand Down Expand Up @@ -511,10 +562,6 @@
"metadata": {},
"outputs": [],
"source": [
"\n",
"from IPython.display import display, HTML\n",
"import seaborn as sns\n",
"\n",
"\n",
"def plot_opened_markets(data: Dict[str, Any]) -> None:\n",
"\n",
Expand Down Expand Up @@ -552,12 +599,15 @@
"def plot_market_state_count(df: pd.DataFrame) -> None:\n",
" state_counts = df[\"State\"].value_counts()\n",
"\n",
" print(state_counts)\n",
" # Plot pie chart\n",
" plt.figure(figsize=(8, 8))\n",
" plt.pie(state_counts, labels=state_counts.index, autopct='%1.1f%%', startangle=140)\n",
" plt.title('Market State Counts')\n",
" plt.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.\n",
"\n",
" # Display legend next to the pie chart\n",
" plt.legend(loc='center left', bbox_to_anchor=(1, 0.5), title=\"States\", fancybox=True)\n",
"\n",
" plt.show()\n",
"\n",
"\n",
Expand Down

0 comments on commit 05974c1

Please sign in to comment.