-
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...
- 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.
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.
alert_system/etl/base/extraction.py
Outdated
| current_payload = filters.copy() if filters else None | ||
|
|
||
| while current_url: | ||
| response = httpx.get(current_url, params=current_payload, timeout=30) |
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 instead of hard code timeout value, would be nice to pass it in the arg with default val of 30.
| "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.
| # NOTE: This logic might change in future | ||
| def compute_people_exposed(self, metadata_list) -> int: | ||
| for data in metadata_list: | ||
| if data["category"] == "people" and data["type"] == "affected_total": |
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 instead of hard coding the types, can we make use of Enums ?
| return { | ||
| "severity_unit": "", | ||
| "severity_label": "", | ||
| "severity_value": 0, |
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 The severity_value: 0 carries a meaning. If the hazard_item is not present, can we use None or do it differently.
| return { | ||
| "severity_unit": detail.get("severity_unit", ""), | ||
| "severity_label": detail.get("severity_label", ""), | ||
| "severity_value": detail.get("severity_value", 0), |
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 The severity_value: 0 carries a meaning. If the hazard_item is not present, can we use None or do it differently.
| return { | ||
| "severity_unit": "", | ||
| "severity_label": "", | ||
| "severity_value": 0, |
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 check the comment above
- 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.
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.