Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 13
Fixed getSamplingFeatureDatasets issue #130#131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -74,9 +74,11 @@ def __init__(self, affiliation, person, org): | ||
| class SamplingFeatureDataSet(): | ||
| datasets={} | ||
| def __init__(self, samplingfeature, datasetresults): | ||
| related_features={} | ||
| def __init__(self, samplingfeature, datasetresults, relatedfeatures): | ||
| sf = samplingfeature | ||
| self.SamplingFeature = sf | ||
| self.SamplingFeatureID = sf.SamplingFeatureID | ||
| self.SamplingFeatureUUID = sf.SamplingFeatureUUID | ||
| self.SamplingFeatureTypeCV = sf.SamplingFeatureTypeCV | ||
| @@ -88,23 +90,35 @@ def __init__(self, samplingfeature, datasetresults): | ||
| self.ElevationDatumCV = sf.ElevationDatumCV | ||
| self.FeatureGeometryWKT = sf.FeatureGeometryWKT | ||
| self.assignDatasets(datasetresults) | ||
| self.assignRelatedFeatures(relatedfeatures) | ||
| print(self.datasets) | ||
| print(self.datasets) | ||
| def assignDatasets(self, datasetresults): | ||
| for dsr in datasetresults: | ||
| if dsr.DataSetObj not in self.datasets: | ||
| #if the dataset is not in the dictionary, add it and the first result | ||
| self.datasets[dsr.DataSetObj]=[] | ||
| res = dsr.ResultObj | ||
| # res.FeatureActionObj = None | ||
| self.datasets[dsr.DataSetObj].append(res) | ||
| else: | ||
| #if the dataset is in the dictionary, append the result object to the list | ||
| res = dsr.ResultObj | ||
| # res.FeatureActionObj = None | ||
| self.datasets[dsr.DataSetObj].append(res) | ||
| self.datasets = {} | ||
| if datasetresults: | ||
| for dsr in datasetresults: | ||
| if dsr.DataSetObj not in self.datasets: | ||
| #if the dataset is not in the dictionary, add it and the first result | ||
| self.datasets[dsr.DataSetObj]=[] | ||
| res = dsr.ResultObj | ||
| # res.FeatureActionObj = None | ||
| self.datasets[dsr.DataSetObj].append(res) | ||
| else: | ||
| #if the dataset is in the dictionary, append the result object to the list | ||
| res = dsr.ResultObj | ||
| # res.FeatureActionObj = None | ||
| self.datasets[dsr.DataSetObj].append(res) | ||
| def assignRelatedFeatures(self, relatedfeatures): | ||
| self.related_features = {} | ||
| if relatedfeatures: | ||
| ||
| for related in relatedfeatures: | ||
| if related.SamplingFeatureTypeCV == 'Site': | ||
| self.related_features = related | ||
| @@ -875,7 +889,7 @@ def getDataSetsValues(self, ids=None, codes=None, uuids=None, dstype=None): | ||
| return None | ||
| def getSamplingFeatureDatasets(self, ids=None, codes=None, uuids=None, dstype=None): | ||
| def getSamplingFeatureDatasets(self, ids=None, codes=None, uuids=None, dstype=None, sftype=None): | ||
| """ | ||
| Retrieve a list of Datasets associated with the given sampling feature data. | ||
| @@ -887,7 +901,8 @@ def getSamplingFeatureDatasets(self, ids=None, codes=None, uuids=None, dstype=No | ||
| uuids (list, optional): List of UUIDs string. | ||
| dstype (str, optional): Type of Dataset from | ||
| `controlled vocabulary name <http://vocabulary.odm2.org/datasettype/>`_. | ||
| sftype (str, optional): Type of SamplingFeature from | ||
| `controlled vocabulary name <http://vocabulary.odm2.org/samplingfeaturetype/>`_. | ||
| Returns: | ||
| list: List of DataSetsResults Objects associated with the given sampling feature | ||
| @@ -899,26 +914,30 @@ def getSamplingFeatureDatasets(self, ids=None, codes=None, uuids=None, dstype=No | ||
| >>> READ.getSamplingFeatureDatasets(uuids=['a6f114f1-5416-4606-ae10-23be32dbc202', | ||
| ... '5396fdf3-ceb3-46b6-aaf9-454a37278bb4']) | ||
| >>> READ.getSamplingFeatureDatasets(dstype='singleTimeSeries') | ||
| >>> READ.getSamplingFeatureDatasets(sftype='Specimen') | ||
| """ | ||
| # make sure one of the three arguments has been sent in | ||
| if all(v is None for v in [ids, codes, uuids]): | ||
| raise ValueError('Expected samplingFeatureID OR samplingFeatureUUID OR samplingFeatureCode argument') | ||
| if all(v is None for v in [ids, codes, uuids, sftype]): | ||
| raise ValueError('Expected samplingFeatureID OR samplingFeatureUUID OR samplingFeatureCode OR samplingFeatureType ' | ||
| 'argument') | ||
| sf_query = self._session.query(SamplingFeatures) | ||
| if sftype: | ||
| sf_query = sf_query.filter(SamplingFeatures.SamplingFeatureTypeCV == sftype) | ||
| if ids: | ||
| sf_query = sf_query.filter(SamplingFeatures.SamplingFeatureID.in_(ids)) | ||
| if codes: | ||
| sf_query = sf_query.filter(SamplingFeatures.SamplingFeatureCode.in_(codes)) | ||
| if uuids: | ||
| sf_query = sf_query.filter(SamplingFeatures.SamplingFeatureUUID.in_(uuids)) | ||
| sf_list = [] | ||
| for sf in sf_query.all(): | ||
| sf_list.append(sf) | ||
| sfds = None | ||
| try: | ||
| sfds=[] | ||
| for sf in sf_list: | ||
| @@ -934,7 +953,9 @@ def getSamplingFeatureDatasets(self, ids=None, codes=None, uuids=None, dstype=No | ||
| vals = q.all() | ||
| sfds.append(SamplingFeatureDataSet(sf, vals)) | ||
| related = self.getRelatedSamplingFeatures(sf.SamplingFeatureID) | ||
| sfds.append(SamplingFeatureDataSet(sf, vals, related)) | ||
| except Exception as e: | ||
| print('Error running Query: {}'.format(e)) | ||
| return None | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this line to handle cases that there are no datasets associated.