Skip to content
Snippets Groups Projects
Commit 12867ab2 authored by Fanna Lautenbach's avatar Fanna Lautenbach
Browse files

Merge branch 'hotfix/dataproduct_info-fix' into 'main'

fix dataproduct information view with tests

See merge request !61
parents 737771c4 a49a8f3e
No related branches found
No related tags found
1 merge request!61fix dataproduct information view with tests
Pipeline #42298 passed
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
{% load crispy_forms_tags %} {% load crispy_forms_tags %}
{% load define_action %} {% load define_action %}
{% load widget_tweaks %} {% load widget_tweaks %}
{% load format_to_percentage %}
{% block myBlock %} {% block myBlock %}
<div class="overlay"> <div class="overlay">
...@@ -25,15 +26,21 @@ ...@@ -25,15 +26,21 @@
</div> </div>
<div class="table__content"> <div class="table__content">
{% for key, value in dataproduct_info.items %} {% for key, value in dataproduct_info.items %}
<div class="table__row table__row--dark table__row--padding"> {% if value|length > 0 %}
<div class="table__cell table__cell--title">{{ key }}</div> <div class="table__row table__row--dark table__row--padding">
<div class="table__cell"> <div class="table__cell table__cell--title">{{ key }}</div>
{% for item in value %} <div class="table__cell">
{{ item }} {% for item in value %}
{% if not forloop.last %}&{% endif %} {% if key == 'dysco_compression' %}
{% endfor %} {% format_to_percentage item %}
{% else %}
{{ item }}
{% endif %}
{% if not forloop.last %}&{% endif %}
{% endfor %}
</div>
</div> </div>
</div> {% endif %}
{% endfor %} {% endfor %}
</div> </div>
</div> </div>
......
from django import template
register = template.Library()
@register.simple_tag
def format_to_percentage(val):
return '{:.0%}'.format(val)
import unittest
from lofardata.models import DataProduct
from lofardata.views import retrieve_general_dataproduct_information
test_object_value_one = dict(obs_id='12345', oid_source='SAS', dataproduct_source='lofar',
dataproduct_type='observation',
project='LT10_10',
location='lta-head.lofar.psnc.pl',
activity='secret stuff',
surl='srm://lta-head.lofar.psnc.pl:4884/subfolder/some_nice.tar',
filesize=40,
antenna_set='HBA Dual Inner',
instrument_filter='110-190 MHz',
dysco_compression=True)
test_object_value_two = dict(obs_id='123789', oid_source='SAS', dataproduct_source='lofar',
dataproduct_type='observation',
project='LT10_10',
location='lta-head.lofar.psnc.pl',
activity='secret stuff',
surl='srm://lta-head.lofar.psnc.pl:4884/subfolder/some_very_nice.tar',
filesize=40,
antenna_set='HBA Dual Inner',
instrument_filter='110-190 MHz',
dysco_compression=True)
test_object_value_three = dict(obs_id='123789', oid_source='SAS', dataproduct_source='lofar',
dataproduct_type='observation',
project='LT10_10_Classified',
location='lta-head.lofar.psnc.pl',
activity='secret stuff',
surl='srm://lta-head.lofar.psnc.pl:4884/subfolder/some_not_nice.tar',
filesize=40,
antenna_set='HBA Dual Inner',
instrument_filter='110-190 MHz',
dysco_compression=False)
test_object_value_four = dict(obs_id='1337', oid_source='SAS', dataproduct_source='lofar',
dataproduct_type='observation',
project='LT10_10_Classified',
location='lta-head.lofar.psnc.pl',
activity='secret stuff',
surl='srm://lta-head.lofar.psnc.pl:4884/subfolder/some_not_very_nice.tar',
filesize=40,
antenna_set='HBA Dual Inner',
instrument_filter='110-190 MHz',
dysco_compression=False)
test_object_value_five = dict(obs_id='3773', oid_source='SAS', dataproduct_source='lofar',
dataproduct_type='observation',
project='LT10_10_Classified',
location='lta-head.lofar.psnc.pl',
activity='secret stuff',
surl='srm://lta-head.lofar.psnc.pl:4884/subfolder/some_not_very_super_nice.tar',
filesize=40,
antenna_set=None,
instrument_filter='110-190 MHz',
dysco_compression=False)
test_object_value_six = dict(obs_id='0987', oid_source='SAS', dataproduct_source='lofar',
dataproduct_type='observation',
project='LT10_10_Classified',
location='lta-head.lofar.psnc.pl',
activity='secret stuff',
surl='srm://lta-head.lofar.psnc.pl:4884/subfolder/some_very_super_nice.tar',
filesize=40,
antenna_set='',
instrument_filter='',
dysco_compression=False)
class RetrieveDataProductInformation(unittest.TestCase):
def setUp(self):
DataProduct.objects.create(**test_object_value_one)
DataProduct.objects.create(**test_object_value_two)
DataProduct.objects.create(**test_object_value_three)
DataProduct.objects.create(**test_object_value_four)
DataProduct.objects.create(**test_object_value_five)
DataProduct.objects.create(**test_object_value_six)
def test_single_database_entry(self):
actual = retrieve_general_dataproduct_information('12345')
self.assertEqual(actual['dataproduct_source'], ['lofar'])
self.assertEqual(actual['dataproduct_type'], ['observation'])
self.assertEqual(actual['project'], ['LT10_10'])
self.assertEqual(actual['activity'], ['secret stuff'])
self.assertEqual(actual['antenna_set'], ['HBA Dual Inner'])
self.assertEqual(actual['instrument_filter'], ['110-190 MHz'])
def test_combined_database_entries(self):
actual = retrieve_general_dataproduct_information('123789')
self.assertEqual(actual['project'], ['LT10_10', 'LT10_10_Classified'])
def test_single_with_none_value(self):
actual = retrieve_general_dataproduct_information('3773')
self.assertEqual(actual['antenna_set'], [])
def test_single_with_default_values(self):
actual = retrieve_general_dataproduct_information('0987')
self.assertEqual(actual['antenna_set'], [])
def test_dysco_compression_true_and_false(self):
actual = retrieve_general_dataproduct_information('123789')
self.assertEqual(actual['dysco_compression'], [0.5])
def test_dysco_compression_true(self):
actual = retrieve_general_dataproduct_information('12345')
self.assertEqual(actual['dysco_compression'], [1])
def test_dysco_compression_false(self):
actual = retrieve_general_dataproduct_information('1337')
self.assertEqual(actual['dysco_compression'], [0])
...@@ -147,14 +147,21 @@ def preprocess_filters_specification_view(specification): ...@@ -147,14 +147,21 @@ def preprocess_filters_specification_view(specification):
def retrieve_general_dataproduct_information(sas_id): def retrieve_general_dataproduct_information(sas_id):
# Per SAS ID, the retrieved data products should have these unique values # Per SAS ID, the retrieved data products should have these unique values
data_products = DataProduct.objects.filter(obs_id=sas_id).values("dataproduct_source", data_products = DataProduct.objects.filter(obs_id=sas_id).values('dataproduct_source',
"dataproduct_type", 'dataproduct_type',
"project", 'project',
"location", 'location',
"activity", 'activity',
"additional_meta").distinct() 'antenna_set',
'instrument_filter',
'dysco_compression').distinct()
combined_data_products_on_key = combine_dataproducts_on_key(data_products, {}) combined_data_products_on_key = combine_dataproducts_on_key(data_products, {})
dysco_compressions = combined_data_products_on_key['dysco_compression']
true_count = len([dysco_compression for dysco_compression in dysco_compressions if dysco_compression])
dysco_compression_true_percentage = true_count / len(combined_data_products_on_key['dysco_compression'])
# put in a list for template convenience
combined_data_products_on_key['dysco_compression'] = [dysco_compression_true_percentage]
return combined_data_products_on_key return combined_data_products_on_key
...@@ -166,12 +173,12 @@ def combine_dataproducts_on_key(data_products, combined_data_products): ...@@ -166,12 +173,12 @@ def combine_dataproducts_on_key(data_products, combined_data_products):
def fill_unique_nested_dict(data_product, combined_data_products_on_key): def fill_unique_nested_dict(data_product, combined_data_products_on_key):
for key, value in data_product.items(): for key, value in data_product.items():
if isinstance(value, dict): if combined_data_products_on_key.get(key) and \
combined_data_products_on_key = fill_unique_nested_dict(value, combined_data_products_on_key) value not in combined_data_products_on_key.get(key) and \
elif combined_data_products_on_key.get(key) and value not in combined_data_products_on_key.get(key): value is not None and value is not '':
combined_data_products_on_key[key].append(value) combined_data_products_on_key[key].append(value)
else: else:
combined_data_products_on_key[key] = [value] combined_data_products_on_key[key] = [value] if value is not None and value is not '' else []
return combined_data_products_on_key return combined_data_products_on_key
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment