From 05974c18e32acda6796df31b75fda4fad8cf4b69 Mon Sep 17 00:00:00 2001 From: jmoreira-valory Date: Mon, 6 May 2024 15:57:46 +0200 Subject: [PATCH] chore: script --- scripts/list_finalizing_markets.ipynb | 68 +++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 9 deletions(-) diff --git a/scripts/list_finalizing_markets.ipynb b/scripts/list_finalizing_markets.ipynb index bc7e3bb..237e775 100644 --- a/scripts/list_finalizing_markets.ipynb +++ b/scripts/list_finalizing_markets.ipynb @@ -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": {}, @@ -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", @@ -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", @@ -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" ] }, { @@ -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", @@ -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",