Skip to content

Commit 31911ee

Browse files
committed
Add sample_category (primary/replacement) to ODK pixel entity export
Pixels with replacement_for set are exported with sample_category "replacement", others as "primary".
1 parent 8f727c1 commit 31911ee

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

truecover-backend/temporal/activities/entity_export.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ async def fetch_pixel_coverage_activity(
8383
p.latitude,
8484
p.longitude,
8585
p.adm4_pcode,
86-
pc.rounds
86+
pc.rounds,
87+
(pc.replacement_for IS NOT NULL) AS is_replacement
8788
FROM coverage_pixel pc
8889
JOIN pixels p ON p.quadkey = pc.quadkey
8990
WHERE pc.campaign_id = %s
@@ -94,14 +95,15 @@ async def fetch_pixel_coverage_activity(
9495

9596
pixels = []
9697
for row in cursor.fetchall():
97-
pixel_id, quadkey, latitude, longitude, adm4_pcode, rounds = row
98+
pixel_id, quadkey, latitude, longitude, adm4_pcode, rounds, is_replacement = row
9899
pixels.append({
99100
'id': str(pixel_id),
100101
'quadkey': quadkey,
101102
'latitude': float(latitude) if latitude else None,
102103
'longitude': float(longitude) if longitude else None,
103104
'adm4_pcode': adm4_pcode or '',
104-
'rounds': rounds or []
105+
'rounds': rounds or [],
106+
'is_replacement': is_replacement
105107
})
106108

107109
return pixels
@@ -233,14 +235,23 @@ async def create_odk_entity_activity(
233235
geometry = f"{entity_data['latitude']} {entity_data['longitude']} 0 0"
234236
details = entity_data['adm4_pcode']
235237

238+
# Determine sample category for pixels (primary vs replacement)
239+
sample_category = None
240+
if entity_type == 'pixel':
241+
sample_category = 'replacement' if entity_data.get('is_replacement') else 'primary'
242+
236243
# Build entity payload
244+
entity_data_payload = {
245+
'geometry': geometry,
246+
'status': 'not_visited',
247+
'details': details
248+
}
249+
if sample_category:
250+
entity_data_payload['sample_category'] = sample_category
251+
237252
entity_payload = {
238253
'label': label,
239-
'data': {
240-
'geometry': geometry,
241-
'status': 'not_visited',
242-
'details': details
243-
}
254+
'data': entity_data_payload
244255
}
245256

246257
# Make POST request to Ona API

0 commit comments

Comments
 (0)