changed the contamination handling logic to also exclude contaminated pixels from the source region

This commit is contained in:
2025-06-05 13:07:33 +03:00
parent d346bbadbc
commit f680039e9a
3 changed files with 93 additions and 30 deletions

View File

@@ -11,6 +11,9 @@ from django.db import transaction
from uplim.models import Pixel
from django.db.models import Max
from tqdm import tqdm
import sys
# DEFINE BATCH SIZE AND BATCH
# **************************************************************
@@ -121,6 +124,11 @@ class Command(BaseCommand):
)
start_index = last_hpid + 1
pixels_to_insert = total_pixels - start_index
if pixels_to_insert <= 0:
self.stdout.write("All pixels have already been inserted. Exiting.")
pixel_generator = (
Pixel(
hpid=i,
@@ -133,13 +141,23 @@ class Command(BaseCommand):
)
total_inserted = start_index
pbar = tqdm(
total=pixels_to_insert,
unit="pix",
desc=f"Survey {survey_number}",
# file=sys.stdout,
)
# Process in batches
for pixel_batch in batch(pixel_generator, BATCH_SIZE):
with transaction.atomic():
Pixel.objects.bulk_create(pixel_batch)
total_inserted += len(pixel_batch)
percentage = total_inserted / total_pixels * 100
timestamp = datetime.now().strftime("%H:%M:%S")
self.stdout.write(f"[{timestamp}] {percentage:.2f}% inserted")
# total_inserted += len(pixel_batch)
# percentage = total_inserted / total_pixels * 100
# timestamp = datetime.now().strftime("%H:%M:%S")
# self.stdout.write(f"[{timestamp}] {percentage:.2f}% inserted")
pbar.update(BATCH_SIZE)
self.stdout.write(f"Inserted a total of {total_inserted} pixels.")
pbar.close()
self.stdout.write(f"Done: Inserted a total of {total_inserted} pixels.")