Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions back-end/controllers/database_controller/kml_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,17 @@ def add_to_db(pandaDF, kmlid, download, upload, tech, wireless, latency, categor
return True


def filter_max_service(availability_csv):
"""One BDC row per location: the fastest claim wins (download desc, then
upload desc, then low-latency first, then lowest technology code as a
deterministic tiebreak). The surviving row keeps its own values. The BDC
accepts multiple technology claims per location, so this is OPTIONAL
behavior behind the export_max_service_only site setting — default is to
report every claim."""
ordered = availability_csv.sort_values(
# BDC fixed-wireless technology codes: 70 unlicensed, 71 licensed, 72
# licensed-by-rule. The BDC rejects a filing claiming more than one of these
# at a single location, while claims across other technologies may coexist.
FIXED_WIRELESS_TECH_CODES = (70, 71, 72)


def _fastest_first(availability_csv):
"""Rank claims fastest-first: download desc, then upload desc, then
low-latency first, then lowest technology code as a deterministic
tiebreak."""
return availability_csv.sort_values(
by=[
"max_advertised_download_speed",
"max_advertised_upload_speed",
Expand All @@ -276,9 +279,31 @@ def filter_max_service(availability_csv):
ascending=[False, False, False, True],
kind="mergesort",
)


def filter_max_service(availability_csv):
"""One BDC row per location: the fastest claim wins and keeps its own
values. The BDC accepts claims under multiple technologies per location,
so this is OPTIONAL behavior behind the export_max_service_only site
setting — default is to report every claim the BDC will take (see
filter_max_fixed_wireless)."""
ordered = _fastest_first(availability_csv)
return ordered.drop_duplicates(subset=["location_id"], keep="first")


def filter_max_fixed_wireless(availability_csv):
"""At most one fixed-wireless BDC row per location: among claims with a
technology in FIXED_WIRELESS_TECH_CODES, only the fastest survives (same
ranking as filter_max_service) since the BDC rejects filings claiming two
fixed-wireless technologies at one location. Claims under other
technologies are untouched. Always applied — this is the shipped default,
not a setting."""
ordered = _fastest_first(availability_csv)
fixed_wireless = ordered[ordered["technology"].isin(FIXED_WIRELESS_TECH_CODES)]
losers = fixed_wireless.duplicated(subset=["location_id"], keep="first")
return availability_csv.drop(fixed_wireless.index[losers])


def generate_csv_data(results, provider_id, brand_name, max_service_only=False):
availability_csv = pandas.DataFrame()

Expand All @@ -294,6 +319,7 @@ def generate_csv_data(results, provider_id, brand_name, max_service_only=False):
availability_csv.drop_duplicates(
subset=["location_id", "technology"], keep="first", inplace=True
)
availability_csv = filter_max_fixed_wireless(availability_csv)
if max_service_only:
availability_csv = filter_max_service(availability_csv)
availability_csv = availability_csv[
Expand Down
7 changes: 5 additions & 2 deletions back-end/templates/admin/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ <h1>Site settings</h1>
Only report maximum service at a location
</label>
<p class="muted">When on, generated BDC reports include just the fastest claim per location
(by download, then upload) instead of every technology claim. The BDC accepts multiple
claims per location, so this is off by default.</p>
(by download, then upload) instead of a claim per technology. The BDC accepts claims under
multiple technologies per location, so this is off by default. Regardless of this setting,
fixed-wireless claims (technology codes 70/71/72) always collapse to the single fastest at
each location — the BDC rejects reports claiming more than one fixed-wireless technology
there.</p>
<button type="submit">Save</button>
</form>
{% endblock %}
46 changes: 41 additions & 5 deletions back-end/tests/test_csv_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,48 @@ def test_provider_and_brand_are_filled():
assert (df.brand_name == "Acme").all()


def test_default_reports_every_technology_claim():
"""The BDC accepts multiple technology claims per location; by default a
location under several coverages files a row per technology."""
rows = [_row(1, tech=50), _row(1, tech=70), _row(1, tech=71)]
def test_default_reports_every_technology_claim_outside_fixed_wireless():
"""The BDC accepts multiple technology claims per location as long as at
most one is fixed wireless; by default a location under several coverages
files a row per (non-conflicting) technology."""
rows = [_row(1, tech=50), _row(1, tech=10), _row(1, tech=71)]
df = generate_csv_data(rows, provider_id=330054, brand_name="Acme")
assert set(zip(df.location_id, df.technology)) == {(1, 50), (1, 70), (1, 71)}
assert set(zip(df.location_id, df.technology)) == {(1, 10), (1, 50), (1, 71)}


def test_default_collapses_fixed_wireless_to_the_fastest_claim():
"""The BDC rejects a filing that claims more than one fixed-wireless
technology (70/71/72) at a location, so by default only the fastest
fixed-wireless claim survives; claims under other technologies still file
alongside it."""
rows = [
_row(1, tech=70, dl=25, ul=3),
_row(1, tech=71, dl=100, ul=20), # fastest fixed wireless -> survives
_row(1, tech=72, dl=50, ul=10),
_row(1, tech=50, dl=1000, ul=1000), # not fixed wireless -> kept too
_row(2, tech=70, dl=25, ul=3), # sole fixed-wireless claim -> untouched
]
df = generate_csv_data(rows, provider_id=330054, brand_name="Acme")
assert set(zip(df.location_id, df.technology)) == {(1, 50), (1, 71), (2, 70)}
kept = df[(df.location_id == 1) & (df.technology == 71)].iloc[0]
assert kept.max_advertised_download_speed == 100 # the winner's own values
assert kept.max_advertised_upload_speed == 20


def test_fixed_wireless_collapse_uses_the_max_service_tiebreaks():
"""The fixed-wireless collapse ranks claims exactly like max_service_only:
download desc, then upload desc, then low-latency first, then the lowest
technology code."""
rows = [
_row(2, tech=70, dl=100, ul=50),
_row(2, tech=71, dl=100, ul=75), # same download, faster upload -> wins
_row(3, tech=72, dl=100, ul=20, latency=1), # low latency wins the tie
_row(3, tech=71, dl=100, ul=20, latency=0),
_row(4, tech=71, dl=100, ul=20),
_row(4, tech=70, dl=100, ul=20), # full tie -> lowest tech code
]
df = generate_csv_data(rows, provider_id=330054, brand_name="Acme")
assert set(zip(df.location_id, df.technology)) == {(2, 71), (3, 72), (4, 70)}


def test_max_service_only_picks_the_fastest_claim_per_location():
Expand Down
15 changes: 9 additions & 6 deletions back-end/tests/test_prod_golden_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
prod actually stored (the BDC report the provider filed).

This pins the export-layer behavior that kml_data equality cannot see. The
shipped default reports every (location, technology) claim — the BDC accepts
multiple claims per location — which matches the reference era pinned here.
(Some historical snapshots were generated with a since-retired per-location
wireless dedup; they stay in the fixture set as reference only — see
csv-golden.json. The optional export_max_service_only setting, pinned by
unit tests in test_csv_export.py, is the supported variant of that idea.)
shipped default reports every (location, technology) claim the BDC will
accept: claims under multiple technologies may coexist at a location, but at
most one fixed-wireless claim (tech 70/71/72) survives — the fastest — since
the BDC rejects filings claiming two fixed-wireless technologies at one
location. The pinned reference exports were filed under that one-fixed-
wireless-row shape. (Earlier report-every-claim-era snapshots stay in the
fixture set as reference only — see csv-golden.json. The optional
export_max_service_only setting, pinned by unit tests in test_csv_export.py,
further collapses to a single row per location.)

References: prod-extract/<export_folder>/output/prod-stored-export.csv and
prod-extract/csv-golden.json, which maps each upload folder to the stored
Expand Down
Loading