From 171b39291d6edc97e6e98c094dc98f410f09ccc9 Mon Sep 17 00:00:00 2001 From: Mohamed Cheikh Sidiya Date: Fri, 20 Oct 2023 23:47:08 +0200 Subject: [PATCH] ~ --- playground.ipynb | 161 ++--------------------------------------------- 1 file changed, 6 insertions(+), 155 deletions(-) diff --git a/playground.ipynb b/playground.ipynb index 00d40ef..c6cffd9 100644 --- a/playground.ipynb +++ b/playground.ipynb @@ -37,7 +37,7 @@ "source": [ "import json\n", "from pathlib import Path\n", - "from typing import Callable, List\n", + "from typing import Callable\n", "\n", "import controllers.file_system as fs\n", "from models.conversation import Conversation\n", @@ -89,15 +89,13 @@ "metadata": {}, "outputs": [], "source": [ - "# function type\n", - "AttrFunc = Callable[[Conversation], int]\n", - "\n", - "\n", "# Utility function to get statistics and print conversations based on a criteria\n", - "def get_top_convos(attr_func: AttrFunc, description: str, count: int = 5) -> None:\n", + "def get_top_convos(\n", + " attr_func: Callable[[Conversation], int], description: str, count: int = 5\n", + ") -> None:\n", " \"\"\"Get statistics and save top conversations based on a criteria\"\"\"\n", "\n", - " stats: List[int] = [attr_func(c) for c in conversation_set.conversation_list]\n", + " stats: list[int] = [attr_func(c) for c in conversation_set.conversation_list]\n", " avg_stat: float = sum(stats) / len(stats)\n", " median_stat: int = sorted(stats)[len(stats) // 2]\n", " max_stat: int = max(stats)\n", @@ -221,153 +219,6 @@ "source": [ "### Graphs" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import random\n", - "import time\n", - "from collections import defaultdict\n", - "from datetime import datetime, timedelta\n", - "\n", - "import matplotlib.pyplot as plt\n", - "\n", - "\n", - "def generate_random_timestamps(start_date: str, num_days: int) -> list[float]:\n", - " \"\"\"\n", - " Generates a list of random timestamps starting from the given date and spanning the specified number of days.\n", - "\n", - " Parameters:\n", - " - start_date: Starting date in the format 'YYYY-MM-DD'.\n", - " - num_days: Number of days to span.\n", - "\n", - " Returns:\n", - " List of timestamps as floats.\n", - " \"\"\"\n", - "\n", - " current_date: datetime = datetime.strptime(start_date, \"%Y-%m-%d\")\n", - " end_date: datetime = current_date + timedelta(days=num_days)\n", - "\n", - " timestamps: list[float] = []\n", - "\n", - " while current_date < end_date:\n", - " # Generate a random number of timestamps for this day (e.g., between 1 to 10)\n", - " for _ in range(random.randint(a=1, b=10)):\n", - " # Generate a random second of the day (0 to 86399, which is 24*60*60 - 1)\n", - " random_second: int = random.randint(a=0, b=86399)\n", - " random_time: datetime = current_date + timedelta(seconds=random_second)\n", - " timestamps.append(time.mktime(random_time.timetuple()))\n", - " current_date += timedelta(days=1)\n", - "\n", - " return timestamps\n", - "\n", - "\n", - "def create_weekwise_timeseries_graph(timestamps: list[float]) -> None:\n", - " \"\"\"\n", - " Creates a week-wise timeseries graph from a list of timestamps.\n", - "\n", - " Parameters:\n", - " - timestamps: List of timestamps as floats.\n", - "\n", - " Returns:\n", - " None. Displays the plot.\n", - " \"\"\"\n", - "\n", - " dates: list[datetime] = [datetime.fromtimestamp(ts) for ts in timestamps]\n", - "\n", - " weekday_counts: defaultdict[str, int] = defaultdict(int)\n", - " days: list[str] = [\n", - " \"Monday\",\n", - " \"Tuesday\",\n", - " \"Wednesday\",\n", - " \"Thursday\",\n", - " \"Friday\",\n", - " \"Saturday\",\n", - " \"Sunday\",\n", - " ]\n", - "\n", - " for date in dates:\n", - " weekday_counts[days[date.weekday()]] += 1\n", - "\n", - " x: list[str] = days\n", - " y: list[int] = [weekday_counts[day] for day in days]\n", - "\n", - " plt.bar(x=x, height=y) # type: ignore\n", - " plt.xlabel(xlabel=\"Day of the Week\") # type: ignore\n", - " plt.ylabel(ylabel=\"Frequency\") # type: ignore\n", - " plt.title(label=\"Week-wise Frequency of Timestamps\") # type: ignore\n", - " plt.xticks(rotation=45) # type: ignore\n", - " plt.tight_layout() # type: ignore\n", - " plt.show() # type: ignore\n", - "\n", - "\n", - "timestamps: list[float] = generate_random_timestamps(\n", - " start_date=\"2023-01-01\", num_days=60\n", - ")\n", - "\n", - "\n", - "create_weekwise_timeseries_graph(timestamps=timestamps)\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def create_monthwise_timeseries_graph(timestamps: list[float]) -> None:\n", - " \"\"\"\n", - " Creates a month-wise timeseries graph from a list of timestamps.\n", - "\n", - " Parameters:\n", - " - timestamps: List of timestamps as floats.\n", - "\n", - " Returns:\n", - " None. Displays the plot.\n", - " \"\"\"\n", - "\n", - " dates: list[datetime] = [datetime.fromtimestamp(ts) for ts in timestamps]\n", - "\n", - " month_counts: defaultdict[str, int] = defaultdict(int)\n", - " months: list[str] = [\n", - " \"January\",\n", - " \"February\",\n", - " \"March\",\n", - " \"April\",\n", - " \"May\",\n", - " \"June\",\n", - " \"July\",\n", - " \"August\",\n", - " \"September\",\n", - " \"October\",\n", - " \"November\",\n", - " \"December\",\n", - " ]\n", - "\n", - " for date in dates:\n", - " month_counts[months[date.month - 1]] += 1\n", - "\n", - " x: list[str] = months\n", - " y: list[int] = [month_counts[month] for month in months]\n", - "\n", - " plt.bar(x=x, height=y) # type: ignore\n", - " plt.xlabel(xlabel=\"Month\") # type: ignore\n", - " plt.ylabel(ylabel=\"Frequency\") # type: ignore\n", - " plt.title(label=\"Month-wise Frequency of Timestamps\") # type: ignore\n", - " plt.xticks(rotation=45) # type: ignore\n", - " plt.tight_layout() # type: ignore\n", - " plt.show() # type: ignore\n", - "\n", - "\n", - "timestamps: list[float] = generate_random_timestamps(\n", - " start_date=\"2023-01-01\", num_days=365\n", - ")\n", - "\n", - "create_monthwise_timeseries_graph(timestamps=timestamps)\n" - ] } ], "metadata": { @@ -386,7 +237,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.0" + "version": "3.10.5" } }, "nbformat": 4,