Skip to content

Commit

Permalink
Adding new subdivision or plat alternatename re-saves all matching zo…
Browse files Browse the repository at this point in the history
…oniverse subjects.
  • Loading branch information
mikejcorey committed Nov 15, 2023
1 parent d2f5425 commit 67492c6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 8 additions & 1 deletion apps/plat/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ def save(self, *args, **kwargs):
))
ParcelJoinCandidate.objects.bulk_create(join_cands, batch_size=5000)

print(self.alternate_name)
for z in ZooniverseSubject.objects.filter(workflow=self.workflow, addition_final__iexact=self.alternate_name):
# print(z.pk, z.addition_final)
z.save()


class Subdivision(models.Model):
'''This is presumed to be a modern Subdivision GIS layer (as opposed to a plat map), but there may be other uses'''
Expand Down Expand Up @@ -135,6 +140,7 @@ def save(self, *args, **kwargs):
self.name_standardized = self.standardize_addition(
self.name)


class SubdivisionAlternateName(models.Model):
workflow = models.ForeignKey(
'zoon.ZooniverseWorkflow', null=True, on_delete=models.SET_NULL)
Expand Down Expand Up @@ -195,7 +201,8 @@ def save(self, *args, **kwargs):
ParcelJoinCandidate.objects.bulk_create(join_cands, batch_size=5000)

# Re-save all zooniverse subjects with this alternate name
# TODO: Do this in a more bulky way
print(self.alternate_name)
for z in ZooniverseSubject.objects.filter(workflow=self.workflow, addition_final=self.alternate_name):
for z in ZooniverseSubject.objects.filter(workflow=self.workflow, addition_final__iexact=self.alternate_name):
# print(z.pk, z.addition_final)
z.save()
4 changes: 3 additions & 1 deletion apps/zoon/management/commands/load_zooniverse_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ def consolidate_responses(self, workflow, question_lookup: dict):
lambda x: json.dumps(x))

# S3 lookups, not image links
subject_df['image_ids'] = subject_df['subject_data_flat__image_ids'].apply(lambda x: json.dumps(split(x)))
# TODO: Not sure what is up with the split here -- in Anoka County, early data comes back as a single string.
# Might be error in building of Zooniverse manifest, or might be early data only, as this got changed later.
subject_df['image_ids'] = subject_df['subject_data_flat__image_ids'].apply(lambda x: json.dumps(x.split(',') if x is not None else ''))

subject_df.drop(columns=['subject_data_flat__image_ids'], inplace=True)
subject_df.drop(columns=image_cols, inplace=True)
Expand Down

0 comments on commit 67492c6

Please sign in to comment.