Skip to content

Commit

Permalink
Merge pull request #132 from nansencenter/issue51-no-need-for-Dataset…
Browse files Browse the repository at this point in the history
…Parameter-model-at-all

Issue51 no need for dataset parameter model at all
  • Loading branch information
opsdep authored Oct 14, 2020
2 parents 48f0e2d + c519004 commit 7a9b85b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 42 deletions.
27 changes: 27 additions & 0 deletions geospaas/catalog/migrations/0009_auto_20201012_0905.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 3.0.6 on 2020-10-12 09:05

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('vocabularies', '0004_auto_20200331_0806'),
('catalog', '0008_auto_20200331_0806'),
]

operations = [
migrations.RemoveField(
model_name='dataset',
name='parameters',
field=models.ManyToManyField(to='vocabularies.Parameter'),
),
migrations.DeleteModel(
name='DatasetParameter',
),
migrations.AddField(
model_name='dataset',
name='parameters',
field=models.ManyToManyField(to='vocabularies.Parameter'),
),
]
8 changes: 1 addition & 7 deletions geospaas/catalog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class Dataset(models.Model):
]
)
entry_title = models.CharField(max_length=220)
parameters = models.ManyToManyField(Parameter, through='DatasetParameter')
parameters = models.ManyToManyField(Parameter)
ISO_topic_category = models.ForeignKey(ISOTopicCategory, on_delete=models.CASCADE)
data_center = models.ForeignKey(DataCenter, on_delete=models.CASCADE)
summary = models.TextField()
Expand Down Expand Up @@ -174,12 +174,6 @@ def __str__(self):
# temporal_resolution = models.CharField(max_length=220)
# temporal_resolution_range = models.ForeignKey(TemporalDataResolution)

class DatasetParameter(models.Model):
dataset = models.ForeignKey(Dataset, on_delete=models.CASCADE)
parameter = models.ForeignKey(Parameter, on_delete=models.CASCADE)

def __str__(self):
return '%s:%s' %(self.dataset, self.parameter)

class DatasetURI(models.Model):

Expand Down
33 changes: 4 additions & 29 deletions geospaas/catalog/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,6 @@ def test_entry_id_is_correct(self):
ds.full_clean()
self.assertEqual(ds.entry_id, id)

def test_search_datasets(self):
''' Shall add one parameter to the first dataset
shall find one Dataset without sst '''
dataset1 = Dataset.objects.get(pk=1)
p = Parameter.objects.get(
standard_name='sea_surface_temperature')
dp = DatasetParameter(dataset=dataset1, parameter=p)
dp.save()
dsearch = Dataset.objects.filter( source__instrument__short_name =
'MODIS')
dsearch = dsearch.exclude(datasetparameter__parameter__short_name =
'SST' )
self.assertEqual(dsearch.count(), 1)

class DatasetURITests(TestCase):

Expand All @@ -152,20 +139,6 @@ def test_DatasetURI_created(self, mock_isfile):
self.assertEqual(dsuri.uri, uri)



class DatasetParameterTests(TestCase):

fixtures = ["vocabularies", "catalog"]

def test_add_sar_sigma0(self):
ds = Dataset.objects.get(pk=1)
p = Parameter.objects.get(
standard_name='surface_backwards_scattering_coefficient_of_radar_wave',
short_name='sigma0')
dp = DatasetParameter(dataset=ds, parameter=p)
dp.save()
self.assertEqual(dp.parameter.short_name, 'sigma0')

class DatasetRelationshipTests(TestCase):

fixtures = ["vocabularies", "catalog"]
Expand All @@ -181,6 +154,7 @@ def test_variable(self):
dr.save()
self.assertEqual(dr.child.source, dr.parent.source)


class GeographicLocationTests(TestCase):
def test_geographiclocation(self):
''' Shall create GeographicLocation instance '''
Expand Down Expand Up @@ -210,17 +184,18 @@ def test__reproduce__not_null_constraint_failed(self):
self.assertFalse(created)
# Conclusion: db can't handle numbers with too many decimals (NOT NULL constraint failed)

class PersonnelTests(TestCase):

class PersonnelTests(TestCase):
''' We should add user admin with, e.g., with the Personnel model. Skip
testing before that is in place
'''
pass

class RoleTests(TestCase):

class RoleTests(TestCase):
pass


class SourceTests(TestCase):

fixtures = ["vocabularies"]
Expand Down
6 changes: 2 additions & 4 deletions geospaas/nansat_ingestor/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.db import models

from geospaas.catalog.managers import FILE_SERVICE_NAME, LOCAL_FILE_SERVICE
from geospaas.catalog.models import (Dataset, DatasetParameter, DatasetURI,
from geospaas.catalog.models import (Dataset, DatasetURI,
GeographicLocation, Source)
from geospaas.utils.utils import nansat_filename, validate_uri
from geospaas.vocabularies.models import (DataCenter, Instrument,
Expand Down Expand Up @@ -132,7 +132,7 @@ def get_or_create(self,
geometry=WKTReader().read(n.get_border_wkt(nPoints=n_points)))[0]

# create dataset
# - the get_or_create method should use get_or_create here as well,
# - the get_or_create method should use get_or_create here as well,
# or its name should be changed - see issue #127
ds, created = Dataset.objects.update_or_create(entry_id=options['entry_id'], defaults={
'time_coverage_start': n.get_metadata('time_coverage_start'),
Expand Down Expand Up @@ -161,8 +161,6 @@ def get_or_create(self,
if params.count() > 1 and units is not None:
params = params.filter(units=units)
if params.count() >= 1:
DatasetParameter.objects.get_or_create(
dataset=ds, parameter=params[0])
ds.parameters.add(params[0])

# create dataset URI
Expand Down
4 changes: 2 additions & 2 deletions geospaas/nansat_ingestor/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def test_getorcreate_localfile_filtering_base_on_parameter(self):
self.predefined_band_metadata_dict[2]['standard_name'])

def test_dont_add_longitude_latitude(self):
""" shall not add latitude and longitude into DatasetParameter table """
""" shall not add latitude and longitude into Parameters of Dataset table """
uri = 'file://localhost/some/folder/filename.ext'
ds0, _ = Dataset.objects.get_or_create(uri)
ds_params_standard_names = ds0.parameters.values_list('standard_name', flat=True)
Expand All @@ -184,7 +184,7 @@ def test_dont_add_longitude_latitude(self):
self.assertNotIn('latidtude', ds_params_standard_names)

def test_add_sigma0_gamma0(self):
""" shall add both sigma0 and gamma0 with same standard name into DatasetParameter table """
""" shall add both sigma0 and gamma0 with same standard name into Parameters of Dataset table """
uri = 'file://localhost/some/folder/filename.ext'
ds0, _ = Dataset.objects.get_or_create(uri)
ds_params_standard_names = ds0.parameters.values_list('standard_name', flat=True)
Expand Down

0 comments on commit 7a9b85b

Please sign in to comment.