Created
November 14, 2017 22:00
-
-
Save sebabouche/e44602927c9f6bdb3dd32ea359a301ad to your computer and use it in GitHub Desktop.
Batch update a big query based on total and batch quantity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
# from b_estimates.models import BEstimate | |
# | |
# be_list = BEstimate.objects.all() | |
be_list = list(range(4934)) | |
# total_count = be_list.count() | |
total_count = 4934 | |
batch_count = 500 | |
iterations = math.ceil(total_count / batch_count) | |
for i in list(range(iterations)): | |
start = i * batch_count | |
if (i == iterations - 1): | |
end = start + total_count % batch_count | |
else: | |
end = (i + 1) * batch_count - 1 | |
print(start, end) | |
# batch = be_list[i * batch_count] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment