Skip to content

Commit

Permalink
~
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamed-chs committed Oct 19, 2023
1 parent 57e7033 commit ac8414a
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 1 deletion.
6 changes: 5 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ Check the `Issues` tab for bugs, enhancements, or first-timer tasks. If you have

The [Project Todo](TODO.md) and [JavaScript Todo](js/how_to_use.md#still-working-on) also offer areas needing attention.

See also a rough internal dependency graph of the project [here](assets/deps_graph.png) (the graph is not complete, but it gives a general idea of the project's structure). Generated using [pydeps](https://github.com/thebjorn/pydeps).
See also a rough internal dependency graph of the project [here](assets/deps_graph.png) (the graph is not complete, but it gives a general idea of the project's structure). Generated using :

```bash
pydeps main.py -o assets/deps_graph.png -T png --noshow --reverse --rankdir BT --exclude-exact models views controllers
```

## Documentation

Expand Down
Binary file modified assets/deps_graph.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
154 changes: 154 additions & 0 deletions playground.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,160 @@
" f\"saved to '{output_path.resolve()}'\\n\"\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"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)"
]
},
{
"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)"
]
}
],
"metadata": {
Expand Down

0 comments on commit ac8414a

Please sign in to comment.