-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this line to handle cases that there are no 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 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.