From e3024f1e57e1cbae91543dc6569b63e3af302175 Mon Sep 17 00:00:00 2001 From: Roman Dvorak Date: Sat, 30 Mar 2024 00:55:27 +0100 Subject: [PATCH] rozsireni modelu pro record --- DOSPORTAL/admin.py | 2 +- DOSPORTAL/forms.py | 8 +- DOSPORTAL/migrations/0001_initial.py | 40 +++++-- .../0002_rename_metadata_record_metadatar.py | 18 +++ DOSPORTAL/migrations/0002_spectrumdata.py | 27 ----- .../0003_rename_metadatar_record_metadata.py | 18 +++ .../migrations/0003_spectrumdata_spectrum.py | 19 ---- ...log_original_filename_alter_record_text.py | 23 ++++ ...etadata_spectrumdata_particles_and_more.py | 31 ------ .../migrations/0005_alter_record_text.py | 32 ++++++ ...05_alter_spectrumdata_metadata_and_more.py | 24 ---- .../migrations/0006_remove_record_text.py | 17 +++ ...integration_alter_spectrumdata_spectrum.py | 23 ---- DOSPORTAL/migrations/0007_record_author.py | 21 ---- DOSPORTAL/migrations/0007_record_data_file.py | 18 +++ DOSPORTAL/models.py | 68 +++++++----- DOSPORTAL/settings.py | 1 + DOSPORTAL/signals.py | 105 ++++++++++++++++-- .../templates/records/record_detail.html | 5 +- DOSPORTAL/templates/records/records_list.html | 8 +- DOSPORTAL/users/views_users.py | 2 +- DOSPORTAL/views.py | 16 +-- DOSPORTAL/views_detectors.py | 2 +- DOSPORTAL/views_record.py | 13 ++- api/serializers.py | 4 +- docker-compose.yml | 2 +- requirements.txt | 5 +- 27 files changed, 322 insertions(+), 230 deletions(-) create mode 100644 DOSPORTAL/migrations/0002_rename_metadata_record_metadatar.py delete mode 100644 DOSPORTAL/migrations/0002_spectrumdata.py create mode 100644 DOSPORTAL/migrations/0003_rename_metadatar_record_metadata.py delete mode 100644 DOSPORTAL/migrations/0003_spectrumdata_spectrum.py create mode 100644 DOSPORTAL/migrations/0004_alter_record_log_original_filename_alter_record_text.py delete mode 100644 DOSPORTAL/migrations/0004_spectrumdata_metadata_spectrumdata_particles_and_more.py create mode 100644 DOSPORTAL/migrations/0005_alter_record_text.py delete mode 100644 DOSPORTAL/migrations/0005_alter_spectrumdata_metadata_and_more.py create mode 100644 DOSPORTAL/migrations/0006_remove_record_text.py delete mode 100644 DOSPORTAL/migrations/0006_spectrumdata_integration_alter_spectrumdata_spectrum.py delete mode 100644 DOSPORTAL/migrations/0007_record_author.py create mode 100644 DOSPORTAL/migrations/0007_record_data_file.py diff --git a/DOSPORTAL/admin.py b/DOSPORTAL/admin.py index 3dde1cf..87ed70c 100644 --- a/DOSPORTAL/admin.py +++ b/DOSPORTAL/admin.py @@ -43,7 +43,7 @@ def user_count(self, obj): admin.site.register(measurement) admin.site.register(Organization, OrganizationAdmin) #admin.site.register(OrganizationUser) -admin.site.register(record) +admin.site.register(Record) admin.site.register(Detector) admin.site.register(DetectorLogbook) admin.site.register(DetectorType) diff --git a/DOSPORTAL/forms.py b/DOSPORTAL/forms.py index b1900bd..08c7f2a 100644 --- a/DOSPORTAL/forms.py +++ b/DOSPORTAL/forms.py @@ -1,5 +1,5 @@ from django import forms -from .models import Detector, record, Profile, Organization +from .models import Detector, Record, Profile, Organization from django import forms from django.contrib.auth.models import User @@ -70,7 +70,7 @@ def __init__(self,*args, user=None, **kwargs): ) record_type = forms.ChoiceField( - choices=record.RECORD_TYPES + choices=Record.RECORD_TYPES ) belongs = forms.ModelChoiceField( @@ -81,8 +81,8 @@ def __init__(self,*args, user=None, **kwargs): ) class Meta: - model = record - exclude = ("time_end", "measurement", "log_original_filename", "metadata", "duration", "time_start", "record_duration") + model = Record + exclude = ("time_end", "measurement", "log_original_filename", "metadata", "duration", "time_start", "record_duration", "author", 'data_file') class DetectorEditForm(forms.ModelForm): diff --git a/DOSPORTAL/migrations/0001_initial.py b/DOSPORTAL/migrations/0001_initial.py index b8c29e0..83d176b 100644 --- a/DOSPORTAL/migrations/0001_initial.py +++ b/DOSPORTAL/migrations/0001_initial.py @@ -1,8 +1,9 @@ -# Generated by Django 4.2.11 on 2024-03-27 09:18 +# Generated by Django 4.2.11 on 2024-03-28 14:34 import DOSPORTAL.models from django.conf import settings import django.contrib.gis.db.models.fields +import django.contrib.postgres.fields from django.db import migrations, models import django.db.models.deletion import martor.models @@ -128,6 +129,26 @@ class Migration(migrations.Migration): 'abstract': False, }, ), + migrations.CreateModel( + name='Record', + fields=[ + ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)), + ('log_file', models.FileField(blank=True, upload_to=DOSPORTAL.models.Record.user_directory_path, verbose_name='File log')), + ('log_original_filename', models.CharField()), + ('time_start', models.DateTimeField(null=True, verbose_name='Measurement beginning time')), + ('record_duration', models.DurationField(help_text='Duration of record', null=True, verbose_name='Record duration')), + ('record_type', models.CharField(choices=[('U', 'Unknown'), ('S', 'Spectral measurements'), ('E', 'Event measurements'), ('L', 'Location')], default='U', help_text='Type of log file', verbose_name='Certain record type, enum')), + ('metadata', models.JSONField(default='[{}]', help_text='record metadata, used for advanced data processing and maintaining', verbose_name='record_metadata')), + ('text', models.TextField()), + ('data_policy', models.CharField(choices=[('PR', 'Private'), ('PU', 'Public'), ('NV', 'Non-public')], default='PU', max_length=2)), + ('author', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ('belongs', models.ForeignKey(help_text='Organization, which owns this record', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='records_owning', to='DOSPORTAL.organization')), + ('detector', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='records', to='DOSPORTAL.detector')), + ], + options={ + 'abstract': False, + }, + ), migrations.CreateModel( name='Trajectory', fields=[ @@ -149,18 +170,15 @@ class Migration(migrations.Migration): ], ), migrations.CreateModel( - name='record', + name='SpectrumData', fields=[ ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)), - ('log_file', models.FileField(blank=True, upload_to=DOSPORTAL.models.record.user_directory_path, verbose_name='File log')), - ('log_original_filename', models.CharField()), - ('time_start', models.DateTimeField(null=True, verbose_name='Measurement beginning time')), - ('record_duration', models.DurationField(help_text='Duration of record', null=True, verbose_name='Record duration')), - ('record_type', models.CharField(choices=[('U', 'Unknown'), ('S', 'Spectral measurements'), ('E', 'Event measurements'), ('L', 'Location')], default='U', help_text='Type of log file', verbose_name='Certain record type, enum')), - ('metadata', models.JSONField(help_text='record metadata, used for advanced data processing and maintaining', null=True, verbose_name='record_metadata')), - ('data_policy', models.CharField(choices=[('PR', 'Private'), ('PU', 'Public'), ('NV', 'Non-public')], default='PU', max_length=2)), - ('belongs', models.ForeignKey(help_text='Organization, which owns this record', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='records_owning', to='DOSPORTAL.organization')), - ('detector', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='records', to='DOSPORTAL.detector')), + ('spectrum', django.contrib.postgres.fields.ArrayField(base_field=models.IntegerField(), blank=True, null=True, size=None)), + ('integration', models.FloatField(blank=True, help_text='Duration of last exposition', null=True, verbose_name='Integration time')), + ('particles', models.IntegerField(blank=True, help_text='Particles detected in the spectrum', null=True, verbose_name='Particles')), + ('time', models.DurationField(help_text='Time difference from the start of the measurement', null=True, verbose_name='Time difference')), + ('location', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='spectrum_data', to='DOSPORTAL.trajectorypoint')), + ('record', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='spectrum_data', to='DOSPORTAL.record', verbose_name='Record')), ], options={ 'abstract': False, diff --git a/DOSPORTAL/migrations/0002_rename_metadata_record_metadatar.py b/DOSPORTAL/migrations/0002_rename_metadata_record_metadatar.py new file mode 100644 index 0000000..cfb971b --- /dev/null +++ b/DOSPORTAL/migrations/0002_rename_metadata_record_metadatar.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.11 on 2024-03-28 17:22 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('DOSPORTAL', '0001_initial'), + ] + + operations = [ + migrations.RenameField( + model_name='record', + old_name='metadata', + new_name='metadatar', + ), + ] diff --git a/DOSPORTAL/migrations/0002_spectrumdata.py b/DOSPORTAL/migrations/0002_spectrumdata.py deleted file mode 100644 index 992d619..0000000 --- a/DOSPORTAL/migrations/0002_spectrumdata.py +++ /dev/null @@ -1,27 +0,0 @@ -# Generated by Django 4.2.11 on 2024-03-27 10:17 - -from django.db import migrations, models -import django.db.models.deletion -import uuid - - -class Migration(migrations.Migration): - - dependencies = [ - ('DOSPORTAL', '0001_initial'), - ] - - operations = [ - migrations.CreateModel( - name='SpectrumData', - fields=[ - ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)), - ('time_difference', models.DurationField(help_text='Time difference from the start of the measurement', null=True, verbose_name='Time difference')), - ('location', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='spectrum_data', to='DOSPORTAL.trajectorypoint')), - ('record', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='spectrum_data', to='DOSPORTAL.record')), - ], - options={ - 'abstract': False, - }, - ), - ] diff --git a/DOSPORTAL/migrations/0003_rename_metadatar_record_metadata.py b/DOSPORTAL/migrations/0003_rename_metadatar_record_metadata.py new file mode 100644 index 0000000..2dc15d2 --- /dev/null +++ b/DOSPORTAL/migrations/0003_rename_metadatar_record_metadata.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.11 on 2024-03-28 17:22 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('DOSPORTAL', '0002_rename_metadata_record_metadatar'), + ] + + operations = [ + migrations.RenameField( + model_name='record', + old_name='metadatar', + new_name='metadata', + ), + ] diff --git a/DOSPORTAL/migrations/0003_spectrumdata_spectrum.py b/DOSPORTAL/migrations/0003_spectrumdata_spectrum.py deleted file mode 100644 index e414b98..0000000 --- a/DOSPORTAL/migrations/0003_spectrumdata_spectrum.py +++ /dev/null @@ -1,19 +0,0 @@ -# Generated by Django 4.2.11 on 2024-03-27 10:25 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('DOSPORTAL', '0002_spectrumdata'), - ] - - operations = [ - migrations.AddField( - model_name='spectrumdata', - name='spectrum', - field=models.JSONField(default=[], help_text='Energy spectrum data as an array of integers', verbose_name='Spectrum data'), - preserve_default=False, - ), - ] diff --git a/DOSPORTAL/migrations/0004_alter_record_log_original_filename_alter_record_text.py b/DOSPORTAL/migrations/0004_alter_record_log_original_filename_alter_record_text.py new file mode 100644 index 0000000..259df0c --- /dev/null +++ b/DOSPORTAL/migrations/0004_alter_record_log_original_filename_alter_record_text.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2.11 on 2024-03-29 20:32 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('DOSPORTAL', '0003_rename_metadatar_record_metadata'), + ] + + operations = [ + migrations.AlterField( + model_name='record', + name='log_original_filename', + field=models.CharField(blank=True, max_length=150, null=True, verbose_name='Original filename of log file'), + ), + migrations.AlterField( + model_name='record', + name='text', + field=models.TextField(help_text='Text log from detector', verbose_name='Text log'), + ), + ] diff --git a/DOSPORTAL/migrations/0004_spectrumdata_metadata_spectrumdata_particles_and_more.py b/DOSPORTAL/migrations/0004_spectrumdata_metadata_spectrumdata_particles_and_more.py deleted file mode 100644 index 0b8c546..0000000 --- a/DOSPORTAL/migrations/0004_spectrumdata_metadata_spectrumdata_particles_and_more.py +++ /dev/null @@ -1,31 +0,0 @@ -# Generated by Django 4.2.11 on 2024-03-27 10:52 - -import django.contrib.postgres.fields.hstore -from django.db import migrations, models -import django.db.models.deletion -from django.contrib.postgres.operations import HStoreExtension - -class Migration(migrations.Migration): - - dependencies = [ - ('DOSPORTAL', '0003_spectrumdata_spectrum'), - ] - - operations = [ - HStoreExtension(), - migrations.AddField( - model_name='spectrumdata', - name='metadata', - field=django.contrib.postgres.fields.hstore.HStoreField(blank=True, help_text='Additional metadata for the spectrum data', null=True, verbose_name='Metadata'), - ), - migrations.AddField( - model_name='spectrumdata', - name='particles', - field=models.ImageField(blank=True, help_text='Particles detected in the spectrum', null=True, upload_to='', verbose_name='Particles'), - ), - migrations.AlterField( - model_name='spectrumdata', - name='record', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='spectrum_data', to='DOSPORTAL.record', verbose_name='Record'), - ), - ] diff --git a/DOSPORTAL/migrations/0005_alter_record_text.py b/DOSPORTAL/migrations/0005_alter_record_text.py new file mode 100644 index 0000000..e6766e6 --- /dev/null +++ b/DOSPORTAL/migrations/0005_alter_record_text.py @@ -0,0 +1,32 @@ +# Generated by Django 4.2.11 on 2024-03-29 20:33 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('DOSPORTAL', '0004_alter_record_log_original_filename_alter_record_text'), + ] + + #operations = [ + # migrations.AlterField( + # model_name='record', + # name='text', + # field=models.TextField(blank=True, help_text='Text log from detector', null=True, verbose_name='Text log'), + # ), + #] + + + operations = [ + migrations.AddField( + model_name='record', + name='text', + field=models.TextField(blank=True, null=True), + ), + migrations.AlterField( + model_name='record', + name='text', + field=models.TextField(blank=True, help_text='Text log from detector', null=True, verbose_name='Text log'), + ), + ] diff --git a/DOSPORTAL/migrations/0005_alter_spectrumdata_metadata_and_more.py b/DOSPORTAL/migrations/0005_alter_spectrumdata_metadata_and_more.py deleted file mode 100644 index fef434a..0000000 --- a/DOSPORTAL/migrations/0005_alter_spectrumdata_metadata_and_more.py +++ /dev/null @@ -1,24 +0,0 @@ -# Generated by Django 4.2.11 on 2024-03-27 10:54 - -import django.contrib.postgres.fields.hstore -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('DOSPORTAL', '0004_spectrumdata_metadata_spectrumdata_particles_and_more'), - ] - - operations = [ - migrations.AlterField( - model_name='spectrumdata', - name='metadata', - field=django.contrib.postgres.fields.hstore.HStoreField(blank=True, default={}, help_text='Additional metadata for the spectrum data', null=True, verbose_name='Metadata'), - ), - migrations.AlterField( - model_name='spectrumdata', - name='particles', - field=models.IntegerField(blank=True, help_text='Particles detected in the spectrum', null=True, verbose_name='Particles'), - ), - ] diff --git a/DOSPORTAL/migrations/0006_remove_record_text.py b/DOSPORTAL/migrations/0006_remove_record_text.py new file mode 100644 index 0000000..b325489 --- /dev/null +++ b/DOSPORTAL/migrations/0006_remove_record_text.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2.11 on 2024-03-29 20:41 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('DOSPORTAL', '0005_alter_record_text'), + ] + + operations = [ + migrations.RemoveField( + model_name='record', + name='text', + ), + ] diff --git a/DOSPORTAL/migrations/0006_spectrumdata_integration_alter_spectrumdata_spectrum.py b/DOSPORTAL/migrations/0006_spectrumdata_integration_alter_spectrumdata_spectrum.py deleted file mode 100644 index 8789e3c..0000000 --- a/DOSPORTAL/migrations/0006_spectrumdata_integration_alter_spectrumdata_spectrum.py +++ /dev/null @@ -1,23 +0,0 @@ -# Generated by Django 4.2.11 on 2024-03-27 11:02 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('DOSPORTAL', '0005_alter_spectrumdata_metadata_and_more'), - ] - - operations = [ - migrations.AddField( - model_name='spectrumdata', - name='integration', - field=models.FloatField(blank=True, help_text='Duration of last exposition', null=True, verbose_name='Integration time'), - ), - migrations.AlterField( - model_name='spectrumdata', - name='spectrum', - field=models.JSONField(default=[], help_text='Energy spectrum data as an array of integers', verbose_name='Spectrum data'), - ), - ] diff --git a/DOSPORTAL/migrations/0007_record_author.py b/DOSPORTAL/migrations/0007_record_author.py deleted file mode 100644 index 15dd3dd..0000000 --- a/DOSPORTAL/migrations/0007_record_author.py +++ /dev/null @@ -1,21 +0,0 @@ -# Generated by Django 4.2.11 on 2024-03-27 12:55 - -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ('DOSPORTAL', '0006_spectrumdata_integration_alter_spectrumdata_spectrum'), - ] - - operations = [ - migrations.AddField( - model_name='record', - name='author', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), - ), - ] diff --git a/DOSPORTAL/migrations/0007_record_data_file.py b/DOSPORTAL/migrations/0007_record_data_file.py new file mode 100644 index 0000000..0e62541 --- /dev/null +++ b/DOSPORTAL/migrations/0007_record_data_file.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.11 on 2024-03-29 21:04 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('DOSPORTAL', '0006_remove_record_text'), + ] + + operations = [ + migrations.AddField( + model_name='record', + name='data_file', + field=models.FileField(blank=True, help_text='Processed spectral file', null=True, upload_to='', verbose_name='Log file'), + ), + ] diff --git a/DOSPORTAL/models.py b/DOSPORTAL/models.py index 8acdf4d..beff7df 100644 --- a/DOSPORTAL/models.py +++ b/DOSPORTAL/models.py @@ -14,6 +14,7 @@ from django.db import models from django.contrib.gis.db import models as geomodels +import json from .tasks import process_flight_entry, process_record_entry @@ -447,17 +448,8 @@ def __str__(self): -class record(UUIDMixin): - """ - Obsahuje jednotlivĂ˝ log z detektoru - """ +class Record(UUIDMixin): - # measurement = models.ForeignKey( - # measurement, - # on_delete=models.CASCADE, - # related_name='records' - # ) - detector = models.ForeignKey( Detector, on_delete=models.CASCADE, @@ -469,6 +461,10 @@ class record(UUIDMixin): def user_directory_path(instance, filename): print("USER FILENAME", filename) return "user_records/record_{0}".format(instance.pk) + + def user_directory_path_data(instance, filename): + print("USER FILENAME", filename) + return "user_records/record_{0}.pk".format(instance.pk) log_file = models.FileField( verbose_name=_("File log"), @@ -478,7 +474,18 @@ def user_directory_path(instance, filename): log_original_filename = models.CharField( + verbose_name = _("Original filename of log file"), + null=True, + blank=True, + max_length=150 + ) + data_file = models.FileField( + verbose_name=_("Log file"), + help_text=_("Processed spectral file"), + upload_to=user_directory_path_data, + null=True, + blank=True ) time_start = models.DateTimeField( @@ -486,7 +493,6 @@ def user_directory_path(instance, filename): null=True, ) - record_duration = models.DurationField( verbose_name = _("Record duration"), help_text=_("Duration of record"), @@ -512,9 +518,10 @@ def user_directory_path(instance, filename): metadata = models.JSONField( _("record_metadata"), help_text=_("record metadata, used for advanced data processing and maintaining"), - null=True + default='[{}]' ) + belongs = models.ForeignKey( Organization, on_delete=models.DO_NOTHING, @@ -533,10 +540,10 @@ def user_directory_path(instance, filename): ) def save(self, *args, **kwargs): - super(record, self).save(*args, **kwargs) + super(Record, self).save(*args, **kwargs) def __str__(self) -> str: - return "record ({}, {}, start {}, {})".format( get_enum_dsc(self.RECORD_TYPES, self.record_type), self.id, self.time_start, 0) + return "record ({}, {}, start {}, {})".format(self.belongs, self.log_original_filename, self.time_start, 0) def description(self) -> str: return "Record ({}, {})".format(get_enum_dsc(self.RECORD_TYPES, self.record_type), self.time_start.strftime("%Y-%m-%d_%H:%M")) @@ -596,11 +603,13 @@ class SpectrumData(UUIDMixin): verbose_name=_("Record") ) - spectrum = models.JSONField( - _("Spectrum data"), - help_text=_("Energy spectrum data as an array of integers"), - default=list(), - ) + # spectrum = models.JSONField( + # _("Spectrum data"), + # help_text=_("Energy spectrum data as an array of integers"), + # default=list(), + # ) + + spectrum = ArrayField(models.IntegerField(), blank=True, null=True, size=None) integration = models.FloatField( _("Integration time"), @@ -615,14 +624,15 @@ class SpectrumData(UUIDMixin): null=True, blank=True, ) + - metadata = HStoreField( - _("Metadata"), - help_text=_("Additional metadata for the spectrum data"), - null=True, - blank=True, - default=dict() - ) + # metadata = HStoreField( + # _("Metadata"), + # help_text=_("Additional metadata for the spectrum data"), + # null=True, + # blank=True, + # default=dict() + # ) location = models.ForeignKey( TrajectoryPoint, @@ -631,7 +641,7 @@ class SpectrumData(UUIDMixin): null=True, blank=True ) - time_difference = models.DurationField( + time = models.DurationField( verbose_name=_("Time difference"), help_text=_("Time difference from the start of the measurement"), null=True @@ -642,9 +652,9 @@ def __str__(self) -> str: return f"Spectrum data {self.record.id}" def save(self, *args, **kwargs): - self.particles = sum(self.spectrum) + #self.particles = sum(self.spectrum) - self.metadata['particles'] = self.particles + #self.metadata['particles'] = self.particles super(SpectrumData, self).save(*args, **kwargs) diff --git a/DOSPORTAL/settings.py b/DOSPORTAL/settings.py index dd53230..ddb7376 100644 --- a/DOSPORTAL/settings.py +++ b/DOSPORTAL/settings.py @@ -58,6 +58,7 @@ 'django_gravatar', + 'prettyjson', 'organizations', ] diff --git a/DOSPORTAL/signals.py b/DOSPORTAL/signals.py index ac30546..f96fbb1 100644 --- a/DOSPORTAL/signals.py +++ b/DOSPORTAL/signals.py @@ -1,7 +1,9 @@ from django.db.models.signals import post_save from django.contrib.auth.models import User from django.dispatch import receiver -from .models import Profile, record +from .models import Profile, Record, SpectrumData +import json +import pandas as pd @receiver(post_save, sender=User) @@ -16,22 +18,101 @@ def save_profile(sender, instance, **kwargs): -@receiver(post_save, sender=record) -def save_record(sender, instance, **kwargs): +@receiver(post_save, sender=Record) +def save_record(sender, instance, created = None, **kwargs): print("AFTER SAVE.... ") - print(sender) + print(sender, created) print(instance) print(kwargs) + print(".................") + print(instance.log_file.path, type(instance.log_file)) - filepath = 'data/media/'+instance.log_file - print(filepath) + if created: + + filepath = instance.log_file.path + print(filepath) + + metadata = json.loads(instance.metadata) if instance.metadata else {} + + if type(metadata) is not dict: + metadata = {} + + print("MEDATADA") + print(type(metadata)) + print(metadata) + + + metadata['log_device_info'] = {} + metadata['log_runs_count'] = 0 + + max_size = 0 + + with open(filepath, 'r') as file: + for line in file: + parts_size = len(line.split(",")) + if parts_size > max_size: max_size = parts_size + + if line.startswith("$HIST"): + parts = line.split(",") + # spec_mod = SpectrumData() + # spec_mod.record = instance + # spec_mod.spectrum = parts[8:] + # spec_mod.integration = 10 + # spec_mod.time = parts[2] + # spec_mod.save() + + elif line.startswith("$DOS"): + print("DOS", line) + metadata['log_runs_count'] += 1 + parts = line.split(",") + metadata['log_device_info']['DOS'] = { + "type": parts[0], + "hw-model": parts[1], + "fw-version": parts[2], + "fw-build_info": parts[5], + "fw-commit": parts[4], + 'hw-sn': parts[5] + } + + elif line.startswith("$DIG"): + print("DIG", line) + parts = line.split(",") + metadata['log_device_info']['DIG'] = { + "type": parts[0], + "hw-model": parts[1], + "hw-sn": parts[2], + '-': parts[3] + } + + elif line.startswith("$ADC"): + print("ADC", line) + parts = line.split(",") + metadata['log_device_info']['ADC'] = { + "type": parts[0], + "hw-model": parts[1], + "hw-sn": parts[2], + '-': parts[3] + } + + df = pd.read_csv(instance.log_file.path, sep = ',', header = None, names=range(max_size)) + print(df) + df = df [df[0] == '$HIST'] + df = df.drop(columns=[0, 1, 3, 4, 5, 6, 7]) + + new_columns = ['time'] + list(range(df.shape[1] - 1)) + df.columns = new_columns + + new_name = instance.user_directory_path_data('pk') + print("BUDU TO UKLADAT DO ",'data/media/'+new_name) + df.to_pickle('data/media/'+new_name) - metadata = instance.metadata + instance.data_file.name = new_name - if 'device_info' not in metadata: - metadata['device_info'] = {} + print(instance.data_file) - with open(filepath, 'r') as file: - for line in file: - print(line) + print("Po ") + print(df) + + instance.metadata = json.dumps(metadata) + instance.save() diff --git a/DOSPORTAL/templates/records/record_detail.html b/DOSPORTAL/templates/records/record_detail.html index cec51b8..1be67ef 100644 --- a/DOSPORTAL/templates/records/record_detail.html +++ b/DOSPORTAL/templates/records/record_detail.html @@ -1,11 +1,8 @@ {% extends "base.html" %} - {% block content %} - - @@ -34,7 +31,7 @@
  • Record duration: {{ record.record_duration }}
  • Type: {{ record.record_type }}
  • Advanced metadata:
  • -
    {{record.metadata }}
    +
    {{ record.metadata }}
  • Description: {{record}} {#
  • File size: {{record.log_file.size}} #} diff --git a/DOSPORTAL/templates/records/records_list.html b/DOSPORTAL/templates/records/records_list.html index e481cc9..87e3aad 100644 --- a/DOSPORTAL/templates/records/records_list.html +++ b/DOSPORTAL/templates/records/records_list.html @@ -11,23 +11,23 @@ {% endif %} - {% if record_list %} + {% if records_list %} - + - {% for record in record_list.reverse %} + {% for record in records_list.reverse %} - + diff --git a/DOSPORTAL/users/views_users.py b/DOSPORTAL/users/views_users.py index 1fef66a..29e798b 100644 --- a/DOSPORTAL/users/views_users.py +++ b/DOSPORTAL/users/views_users.py @@ -4,7 +4,7 @@ from django.http import HttpResponse, JsonResponse from django.views import generic from ..models import (DetectorManufacturer, measurement, - record, Detector, DetectorType) + Record, Detector, DetectorType) from django.shortcuts import get_object_or_404, redirect, render from django.contrib.auth.decorators import login_required diff --git a/DOSPORTAL/views.py b/DOSPORTAL/views.py index d58a597..cff4c5c 100644 --- a/DOSPORTAL/views.py +++ b/DOSPORTAL/views.py @@ -2,7 +2,7 @@ from django.http import HttpResponse, JsonResponse from django.views import generic from .models import (DetectorManufacturer, measurement, - record, Detector, DetectorType) + Record, Detector, DetectorType) from django.shortcuts import get_object_or_404, redirect, render from django.contrib.auth.decorators import login_required @@ -184,8 +184,8 @@ def MeasurementDataView(request, pk): print("MAM GET... ") a=measurement.objects.get(pk=pk) - rec=record.objects.filter(measurement=pk, record_type="S") - loc=record.objects.filter(measurement=pk, record_type="L") + rec=Record.objects.filter(measurement=pk, record_type="S") + loc=Record.objects.filter(measurement=pk, record_type="L") #return HttpResponse(a) @@ -204,8 +204,8 @@ def measuredDataGet(request, pk): series = [] a=measurement.objects.get(pk=pk) - rec=record.objects.filter(measurement=pk, record_type="S") - loc=record.objects.filter(measurement=pk, record_type="L") + rec=Record.objects.filter(measurement=pk, record_type="S") + loc=Record.objects.filter(measurement=pk, record_type="L") b = rec[0] @@ -383,7 +383,7 @@ def measuredSpectraGet(request, pk): part_from = int(float(request.GET.get('start', 0))) part_to = int(float(request.GET.get('end', 0))) - rec=record.objects.filter(measurement=pk, record_type="S") + rec=Record.objects.filter(measurement=pk, record_type="S") #loc=record.objects.filter(measurement=pk, record_type="L") #l=[] @@ -451,6 +451,6 @@ def measuredSpectraGet(request, pk): def measurementGetData(request, pk): a=measurement.objects.get(pk=pk) - rec=record.objects.filter(measurement=pk, record_type="S") - loc=record.objects.filter(measurement=pk, record_type="L") + rec=Record.objects.filter(measurement=pk, record_type="S") + loc=Record.objects.filter(measurement=pk, record_type="L") diff --git a/DOSPORTAL/views_detectors.py b/DOSPORTAL/views_detectors.py index ca7d8d6..0fad98a 100644 --- a/DOSPORTAL/views_detectors.py +++ b/DOSPORTAL/views_detectors.py @@ -2,7 +2,7 @@ from django.http import HttpResponse, JsonResponse from django.views import generic from .models import (DetectorManufacturer, measurement, - record, Detector, DetectorType, DetectorLogbook) + Record, Detector, DetectorType, DetectorLogbook) from .forms import DetectorLogblogForm, DetectorEditForm from django.shortcuts import get_object_or_404, redirect, render diff --git a/DOSPORTAL/views_record.py b/DOSPORTAL/views_record.py index 4d89f29..b7fcae6 100644 --- a/DOSPORTAL/views_record.py +++ b/DOSPORTAL/views_record.py @@ -1,7 +1,7 @@ from django import forms from django.http import HttpResponse, JsonResponse from django.views import generic -from .models import (DetectorManufacturer, measurement, record, +from .models import (DetectorManufacturer, measurement, Record, Detector, DetectorType, DetectorLogbook) from .forms import DetectorLogblogForm import os @@ -19,9 +19,9 @@ FIRST_CHANNEL = 10 class RecordsListView(generic.ListView): - model = record + model = Record context_object_name = 'records_list' - queryset = record.objects.all() + queryset = Record.objects.all() template_name = 'records/records_list.html' def get_context_data(self, **kwargs): @@ -122,6 +122,7 @@ def RecordNewView(request): # data.record_duration = timedelta(seconds = metadata['record']['duration']) # #data.measurement = measurement.objects.get(pk=pk) pk = data.pk + data.author = request.user print(data) data.save() @@ -138,13 +139,13 @@ def RecordNewView(request): return render(request, 'records/record_new.html', {'form': form}) def RecordView(request, pk): - rec = record.objects.get(pk=pk) + rec = Record.objects.get(pk=pk) return render(request, 'records/record_detail.html', context={'record': rec}) def GetSpectrum(request, pk): - record_o = record.objects.filter(pk=pk) + record_o = Record.objects.filter(pk=pk) print(record_o) pass @@ -152,6 +153,6 @@ def GetSpectrum(request, pk): def GetEvolution(request, pk): - record_o = record.objects.filter(pk=pk) + record_o = Record.objects.filter(pk=pk) print(record_o) pass \ No newline at end of file diff --git a/api/serializers.py b/api/serializers.py index 83a8e15..26a93d7 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -1,5 +1,5 @@ from rest_framework import serializers -from DOSPORTAL.models import measurement, record, Detector +from DOSPORTAL.models import measurement, Record, Detector @@ -12,7 +12,7 @@ class Meta: class RecordSerializer(serializers.ModelSerializer): #detector = DetectorSerializer(read_only = True, many=True) class Meta: - model = record + model = Record fields = '__all__' diff --git a/docker-compose.yml b/docker-compose.yml index 28775d4..a268332 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -51,7 +51,7 @@ services: - "8100:8000" depends_on: - db_dosportal - -redis + - redis networks: inet: ipv4_address: 10.5.0.6 diff --git a/requirements.txt b/requirements.txt index e08af85..6865e51 100644 --- a/requirements.txt +++ b/requirements.txt @@ -27,4 +27,7 @@ gpxpy django-crispy-forms crispy-bootstrap5 django-organizations -django-gravatar2 \ No newline at end of file +django-gravatar2 +django-prettyjson + +tables \ No newline at end of file
    # Name TypeAuthorOrganization/Author
    {{ forloop.counter }} {{ record | truncatechars:50 }} {{ record.record_type }}{{record.author}}{{record.belongs}}, {{record.author}}
    {{ record }}