mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-12 13:29:04 +00:00
Batches never split a postcode 🟩
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
80c474b37b
commit
2dd948259f
1 changed files with 15 additions and 1 deletions
|
|
@ -16,4 +16,18 @@ def pack_postcode_batches(
|
|||
"""Pack *properties* into batches of ~*batch_size*, never splitting a
|
||||
postcode across batches. A single postcode larger than *batch_size*
|
||||
becomes its own oversized batch."""
|
||||
raise NotImplementedError
|
||||
groups: dict[str, list[FilteredProperty]] = {}
|
||||
for prop in properties:
|
||||
groups.setdefault(prop.postcode or "", []).append(prop)
|
||||
|
||||
batches: list[list[FilteredProperty]] = []
|
||||
current: list[FilteredProperty] = []
|
||||
for group in groups.values():
|
||||
if current and len(current) + len(group) > batch_size:
|
||||
batches.append(current)
|
||||
current = list(group)
|
||||
else:
|
||||
current.extend(group)
|
||||
if current:
|
||||
batches.append(current)
|
||||
return batches
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue