-
Notifications
You must be signed in to change notification settings - Fork 7
Feat/alert system #2599
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: project/alert-system-workflow
Are you sure you want to change the base?
Feat/alert system #2599
Conversation
3fa8ab2 to
9fd5372
Compare
susilnem
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor changes...
susilnem
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small changes!
sudip-khanal
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor changes
susilnem
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have any analytics on usage and memory consumption?
Has any profiling been done so far?
alert_system/tasks.py
Outdated
| go_event_ids = list( | ||
| Event.objects.filter(field_reports__num_affected__gte=item.total_people_exposed, dtype=connector.dtype) | ||
| .values_list("id", flat=True) | ||
| .distinct() | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
N+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
N+M+1
alert_system/tasks.py
Outdated
| .distinct() | ||
| ) | ||
|
|
||
| item.related_go_events = go_event_ids |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check if we have instead use M2M
Use bulk insert to add M2M (Use ignore existing)
alert_system/etl/base/loader.py
Outdated
| ) | ||
|
|
||
| action = "Created" if created else "Updated" | ||
| logger.info(f"{action} Event for correlation_id={correlation_id}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| logger.info(f"{action} Event for correlation_id={correlation_id}") | |
| logger.info(f"{action} Event for {correlation_id=}") |
| event_collection_type = gdacs_flood_config.event_collection_type | ||
| hazard_collection_type = getattr(gdacs_flood_config, "hazard_collection_type", None) | ||
| impact_collection_type = getattr(gdacs_flood_config, "impact_collection_type", None) | ||
| filter_event = getattr(gdacs_flood_config, "filter_event", None) | ||
| transformer_class = GdacsTransformer | ||
| loader_class = GdacsLoader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can replace all this with a single typed dict...
c4d7b89 to
fcc9bdd
Compare
alert_system/etl/base/extraction.py
Outdated
| def _hazard_filter(self, unit: str, value: int) -> str: | ||
| return f"monty:hazard_detail.severity_unit = '{unit}' AND " f"monty:hazard_detail.severity_value >= {value}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sandeshit To verify: unit and value mayn't exist in all the source items. Handle it if it is None or NaN.
| "event_collection_type": "gdacs-events", | ||
| "hazard_collection_type": "gdacs-hazards", | ||
| "impact_collection_type": "gdacs-impacts", | ||
| "filter_event": {"hazard_codes": ["FL", "MH0600", "nat-hyd-flo-flo"]}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sandeshit can we handle multiple set of same/similar hazards? Example: FL is a general one for Flood but there are other types of Flood as well like Flash Flood etc. What if we want to handle different sets of similar hazard types. Might need to discuss.
d71e1d0 to
7dc5624
Compare
- Nested extraction with correlation id as fliter. - Self retry with exponential backoff. - Different models for Hazards and Impacts.
This commit splits the data extraction, transform and load part. The filtration part is also included in the load part.
- Added category and type enum. - Alter people and building exposed fallback to None. - Add polling start date and lookback weeks field in Connector. - Squash Migrations.
ad0aa8c to
13121a5
Compare
alert_system/models.py
Outdated
| class Meta: | ||
| verbose_name = _("Connector") | ||
| verbose_name_plural = _("Connectors") | ||
| ordering = ["type"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ordering = ["type"] | |
| ordering = ["id","type"] |
alert_system/helpers.py
Outdated
| connector.save(update_fields=["status", "last_success_run"] if status == Connector.Status.SUCCESS else ["status"]) | ||
|
|
||
|
|
||
| def get_connector_processor(connector_id: int): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this section to model.py
alert_system/helpers.py
Outdated
| from alert_system.models import Connector | ||
|
|
||
|
|
||
| def set_connector_status(connector, status): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one too
alert_system/tasks.py
Outdated
| processor, connector = get_connector_processor(connector_id) | ||
|
|
||
| try: | ||
| set_connector_status(connector, Connector.Status.RUNNING) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| set_connector_status(connector, Connector.Status.RUNNING) | |
| connector.set_connector_status(Connector.Status.RUNNING) |
| SOURCE_TYPE = Connector.ConnectorType.GDACS_CYCLONE | ||
|
|
||
| def handle(self, *args, **options): | ||
| self.stdout.write("Starting extraction task...") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| self.stdout.write("Starting extraction task...") | |
| self.stdout.write("Starting extraction task for SOURCE_TYPE.label ...") |
- Remove mappings.py. - Move connector registry inside connector model. - Rename variables in tasks.py.
Changes
Checklist
Things that should succeed before merging.
Release
If there is a version update, make sure to tag the repository with the latest version.