From d4083996802842cc96fb633ba8dddba6c223dc13 Mon Sep 17 00:00:00 2001
From: Bryon Lewis <61746913+BryonLewis@users.noreply.github.com>
Date: Tue, 29 Oct 2024 12:59:14 -0400
Subject: [PATCH] fix-presigned url (#104)
* fix-presigned url
* fix-presigned url
* adding admin viewing of compressed spectrograms
* linting
* fix compressed link
---
bats_ai/core/admin/recording.py | 14 ++++
bats_ai/core/models/recording.py | 22 ++++++
bats_ai/core/views/guanometadata.py | 2 +-
bats_ai/core/views/recording.py | 4 --
client/src/views/Spectrogram.vue | 107 ++++++++++++++++++++--------
5 files changed, 115 insertions(+), 34 deletions(-)
diff --git a/bats_ai/core/admin/recording.py b/bats_ai/core/admin/recording.py
index bb2d5d3..36bec2e 100644
--- a/bats_ai/core/admin/recording.py
+++ b/bats_ai/core/admin/recording.py
@@ -15,6 +15,7 @@ class RecordingAdmin(admin.ModelAdmin):
'name',
'audio_file',
'spectrogram_status',
+ 'compressed_spectrogram_status',
'owner',
'recorded_date',
'recorded_time',
@@ -60,6 +61,19 @@ def spectrogram_status(self, recording: Recording):
return link
return None
+ @admin.display(
+ description='Compressed Spectrogram',
+ empty_value='Not computed',
+ )
+ def compressed_spectrogram_status(self, recording: Recording):
+ if recording.has_compressed_spectrogram:
+ spectrogram = recording.compressed_spectrogram
+ href = reverse('admin:core_compressedspectrogram_change', args=(spectrogram.pk,))
+ description = str(spectrogram)
+ link = mark_safe(f'{description}')
+ return link
+ return None
+
@admin.action(description='Compute Spectrograms')
def compute_spectrograms(self, request: HttpRequest, queryset: QuerySet):
counter = 0
diff --git a/bats_ai/core/models/recording.py b/bats_ai/core/models/recording.py
index 4eb3b42..39e5bb0 100644
--- a/bats_ai/core/models/recording.py
+++ b/bats_ai/core/models/recording.py
@@ -77,6 +77,28 @@ def spectrogram(self):
return spectrogram
+ @property
+ def has_compressed_spectrogram(self):
+ return len(self.compressed_spectrograms) > 0
+
+ @property
+ def compressed_spectrograms(self):
+ from bats_ai.core.models import CompressedSpectrogram
+
+ query = CompressedSpectrogram.objects.filter(recording=self).order_by('-created')
+ return query.all()
+
+ @property
+ def compressed_spectrogram(self):
+ pass
+
+ compressed_spectrograms = self.compressed_spectrograms
+
+ assert len(compressed_spectrograms) >= 1
+ spectrogram = compressed_spectrograms[0] # most recently created
+
+ return spectrogram
+
@receiver(models.signals.pre_delete, sender=Recording)
def delete_content(sender, instance, **kwargs):
diff --git a/bats_ai/core/views/guanometadata.py b/bats_ai/core/views/guanometadata.py
index 4a1b304..add1859 100644
--- a/bats_ai/core/views/guanometadata.py
+++ b/bats_ai/core/views/guanometadata.py
@@ -45,7 +45,7 @@ def default_data(
'nabat_site_name': gfile.get('NABat|Site Name', None),
}
if (
- nabat_fields['nabat_longitude'] and nabat_fields['nabat_longitude'] > 0
+ nabat_fields['nabat_longitude'] and float(nabat_fields['nabat_longitude']) > 0
): # individuals don't put the - in the longitude
nabat_fields['nabat_longitude'] = str(float(nabat_fields['nabat_longitude']) * -1)
# Extract additional fields with conditionals
diff --git a/bats_ai/core/views/recording.py b/bats_ai/core/views/recording.py
index a56bcbb..e7c892c 100644
--- a/bats_ai/core/views/recording.py
+++ b/bats_ai/core/views/recording.py
@@ -342,10 +342,6 @@ def get_spectrogram_compressed(request: HttpRequest, id: int):
except recording.DoesNotExist:
return {'error': 'Recording does not exist'}
- with colormap():
- label, score, confs = compressed_spectrogram.predict()
- print(label, score, confs)
-
spectro_data = {
'url': compressed_spectrogram.image_url,
'spectroInfo': {
diff --git a/client/src/views/Spectrogram.vue b/client/src/views/Spectrogram.vue
index 88a3710..379d2ef 100644
--- a/client/src/views/Spectrogram.vue
+++ b/client/src/views/Spectrogram.vue
@@ -1,5 +1,13 @@