From 2a226760f19b81b97599781db586bc9a21176a9b Mon Sep 17 00:00:00 2001 From: sreeder Date: Thu, 9 Nov 2017 10:46:26 -0700 Subject: [PATCH 01/13] update getDatasets and create getDatasetsResults functions --- odm2api/ODM2/services/readService.py | 73 ++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 4 deletions(-) diff --git a/odm2api/ODM2/services/readService.py b/odm2api/ODM2/services/readService.py index 06252ad..7dde058 100644 --- a/odm2api/ODM2/services/readService.py +++ b/odm2api/ODM2/services/readService.py @@ -686,23 +686,88 @@ def getResults(self, ids=None, type=None, uuids=None, actionid=None, simulationi return None # Datasets - def getDataSets(self, codes=None, uuids=None): + def getDataSets(self, ids= None, codes=None, uuids=None, dstype=None): """ - * Pass nothing - returns a list of all DataSet objects - * Pass a list of DataSetCode - returns a single DataSet object for each code - * Pass a list of UUIDS - returns a single DataSet object for each UUID + Retrieve a list of Datasets + + Args: + ids (list, optional): List of DataSetsIDs. + codes (list, optional): List of DataSet Codes. + uuids (list, optional): List of Dataset UUIDs string. + dstype (str, optional): Type of Dataset from + `controlled vocabulary name `_. + + + Returns: + list: List of DataSets Objects + + Examples: + >>> READ = ReadODM2(SESSION_FACTORY) + >>> READ.getDataSets(ids=[39, 40]) + >>> READ.getDataSets(codes=['HOME', 'FIELD']) + >>> READ.getDataSets(uuids=['a6f114f1-5416-4606-ae10-23be32dbc202', + ... '5396fdf3-ceb3-46b6-aaf9-454a37278bb4']) + >>> READ.getDataSets(dstype='singleTimeSeries') + """ q = self._session.query(DataSets) + if ids: + q = q.filter(DataSets.DataSetID.in_(codes)) if codes: q = q.filter(DataSets.DataSetCode.in_(codes)) if uuids: q.filter(DataSets.DataSetUUID.in_(uuids)) + if dstype: + q = q.filter(DataSets.DataSetTypeCV == dstype) try: return q.all() except Exception as e: print('Error running Query {}'.format(e)) return None + # Datasets + + def getDataSetsResults(self, ids= None, codes=None, uuids=None, dstype=None): + """ + Retrieve a detailed list of Datasets along with detailed metadata about the datasets + and the results contained within them + + Args: + ids (list, optional): List of DataSetsIDs. + codes (list, optional): List of DataSet Codes. + uuids (list, optional): List of Dataset UUIDs string. + dstype (str, optional): Type of Dataset from + `controlled vocabulary name `_. + + + Returns: + list: List of DataSetsResults Objects + + Examples: + >>> READ = ReadODM2(SESSION_FACTORY) + >>> READ.getDataSetsResults(ids=[39, 40]) + >>> READ.getDataSetsResults(codes=['HOME', 'FIELD']) + >>> READ.getDataSetsResults(uuids=['a6f114f1-5416-4606-ae10-23be32dbc202', + ... '5396fdf3-ceb3-46b6-aaf9-454a37278bb4']) + >>> READ.getDataSetsResults(dstype='singleTimeSeries') + + """ + q = self._session.query(DataSetsResults)\ + .join(DataSets) + if ids: + q = q.filter(DataSets.DataSetID.in_(codes)) + if codes: + q = q.filter(DataSets.DataSetCode.in_(codes)) + if uuids: + q.filter(DataSets.DataSetUUID.in_(uuids)) + if dstype: + q = q.filter(DataSets.DataSetTypeCV == dstype) + try: + return q.all() + except Exception as e: + print('Error running Query {}'.format(e)) + return None + def getSamplingFeatureDatasets(self, ids=None, codes=None, uuids=None, dstype=None): """ Retrieve a list of Datasets associated with the given sampling feature data. From 1ce6c3712981c5faeabf52bd041df5811a47293a Mon Sep 17 00:00:00 2001 From: sreeder Date: Thu, 9 Nov 2017 10:48:18 -0700 Subject: [PATCH 02/13] add condition to getDatasetREsults function --- Examples/Sample.py | 9 ++++++++- odm2api/ODM2/services/readService.py | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Examples/Sample.py b/Examples/Sample.py index 3292780..27a4a15 100644 --- a/Examples/Sample.py +++ b/Examples/Sample.py @@ -17,7 +17,7 @@ #connect to database # createconnection (dbtype, servername, dbname, username, password) # session_factory = dbconnection.createConnection('connection type: sqlite|mysql|mssql|postgresql', '/your/path/to/db/goes/here', 2.0)#sqlite -session_factory = dbconnection.createConnection('postgresql', 'localhost', 'odm2', 'ODM', 'odm') +# session_factory = dbconnection.createConnection('postgresql', 'localhost', 'odm2', 'ODM', 'odm') # session_factory = dbconnection.createConnection('mysql', 'localhost', 'odm2', 'ODM', 'odm')#mysql # session_factory= dbconnection.createConnection('mssql', "(local)", "ODM2", "ODM", "odm")#win MSSQL @@ -27,6 +27,13 @@ # session_factory = dbconnection.createConnection('sqlite', '/Users/stephanie/DEV/YODA-Tools/tests/test_files/XL_specimen.sqlite', 2.0) +session_factory = dbconnection.createConnection('postgresql', 'odm2wofpy1.uwrl.usu.edu', 'odm2', 'dbadmin', 'pinkbananastastegross') + + + + + + diff --git a/odm2api/ODM2/services/readService.py b/odm2api/ODM2/services/readService.py index 7dde058..7269a69 100644 --- a/odm2api/ODM2/services/readService.py +++ b/odm2api/ODM2/services/readService.py @@ -732,6 +732,7 @@ def getDataSetsResults(self, ids= None, codes=None, uuids=None, dstype=None): Retrieve a detailed list of Datasets along with detailed metadata about the datasets and the results contained within them + **Must specify either DataSetID OR DataSetUUID OR DataSetCode)** Args: ids (list, optional): List of DataSetsIDs. codes (list, optional): List of DataSet Codes. @@ -752,6 +753,11 @@ def getDataSetsResults(self, ids= None, codes=None, uuids=None, dstype=None): >>> READ.getDataSetsResults(dstype='singleTimeSeries') """ + + # 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 DataSetID OR DataSetUUID OR DataSetCode argument') + q = self._session.query(DataSetsResults)\ .join(DataSets) if ids: From 4ea939503d8c164d954094d93cdba127f07c6ad3 Mon Sep 17 00:00:00 2001 From: sreeder Date: Mon, 13 Nov 2017 09:42:03 -0700 Subject: [PATCH 03/13] fix typo in get from ids --- odm2api/ODM2/services/readService.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/odm2api/ODM2/services/readService.py b/odm2api/ODM2/services/readService.py index 7269a69..2e18772 100644 --- a/odm2api/ODM2/services/readService.py +++ b/odm2api/ODM2/services/readService.py @@ -712,7 +712,7 @@ def getDataSets(self, ids= None, codes=None, uuids=None, dstype=None): """ q = self._session.query(DataSets) if ids: - q = q.filter(DataSets.DataSetID.in_(codes)) + q = q.filter(DataSets.DataSetID.in_(ids)) if codes: q = q.filter(DataSets.DataSetCode.in_(codes)) if uuids: @@ -761,7 +761,7 @@ def getDataSetsResults(self, ids= None, codes=None, uuids=None, dstype=None): q = self._session.query(DataSetsResults)\ .join(DataSets) if ids: - q = q.filter(DataSets.DataSetID.in_(codes)) + q = q.filter(DataSets.DataSetID.in_(ids)) if codes: q = q.filter(DataSets.DataSetCode.in_(codes)) if uuids: From 11b0c36c28557f41f0ff62f8c840f5f6382f3dd6 Mon Sep 17 00:00:00 2001 From: sreeder Date: Mon, 13 Nov 2017 09:53:03 -0700 Subject: [PATCH 04/13] update Sample.py --- Examples/Sample.py | 8 +------- tests/test_odm2/test_readservice.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Examples/Sample.py b/Examples/Sample.py index 27a4a15..dcd8896 100644 --- a/Examples/Sample.py +++ b/Examples/Sample.py @@ -17,18 +17,15 @@ #connect to database # createconnection (dbtype, servername, dbname, username, password) # session_factory = dbconnection.createConnection('connection type: sqlite|mysql|mssql|postgresql', '/your/path/to/db/goes/here', 2.0)#sqlite -# session_factory = dbconnection.createConnection('postgresql', 'localhost', 'odm2', 'ODM', 'odm') +session_factory = dbconnection.createConnection('postgresql', 'localhost', 'odm2', 'ODM', 'odm') # session_factory = dbconnection.createConnection('mysql', 'localhost', 'odm2', 'ODM', 'odm')#mysql # session_factory= dbconnection.createConnection('mssql', "(local)", "ODM2", "ODM", "odm")#win MSSQL - # session_factory= dbconnection.createConnection('mssql', "arroyoodm2", "", "ODM", "odm")#mac/linux MSSQL # session_factory = dbconnection.createConnection('sqlite', '/Users/stephanie/DEV/YODA-Tools/tests/test_files/XL_specimen.sqlite', 2.0) -session_factory = dbconnection.createConnection('postgresql', 'odm2wofpy1.uwrl.usu.edu', 'odm2', 'dbadmin', 'pinkbananastastegross') - @@ -42,9 +39,6 @@ create = CreateODM2(session_factory) - - - # Run some basic sample queries. # ------------------------------ # Get all of the variables from the database and print their names to the console diff --git a/tests/test_odm2/test_readservice.py b/tests/test_odm2/test_readservice.py index 6ea9154..3311ab8 100644 --- a/tests/test_odm2/test_readservice.py +++ b/tests/test_odm2/test_readservice.py @@ -92,6 +92,26 @@ def test_getSamplingFeatureByID(self): resapi = self.reader.getSamplingFeatures(ids=[sfid]) assert resapi is not None +#DataSets + def test_getDataSets(self): + # get all datasets from the database + ds = self.engine.execute('SELECT * FROM DataSets').fetchone() + dsid = ds[0] + + dsapi = self.reader.getDataSets(ids=[dsid]) + assert dsapi is not None + assert True + + def test_getDataSetsResults(self): + # get all datasetresults from the database + dsr = self.engine.execute('SELECT * FROM DataSetsResults').fetchone() + dsid = dsr[2] + + dsrapi = self.reader.getDataSetsResults(ids=[dsid]) + assert dsrapi is not None + assert True + + # Models """ TABLE Models From 8a8ffe7d795cab657798c7149c9d4355e5c47bb5 Mon Sep 17 00:00:00 2001 From: sreeder Date: Mon, 13 Nov 2017 13:27:56 -0700 Subject: [PATCH 05/13] update tests, update DateTime data type to be compatible with sqlite, some BigInteger values in models.py were the incorrect type --- odm2api/ODM2/models.py | 58 +++++++++++--------- odm2api/ODM2/services/readService.py | 17 +++++- tests/test_odm2/data/populated.sql | 82 ++++++++++++++-------------- tests/test_odm2/test_readservice.py | 15 +++++ 4 files changed, 103 insertions(+), 69 deletions(-) diff --git a/odm2api/ODM2/models.py b/odm2api/ODM2/models.py index 7b6d5b2..f238659 100644 --- a/odm2api/ODM2/models.py +++ b/odm2api/ODM2/models.py @@ -2,9 +2,10 @@ from odm2api.base import modelBase -from sqlalchemy import BigInteger, Boolean, Column, Date, DateTime, Float, ForeignKey, Integer, String, case +from sqlalchemy import BigInteger, Boolean, Column, Date, DateTime, Float, ForeignKey, Integer, String, case, types, Table, event from sqlalchemy.dialects import mysql, postgresql, sqlite from sqlalchemy.orm import relationship +from datetime import datetime, timedelta Base = modelBase.Base @@ -13,6 +14,9 @@ BigIntegerType = BigIntegerType.with_variant(postgresql.BIGINT(), 'postgresql') BigIntegerType = BigIntegerType.with_variant(mysql.BIGINT(), 'mysql') +DateTimeType = DateTime() +DateTimeType = DateTimeType.with_variant(sqlite.INTEGER(), 'sqlite') + def is_hex(s): try: @@ -404,9 +408,9 @@ class Results(Base): ProcessingLevelID = Column('processinglevelid', ForeignKey(ProcessingLevels.ProcessingLevelID), nullable=False) ResultDateTime = Column('resultdatetime', DateTime) - ResultDateTimeUTCOffset = Column('resultdatetimeutcoffset', BigInteger) + ResultDateTimeUTCOffset = Column('resultdatetimeutcoffset', BigIntegerType) ValidDateTime = Column('validdatetime', DateTime) - ValidDateTimeUTCOffset = Column('validdatetimeutcoffset', BigInteger) + ValidDateTimeUTCOffset = Column('validdatetimeutcoffset', BigIntegerType) StatusCV = Column('statuscv', ForeignKey(CVStatus.Name), index=True) SampledMediumCV = Column('sampledmediumcv', ForeignKey(CVMediumType.Name), nullable=False, index=True) ValueCount = Column('valuecount', Integer, nullable=False) @@ -503,7 +507,7 @@ class InstrumentOutputVariables(Base): class DataLoggerFileColumns(Base): DataLoggerFileColumnID = Column('dataloggerfilecolumnid', Integer, primary_key=True, nullable=False) - ResultID = Column('resultid', BigInteger, ForeignKey(Results.ResultID)) + ResultID = Column('resultid', BigIntegerType, ForeignKey(Results.ResultID)) DataLoggerFileID = Column('dataloggerfileid', Integer, ForeignKey(DataLoggerFiles.DataLoggerFileID), nullable=False) InstrumentOutputVariableID = Column('instrumentoutputvariableid', Integer, @@ -861,7 +865,7 @@ class ActionAnnotations(Base): class EquipmentAnnotations(Base): BridgeID = Column('bridgeid', Integer, primary_key=True, nullable=False) - EquipmentID = Column('valueid', BigInteger, ForeignKey(Equipment.EquipmentID), nullable=False) + EquipmentID = Column('valueid', BigIntegerType, ForeignKey(Equipment.EquipmentID), nullable=False) AnnotationID = Column('annotationid', ForeignKey(Annotations.AnnotationID), nullable=False) AnnotationObj = relationship(Annotations) @@ -1640,7 +1644,7 @@ class CategoricalResultValues(Base): ValueID = Column('valueid', BigIntegerType, primary_key=True) ResultID = Column('resultid', ForeignKey(CategoricalResults.ResultID), nullable=False) DataValue = Column('datavalue', String(255), nullable=False) - ValueDateTime = Column('valuedatetime', DateTime, nullable=False) + ValueDateTime = Column('valuedatetime', DateTimeType, nullable=False) ValueDateTimeUTCOffset = Column('valuedatetimeutcoffset', Integer, nullable=False) ResultObj = relationship(CategoricalResults) @@ -1651,7 +1655,7 @@ class MeasurementResultValues(Base): ValueID = Column('valueid', BigIntegerType, primary_key=True) ResultID = Column('resultid', ForeignKey(MeasurementResults.ResultID), nullable=False) DataValue = Column('datavalue', Float(53), nullable=False) - ValueDateTime = Column('valuedatetime', DateTime, nullable=False) + ValueDateTime = Column('valuedatetime', DateTimeType, nullable=False) ValueDateTimeUTCOffset = Column('valuedatetimeutcoffset', Integer, nullable=False) ResultObj = relationship(MeasurementResults) @@ -1661,8 +1665,8 @@ class PointCoverageResultValues(Base): ValueID = Column('valueid', BigIntegerType, primary_key=True) ResultID = Column('resultid', ForeignKey(PointCoverageResults.ResultID), nullable=False) - DataValue = Column('datavalue', BigInteger, nullable=False) - ValueDateTime = Column('valuedatetime', DateTime, nullable=False) + DataValue = Column('datavalue', BigIntegerType, nullable=False) + ValueDateTime = Column('valuedatetime', DateTimeType, nullable=False) ValueDateTimeUTCOffset = Column('valuedatetimeutcoffset', Integer, nullable=False) XLocation = Column('xlocation', Float(53), nullable=False) XLocationUnitsID = Column('xlocationunitsid', ForeignKey(Units.UnitsID), nullable=False) @@ -1687,7 +1691,7 @@ class ProfileResultValues(Base): ValueID = Column('valueid', BigIntegerType, primary_key=True) ResultID = Column('resultid', ForeignKey(ProfileResults.ResultID), nullable=False) DataValue = Column('datavalue', Float(53), nullable=False) - ValueDateTime = Column('valuedatetime', DateTime, nullable=False) + ValueDateTime = Column('valuedatetime', DateTimeType, nullable=False) ValueDateTimeUTCOffset = Column('valuedatetimeutcoffset', Integer, nullable=False) ZLocation = Column('zlocation', Float(53), nullable=False) ZAggregationInterval = Column('zaggregationinterval', Float(53), nullable=False) @@ -1714,12 +1718,12 @@ class SectionResultValues(Base): ValueID = Column('valueid', BigIntegerType, primary_key=True) ResultID = Column('resultid', ForeignKey(SectionResults.ResultID), nullable=False) DataValue = Column('datavalue', Float(53), nullable=False) - ValueDateTime = Column('valuedatetime', BigInteger, nullable=False) - ValueDateTimeUTCOffset = Column('valuedatetimeutcoffset', BigInteger, nullable=False) + ValueDateTime = Column('valuedatetime', DateTimeType, nullable=False) + ValueDateTimeUTCOffset = Column('valuedatetimeutcoffset', Integer, nullable=False) XLocation = Column('xlocation', Float(53), nullable=False) XAggregationInterval = Column('xaggregationinterval', Float(53), nullable=False) XLocationUnitsID = Column('xlocationunitsid', ForeignKey(Units.UnitsID), nullable=False) - ZLocation = Column('zlocation', BigInteger, nullable=False) + ZLocation = Column('zlocation', BigIntegerType, nullable=False) ZAggregationInterval = Column('zaggregationinterval', Float(53), nullable=False) ZLocationUnitsID = Column('zlocationunitsid', ForeignKey(Units.UnitsID), nullable=False) CensorCodeCV = Column('censorcodecv', ForeignKey(CVCensorCode.Name), nullable=False, index=True) @@ -1750,7 +1754,7 @@ class SpectraResultValues(Base): ValueID = Column('valueid', BigIntegerType, primary_key=True) ResultID = Column('resultid', ForeignKey(SpectraResults.ResultID), nullable=False) DataValue = Column('datavalue', Float(53), nullable=False) - ValueDateTime = Column('valuedatetime', DateTime, nullable=False) + ValueDateTime = Column('valuedatetime', DateTimeType, nullable=False) ValueDateTimeUTCOffset = Column('valuedatetimeutcoffset', Integer, nullable=False) ExcitationWavelength = Column('excitationwavelength', Float(53), nullable=False) EmissionWavelength = Column('emmistionwavelength', Float(53), nullable=False) @@ -1779,7 +1783,7 @@ class TimeSeriesResultValues(Base): ValueID = Column('valueid', BigIntegerType, primary_key=True) ResultID = Column('resultid', ForeignKey(TimeSeriesResults.ResultID), nullable=False) DataValue = Column('datavalue', Float(53), nullable=False) - ValueDateTime = Column('valuedatetime', DateTime, nullable=False) + ValueDateTime = Column('valuedatetime', DateTimeType, nullable=False) ValueDateTimeUTCOffset = Column('valuedatetimeutcoffset', Integer, nullable=False) CensorCodeCV = Column('censorcodecv', ForeignKey(CVCensorCode.Name), nullable=False, index=True) QualityCodeCV = Column('qualitycodecv', ForeignKey(CVQualityCode.Name), nullable=False, index=True) @@ -1805,7 +1809,7 @@ class TrajectoryResultValues(Base): ValueID = Column('valueid', BigIntegerType, primary_key=True) ResultID = Column('resultid', ForeignKey(TrajectoryResults.ResultID), nullable=False) DataValue = Column('datavalue', Float(53), nullable=False) - ValueDateTime = Column('valuedatetime', DateTime, nullable=False) + ValueDateTime = Column('valuedatetime', DateTimeType, nullable=False) ValueDateTimeUTCOffset = Column('valuedatetimeutcoffset', Integer, nullable=False) XLocation = Column('xlocation', Float(53), nullable=False) XLocationUnitsID = Column('xlocationunitsid', ForeignKey(Units.UnitsID), nullable=False) @@ -1850,8 +1854,8 @@ class TransectResultValues(Base): ValueID = Column('valueid', BigIntegerType, primary_key=True) ResultID = Column('resultid', ForeignKey(TransectResults.ResultID), nullable=False) DataValue = Column('datavalue', Float(53), nullable=False) - ValueDateTime = Column('valuedatetime', DateTime, nullable=False) - ValueDateTimeUTCOffset = Column('valuedatetimeutcoffset', DateTime, nullable=False) + ValueDateTime = Column('valuedatetime', DateTimeType, nullable=False) + ValueDateTimeUTCOffset = Column('valuedatetimeutcoffset', Integer, nullable=False) XLocation = Column('xlocation', Float(53), nullable=False) XLocationUnitsID = Column('xlocationunitsid', ForeignKey(Units.UnitsID), nullable=False) YLocation = Column('ylocation', Float(53), nullable=False) @@ -1896,7 +1900,7 @@ class TransectResultValues(Base): class CategoricalResultValueAnnotations(Base): BridgeID = Column('bridgeid', Integer, primary_key=True, nullable=False) - ValueID = Column('valueid', BigInteger, ForeignKey(CategoricalResultValues.ValueID), nullable=False) + ValueID = Column('valueid', BigIntegerType, ForeignKey(CategoricalResultValues.ValueID), nullable=False) AnnotationID = Column('annotationid', ForeignKey(Annotations.AnnotationID), nullable=False) AnnotationObj = relationship(Annotations) @@ -1906,7 +1910,7 @@ class CategoricalResultValueAnnotations(Base): class MeasurementResultValueAnnotations(Base): BridgeID = Column('bridgeid', Integer, primary_key=True, nullable=False) - ValueID = Column('valueid', BigInteger, ForeignKey(MeasurementResultValues.ValueID), nullable=False) + ValueID = Column('valueid', BigIntegerType, ForeignKey(MeasurementResultValues.ValueID), nullable=False) AnnotationID = Column('annotationid', ForeignKey(Annotations.AnnotationID), nullable=False) AnnotationObj = relationship(Annotations) @@ -1916,7 +1920,7 @@ class MeasurementResultValueAnnotations(Base): class PointCoverageResultValueAnnotations(Base): BridgeID = Column('bridgeid', Integer, primary_key=True, nullable=False) - ValueID = Column('valueid', BigInteger, ForeignKey(PointCoverageResultValues.ValueID), nullable=False) + ValueID = Column('valueid', BigIntegerType, ForeignKey(PointCoverageResultValues.ValueID), nullable=False) AnnotationID = Column('annotationid', ForeignKey(Annotations.AnnotationID), nullable=False) AnnotationObj = relationship(Annotations) @@ -1926,7 +1930,7 @@ class PointCoverageResultValueAnnotations(Base): class ProfileResultValueAnnotations(Base): BridgeID = Column('bridgeid', Integer, primary_key=True, nullable=False) - ValueID = Column('valueid', BigInteger, ForeignKey(ProfileResultValues.ValueID), nullable=False) + ValueID = Column('valueid', BigIntegerType, ForeignKey(ProfileResultValues.ValueID), nullable=False) AnnotationID = Column('annotationid', ForeignKey(Annotations.AnnotationID), nullable=False) AnnotationObj = relationship(Annotations) @@ -1936,7 +1940,7 @@ class ProfileResultValueAnnotations(Base): class SectionResultValueAnnotations(Base): BridgeID = Column('bridgeid', Integer, primary_key=True, nullable=False) - ValueID = Column('valueid', BigInteger, ForeignKey(SectionResultValues.ValueID), nullable=False) + ValueID = Column('valueid', BigIntegerType, ForeignKey(SectionResultValues.ValueID), nullable=False) AnnotationID = Column('annotationid', ForeignKey(Annotations.AnnotationID), nullable=False) AnnotationObj = relationship(Annotations) @@ -1946,7 +1950,7 @@ class SectionResultValueAnnotations(Base): class SpectraResultValueAnnotations(Base): BridgeID = Column('bridgeid', Integer, primary_key=True, nullable=False) - ValueID = Column('valueid', BigInteger, ForeignKey(SpectraResultValues.ValueID), nullable=False) + ValueID = Column('valueid', BigIntegerType, ForeignKey(SpectraResultValues.ValueID), nullable=False) AnnotationID = Column('annotationid', ForeignKey(Annotations.AnnotationID), nullable=False) AnnotationObj = relationship(Annotations) @@ -1956,7 +1960,7 @@ class SpectraResultValueAnnotations(Base): class TimeSeriesResultValueAnnotations(Base): BridgeID = Column('bridgeid', Integer, primary_key=True, nullable=False) - ValueID = Column('valueid', BigInteger, ForeignKey(TimeSeriesResultValues.ValueID), nullable=False) + ValueID = Column('valueid', BigIntegerType, ForeignKey(TimeSeriesResultValues.ValueID), nullable=False) AnnotationID = Column('annotationid', ForeignKey(Annotations.AnnotationID), nullable=False) AnnotationObj = relationship(Annotations) @@ -1966,7 +1970,7 @@ class TimeSeriesResultValueAnnotations(Base): class TrajectoryResultValueAnnotations(Base): BridgeID = Column('bridgeid', Integer, primary_key=True, nullable=False) - ValueID = Column('valueid', BigInteger, ForeignKey(TrajectoryResultValues.ValueID), nullable=False) + ValueID = Column('valueid', BigIntegerType, ForeignKey(TrajectoryResultValues.ValueID), nullable=False) AnnotationID = Column('annotationid', ForeignKey(Annotations.AnnotationID), nullable=False) AnnotationObj = relationship(Annotations) @@ -1976,7 +1980,7 @@ class TrajectoryResultValueAnnotations(Base): class TransectResultValueAnnotations(Base): BridgeID = Column('bridgeid', Integer, primary_key=True, nullable=False) - ValueID = Column('valueid', BigInteger, ForeignKey(TransectResultValues.ValueID), nullable=False) + ValueID = Column('valueid', BigIntegerType, ForeignKey(TransectResultValues.ValueID), nullable=False) AnnotationID = Column('annotationid', ForeignKey(Annotations.AnnotationID), nullable=False) AnnotationObj = relationship(Annotations) diff --git a/odm2api/ODM2/services/readService.py b/odm2api/ODM2/services/readService.py index 2e18772..c921759 100644 --- a/odm2api/ODM2/services/readService.py +++ b/odm2api/ODM2/services/readService.py @@ -774,6 +774,21 @@ def getDataSetsResults(self, ids= None, codes=None, uuids=None, dstype=None): print('Error running Query {}'.format(e)) return None + def getDataSetsValues(self, ids=None, codes=None, uuids=None, dstype=None): + + dsr = self.getDataSetsResults(ids, codes, uuids, dstype) + + resids = [] + for ds in dsr: + resids.append(ds.ResultID) + + try: + return self.getResultValues(resultids = resids) + except Exception as e: + print('Error running Query {}'.format(e)) + return None + + def getSamplingFeatureDatasets(self, ids=None, codes=None, uuids=None, dstype=None): """ Retrieve a list of Datasets associated with the given sampling feature data. @@ -1133,7 +1148,7 @@ def getResultValues(self, resultids, starttime=None, endtime=None): """ type = self._session.query(Results).filter_by(ResultID=resultids[0]).first().ResultTypeCV - ResultType = TimeSeriesResults + ResultType = TimeSeriesResultValues if 'categorical' in type.lower(): ResultType = CategoricalResultValues elif 'measurement' in type.lower(): diff --git a/tests/test_odm2/data/populated.sql b/tests/test_odm2/data/populated.sql index 84a1e23..c9f8689 100644 --- a/tests/test_odm2/data/populated.sql +++ b/tests/test_odm2/data/populated.sql @@ -11541,47 +11541,47 @@ INSERT INTO "TimeSeriesResultValues" VALUES(9982,1,11.9,'2014-12-31 23:30:00',-7 INSERT INTO "TimeSeriesResultValues" VALUES(9983,1,11.9,'2014-12-31 23:45:00',-7,'nc','Unknown',0.0,102); INSERT INTO "TimeSeriesResultValues" VALUES(9984,1,11.9,'2014-12-31 23:45:00',-7,'nc','Unknown',0.0,102); INSERT INTO "TimeSeriesResultValues" VALUES(9985,1,11.9,'2015-01-01 00:00:00',-7,'nc','Unknown',0.0,102); -INSERT INTO "TimeSeriesResultValues" VALUES(9986,1,184.0,'2013-06-15',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(9987,1,200.0,'2013-05-06',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(9988,1,201.0,'2013-06-14',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(9989,1,208.0,'2013-06-13',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(9990,1,214.0,'2013-05-07',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(9991,1,221.0,'2013-06-12',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(9992,1,229.0,'2013-05-08',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(9993,1,233.0,'2013-05-09',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(9994,1,242.0,'2013-06-06',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(9995,1,243.0,'2013-06-07',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(9996,1,245.0,'2013-06-11',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(9997,1,249.0,'2013-06-02',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(9998,1,251.0,'2013-06-08',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(9999,1,254.0,'2013-06-01',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10000,1,256.0,'2013-06-10',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10001,1,258.0,'2013-06-05',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10002,1,260.0,'2013-06-09',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10003,1,263.0,'2013-06-03',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10004,1,265.0,'2013-05-10',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10005,1,265.0,'2013-06-04',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10006,1,270.0,'2013-05-31',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10007,1,291.0,'2013-05-11',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10008,1,306.0,'2013-05-30',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10009,1,315.0,'2013-05-27',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10010,1,316.0,'2013-05-12',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10011,1,317.0,'2013-05-29',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10012,1,320.0,'2013-05-25',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10013,1,321.0,'2013-05-28',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10014,1,322.0,'2013-05-26',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10015,1,338.0,'2013-05-24',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10016,1,341.0,'2013-05-22',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10017,1,346.0,'2013-05-21',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10018,1,347.0,'2013-05-23',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10019,1,358.0,'2013-05-13',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10020,1,367.0,'2013-05-20',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10021,1,393.0,'2013-05-19',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10022,1,422.0,'2013-05-14',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10023,1,453.0,'2013-05-18',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10024,1,458.0,'2013-05-15',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10025,1,478.0,'2013-05-16',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10026,1,480.0,'2013-05-17',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(9986,1,184.0,'2013-06-15 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(9987,1,200.0,'2013-05-06 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(9988,1,201.0,'2013-06-14 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(9989,1,208.0,'2013-06-13 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(9990,1,214.0,'2013-05-07 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(9991,1,221.0,'2013-06-12 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(9992,1,229.0,'2013-05-08 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(9993,1,233.0,'2013-05-09 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(9994,1,242.0,'2013-06-06 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(9995,1,243.0,'2013-06-07 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(9996,1,245.0,'2013-06-11 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(9997,1,249.0,'2013-06-02 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(9998,1,251.0,'2013-06-08 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(9999,1,254.0,'2013-06-01 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10000,1,256.0,'2013-06-10 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10001,1,258.0,'2013-06-05 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10002,1,260.0,'2013-06-09 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10003,1,263.0,'2013-06-03 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10004,1,265.0,'2013-05-10 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10005,1,265.0,'2013-06-04 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10006,1,270.0,'2013-05-31 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10007,1,291.0,'2013-05-11 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10008,1,306.0,'2013-05-30 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10009,1,315.0,'2013-05-27 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10010,1,316.0,'2013-05-12 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10011,1,317.0,'2013-05-29 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10012,1,320.0,'2013-05-25 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10013,1,321.0,'2013-05-28 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10014,1,322.0,'2013-05-26 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10015,1,338.0,'2013-05-24 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10016,1,341.0,'2013-05-22 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10017,1,346.0,'2013-05-21 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10018,1,347.0,'2013-05-23 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10019,1,358.0,'2013-05-13 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10020,1,367.0,'2013-05-20 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10021,1,393.0,'2013-05-19 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10022,1,422.0,'2013-05-14 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10023,1,453.0,'2013-05-18 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10024,1,458.0,'2013-05-15 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10025,1,478.0,'2013-05-16 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10026,1,480.0,'2013-05-17 00:00:00',-6,'nc','provisional',0.0,204); INSERT INTO "TimeSeriesResultValues" VALUES(10027,2,0.0,'02/07/2013 00:00:00',-5,'nc','provisional',1.0,206); INSERT INTO "TimeSeriesResultValues" VALUES(10028,2,0.254,'02/07/2013 00:01:00',-5,'nc','provisional',1.0,206); INSERT INTO "TimeSeriesResultValues" VALUES(10029,2,0.254,'02/07/2013 00:02:00',-5,'nc','provisional',1.0,206); diff --git a/tests/test_odm2/test_readservice.py b/tests/test_odm2/test_readservice.py index 3311ab8..1675929 100644 --- a/tests/test_odm2/test_readservice.py +++ b/tests/test_odm2/test_readservice.py @@ -111,6 +111,21 @@ def test_getDataSetsResults(self): assert dsrapi is not None assert True + def test_getDataSetsValues(self): + + dsr = self.engine.execute('SELECT * FROM DataSetsResults').fetchone() + dsid = dsr[2] + + values= self.reader.getDataSetsValues(ids=[dsid]) + assert values is not None + assert len(values) > 0 + + + + #ToDo figure out how to actually test this function + def test_getSamplingFeatureDataSets(self): + assert True + # Models """ From 120008d29e7cfbbe72bc222c5ba2a6779529c033 Mon Sep 17 00:00:00 2001 From: sreeder Date: Mon, 13 Nov 2017 13:30:32 -0700 Subject: [PATCH 06/13] fix sample.py file --- Examples/Sample.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Examples/Sample.py b/Examples/Sample.py index dcd8896..b441620 100644 --- a/Examples/Sample.py +++ b/Examples/Sample.py @@ -28,7 +28,9 @@ - +#_session = session_factory.getSession() +read = ReadODM2(session_factory) +create = CreateODM2(session_factory) From a88c8aec7410e65f54f4135b8b7c1e0796cdfcba Mon Sep 17 00:00:00 2001 From: sreeder Date: Mon, 13 Nov 2017 13:31:06 -0700 Subject: [PATCH 07/13] accidentally duplicated code --- Examples/Sample.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Examples/Sample.py b/Examples/Sample.py index b441620..e0a315f 100644 --- a/Examples/Sample.py +++ b/Examples/Sample.py @@ -28,14 +28,6 @@ -#_session = session_factory.getSession() -read = ReadODM2(session_factory) -create = CreateODM2(session_factory) - - - - - #_session = session_factory.getSession() read = ReadODM2(session_factory) create = CreateODM2(session_factory) From 9624cc5b8e74da79e45fe3b0b11743814e58ee87 Mon Sep 17 00:00:00 2001 From: sreeder Date: Mon, 13 Nov 2017 13:31:52 -0700 Subject: [PATCH 08/13] remvoe unused imports in models.py --- odm2api/ODM2/models.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/odm2api/ODM2/models.py b/odm2api/ODM2/models.py index f238659..1b7a049 100644 --- a/odm2api/ODM2/models.py +++ b/odm2api/ODM2/models.py @@ -2,11 +2,9 @@ from odm2api.base import modelBase -from sqlalchemy import BigInteger, Boolean, Column, Date, DateTime, Float, ForeignKey, Integer, String, case, types, Table, event +from sqlalchemy import BigInteger, Boolean, Column, Date, DateTime, Float, ForeignKey, Integer, String, case from sqlalchemy.dialects import mysql, postgresql, sqlite from sqlalchemy.orm import relationship -from datetime import datetime, timedelta - Base = modelBase.Base BigIntegerType = BigInteger() From a4febb43a430f90b08e0f03c29e73e2e52117c7d Mon Sep 17 00:00:00 2001 From: sreeder Date: Mon, 13 Nov 2017 14:17:20 -0700 Subject: [PATCH 09/13] fix issue with getSamplingFeatureDatasets --- odm2api/ODM2/services/readService.py | 8 ++++--- tests/test_odm2/data/populated.sql | 28 +++++++++++------------ tests/test_odm2/test_readservice.py | 33 ++++++++++++++++++++++++---- 3 files changed, 48 insertions(+), 21 deletions(-) diff --git a/odm2api/ODM2/services/readService.py b/odm2api/ODM2/services/readService.py index c921759..66bfbca 100644 --- a/odm2api/ODM2/services/readService.py +++ b/odm2api/ODM2/services/readService.py @@ -632,7 +632,8 @@ def getResults(self, ids=None, type=None, uuids=None, actionid=None, simulationi simulationid (int, optional): SimulationID. sfid (int, optional): SamplingFeatureID. variableid (int, optional): VariableID. - siteid (int, optional): SiteID. + siteid (int, optional): SiteID. - goes through related features table and finds all of the measurement + values recorded at the given site Returns: list: List of Result objects @@ -829,8 +830,9 @@ def getSamplingFeatureDatasets(self, ids=None, codes=None, uuids=None, dstype=No sf_query = sf_query.filter(SamplingFeatures.SamplingFeatureCode.in_(codes)) if uuids: sf_query = sf_query.filter(SamplingFeatures.SamplingFeatureUUID.in_(uuids)) - sf_list = sf_query.all() - + sf_list = [] + for sf in sf_query.all(): + sf_list.append(sf[0]) q = self._session.query(DataSetsResults)\ .join(Results)\ diff --git a/tests/test_odm2/data/populated.sql b/tests/test_odm2/data/populated.sql index c9f8689..8188a01 100644 --- a/tests/test_odm2/data/populated.sql +++ b/tests/test_odm2/data/populated.sql @@ -11568,20 +11568,20 @@ INSERT INTO "TimeSeriesResultValues" VALUES(10009,1,315.0,'2013-05-27 00:00:00', INSERT INTO "TimeSeriesResultValues" VALUES(10010,1,316.0,'2013-05-12 00:00:00',-6,'nc','provisional',0.0,204); INSERT INTO "TimeSeriesResultValues" VALUES(10011,1,317.0,'2013-05-29 00:00:00',-6,'nc','provisional',0.0,204); INSERT INTO "TimeSeriesResultValues" VALUES(10012,1,320.0,'2013-05-25 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10013,1,321.0,'2013-05-28 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10014,1,322.0,'2013-05-26 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10015,1,338.0,'2013-05-24 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10016,1,341.0,'2013-05-22 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10017,1,346.0,'2013-05-21 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10018,1,347.0,'2013-05-23 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10019,1,358.0,'2013-05-13 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10020,1,367.0,'2013-05-20 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10021,1,393.0,'2013-05-19 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10022,1,422.0,'2013-05-14 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10023,1,453.0,'2013-05-18 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10024,1,458.0,'2013-05-15 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10025,1,478.0,'2013-05-16 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10026,1,480.0,'2013-05-17 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10013,1,321.0,'2013-05-28',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10014,1,322.0,'2013-05-26',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10015,1,338.0,'2013-05-24',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10016,1,341.0,'2013-05-22',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10017,1,346.0,'2013-05-21',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10018,1,347.0,'2013-05-23',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10019,1,358.0,'2013-05-13',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10020,1,367.0,'2013-05-20',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10021,1,393.0,'2013-05-19',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10022,1,422.0,'2013-05-14',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10023,1,453.0,'2013-05-18',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10024,1,458.0,'2013-05-15',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10025,1,478.0,'2013-05-16',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10026,1,480.0,'2013-05-17',-6,'nc','provisional',0.0,204); INSERT INTO "TimeSeriesResultValues" VALUES(10027,2,0.0,'02/07/2013 00:00:00',-5,'nc','provisional',1.0,206); INSERT INTO "TimeSeriesResultValues" VALUES(10028,2,0.254,'02/07/2013 00:01:00',-5,'nc','provisional',1.0,206); INSERT INTO "TimeSeriesResultValues" VALUES(10029,2,0.254,'02/07/2013 00:02:00',-5,'nc','provisional',1.0,206); diff --git a/tests/test_odm2/test_readservice.py b/tests/test_odm2/test_readservice.py index 1675929..a2ce719 100644 --- a/tests/test_odm2/test_readservice.py +++ b/tests/test_odm2/test_readservice.py @@ -124,7 +124,32 @@ def test_getDataSetsValues(self): #ToDo figure out how to actually test this function def test_getSamplingFeatureDataSets(self): - assert True + + #find a sampling feature that is associated with a dataset + sf = self.engine.execute( + 'SELECT * from SamplingFeatures as sf ' + 'inner join FeatureActions as fa on fa.SamplingFeatureID == sf.SamplingFeatureID ' + 'inner join Results as r on fa.FeatureActionID == r.FeatureActionID ' + 'inner join DataSetsResults as ds on r.ResultID == ds.ResultID ' + ).fetchone() + assert len(sf) > 0 + + #get the dataset associated with the sampling feature + ds = self.engine.execute( + 'SELECT * from DataSetsResults as ds ' + 'inner join Results as r on r.ResultID == ds.ResultID ' + 'inner join FeatureActions as fa on fa.FeatureActionID == r.FeatureActionID ' + 'where fa.SamplingFeatureID = ' + str(sf[0]) + ).fetchone() + assert len(ds) > 0 + + print (sf[0]) + # get the dataset associated with the sampling feature using hte api + dsapi = self.reader.getSamplingFeatureDatasets(ids=[sf[0]]) + + assert dsapi is not None + assert len(dsapi) > 0 + assert ds[1] == dsapi[0].DataSetID # Models @@ -178,7 +203,7 @@ def test_getRelatedModelsByCode(self): resapi = self.reader.getRelatedModels(code='swat') assert resapi is not None assert len(resapi) > 0 - print(resapi[0].ModelCode) + # print(resapi[0].ModelCode) assert resapi[0].ModelCode == 'swat' # test converter code that doesn't exist resapi = self.reader.getRelatedModels(code='None') @@ -213,7 +238,7 @@ def test_getRelatedModelsByCode(self): def test_getAllResults(self): # get all results from the database res = self.engine.execute('SELECT * FROM Results').fetchall() - print(res) + # print(res) # get all results using the api resapi = self.reader.getResults() assert len(res) == len(resapi) @@ -281,7 +306,7 @@ def test_getResultsBySimulationID(self): ).first() assert len(res) > 0 res = rawSql2Alchemy(res, models.Results) - print(res) + # print(res) # get simulation by id using the api # resapi = self.reader.getResultsBySimulationID(simulation.SimulationID) From 9401656d6a56a964c68d9047c94276d2a56c422d Mon Sep 17 00:00:00 2001 From: sreeder Date: Mon, 13 Nov 2017 14:18:01 -0700 Subject: [PATCH 10/13] fix issue with sf in datasets --- odm2api/ODM2/services/readService.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/odm2api/ODM2/services/readService.py b/odm2api/ODM2/services/readService.py index 66bfbca..c003019 100644 --- a/odm2api/ODM2/services/readService.py +++ b/odm2api/ODM2/services/readService.py @@ -822,7 +822,7 @@ def getSamplingFeatureDatasets(self, ids=None, codes=None, uuids=None, dstype=No if all(v is None for v in [ids, codes, uuids]): raise ValueError('Expected samplingFeatureID OR samplingFeatureUUID OR samplingFeatureCode argument') - sf_query = self._session.query(SamplingFeatures.SamplingFeatureID) + sf_query = self._session.query(SamplingFeatures) if ids: sf_query = sf_query.filter(SamplingFeatures.SamplingFeatureID.in_(ids)) @@ -832,7 +832,7 @@ def getSamplingFeatureDatasets(self, ids=None, codes=None, uuids=None, dstype=No sf_query = sf_query.filter(SamplingFeatures.SamplingFeatureUUID.in_(uuids)) sf_list = [] for sf in sf_query.all(): - sf_list.append(sf[0]) + sf_list.append(sf.SamplingFeatureID) q = self._session.query(DataSetsResults)\ .join(Results)\ From 91ee0c30d2905c2bcead055aef1e1c8910cbde6b Mon Sep 17 00:00:00 2001 From: sreeder Date: Mon, 13 Nov 2017 14:19:56 -0700 Subject: [PATCH 11/13] undo changes made to test sql query --- tests/test_odm2/data/populated.sql | 54 +++++++++++++++--------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/tests/test_odm2/data/populated.sql b/tests/test_odm2/data/populated.sql index 8188a01..84a1e23 100644 --- a/tests/test_odm2/data/populated.sql +++ b/tests/test_odm2/data/populated.sql @@ -11541,33 +11541,33 @@ INSERT INTO "TimeSeriesResultValues" VALUES(9982,1,11.9,'2014-12-31 23:30:00',-7 INSERT INTO "TimeSeriesResultValues" VALUES(9983,1,11.9,'2014-12-31 23:45:00',-7,'nc','Unknown',0.0,102); INSERT INTO "TimeSeriesResultValues" VALUES(9984,1,11.9,'2014-12-31 23:45:00',-7,'nc','Unknown',0.0,102); INSERT INTO "TimeSeriesResultValues" VALUES(9985,1,11.9,'2015-01-01 00:00:00',-7,'nc','Unknown',0.0,102); -INSERT INTO "TimeSeriesResultValues" VALUES(9986,1,184.0,'2013-06-15 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(9987,1,200.0,'2013-05-06 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(9988,1,201.0,'2013-06-14 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(9989,1,208.0,'2013-06-13 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(9990,1,214.0,'2013-05-07 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(9991,1,221.0,'2013-06-12 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(9992,1,229.0,'2013-05-08 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(9993,1,233.0,'2013-05-09 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(9994,1,242.0,'2013-06-06 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(9995,1,243.0,'2013-06-07 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(9996,1,245.0,'2013-06-11 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(9997,1,249.0,'2013-06-02 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(9998,1,251.0,'2013-06-08 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(9999,1,254.0,'2013-06-01 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10000,1,256.0,'2013-06-10 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10001,1,258.0,'2013-06-05 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10002,1,260.0,'2013-06-09 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10003,1,263.0,'2013-06-03 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10004,1,265.0,'2013-05-10 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10005,1,265.0,'2013-06-04 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10006,1,270.0,'2013-05-31 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10007,1,291.0,'2013-05-11 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10008,1,306.0,'2013-05-30 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10009,1,315.0,'2013-05-27 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10010,1,316.0,'2013-05-12 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10011,1,317.0,'2013-05-29 00:00:00',-6,'nc','provisional',0.0,204); -INSERT INTO "TimeSeriesResultValues" VALUES(10012,1,320.0,'2013-05-25 00:00:00',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(9986,1,184.0,'2013-06-15',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(9987,1,200.0,'2013-05-06',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(9988,1,201.0,'2013-06-14',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(9989,1,208.0,'2013-06-13',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(9990,1,214.0,'2013-05-07',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(9991,1,221.0,'2013-06-12',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(9992,1,229.0,'2013-05-08',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(9993,1,233.0,'2013-05-09',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(9994,1,242.0,'2013-06-06',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(9995,1,243.0,'2013-06-07',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(9996,1,245.0,'2013-06-11',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(9997,1,249.0,'2013-06-02',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(9998,1,251.0,'2013-06-08',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(9999,1,254.0,'2013-06-01',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10000,1,256.0,'2013-06-10',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10001,1,258.0,'2013-06-05',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10002,1,260.0,'2013-06-09',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10003,1,263.0,'2013-06-03',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10004,1,265.0,'2013-05-10',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10005,1,265.0,'2013-06-04',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10006,1,270.0,'2013-05-31',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10007,1,291.0,'2013-05-11',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10008,1,306.0,'2013-05-30',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10009,1,315.0,'2013-05-27',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10010,1,316.0,'2013-05-12',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10011,1,317.0,'2013-05-29',-6,'nc','provisional',0.0,204); +INSERT INTO "TimeSeriesResultValues" VALUES(10012,1,320.0,'2013-05-25',-6,'nc','provisional',0.0,204); INSERT INTO "TimeSeriesResultValues" VALUES(10013,1,321.0,'2013-05-28',-6,'nc','provisional',0.0,204); INSERT INTO "TimeSeriesResultValues" VALUES(10014,1,322.0,'2013-05-26',-6,'nc','provisional',0.0,204); INSERT INTO "TimeSeriesResultValues" VALUES(10015,1,338.0,'2013-05-24',-6,'nc','provisional',0.0,204); From f33c2cbedf648e644e7cae4a3fb9d0dc5dc0342f Mon Sep 17 00:00:00 2001 From: sreeder Date: Mon, 13 Nov 2017 14:56:40 -0700 Subject: [PATCH 12/13] add datasetsvalues docstrings --- odm2api/ODM2/services/readService.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/odm2api/ODM2/services/readService.py b/odm2api/ODM2/services/readService.py index c003019..3c725a1 100644 --- a/odm2api/ODM2/services/readService.py +++ b/odm2api/ODM2/services/readService.py @@ -776,6 +776,30 @@ def getDataSetsResults(self, ids= None, codes=None, uuids=None, dstype=None): return None def getDataSetsValues(self, ids=None, codes=None, uuids=None, dstype=None): + """ + Retrieve a list of datavalues associated with the given dataset info + + **Must specify either DataSetID OR DataSetUUID OR DataSetCode)** + Args: + ids (list, optional): List of DataSetsIDs. + codes (list, optional): List of DataSet Codes. + uuids (list, optional): List of Dataset UUIDs string. + dstype (str, optional): Type of Dataset from + `controlled vocabulary name `_. + + + Returns: + list: List of Result Values Objects + + Examples: + >>> READ = ReadODM2(SESSION_FACTORY) + >>> READ.getDataSetsValues(ids=[39, 40]) + >>> READ.getDataSetsValues(codes=['HOME', 'FIELD']) + >>> READ.getDataSetsValues(uuids=['a6f114f1-5416-4606-ae10-23be32dbc202', + ... '5396fdf3-ceb3-46b6-aaf9-454a37278bb4']) + >>> READ.getDataSetsValues(dstype='singleTimeSeries') + + """ dsr = self.getDataSetsResults(ids, codes, uuids, dstype) From 644cb6f9245b105ddf66c61f1397628e3e905755 Mon Sep 17 00:00:00 2001 From: sreeder Date: Mon, 13 Nov 2017 15:06:23 -0700 Subject: [PATCH 13/13] update doc strings --- odm2api/ODM2/services/readService.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/odm2api/ODM2/services/readService.py b/odm2api/ODM2/services/readService.py index 3c725a1..78ba586 100644 --- a/odm2api/ODM2/services/readService.py +++ b/odm2api/ODM2/services/readService.py @@ -632,8 +632,8 @@ def getResults(self, ids=None, type=None, uuids=None, actionid=None, simulationi simulationid (int, optional): SimulationID. sfid (int, optional): SamplingFeatureID. variableid (int, optional): VariableID. - siteid (int, optional): SiteID. - goes through related features table and finds all of the measurement - values recorded at the given site + siteid (int, optional): SiteID. - goes through related features table and finds all of results + recorded at the given site Returns: list: List of Result objects @@ -728,7 +728,7 @@ def getDataSets(self, ids= None, codes=None, uuids=None, dstype=None): # Datasets - def getDataSetsResults(self, ids= None, codes=None, uuids=None, dstype=None): + def getDataSetsResults(self, ids=None, codes=None, uuids=None, dstype=None): """ Retrieve a detailed list of Datasets along with detailed metadata about the datasets and the results contained within them