Skip to content

Commit

Permalink
Merge pull request #10 from adybbroe/fix-output-message-type
Browse files Browse the repository at this point in the history
Fix output message
  • Loading branch information
mraspaud committed Aug 29, 2022
2 parents 4ea9441 + 4d7c6e4 commit 455af3e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
15 changes: 5 additions & 10 deletions activefires_pp/spatiotemporal_alarm_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,8 @@ def send_alarms(self, geojson_alarms, msg):
output_filename = store_geojson_alarm(self.fire_alarms_dir, p__, idx, alarm)
post_alarm(alarm, self.restapi_url)
output_message = _create_output_message(msg, self.output_topic, alarm, output_filename)
if output_message:
LOG.debug("Sending message: %s", str(output_message))
self.publisher.send(str(output_message))
else:
LOG.debug("No message to send")
LOG.debug("Sending message: %s", str(output_message))
self.publisher.send(str(output_message))

def close(self):
"""Shutdown the AlarmFilterRunner process."""
Expand Down Expand Up @@ -436,17 +433,15 @@ def check_if_fire_should_trigger_alarm(gjson_data, past_alarms_dir, sos_alarms_f
def _create_output_message(msg, topic, geojson, filename):
"""Create the output message from the input message and the geojson payload."""
to_send = msg.data.copy()
to_send.pop('file', None)
to_send.pop('uri', None)
to_send.pop('uid', None)
to_send.pop('format', None)
to_send.pop('type', None)
to_send['related_detection'] = geojson['features']['properties']['related_detection']
to_send['power'] = geojson['features']['properties']['power']
to_send['tb'] = geojson['features']['properties']['tb']
to_send['platform_name'] = geojson['features']['properties']['platform_name']
to_send['coordinates'] = geojson['features']['geometry']['coordinates']
to_send['file'] = filename.name
to_send['format'] = 'geojson'
to_send['uri'] = str(filename)
to_send.pop('uid', None)

return Message(topic, 'info', to_send)
return Message(topic, 'file', to_send)
8 changes: 5 additions & 3 deletions activefires_pp/tests/test_geojson_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,15 @@ def test_get_recent_geojson_files(fake_past_detections_dir):
pattern = "sos_{start_time:%Y%m%d_%H%M%S}_{id:d}.geojson"

recent = get_recent_geojson_files(fake_past_detections_dir, pattern, (starttime, endtime))
assert recent == ['sos_20210618_124819_0.geojson', 'sos_20210619_000651_1.geojson', 'sos_20210619_000651_0.geojson']
assert set(recent) == {'sos_20210618_124819_0.geojson', 'sos_20210619_000651_1.geojson',
'sos_20210619_000651_0.geojson'}

starttime = datetime(2021, 6, 18, 12, 0)
endtime = datetime(2021, 6, 19, 12, 0)
recent = get_recent_geojson_files(fake_past_detections_dir, pattern, (starttime, endtime))
assert recent == ['sos_20210618_124819_0.geojson', 'sos_20210619_000651_1.geojson',
'sos_20210619_000651_0.geojson', 'sos_20210619_005803_0.geojson']

assert set(recent) == {'sos_20210618_124819_0.geojson', 'sos_20210619_000651_1.geojson',
'sos_20210619_000651_0.geojson', 'sos_20210619_005803_0.geojson'}

starttime = datetime(2022, 6, 18, 12, 0)
endtime = datetime(2022, 6, 19, 12, 0)
Expand Down
1 change: 1 addition & 0 deletions activefires_pp/tests/test_messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def test_create_output_message(tmp_path):
'platform_name': 'NOAA-20',
'sensor': 'viirs',
'data_processing_level': '2',
'format': 'geojson',
'variant': 'DR',
'orig_orbit_number': 17530,
'origin': '172.29.4.164:9099',
Expand Down

0 comments on commit 455af3e

Please sign in to comment.