|
30 | 30 | "\n", |
31 | 31 | "## Overview\n", |
32 | 32 | "\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", |
34 | 36 | "\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." |
36 | 45 | ] |
37 | 46 | }, |
38 | 47 | { |
|
50 | 59 | "outputs": [], |
51 | 60 | "source": [ |
52 | 61 | "# 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" |
56 | 63 | ] |
57 | 64 | }, |
58 | 65 | { |
|
117 | 124 | }, |
118 | 125 | "outputs": [], |
119 | 126 | "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" |
134 | 152 | ] |
135 | 153 | }, |
136 | 154 | { |
|
220 | 238 | ], |
221 | 239 | "metadata": { |
222 | 240 | "kernelspec": { |
223 | | - "display_name": "Python 3 (ipykernel)", |
| 241 | + "display_name": "iqb", |
224 | 242 | "language": "python", |
225 | 243 | "name": "python3" |
226 | 244 | }, |
|
0 commit comments