added scheduling
This commit is contained in:
@@ -117,12 +117,19 @@ class ClassifiedAudio(models.Model):
|
||||
SENSOR = "sensor", _("Sensor")
|
||||
MANUAL = "manual", _("Manual report")
|
||||
|
||||
class DurationKind(models.TextChoices):
|
||||
ESTIMATED = "estimated", _("Estimated")
|
||||
MEASURED = "measured", _("Measured")
|
||||
|
||||
audio_file = models.FileField(upload_to="fireworks_audio/%Y/%m/%d", blank=True)
|
||||
sensor = models.ForeignKey(Sensor, null=True, blank=True, on_delete=models.SET_NULL, related_name="%(class)s_records")
|
||||
original_filename = models.CharField(max_length=255)
|
||||
classifier_response = models.JSONField()
|
||||
source_type = models.CharField(max_length=10, choices=SourceType.choices, default=SourceType.SENSOR)
|
||||
occurrences = models.PositiveIntegerField(default=1)
|
||||
observation_duration_minutes = models.PositiveSmallIntegerField(null=True, blank=True)
|
||||
observation_duration_kind = models.CharField(max_length=10, choices=DurationKind.choices, blank=True)
|
||||
occurrence_time_approximate = models.BooleanField(default=False)
|
||||
location = models.CharField(max_length=255, blank=True)
|
||||
latitude = models.DecimalField(max_digits=9, decimal_places=6, null=True, blank=True)
|
||||
longitude = models.DecimalField(max_digits=9, decimal_places=6, null=True, blank=True)
|
||||
@@ -154,6 +161,10 @@ class ClassifiedAudio(models.Model):
|
||||
not math.isfinite(self.direction_accuracy_degrees) or self.direction_accuracy_degrees < 0
|
||||
):
|
||||
errors["direction_accuracy_degrees"] = _("Compass accuracy must be a finite, non-negative value.")
|
||||
if self.observation_duration_minutes is not None and not 1 <= self.observation_duration_minutes <= 1440:
|
||||
errors["observation_duration_minutes"] = _("Observation duration must be between 1 and 1,440 minutes.")
|
||||
if bool(self.observation_duration_minutes) != bool(self.observation_duration_kind):
|
||||
errors["observation_duration_kind"] = _("A duration needs an estimated or measured source.")
|
||||
if errors:
|
||||
raise ValidationError(errors)
|
||||
|
||||
@@ -172,6 +183,33 @@ class ClassifiedAudio(models.Model):
|
||||
return "—"
|
||||
return f"{self.direction_degrees:g}° ({self.direction_cardinal})"
|
||||
|
||||
@property
|
||||
def is_burst(self):
|
||||
from .bursts import BURST_MIN_BANGS
|
||||
return self.occurrences >= BURST_MIN_BANGS
|
||||
|
||||
@property
|
||||
def event_kind(self):
|
||||
return "burst" if self.is_burst else "ordinary"
|
||||
|
||||
@property
|
||||
def bangs_per_15_minutes(self):
|
||||
from .bursts import burst_rate
|
||||
if not self.observation_duration_kind:
|
||||
return None
|
||||
return burst_rate(self.occurrences, self.observation_duration_minutes)
|
||||
|
||||
@property
|
||||
def burst_intensity(self):
|
||||
from .bursts import burst_intensity
|
||||
if not self.observation_duration_kind:
|
||||
return None
|
||||
return burst_intensity(self.occurrences, self.observation_duration_minutes)
|
||||
|
||||
@property
|
||||
def burst_intensity_display(self):
|
||||
return {"light": _("Light"), "moderate": _("Moderate"), "intense": _("Intense")}.get(self.burst_intensity)
|
||||
|
||||
|
||||
@property
|
||||
def predictions(self):
|
||||
@@ -229,6 +267,7 @@ class PendingEvent(ClassifiedAudio):
|
||||
@transaction.atomic
|
||||
def approve(self):
|
||||
event = Event.objects.create(
|
||||
submitted_at=self.created_at,
|
||||
audio_file=self.audio_file.name,
|
||||
sensor=self.sensor,
|
||||
captured_at=self.captured_at,
|
||||
@@ -238,6 +277,9 @@ class PendingEvent(ClassifiedAudio):
|
||||
classifier_response=self.classifier_response,
|
||||
source_type=self.source_type,
|
||||
occurrences=self.occurrences,
|
||||
observation_duration_minutes=self.observation_duration_minutes,
|
||||
observation_duration_kind=self.observation_duration_kind,
|
||||
occurrence_time_approximate=self.occurrence_time_approximate,
|
||||
location=self.location,
|
||||
latitude=self.latitude,
|
||||
longitude=self.longitude,
|
||||
@@ -261,12 +303,25 @@ class Event(ClassifiedAudio):
|
||||
"""A reviewed classification that is safe to appear in the event feed."""
|
||||
|
||||
approved_at = models.DateTimeField(auto_now_add=True)
|
||||
submitted_at = models.DateTimeField(null=True, blank=True)
|
||||
|
||||
class Meta(ClassifiedAudio.Meta):
|
||||
verbose_name = _("Event")
|
||||
verbose_name_plural = _("Events")
|
||||
|
||||
|
||||
class ManualReportRevision(models.Model):
|
||||
"""Record edits to a session-owned manual Pending report."""
|
||||
|
||||
pending_event = models.ForeignKey(PendingEvent, null=True, blank=True, on_delete=models.SET_NULL)
|
||||
original_pending_id = models.PositiveBigIntegerField()
|
||||
previous_occurrences = models.PositiveIntegerField()
|
||||
new_occurrences = models.PositiveIntegerField()
|
||||
previous_duration_minutes = models.PositiveSmallIntegerField(null=True, blank=True)
|
||||
new_duration_minutes = models.PositiveSmallIntegerField(null=True, blank=True)
|
||||
changed_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
|
||||
class SensorSubmission(models.Model):
|
||||
"""Durable idempotency receipt, retained after moderation."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user