From 574ba8e9680b66ff1532197b36095c449282eebd Mon Sep 17 00:00:00 2001 From: Roman Dvorak Date: Sun, 7 Apr 2024 02:05:54 +0200 Subject: [PATCH] add calibration parameters, recalc energies in graphs --- DOSPORTAL/admin.py | 25 +++- DOSPORTAL/forms.py | 2 +- DOSPORTAL/migrations/0018_record_calib.py | 19 +++ .../migrations/0019_remove_detector_calib.py | 17 +++ .../0020_detector_detector_calibration.py | 18 +++ .../0021_remove_detectorcalib_cabib.py | 17 +++ ..._detector_detector_calibration_and_more.py | 22 +++ .../0023_rename_calibration_detector_calib.py | 18 +++ ...or_calib_detectorcalib_created_and_more.py | 36 +++++ DOSPORTAL/migrations/0025_detector_calib.py | 18 +++ ...ctor_calib_delete_detectortocalibration.py | 20 +++ DOSPORTAL/migrations/0027_detector_calib.py | 18 +++ ...8_record_time_of_interenst_end_and_more.py | 23 +++ ...nd_record_time_of_interest_end_and_more.py | 23 +++ DOSPORTAL/models.py | 76 +++++++--- .../templates/detectors/detectors_detail.html | 10 +- .../templates/records/record_detail.html | 131 +++++++++--------- DOSPORTAL/views_record.py | 21 ++- 18 files changed, 414 insertions(+), 100 deletions(-) create mode 100644 DOSPORTAL/migrations/0018_record_calib.py create mode 100644 DOSPORTAL/migrations/0019_remove_detector_calib.py create mode 100644 DOSPORTAL/migrations/0020_detector_detector_calibration.py create mode 100644 DOSPORTAL/migrations/0021_remove_detectorcalib_cabib.py create mode 100644 DOSPORTAL/migrations/0022_remove_detector_detector_calibration_and_more.py create mode 100644 DOSPORTAL/migrations/0023_rename_calibration_detector_calib.py create mode 100644 DOSPORTAL/migrations/0024_remove_detector_calib_detectorcalib_created_and_more.py create mode 100644 DOSPORTAL/migrations/0025_detector_calib.py create mode 100644 DOSPORTAL/migrations/0026_remove_detector_calib_delete_detectortocalibration.py create mode 100644 DOSPORTAL/migrations/0027_detector_calib.py create mode 100644 DOSPORTAL/migrations/0028_record_time_of_interenst_end_and_more.py create mode 100644 DOSPORTAL/migrations/0029_rename_time_of_interenst_end_record_time_of_interest_end_and_more.py diff --git a/DOSPORTAL/admin.py b/DOSPORTAL/admin.py index 1e53495..25b7707 100644 --- a/DOSPORTAL/admin.py +++ b/DOSPORTAL/admin.py @@ -6,6 +6,9 @@ from import_export.admin import ImportExportModelAdmin +from django_q import models as q_models +from django_q import admin as q_admin + class AirportsResource(resources.ModelResource): class Meta: model = Airports @@ -43,8 +46,24 @@ 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(Detector) + + +class RecordAdmin(admin.ModelAdmin): + def get_form(self, request, obj=None, **kwargs): + if obj: + form = obj.calibration_select_form() + else: + form = super().get_form(request, obj, **kwargs) + return form + +admin.site.register(Record, RecordAdmin) + + +class DetectorAdmin(admin.ModelAdmin): + filter_horizontal = ('calib',) + pass + +admin.site.register(Detector, DetectorAdmin) admin.site.register(DetectorLogbook) admin.site.register(DetectorType) admin.site.register(DetectorCalib) @@ -59,8 +78,6 @@ def user_count(self, obj): admin.site.register(SpectrumData) -from django_q import models as q_models -from django_q import admin as q_admin admin.site.unregister([q_models.Failure]) @admin.register(q_models.Failure) diff --git a/DOSPORTAL/forms.py b/DOSPORTAL/forms.py index cd80b85..e2b9ae7 100644 --- a/DOSPORTAL/forms.py +++ b/DOSPORTAL/forms.py @@ -107,5 +107,5 @@ class Meta: class DetectorEditForm(forms.ModelForm): class Meta: model = Detector - fields = ["name", "type", 'sn', "calib", "manufactured_date", "data", "owner", "access"] + fields = ["name", "type", 'sn', "manufactured_date", "data", "owner", "access"] diff --git a/DOSPORTAL/migrations/0018_record_calib.py b/DOSPORTAL/migrations/0018_record_calib.py new file mode 100644 index 0000000..2098be9 --- /dev/null +++ b/DOSPORTAL/migrations/0018_record_calib.py @@ -0,0 +1,19 @@ +# Generated by Django 4.2.11 on 2024-04-06 20:21 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('DOSPORTAL', '0017_record_metadata_file'), + ] + + operations = [ + migrations.AddField( + model_name='record', + name='calib', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='records', to='DOSPORTAL.detectorcalib'), + ), + ] diff --git a/DOSPORTAL/migrations/0019_remove_detector_calib.py b/DOSPORTAL/migrations/0019_remove_detector_calib.py new file mode 100644 index 0000000..caf4724 --- /dev/null +++ b/DOSPORTAL/migrations/0019_remove_detector_calib.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2.11 on 2024-04-06 20:24 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('DOSPORTAL', '0018_record_calib'), + ] + + operations = [ + migrations.RemoveField( + model_name='detector', + name='calib', + ), + ] diff --git a/DOSPORTAL/migrations/0020_detector_detector_calibration.py b/DOSPORTAL/migrations/0020_detector_detector_calibration.py new file mode 100644 index 0000000..6a3976d --- /dev/null +++ b/DOSPORTAL/migrations/0020_detector_detector_calibration.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.11 on 2024-04-06 20:24 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('DOSPORTAL', '0019_remove_detector_calib'), + ] + + operations = [ + migrations.AddField( + model_name='detector', + name='Detector calibration', + field=models.ManyToManyField(blank=True, help_text='Detector calibration', related_name='detectors', to='DOSPORTAL.detectorcalib'), + ), + ] diff --git a/DOSPORTAL/migrations/0021_remove_detectorcalib_cabib.py b/DOSPORTAL/migrations/0021_remove_detectorcalib_cabib.py new file mode 100644 index 0000000..5cca376 --- /dev/null +++ b/DOSPORTAL/migrations/0021_remove_detectorcalib_cabib.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2.11 on 2024-04-06 20:28 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('DOSPORTAL', '0020_detector_detector_calibration'), + ] + + operations = [ + migrations.RemoveField( + model_name='detectorcalib', + name='cabib', + ), + ] diff --git a/DOSPORTAL/migrations/0022_remove_detector_detector_calibration_and_more.py b/DOSPORTAL/migrations/0022_remove_detector_detector_calibration_and_more.py new file mode 100644 index 0000000..b50d115 --- /dev/null +++ b/DOSPORTAL/migrations/0022_remove_detector_detector_calibration_and_more.py @@ -0,0 +1,22 @@ +# Generated by Django 4.2.11 on 2024-04-06 20:49 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('DOSPORTAL', '0021_remove_detectorcalib_cabib'), + ] + + operations = [ + migrations.RemoveField( + model_name='detector', + name='Detector calibration', + ), + migrations.AddField( + model_name='detector', + name='calibration', + field=models.ManyToManyField(blank=True, help_text='Detector calibration', to='DOSPORTAL.detectorcalib'), + ), + ] diff --git a/DOSPORTAL/migrations/0023_rename_calibration_detector_calib.py b/DOSPORTAL/migrations/0023_rename_calibration_detector_calib.py new file mode 100644 index 0000000..99377e4 --- /dev/null +++ b/DOSPORTAL/migrations/0023_rename_calibration_detector_calib.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.11 on 2024-04-06 20:49 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('DOSPORTAL', '0022_remove_detector_detector_calibration_and_more'), + ] + + operations = [ + migrations.RenameField( + model_name='detector', + old_name='calibration', + new_name='calib', + ), + ] diff --git a/DOSPORTAL/migrations/0024_remove_detector_calib_detectorcalib_created_and_more.py b/DOSPORTAL/migrations/0024_remove_detector_calib_detectorcalib_created_and_more.py new file mode 100644 index 0000000..95507b7 --- /dev/null +++ b/DOSPORTAL/migrations/0024_remove_detector_calib_detectorcalib_created_and_more.py @@ -0,0 +1,36 @@ +# Generated by Django 4.2.11 on 2024-04-06 22:14 + +from django.db import migrations, models +import django.db.models.deletion +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('DOSPORTAL', '0023_rename_calibration_detector_calib'), + ] + + operations = [ + migrations.RemoveField( + model_name='detector', + name='calib', + ), + migrations.AddField( + model_name='detectorcalib', + name='created', + field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), + preserve_default=False, + ), + migrations.CreateModel( + name='DetectorToCalibration', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('calib', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='DOSPORTAL.detectorcalib')), + ('detector', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='DOSPORTAL.detector')), + ], + options={ + 'ordering': ['calib__created'], + }, + ), + ] diff --git a/DOSPORTAL/migrations/0025_detector_calib.py b/DOSPORTAL/migrations/0025_detector_calib.py new file mode 100644 index 0000000..fb22337 --- /dev/null +++ b/DOSPORTAL/migrations/0025_detector_calib.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.11 on 2024-04-06 22:14 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('DOSPORTAL', '0024_remove_detector_calib_detectorcalib_created_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='detector', + name='calib', + field=models.ManyToManyField(blank=True, help_text='Detector calibration', through='DOSPORTAL.DetectorToCalibration', to='DOSPORTAL.detectorcalib'), + ), + ] diff --git a/DOSPORTAL/migrations/0026_remove_detector_calib_delete_detectortocalibration.py b/DOSPORTAL/migrations/0026_remove_detector_calib_delete_detectortocalibration.py new file mode 100644 index 0000000..60d27f0 --- /dev/null +++ b/DOSPORTAL/migrations/0026_remove_detector_calib_delete_detectortocalibration.py @@ -0,0 +1,20 @@ +# Generated by Django 4.2.11 on 2024-04-06 22:26 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('DOSPORTAL', '0025_detector_calib'), + ] + + operations = [ + migrations.RemoveField( + model_name='detector', + name='calib', + ), + migrations.DeleteModel( + name='DetectorToCalibration', + ), + ] diff --git a/DOSPORTAL/migrations/0027_detector_calib.py b/DOSPORTAL/migrations/0027_detector_calib.py new file mode 100644 index 0000000..c41697d --- /dev/null +++ b/DOSPORTAL/migrations/0027_detector_calib.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.11 on 2024-04-06 22:26 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('DOSPORTAL', '0026_remove_detector_calib_delete_detectortocalibration'), + ] + + operations = [ + migrations.AddField( + model_name='detector', + name='calib', + field=models.ManyToManyField(blank=True, help_text='Detector calibration', to='DOSPORTAL.detectorcalib'), + ), + ] diff --git a/DOSPORTAL/migrations/0028_record_time_of_interenst_end_and_more.py b/DOSPORTAL/migrations/0028_record_time_of_interenst_end_and_more.py new file mode 100644 index 0000000..fcc2802 --- /dev/null +++ b/DOSPORTAL/migrations/0028_record_time_of_interenst_end_and_more.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2.11 on 2024-04-06 23:38 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('DOSPORTAL', '0027_detector_calib'), + ] + + operations = [ + migrations.AddField( + model_name='record', + name='time_of_interenst_end', + field=models.DurationField(blank=True, default=None, null=True, verbose_name='Time of interest end'), + ), + migrations.AddField( + model_name='record', + name='time_of_interenst_start', + field=models.DurationField(blank=True, default=None, null=True, verbose_name='Time of interest start'), + ), + ] diff --git a/DOSPORTAL/migrations/0029_rename_time_of_interenst_end_record_time_of_interest_end_and_more.py b/DOSPORTAL/migrations/0029_rename_time_of_interenst_end_record_time_of_interest_end_and_more.py new file mode 100644 index 0000000..2c825dc --- /dev/null +++ b/DOSPORTAL/migrations/0029_rename_time_of_interenst_end_record_time_of_interest_end_and_more.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2.11 on 2024-04-06 23:50 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('DOSPORTAL', '0028_record_time_of_interenst_end_and_more'), + ] + + operations = [ + migrations.RenameField( + model_name='record', + old_name='time_of_interenst_end', + new_name='time_of_interest_end', + ), + migrations.RenameField( + model_name='record', + old_name='time_of_interenst_start', + new_name='time_of_interest_start', + ), + ] diff --git a/DOSPORTAL/models.py b/DOSPORTAL/models.py index 42978cc..28ce26e 100644 --- a/DOSPORTAL/models.py +++ b/DOSPORTAL/models.py @@ -14,6 +14,10 @@ from django.contrib.contenttypes.models import ContentType from django.db import models from django.contrib.gis.db import models as geomodels +from django.contrib.gis.geos import Point +from django.contrib.gis.measure import Distance +from django import forms + from markdownx.models import MarkdownxField import json from markdownx.utils import markdownify @@ -261,6 +265,8 @@ class DetectorCalib(UUIDMixin): _("Calibration name") ) + created = models.DateTimeField(auto_now_add=True) + description = models.TextField( _("Description of calibration status") ) @@ -288,13 +294,10 @@ class DetectorCalib(UUIDMixin): # on_delete=models.CASCADE, # ) + def __str__(self) -> str: + return f"Calibration '{self.name}' ({self.coef0/1000:.2f}, {self.coef1/1000:.2f}, {self.coef2/1000:.2f} KeV), {self.date}, {self.description}" - cabib = models.JSONField( - _("Slozky kalibrace, json"), - null=True - ) - - + class Detector(UUIDMixin): @@ -312,12 +315,13 @@ class Detector(UUIDMixin): on_delete=models.CASCADE ) - calib = models.ForeignKey( + calib = models.ManyToManyField( DetectorCalib, - on_delete=models.CASCADE, - null=True, blank=True, - related_name="detectors" + #name=_("Detector calibration"), + #related_name="detectors", + help_text=_("Detector calibration"), + #limit_choices_to=, ) manufactured_date = models.DateField( @@ -356,8 +360,8 @@ def __str__(self) -> str: @property def formatted_label(self): - return f""" {self.type.name} - {self.name} ({self.sn})""" + return f""" {self.type.name} + {self.name} ({self.sn})""" class DetectorLogbook(UUIDMixin): @@ -560,6 +564,20 @@ def user_directory_path_data(instance, extension='pk'): default=datetime.datetime(2000, 1, 1, 0, 0, 0) ) + time_of_interest_start = models.DurationField( + verbose_name = _("Time of interest start"), + null=True, + blank=True, + default=None + ) + + time_of_interest_end = models.DurationField( + verbose_name = _("Time of interest end"), + null=True, + blank=True, + default=None + ) + created = models.DateTimeField( verbose_name = _("Time of creation"), null=False, @@ -597,6 +615,14 @@ def user_directory_path_data(instance, extension='pk'): ) + calib = models.ForeignKey( + DetectorCalib, + on_delete=models.CASCADE, + null=True, + blank=True, + related_name='records' + ) + belongs = models.ForeignKey( Organization, on_delete=models.DO_NOTHING, @@ -624,6 +650,22 @@ def __str__(self) -> str: # return "Record ({}, {})".format(get_enum_dsc(self.RECORD_TYPES, self.record_type), self.time_start.strftime("%Y-%m-%d_%H:%M")) + def calibration_select_form(self): + class selectCalibForm(forms.ModelForm): + class Meta: + model = Record + #fields = ['calib'] + exclude = [] + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + detector = self.instance.detector + if detector: + self.fields['calib'].queryset = detector.calib.all() + else: + self.fields['calib'].queryset = DetectorCalib.objects.none() + return selectCalibForm + @property def formatted_markdown(self): return markdownify(self.description) @@ -702,15 +744,6 @@ class SpectrumData(UUIDMixin): blank=True, ) - - # metadata = HStoreField( - # _("Metadata"), - # help_text=_("Additional metadata for the spectrum data"), - # null=True, - # blank=True, - # default=dict() - # ) - location = models.ForeignKey( TrajectoryPoint, on_delete=models.CASCADE, @@ -723,7 +756,6 @@ class SpectrumData(UUIDMixin): help_text=_("Time difference from the start of the measurement"), null=True ) - # Add any other fields that you think might be useful def __str__(self) -> str: return f"Spectrum data {self.record.id}" diff --git a/DOSPORTAL/templates/detectors/detectors_detail.html b/DOSPORTAL/templates/detectors/detectors_detail.html index 5039f97..6721bca 100644 --- a/DOSPORTAL/templates/detectors/detectors_detail.html +++ b/DOSPORTAL/templates/detectors/detectors_detail.html @@ -29,6 +29,12 @@ diff --git a/DOSPORTAL/templates/records/record_detail.html b/DOSPORTAL/templates/records/record_detail.html index 01d13b2..8d5ab1a 100644 --- a/DOSPORTAL/templates/records/record_detail.html +++ b/DOSPORTAL/templates/records/record_detail.html @@ -29,7 +29,9 @@ Detector: - {{ record.detector.formatted_label | safe }} + {{ record.detector.formatted_label | safe }} + {% if record.calib %}{{ record.calib.name }} {% endif %} + Record start time: @@ -49,7 +51,7 @@ Author/Organization: - {{record.author}} {{ record.belongs }} + {{record.author.get_full_name}} {{ record.belongs }} Log file: @@ -119,6 +121,7 @@

Energetic spectrogram:

}); myChart.setOption({ + useUTC: true, title: [{ left: 'center', text: 'Counts evolution', @@ -136,7 +139,11 @@

Energetic spectrogram:

feature: { restore: {}, - saveAsImage: {} + saveAsImage: {}, + dataZoom: { + //yAxisIndex: 'none' + }, + restore: {} } }, legend: { @@ -157,10 +164,21 @@

Energetic spectrogram:

} ], dataZoom: [ + { + type: 'inside', + xAxisIndex: 0 + }, + { + type: 'inside', + xAxisIndex: 1 + }, makeDataZoom({ height: '5%', bottom: '50%', - xAxisIndex: 0 + xAxisIndex: 0, + realtime: true, + start: 5, + end: 24, }), makeDataZoom({ height: '5%', @@ -171,8 +189,8 @@

Energetic spectrogram:

xAxis: [{ {% if record.time_tracked %} type: 'time', {% else %} type: 'value', {% endif %} - // min: 'dataMin', - //max: 'dataMax' + min: 'dataMin', + max: 'dataMax' }, { gridIndex: 1, //type: 'time', @@ -180,26 +198,20 @@

Energetic spectrogram:

max: 'dataMax' }], yAxis: [{ - min: 'dataMin', + //min: 'dataMin', //max: 'dataMax', - type: 'log', - logBase: 1000, - boundaryGap: [0, '100%'] + //type: 'log', + //logBase: 0.00001, + //boundaryGap: [0, '100%'] }, { gridIndex: 1, min: 'dataMin', max: 'dataMax', - type: 'log', - logBase: 5000, + //type: 'log', + //logBase: 5000, //boundaryGap: [0, '100%'] }], series: [ - { - datasetId: 'evolution', - }, - { - datasetId: 'spectrum', - } ] }); @@ -209,54 +221,6 @@

Energetic spectrogram:

myChart.showLoading() - -/* -var chartDom = document.getElementById('graph2'); -var myChart2 = echarts.init(chartDom); - - - -option = { - tooltip: { - position: 'top' - }, - // grid: { - // height: '50%', - // top: '10%' - // }, - xAxis: { - type: 'category', - //data: hours, - splitArea: { - show: true - } - }, - yAxis: { - type: 'category', - //data: days, - splitArea: { - show: true - } - }, - visualMap: { - min: 0, - max: 10, - calculable: true, - orient: 'horizontal', - left: 'center', - bottom: '15%' - }, - series: [ - - ] -}; - -option && myChart2.setOption(option); -myChart2.showLoading(); - -*/ - - function update_chart() { var dataZoomRanges = myChart.getOption().dataZoom; @@ -283,6 +247,41 @@

Energetic spectrogram:

symbolSize: 5, }], }); + + if(data.time_of_interest){ + console.log("Setting time of interest", data.time_of_interest); + start = data.time_of_interest[0]; + stop = data.time_of_interest[1]; + + myChart.setOption({ + series: [{ + id: 'time_of_interest', + data: [[start, 0], [stop, 0]], + type: 'line', + markLine: { + silent: true, + data: [{ + xAxis: start, + label: { + formatter: 'Start' + } + }, { + xAxis: stop, + label: { + formatter: 'Stop' + } + }] + }, + xAxisIndex: 0, + yAxisIndex: 0, + }], + }); + + + } + + + }); $.get("./get_evolution/", { minTime: dataZoomRanges[1].startValue, maxTime: dataZoomRanges[1].endValue }).done(function (data) { diff --git a/DOSPORTAL/views_record.py b/DOSPORTAL/views_record.py index 0074ce7..e157995 100644 --- a/DOSPORTAL/views_record.py +++ b/DOSPORTAL/views_record.py @@ -187,7 +187,6 @@ def GetSpectrum(request, pk): minEnergy = request.GET.get('minEnergy', 'nan') # nan string je tu z duvodu, ze to je vychozi hodnota v js maxEnergy = request.GET.get('maxEnergy', 'nan') - #print("Get Spectrum", pk) record = Record.objects.filter(pk=pk) df = pd.read_pickle(record[0].data_file.path) @@ -197,16 +196,19 @@ def GetSpectrum(request, pk): # maxEnergy = float(maxEnergy) # df = df[(df['energy'] > minEnergy) & (df['energy'] < maxEnergy)] - total_time = df['time'].max() + total_time = df['time'].max()-df['time'].min() sums = df.drop('time', axis=1).sum().to_frame('counts') sums_list = sums sums_list['channel'] = sums_list.index + if record[0].calib: + sums_list = (sums_list * record[0].calib.coef1 + record[0].calib.coef0)/1000.0 + sums_list = sums_list[['channel', 'counts']].apply(tuple, axis=1).tolist() - return JsonResponse({'spectrum_values': sums_list, 'total_time': total_time}) + return JsonResponse({'spectrum_values': sums_list, 'total_time': total_time, 'calib': bool(record[0].calib)}) @@ -227,19 +229,28 @@ def GetEvolution(request, pk): print(start_time) + if not (minTime != 'nan' and maxTime != 'nan'): minTime = (float(minTime)/1000-start_time) maxTime = (float(maxTime)/1000-start_time) df = df[(df['time'] >= minTime) & (df['time'] <= maxTime)] + total_time = df['time'].max()-df['time'].min() + time = df['time'].astype(float).mul(1000).add(start_time) - sums = df.drop('time', axis=1).sum(axis=1) + sums = df.drop('time', axis=1).sum(axis=1).div(total_time) data = pd.DataFrame({'time': time, 'value': sums}) data_list = data[['time', 'value']].apply(tuple, axis=1).tolist() - return JsonResponse({'evolution_values': data_list, 'time_tracked': record[0].time_tracked}) + time_of_interest = None + if record[0].time_of_interest_start and record[0].time_of_interest_end: + time_of_interest = [] + time_of_interest.append(record[0].time_of_interest_start.seconds*1000 + start_time) + time_of_interest.append(record[0].time_of_interest_end.seconds*1000 + start_time) + + return JsonResponse({'evolution_values': data_list, 'time_tracked': record[0].time_tracked, 'time_of_interest': time_of_interest}) def GetHistogram(request, pk):