-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add alert app and models * Add dashboard app * Add analysis * Add layers models * Add base app
- Loading branch information
1 parent
3299f49
commit b66391f
Showing
44 changed files
with
1,306 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from django.contrib import admin | ||
from .models import AlertSetting, IndicatorAlertHistory, Indicator | ||
|
||
|
||
@admin.register(AlertSetting) | ||
class AlertSettingAdmin(admin.ModelAdmin): | ||
list_display = ('name', 'enable_alert', | ||
'email_alert', 'in_app_alert', 'last_alert') | ||
list_filter = ('enable_alert', 'email_alert', | ||
'in_app_alert', 'anomaly_detection_alert') | ||
search_fields = ('name',) | ||
readonly_fields = ('created_at', 'updated_at') | ||
fieldsets = ( | ||
(None, { | ||
'fields': ('name', 'enable_alert', 'last_alert') | ||
}), | ||
('Threshold Settings', { | ||
'fields': ('threshold_comparison', | ||
'threshold_value', 'anomaly_detection_alert') | ||
}), | ||
('Notification Settings', { | ||
'fields': ('email_alert', 'in_app_alert') | ||
}), | ||
('Timestamps', { | ||
'fields': ('created_at', 'updated_at') | ||
}), | ||
('User', { | ||
'fields': ('user',) | ||
}), | ||
) | ||
|
||
|
||
@admin.register(IndicatorAlertHistory) | ||
class IndicatorAlertHistoryAdmin(admin.ModelAdmin): | ||
list_display = ('alert_setting', 'created_at', 'text') | ||
list_filter = ('created_at',) | ||
search_fields = ('alert_setting__name', 'text') | ||
readonly_fields = ('created_at',) | ||
date_hierarchy = 'created_at' | ||
|
||
|
||
@admin.register(Indicator) | ||
class IndicatorAdmin(admin.ModelAdmin): | ||
list_display = ('name',) | ||
search_fields = ('name',) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class AlertsConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'alerts' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Generated by Django 4.2.7 on 2024-11-05 16:38 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='AlertSetting', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(help_text='The name of the alert setting.', max_length=100)), | ||
('enable_alert', models.BooleanField(default=False, help_text='Indicates if the alert is enabled.')), | ||
('last_alert', models.DateTimeField(blank=True, help_text='Timestamp of the last triggered alert.', null=True)), | ||
('threshold_comparison', models.FloatField(default=0, help_text='Value for comparison to trigger an alert if exceeded.')), | ||
('threshold_value', models.FloatField(default=0, help_text='Threshold value to trigger the alert.')), | ||
('anomaly_detection_alert', models.BooleanField(default=False, help_text='Enable to trigger alerts for detected anomalies.')), | ||
('email_alert', models.BooleanField(default=False, help_text='Send alert notifications via email.')), | ||
('in_app_alert', models.BooleanField(default=False, help_text='Enable in-app alert notifications.')), | ||
('created_at', models.DateTimeField(auto_now_add=True, help_text='The date and time when this alert setting was created.')), | ||
('updated_at', models.DateTimeField(auto_now=True, help_text='The date and time when this alert setting was last updated.')), | ||
], | ||
options={ | ||
'verbose_name': 'Alert Setting', | ||
'verbose_name_plural': 'Alert Settings', | ||
'ordering': ['name'], | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='Indicator', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(help_text='The name of the indicator.', max_length=200, unique=True)), | ||
], | ||
options={ | ||
'verbose_name': 'Indicator', | ||
'verbose_name_plural': 'Indicators', | ||
'ordering': ['name'], | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='IndicatorAlertHistory', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('text', models.TextField(blank=True, help_text='The text of the indicator alert history.')), | ||
('created_at', models.DateTimeField(auto_now_add=True, help_text='The date and time when this alert history entry was created.')), | ||
('alert_setting', models.ForeignKey(help_text='The alert setting associated with this alert history.', on_delete=django.db.models.deletion.CASCADE, related_name='alert_histories', to='alerts.alertsetting')), | ||
], | ||
options={ | ||
'verbose_name': 'Indicator Alert History', | ||
'verbose_name_plural': 'Indicator Alert Histories', | ||
'ordering': ['-created_at'], | ||
}, | ||
), | ||
migrations.AddField( | ||
model_name='alertsetting', | ||
name='indicator', | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='alerts.indicator'), | ||
), | ||
migrations.AddField( | ||
model_name='alertsetting', | ||
name='user', | ||
field=models.ForeignKey(help_text='The user associated with this alert setting.', on_delete=django.db.models.deletion.CASCADE, related_name='alert_settings', to=settings.AUTH_USER_MODEL), | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
from django.db import models | ||
from django.contrib.auth.models import User | ||
|
||
|
||
class Indicator(models.Model): | ||
"""Model to represent an indicator used in analyses and alerts.""" | ||
|
||
name = models.CharField( | ||
max_length=200, | ||
unique=True, | ||
help_text='The name of the indicator.' | ||
) | ||
|
||
class Meta: | ||
"""Meta class for the Indicator model.""" | ||
|
||
verbose_name = "Indicator" | ||
verbose_name_plural = "Indicators" | ||
ordering = ['name'] | ||
|
||
def __str__(self): | ||
"""String representation of the Indicator model.""" | ||
return self.name | ||
|
||
|
||
class AlertSetting(models.Model): | ||
"""Model to define settings for alerts.""" | ||
|
||
name = models.CharField( | ||
max_length=100, | ||
help_text="The name of the alert setting." | ||
) | ||
|
||
indicator = models.ForeignKey( | ||
'Indicator', | ||
on_delete=models.CASCADE, | ||
) | ||
|
||
enable_alert = models.BooleanField( | ||
default=False, | ||
help_text="Indicates if the alert is enabled." | ||
) | ||
|
||
last_alert = models.DateTimeField( | ||
null=True, | ||
blank=True, | ||
help_text="Timestamp of the last triggered alert." | ||
) | ||
|
||
threshold_comparison = models.FloatField( | ||
default=0, | ||
help_text="Value for comparison to trigger an alert if exceeded." | ||
) | ||
|
||
threshold_value = models.FloatField( | ||
default=0, | ||
help_text="Threshold value to trigger the alert." | ||
) | ||
|
||
anomaly_detection_alert = models.BooleanField( | ||
default=False, | ||
help_text="Enable to trigger alerts for detected anomalies." | ||
) | ||
|
||
email_alert = models.BooleanField( | ||
default=False, | ||
help_text="Send alert notifications via email." | ||
) | ||
|
||
in_app_alert = models.BooleanField( | ||
default=False, | ||
help_text="Enable in-app alert notifications." | ||
) | ||
|
||
created_at = models.DateTimeField( | ||
auto_now_add=True, | ||
help_text="The date and time when this alert setting was created." | ||
) | ||
|
||
updated_at = models.DateTimeField( | ||
auto_now=True, | ||
help_text="The date and time when this alert setting was last updated." | ||
) | ||
|
||
user = models.ForeignKey( | ||
User, | ||
on_delete=models.CASCADE, | ||
related_name="alert_settings", | ||
help_text="The user associated with this alert setting." | ||
) | ||
|
||
class Meta: | ||
"""Meta class for the AlertSetting model.""" | ||
|
||
verbose_name = "Alert Setting" | ||
verbose_name_plural = "Alert Settings" | ||
ordering = ['name'] | ||
|
||
def __str__(self): | ||
"""String representation of the AlertSetting model.""" | ||
return self.name | ||
|
||
|
||
class IndicatorAlertHistory(models.Model): | ||
"""Model to store the history of alerts for a specific indicator.""" | ||
|
||
text = models.TextField( | ||
blank=True, | ||
help_text='The text of the indicator alert history.' | ||
) | ||
|
||
alert_setting = models.ForeignKey( | ||
'AlertSetting', | ||
on_delete=models.CASCADE, | ||
related_name='alert_histories', | ||
help_text='The alert setting associated with this alert history.' | ||
) | ||
|
||
created_at = models.DateTimeField( | ||
auto_now_add=True, | ||
help_text=( | ||
'The date and time when this alert ' | ||
'history entry was created.' | ||
) | ||
) | ||
|
||
class Meta: | ||
"""Meta class for the IndicatorAlertHistory model.""" | ||
|
||
verbose_name = "Indicator Alert History" | ||
verbose_name_plural = "Indicator Alert Histories" | ||
ordering = ['-created_at'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase # noqa: F401 | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Create your views here. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
from django.contrib import admin | ||
from django.contrib.gis.admin import OSMGeoAdmin | ||
from .models import Analysis, InterventionArea | ||
|
||
|
||
@admin.register(Analysis) | ||
class AnalysisAdmin(OSMGeoAdmin): | ||
list_display = ( | ||
'uuid', 'analysis_type', 'indicator', 'intervention_area', | ||
'temporal_resolution', 'created_at', 'updated_at') | ||
list_filter = ( | ||
'analysis_type', 'temporal_resolution', 'created_at', 'updated_at') | ||
search_fields = ('uuid', 'indicator__name', 'intervention_area__name') | ||
readonly_fields = ('created_at', 'updated_at') | ||
|
||
fieldsets = ( | ||
(None, { | ||
'fields': ('analysis_type', 'indicator', 'intervention_area') | ||
}), | ||
('Resolution & Period', { | ||
'fields': ( | ||
'temporal_resolution', 'reference_period_start', | ||
'reference_period_end') | ||
}), | ||
('Spatial Data', { | ||
'fields': ('geom',), | ||
'classes': ('collapse',), | ||
}), | ||
('User Information', { | ||
'fields': ('created_by',), | ||
}), | ||
('Timestamps', { | ||
'fields': ('created_at', 'updated_at') | ||
}), | ||
) | ||
|
||
map_template = 'gis/admin/osm.html' | ||
default_lon = 0 | ||
default_lat = 0 | ||
default_zoom = 2 | ||
|
||
|
||
@admin.register(InterventionArea) | ||
class InterventionAreaAdmin(OSMGeoAdmin): | ||
list_display = ('name', 'created_at', 'updated_at') | ||
search_fields = ('name',) | ||
readonly_fields = ('created_at', 'updated_at') | ||
list_filter = ('created_at', 'updated_at') | ||
|
||
fieldsets = ( | ||
(None, { | ||
'fields': ('name',) | ||
}), | ||
('Spatial Data', { | ||
'fields': ('geom',), | ||
'classes': ('collapse',), | ||
}), | ||
('Timestamps', { | ||
'fields': ('created_at', 'updated_at') | ||
}), | ||
) | ||
|
||
map_template = 'gis/admin/osm.html' | ||
default_lon = 0 | ||
default_lat = 0 | ||
default_zoom = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class AnalysisConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'analysis' |
Oops, something went wrong.