Skip to content

Commit 58fbbca

Browse files
Refactor Namma Metro and BMTC modules, enhance data handling
- Created a new directory structure for Namma Metro and BMTC APIs, including separate modules for handling routes and ridership. - Added a `get_ridership` function to process ridership data into a DataFrame, improving data accessibility. - Updated the CLI to create a data directory for storing fetched data, ensuring better organization. - Removed outdated and redundant code from previous modules, streamlining the codebase. - Adjusted import paths in various files to reflect the new structure, enhancing maintainability.
1 parent 672814e commit 58fbbca

File tree

20 files changed

+421
-870
lines changed

20 files changed

+421
-870
lines changed

cli.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
repo_directory = Path(get_config().nbs_path).parent
2222

23+
data_directory = repo_directory / "data"
24+
data_directory.mkdir(exist_ok=True, parents=True)
25+
2326
def bmtc_fetch_routes():
2427
data_directory = repo_directory / "data" / "bmtc"
2528
data_directory.mkdir(exist_ok=True, parents=True)
@@ -51,8 +54,6 @@ def bmtc_fetch_route_details_v2():
5154
task_fetch_route_details_v2(data_directory=data_directory)
5255

5356
def namma_metro_fetch_ridership():
54-
data_directory = repo_directory / "data" / "namma_metro"
55-
data_directory.mkdir(exist_ok=True, parents=True)
5657
task_fetch_ridership(data_directory=data_directory)
5758

5859
if __name__ == "__main__":

nbs/apis/01_app.ipynb

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "b540a574",
6+
"metadata": {},
7+
"source": [
8+
"# 01. App"
9+
]
10+
},
11+
{
12+
"cell_type": "code",
13+
"execution_count": null,
14+
"id": "d21ae074",
15+
"metadata": {},
16+
"outputs": [],
17+
"source": [
18+
"#| default_exp apis.app"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": null,
24+
"id": "40d67f82",
25+
"metadata": {},
26+
"outputs": [],
27+
"source": [
28+
"#| export\n",
29+
"from fastapi import FastAPI\n",
30+
"from traffic_data_bengaluru.apis.namma_metro import router as metro_router"
31+
]
32+
},
33+
{
34+
"cell_type": "code",
35+
"execution_count": null,
36+
"id": "dadf8b94",
37+
"metadata": {},
38+
"outputs": [],
39+
"source": [
40+
"#| export\n",
41+
"\n",
42+
"app = FastAPI(title=\"Namma Traffic API\")\n",
43+
"app.include_router(metro_router)\n",
44+
"\n",
45+
"@app.get(\"/\")\n",
46+
"def root():\n",
47+
" return {\"message\": \"Welcome to Namma Traffic API\"}"
48+
]
49+
},
50+
{
51+
"cell_type": "code",
52+
"execution_count": null,
53+
"id": "01cd2457",
54+
"metadata": {},
55+
"outputs": [],
56+
"source": [
57+
"#| hide\n",
58+
"import nbdev; nbdev.nbdev_export()"
59+
]
60+
},
61+
{
62+
"cell_type": "code",
63+
"execution_count": null,
64+
"id": "3f9cb63c",
65+
"metadata": {},
66+
"outputs": [],
67+
"source": []
68+
},
69+
{
70+
"cell_type": "code",
71+
"execution_count": null,
72+
"id": "3370acaf",
73+
"metadata": {},
74+
"outputs": [],
75+
"source": []
76+
}
77+
],
78+
"metadata": {
79+
"kernelspec": {
80+
"display_name": "python3",
81+
"language": "python",
82+
"name": "python3"
83+
}
84+
},
85+
"nbformat": 4,
86+
"nbformat_minor": 5
87+
}

nbs/apis/02_namma_metro.ipynb

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "5b52711b",
6+
"metadata": {},
7+
"source": [
8+
"# 2. Namma Metro"
9+
]
10+
},
11+
{
12+
"cell_type": "code",
13+
"execution_count": null,
14+
"id": "2e24890a",
15+
"metadata": {},
16+
"outputs": [],
17+
"source": [
18+
"%load_ext autoreload\n",
19+
"%autoreload 2"
20+
]
21+
},
22+
{
23+
"cell_type": "code",
24+
"execution_count": null,
25+
"id": "6ad6d63e",
26+
"metadata": {},
27+
"outputs": [],
28+
"source": [
29+
"#| default_exp apis.namma_metro"
30+
]
31+
},
32+
{
33+
"cell_type": "code",
34+
"execution_count": null,
35+
"id": "b191de42",
36+
"metadata": {},
37+
"outputs": [],
38+
"source": [
39+
"#| hide\n",
40+
"\n",
41+
"from nbdev.showdoc import *"
42+
]
43+
},
44+
{
45+
"cell_type": "code",
46+
"execution_count": null,
47+
"id": "57c15550",
48+
"metadata": {},
49+
"outputs": [],
50+
"source": [
51+
"#| export\n",
52+
"from fastapi import APIRouter\n",
53+
"from fastapi import FastAPI\n",
54+
"\n",
55+
"from traffic_data_bengaluru.utils import *\n",
56+
"from traffic_data_bengaluru.namma_metro.ridership import get_ridership"
57+
]
58+
},
59+
{
60+
"cell_type": "code",
61+
"execution_count": null,
62+
"id": "f1104113",
63+
"metadata": {},
64+
"outputs": [],
65+
"source": [
66+
"#| export\n",
67+
"router = APIRouter(prefix=\"/metro\", tags=[\"Namma Metro\"])\n",
68+
"\n",
69+
"@router.get(\"/ridership\")\n",
70+
"def ridership():\n",
71+
" data_directory = get_data_directory()\n",
72+
" return get_ridership(data_directory)"
73+
]
74+
},
75+
{
76+
"cell_type": "code",
77+
"execution_count": null,
78+
"id": "527a3c31",
79+
"metadata": {},
80+
"outputs": [],
81+
"source": []
82+
},
83+
{
84+
"cell_type": "code",
85+
"execution_count": null,
86+
"id": "891958e8",
87+
"metadata": {},
88+
"outputs": [],
89+
"source": [
90+
"#| hide\n",
91+
"import nbdev; nbdev.nbdev_export()"
92+
]
93+
},
94+
{
95+
"cell_type": "code",
96+
"execution_count": null,
97+
"id": "5dd9646f",
98+
"metadata": {},
99+
"outputs": [],
100+
"source": []
101+
}
102+
],
103+
"metadata": {
104+
"kernelspec": {
105+
"display_name": "python3",
106+
"language": "python",
107+
"name": "python3"
108+
}
109+
},
110+
"nbformat": 4,
111+
"nbformat_minor": 5
112+
}

nbs/bmtc/02_route_points.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"from nbdev.config import get_config\n",
6262
"\n",
6363
"from traffic_data_bengaluru.utils import *\n",
64-
"from traffic_data_bengaluru.bmtc.apis.routes import get_routes"
64+
"from traffic_data_bengaluru.bmtc.routes import get_routes"
6565
]
6666
},
6767
{

nbs/index.ipynb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
{
22
"cells": [
3-
{
4-
"cell_type": "code",
5-
"execution_count": null,
6-
"metadata": {},
7-
"outputs": [],
8-
"source": [
9-
"#| hide\n",
10-
"from traffic_data_bengaluru.core import *"
11-
]
12-
},
133
{
144
"cell_type": "code",
155
"execution_count": null,

0 commit comments

Comments
 (0)