Skip to content
Closed
Changes from 2 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
29 changes: 18 additions & 11 deletions uk_bin_collection/uk_bin_collection/councils/BolsoverCouncil.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,20 @@ def is_within_green_sus(dtDay0, greenSusStart, greenSusEnd):
WeekBlack = rows_data["WeekBlack"]
WeekBandG = rows_data["WeekBandG"]

def determine_bin_collection(week_number, txtBlack, txtBurgGreen, week_in_sus):
# WeekBlack/WeekBandG aren't booleans - they hold "1" or "2" to
# say which of the two alternating weeks (odd/even relative to
# week1) that stream is collected on. Round A addresses have
# WeekBlack == "1"; Round B addresses have WeekBlack == "2"
# (and WeekBandG the complementary value).
parity = "1" if week_number % 2 == 1 else "2"
def determine_bin_collection(collection_date, txtBlack, txtBurgGreen, week_in_sus):
# WeekBlack/WeekBandG hold "1" or "2" to say which of the two
# alternating weeks a bin stream is collected on. The original
# code used the *positional* week index (1-4) to derive parity,
# but that index is relative to the scraper's "next occurrence"
# calculation — so the same calendar date could flip between
# parity "1" and "2" depending on which day the scraper ran.
#
# Fix: derive parity from an absolute week count that stays
# stable across runs and also survives ISO week-53 year
# boundaries (where week 53 and week 1 of the next year are
# both odd, which would break a simple week % 2 approach).
iso_year, iso_week, _ = collection_date.isocalendar()
parity = "1" if (iso_year * 53 + iso_week) % 2 == 1 else "2"
Comment thread
JoeGandy marked this conversation as resolved.
Outdated

if txtBlack == parity:
return "Black Bin"
Expand All @@ -155,10 +162,10 @@ def determine_bin_collection(week_number, txtBlack, txtBurgGreen, week_in_sus):

return ""

week1Text = determine_bin_collection(1, WeekBlack, WeekBandG, week1InSus)
week2Text = determine_bin_collection(2, WeekBlack, WeekBandG, week2InSus)
week3Text = determine_bin_collection(3, WeekBlack, WeekBandG, week3InSus)
week4Text = determine_bin_collection(4, WeekBlack, WeekBandG, week4InSus)
week1Text = determine_bin_collection(week1, WeekBlack, WeekBandG, week1InSus)
week2Text = determine_bin_collection(week2, WeekBlack, WeekBandG, week2InSus)
week3Text = determine_bin_collection(week3, WeekBlack, WeekBandG, week3InSus)
week4Text = determine_bin_collection(week4, WeekBlack, WeekBandG, week4InSus)

# print(week1Text)
# print(week2Text)
Expand Down