Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions odm2api/ODM2/services/readService.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ 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):
def getDataSetsValues(self, ids=None, codes=None, uuids=None, dstype=None, lowercols=True):
"""
Retrieve a list of datavalues associated with the given dataset info

Expand All @@ -933,6 +933,12 @@ def getDataSetsValues(self, ids=None, codes=None, uuids=None, dstype=None):
uuids (list, optional): List of Dataset UUIDs string.
dstype (str, optional): Type of Dataset from
`controlled vocabulary name <http://vocabulary.odm2.org/datasettype/>`_.
lowercols (bool, optional): Make column names to be lowercase.
Default to True.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this at the end of the lowercols description: "Please start upgrading your code to rely on CamelCase column names. In a near-future release, the default will be changed to False, and later the parameter may be removed.

**Please start upgrading your code to rely on CamelCase column names,
In a near-future release,
the default will be changed to False,
and later the parameter may be removed**.


Returns:
Expand All @@ -944,7 +950,7 @@ def getDataSetsValues(self, ids=None, codes=None, uuids=None, dstype=None):
>>> READ.getDataSetsValues(codes=['HOME', 'FIELD'])
>>> READ.getDataSetsValues(uuids=['a6f114f1-5416-4606-ae10-23be32dbc202',
... '5396fdf3-ceb3-46b6-aaf9-454a37278bb4'])
>>> READ.getDataSetsValues(dstype='singleTimeSeries')
>>> READ.getDataSetsValues(dstype='singleTimeSeries', lowercols=False)

"""

Expand All @@ -955,7 +961,7 @@ def getDataSetsValues(self, ids=None, codes=None, uuids=None, dstype=None):
resids.append(ds.ResultID)

try:
return self.getResultValues(resultids=resids)
return self.getResultValues(resultids=resids, lowercols=lowercols)
except Exception as e:
print('Error running Query {}'.format(e))
return None
Expand Down Expand Up @@ -1338,7 +1344,7 @@ def getResultDerivationEquations(self):
"""
return self._session.query(ResultDerivationEquations).all()

def getResultValues(self, resultids, starttime=None, endtime=None):
def getResultValues(self, resultids, starttime=None, endtime=None, lowercols=True):
"""
Retrieve result values associated with the given result.

Expand All @@ -1347,6 +1353,12 @@ def getResultValues(self, resultids, starttime=None, endtime=None):
resultids (list): List of SamplingFeatureIDs.
starttime (object, optional): Start time to filter by as datetime object.
endtime (object, optional): End time to filter by as datetime object.
lowercols (bool, optional): Make column names to be lowercase.
Default to True.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this at the end of the lowercols description: "Please start upgrading your code to rely on CamelCase column names. In a near-future release, the default will be changed to False, and later the parameter may be removed.

**Please start upgrading your code to rely on CamelCase column names,
In a near-future release,
the default will be changed to False,
and later the parameter may be removed**.

Returns:
DataFrame: Pandas dataframe of result values.
Expand All @@ -1357,7 +1369,7 @@ def getResultValues(self, resultids, starttime=None, endtime=None):
>>> READ.getResultValues(resultids=[100, 20, 34], starttime=datetime.today())
>>> READ.getResultValues(resultids=[1, 2, 3, 4],
>>> starttime=datetime(2000, 01, 01),
>>> endtime=datetime(2003, 02, 01))
>>> endtime=datetime(2003, 02, 01), lowercols=False)

"""
restype = self._session.query(Results).filter_by(ResultID=resultids[0]).first().ResultTypeCV
Expand Down Expand Up @@ -1395,7 +1407,14 @@ def getResultValues(self, resultids, starttime=None, endtime=None):
con=self._session_factory.engine,
params=query.params
)
df.columns = [self._get_columns(ResultValues)[c] for c in df.columns]
if not lowercols:
df.columns = [self._get_columns(ResultValues)[c] for c in df.columns]
else:
warnings.warn(
'In a near-future release, '
'the parameter \'lowercols\' default will be changed to False, '
'and later the parameter may be removed.',
DeprecationWarning, stacklevel=2)
return df
except Exception as e:
print('Error running Query: {}'.format(e))
Expand Down