|
12 | 12 | CalibrationActions, CalibrationReferenceEquipment, CalibrationStandards, |
13 | 13 | CategoricalResultValueAnnotations, CategoricalResultValues, CitationExtensionPropertyValues, |
14 | 14 | CitationExternalIdentifiers, DataLoggerFileColumns, DataLoggerFiles, DataLoggerProgramFiles, |
15 | | - DataQuality, DataSetCitations, DataSets, DerivationEquations, Directives, Equipment, |
| 15 | + DataQuality, DataSetCitations, DataSets, DataSetsResults, DerivationEquations, Directives, Equipment, |
16 | 16 | EquipmentActions, EquipmentAnnotations, EquipmentModels, EquipmentUsed, ExtensionProperties, |
17 | 17 | ExternalIdentifierSystems, FeatureActions, InstrumentOutputVariables, MaintenanceActions, |
18 | 18 | MeasurementResultValueAnnotations, MeasurementResultValues, MethodAnnotations, |
@@ -462,6 +462,8 @@ def getRelatedSamplingFeatures(self, sfid=None, rfid=None, relationshiptype=None |
462 | 462 | print('Error running Query: {}'.format(e)) |
463 | 463 | return None |
464 | 464 |
|
| 465 | + |
| 466 | + |
465 | 467 | # Action |
466 | 468 | def getActions(self, ids=None, type=None, sfid=None): |
467 | 469 | """ |
@@ -694,13 +696,70 @@ def getDataSets(self, codes=None, uuids=None): |
694 | 696 | if codes: |
695 | 697 | q = q.filter(DataSets.DataSetCode.in_(codes)) |
696 | 698 | if uuids: |
697 | | - q.q.filter(DataSets.DataSetUUID.in_(uuids)) |
| 699 | + q.filter(DataSets.DataSetUUID.in_(uuids)) |
698 | 700 | try: |
699 | 701 | return q.all() |
700 | 702 | except Exception as e: |
701 | 703 | print('Error running Query {}'.format(e)) |
702 | 704 | return None |
703 | 705 |
|
| 706 | + def getSamplingFeatureDatasets(self, ids=None, codes=None, uuids=None, dstype=None): |
| 707 | + """ |
| 708 | + Retrieve a list of Datasets associated with the given sampling feature data. |
| 709 | +
|
| 710 | + **Must specify either samplingFeatureID OR samplingFeatureUUID OR samplingFeatureCode)** |
| 711 | +
|
| 712 | + Args: |
| 713 | + ids (list, optional): List of SamplingFeatureIDs. |
| 714 | + codes (list, optional): List of SamplingFeature Codes. |
| 715 | + uuids (list, optional): List of UUIDs string. |
| 716 | + dstype (str, optional): Type of Dataset from |
| 717 | + `controlled vocabulary name <http://vocabulary.odm2.org/datasettype/>`_. |
| 718 | +
|
| 719 | +
|
| 720 | + Returns: |
| 721 | + list: List of DataSetsResults Objects associated with the given sampling feature |
| 722 | +
|
| 723 | + Examples: |
| 724 | + >>> READ = ReadODM2(SESSION_FACTORY) |
| 725 | + >>> READ.getSamplingFeatureDatasets(ids=[39, 40]) |
| 726 | + >>> READ.getSamplingFeatureDatasets(codes=['HOME', 'FIELD']) |
| 727 | + >>> READ.getSamplingFeatureDatasets(uuids=['a6f114f1-5416-4606-ae10-23be32dbc202', |
| 728 | + ... '5396fdf3-ceb3-46b6-aaf9-454a37278bb4']) |
| 729 | + >>> READ.getSamplingFeatureDatasets(dstype='singleTimeSeries') |
| 730 | +
|
| 731 | + """ |
| 732 | + |
| 733 | + |
| 734 | + # make sure one of the three arguments has been sent in |
| 735 | + if all(v is None for v in [ids, codes, uuids]): |
| 736 | + raise ValueError('Expected samplingFeatureID OR samplingFeatureUUID OR samplingFeatureCode argument') |
| 737 | + |
| 738 | + sf_query = self._session.query(SamplingFeatures.SamplingFeatureID) |
| 739 | + |
| 740 | + if ids: |
| 741 | + sf_query = sf_query.filter(SamplingFeatures.SamplingFeatureID.in_(ids)) |
| 742 | + if codes: |
| 743 | + sf_query = sf_query.filter(SamplingFeatures.SamplingFeatureCode.in_(codes)) |
| 744 | + if uuids: |
| 745 | + sf_query = sf_query.filter(SamplingFeatures.SamplingFeatureUUID.in_(uuids)) |
| 746 | + sf_list = sf_query.all() |
| 747 | + |
| 748 | + |
| 749 | + q = self._session.query(DataSetsResults)\ |
| 750 | + .join(Results)\ |
| 751 | + .join(FeatureActions)\ |
| 752 | + .filter(FeatureActions.SamplingFeatureID.in_(sf_list)) |
| 753 | + |
| 754 | + if dstype: |
| 755 | + q = q.filter_by(DatasetTypeCV=dstype) |
| 756 | + |
| 757 | + try: |
| 758 | + return q.all() |
| 759 | + except Exception as e: |
| 760 | + print('Error running Query: {}'.format(e)) |
| 761 | + return None |
| 762 | + |
704 | 763 | # Data Quality |
705 | 764 | def getDataQuality(self): |
706 | 765 | """ |
|
0 commit comments