Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer announced suburbs that have not been updated in 30 days #227

Merged
merged 2 commits into from
Aug 7, 2023
Merged
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
22 changes: 16 additions & 6 deletions code/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,35 @@ def select_suburb(target_suburb: str, target_state: str) -> Generator[tuple[str,
target_state = target_state.upper()
for suburb in all_suburbs[target_state]:
if suburb.name == target_suburb:
# print(0, suburb.name.upper(), target_state)
yield suburb.name.upper(), target_state
return

# 1. find suburbs that have not been processed
# TODO: prefer announced suburbs
for state, suburb_list in all_suburbs.items():
for suburb in suburb_list:
if suburb.processed_date is None:
# print(1, suburb.name.upper(), state)
yield suburb.name.upper(), state

# 2. find suburbs for reprocessing, ordered by oldest processed date (they should be unique)
# 2. find announced suburbs that have not been updated in 30 days
cutoff_date = datetime.now() - timedelta(days=30)
announced_by_date = {}
for state, suburb_list in all_suburbs.items():
for s in suburb_list:
if s.processed_date is not None and s.announced and s.processed_date < cutoff_date:
announced_by_date[s.processed_date] = (s.name.upper(), state)
for processed_date in sorted(announced_by_date):
yield announced_by_date[processed_date]

# 3. find suburbs for reprocessing
# TODO: prefer suburbs with closer announced dates
by_date = {}
for state, suburb_list in all_suburbs.items():
by_date |= {s.processed_date: (s.name.upper(), state) for s in suburb_list if s.processed_date}
by_date |= {
s.processed_date: (s.name.upper(), state)
for s in suburb_list
if s.processed_date and s.processed_date not in announced_by_date
}
for processed_date in sorted(by_date):
# print(2, by_date[processed_date], processed_date)
yield by_date[processed_date]


Expand Down