-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcompressed_spectrogram.py
More file actions
44 lines (36 loc) · 1.86 KB
/
compressed_spectrogram.py
File metadata and controls
44 lines (36 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from __future__ import annotations
from django.contrib.contenttypes.fields import GenericRelation
from django.contrib.postgres.fields import ArrayField
from django.core.files.storage import default_storage
from django.db import models
from django_extensions.db.models import TimeStampedModel
from .recording import Recording
from .spectrogram import Spectrogram
from .spectrogram_image import SpectrogramImage
# TimeStampedModel also provides "created" and "modified" fields
class CompressedSpectrogram(TimeStampedModel, models.Model):
recording = models.ForeignKey(Recording, on_delete=models.CASCADE)
spectrogram = models.ForeignKey(Spectrogram, on_delete=models.CASCADE)
length = models.FloatField()
images = GenericRelation(SpectrogramImage)
starts = ArrayField(ArrayField(models.FloatField()))
stops = ArrayField(ArrayField(models.FloatField()))
widths = ArrayField(ArrayField(models.FloatField()))
cache_invalidated = models.BooleanField(default=True)
def __str__(self):
return f"CompressedSpectrogram {self.pk} (recording={self.recording_id})"
@property
def image_url_list(self):
"""Ordered list of image URLs for this spectrogram."""
images = self.images.filter(type="compressed").order_by("index")
return [default_storage.url(img.image_file.name) for img in images]
@property
def mask_url_list(self):
"""Ordered list of mask image URLs for this spectrogram."""
images = self.images.filter(type="masks").order_by("index")
return [default_storage.url(img.image_file.name) for img in images]
@property
def waveplot_url_list(self):
"""Ordered list of waveplot image URLs for this compressed spectrogram."""
images = self.images.filter(type="waveform_compressed").order_by("index")
return [default_storage.url(img.image_file.name) for img in images]