Skip to content

Commit

Permalink
adding admin viewing of compressed spectrograms
Browse files Browse the repository at this point in the history
  • Loading branch information
BryonLewis committed May 6, 2024
1 parent 5aca13e commit abb55de
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
15 changes: 15 additions & 0 deletions bats_ai/core/admin/recording.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class RecordingAdmin(admin.ModelAdmin):
'name',
'audio_file',
'spectrogram_status',
'compressed_spectrogram_status',
'owner',
'recorded_date',
'recorded_time',
Expand Down Expand Up @@ -60,6 +61,20 @@ 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_spectrogram_change', args=(spectrogram.pk,))
description = str(spectrogram)
link = mark_safe(f'<a href="{href}">{description}</a>')
return link
return None


@admin.action(description='Compute Spectrograms')
def compute_spectrograms(self, request: HttpRequest, queryset: QuerySet):
counter = 0
Expand Down
21 changes: 21 additions & 0 deletions bats_ai/core/models/recording.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,27 @@ 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):
Expand Down
2 changes: 1 addition & 1 deletion bats_ai/core/views/guanometadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions client/src/views/Spectrogram.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,16 @@ export default defineComponent({
? await getSpectrogramCompressed(props.id)
: await getSpectrogram(props.id);
if (response.data["url"]) {
if (import.meta.env.PROD) {
const updateHost = `${window.location.protocol}//${window.location.hostname}/`;
const updatedURL = response.data["url"].replace(
"http://127.0.0.1:9000/",
updateHost
);
image.value.src = updatedURL.split("?")[0];
} else {
image.value.src = response.data['url'];
}
} else {
// TODO Error Out if there is no URL
console.error("No URL found for the spectrogram");
Expand Down

0 comments on commit abb55de

Please sign in to comment.