start project

This commit is contained in:
Hemmat
2026-08-07 21:17:17 +03:30
commit ea1e1eead6
121 changed files with 8108 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
"""Referrer -> domain bucketing (Chapter 08 rollup, Method A)."""
from __future__ import annotations
from urllib.parse import urlparse
def referrer_domain(referrer: str | None) -> str | None:
"""Bucket a raw referrer URL to its host, stripping a leading 'www.'.
Full-URL cardinality would make the daily rollup unbounded in row
count; domain bucketing keeps it small (Ch03's bounded-resource bias).
Empty/unparsable referrers return None and are excluded from the rollup.
"""
if not referrer:
return None
host = urlparse(referrer).netloc.lower()
if not host:
return None
return host[4:] if host.startswith("www.") else host