Skip to content

Commit

Permalink
Make the batch robust against differnet sorting of keys
Browse files Browse the repository at this point in the history
  • Loading branch information
hellais committed Nov 20, 2023
1 parent ca20afa commit 9b8f594
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions oonidata/workers/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,12 @@ def make_cc_batches(
cc_batches = []
current_cc_batch_size = 0
current_cc_batch = []
while cnt_by_cc:
cnt_by_cc_sorted = sorted(cnt_by_cc.items(), key=lambda x: x[0])
while cnt_by_cc_sorted:
while current_cc_batch_size <= max_obs_per_batch:
try:
cc, cnt = cnt_by_cc.popitem()
except KeyError:
cc, cnt = cnt_by_cc_sorted.pop()
except IndexError:
break
current_cc_batch.append(cc)
current_cc_batch_size += cnt
Expand Down

0 comments on commit 9b8f594

Please sign in to comment.