Skip to content

Commit b9285f0

Browse files
authored
doc(analysis): document the pandas based API (#69)
This diff refactors the analysis notebook to illustrate how a developer can obtain the data as DataFrames. It also shows how to convert the obtained DataFrames to the data format expected by the IQB calculator. The availability of DataFrames allows for additional filtering and exploration while working with the notebooks. We also document how to get additional (large) data from GitHub releases.
1 parent be27589 commit b9285f0

File tree

1 file changed

+38
-20
lines changed

1 file changed

+38
-20
lines changed

analysis/00-template.ipynb

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,18 @@
3030
"\n",
3131
"## Overview\n",
3232
"\n",
33-
"The Internet Quality Barometer (IQB) framework assesses Internet quality beyond simple speed metrics by considering multiple use cases (gaming, video streaming, etc.) and their specific network requirements.\n",
33+
"The Internet Quality Barometer (IQB) framework assesses Internet quality beyond simple speed\n",
34+
"metrics by considering multiple use cases (gaming, video streaming, etc.) and their\n",
35+
"specific network requirements.\n",
3436
"\n",
35-
"This template uses pre-cached data for the United States from October 2024."
37+
"This template uses pre-cached data included in the repository `./data` directory. You can\n",
38+
"download additional data using this command:\n",
39+
"\n",
40+
"```bash\n",
41+
"uv run ./data/ghcache.py sync\n",
42+
"```\n",
43+
"\n",
44+
"This command will download larger data files stored inside GitHub releases."
3645
]
3746
},
3847
{
@@ -50,9 +59,7 @@
5059
"outputs": [],
5160
"source": [
5261
"# Import required libraries\n",
53-
"from datetime import datetime\n",
54-
"\n",
55-
"from iqb import IQBCache, IQBCalculator"
62+
"from iqb import IQBCache, IQBCalculator, IQBDatasetGranularity"
5663
]
5764
},
5865
{
@@ -117,20 +124,31 @@
117124
},
118125
"outputs": [],
119126
"source": [
120-
"# Fetch data for US, October 2024, using 95th percentile\n",
121-
"country = \"US\"\n",
122-
"start_date = datetime(2024, 10, 1)\n",
123-
"percentile = 95\n",
124-
"\n",
125-
"data = cache.get_data(country=country, start_date=start_date, percentile=percentile)\n",
126-
"\n",
127-
"# Display the retrieved data\n",
128-
"print(f\"\\nData for {country} (October 2024, p{percentile}):\")\n",
129-
"print(\"=\" * 50)\n",
130-
"for source, metrics in data.items():\n",
131-
" print(f\"\\nSource: {source}\")\n",
132-
" for metric, value in metrics.items():\n",
133-
" print(f\" {metric}: {value}\")"
127+
"# Get cache entry for the [2024-10-01, 2024-11-01) month with country data\n",
128+
"entry = cache.get_cache_entry(\n",
129+
" start_date=\"2024-10-01\",\n",
130+
" end_date=\"2024-11-01\",\n",
131+
" granularity=IQBDatasetGranularity.COUNTRY,\n",
132+
")\n",
133+
"\n",
134+
"# Filter the M-Lab dataset to focus on the US\n",
135+
"df_pair = entry.mlab.read_data_frame_pair(country_code=\"US\")\n",
136+
"\n",
137+
"print(df_pair.download)\n",
138+
"print(df_pair.upload)\n",
139+
"\n",
140+
"# Extract the 50 percentile\n",
141+
"p50 = df_pair.to_iqb_data(percentile=50)\n",
142+
"\n",
143+
"print(p50)\n",
144+
"\n",
145+
"# Convert the p50 class to dict\n",
146+
"p50_dict = p50.to_dict()\n",
147+
"\n",
148+
"# Create data compatible with the IQB calculator\n",
149+
"data = {\"m-lab\": p50_dict}\n",
150+
"\n",
151+
"print(data)\n"
134152
]
135153
},
136154
{
@@ -220,7 +238,7 @@
220238
],
221239
"metadata": {
222240
"kernelspec": {
223-
"display_name": "Python 3 (ipykernel)",
241+
"display_name": "iqb",
224242
"language": "python",
225243
"name": "python3"
226244
},

0 commit comments

Comments
 (0)