Skip to content

Commit ccb9cd1

Browse files
authored
Merge pull request #141 from lsetiawan/flake8
Flake8
2 parents 292dc84 + 27cf30b commit ccb9cd1

File tree

7 files changed

+100
-227
lines changed

7 files changed

+100
-227
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ script:
7474
fi
7575

7676
- if [[ $TEST_TARGET == 'coding_standards' ]]; then
77-
find . -type f -name "*.py" ! -name 'conf.py' ! -name '_version.py' ! -name 'versioneer.py' | xargs flake8 --max-line-length=110 ;
77+
find . -type f -name "*.py" ! -name 'conf.py' ! -name '_version.py' ! -name 'versioneer.py' ! -name '*DBConfig.py' ! -name 'Sample.py' | xargs flake8 --max-line-length=110 ;
7878
fi
7979

8080
- if [[ $TEST_TARGET == 'docs' ]]; then

odm2api/ODM2/models.py

Lines changed: 10 additions & 100 deletions
Large diffs are not rendered by default.

odm2api/ODM2/services/readService.py

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import (absolute_import, division, print_function)
22

3+
import warnings
4+
35
from odm2api.ODM2 import serviceBase
46
from odm2api.ODM2.models import (
57
ActionAnnotations, ActionDirectives, ActionExtensionPropertyValues, Actions,
@@ -29,7 +31,7 @@
2931
SpatialReferenceExternalIdentifiers, SpatialReferences, SpecimenBatchPositions,
3032
SpectraResultValueAnnotations, SpectraResultValues, TaxonomicClassifierExternalIdentifiers,
3133
TaxonomicClassifiers, TimeSeriesResultValueAnnotations, TimeSeriesResultValues,
32-
TimeSeriesResults, TrajectoryResultValueAnnotations, TrajectoryResultValues,
34+
TrajectoryResultValueAnnotations, TrajectoryResultValues,
3335
TransectResultValueAnnotations, TransectResultValues, Units, VariableExtensionPropertyValues,
3436
VariableExternalIdentifiers, Variables,
3537
)
@@ -38,8 +40,6 @@
3840

3941
from sqlalchemy import distinct, exists
4042

41-
import warnings
42-
4343
__author__ = 'sreeder'
4444

4545

@@ -75,8 +75,9 @@ def __init__(self, affiliation, person, org):
7575

7676

7777
class SamplingFeatureDataSet():
78-
datasets={}
79-
related_features={}
78+
datasets = {}
79+
related_features = {}
80+
8081
def __init__(self, samplingfeature, datasetresults, relatedfeatures):
8182
sf = samplingfeature
8283

@@ -94,26 +95,24 @@ def __init__(self, samplingfeature, datasetresults, relatedfeatures):
9495
self.assignDatasets(datasetresults)
9596
self.assignRelatedFeatures(relatedfeatures)
9697

97-
9898
print(self.datasets)
9999

100100
def assignDatasets(self, datasetresults):
101101
self.datasets = {}
102102
if datasetresults:
103103
for dsr in datasetresults:
104104
if dsr.DataSetObj not in self.datasets:
105-
#if the dataset is not in the dictionary, add it and the first result
106-
self.datasets[dsr.DataSetObj]=[]
105+
# if the dataset is not in the dictionary, add it and the first result
106+
self.datasets[dsr.DataSetObj] = []
107107
res = dsr.ResultObj
108108
# res.FeatureActionObj = None
109109
self.datasets[dsr.DataSetObj].append(res)
110110
else:
111-
#if the dataset is in the dictionary, append the result object to the list
111+
# if the dataset is in the dictionary, append the result object to the list
112112
res = dsr.ResultObj
113113
# res.FeatureActionObj = None
114114
self.datasets[dsr.DataSetObj].append(res)
115115

116-
117116
def assignRelatedFeatures(self, relatedfeatures):
118117
self.related_features = {}
119118
if relatedfeatures:
@@ -169,7 +168,8 @@ def resultExists(self, result):
169168
)
170169
return ret.scalar()
171170

172-
except:
171+
except Exception as e:
172+
print('Error running Query: {}'.format(e))
173173
return None
174174

175175
# Annotations
@@ -225,7 +225,8 @@ def getAnnotations(self, annottype=None, codes=None, ids=None, **kwargs):
225225
query = query.filter(Annotations.AnnotationID.in_(ids))
226226
return query.all()
227227

228-
except:
228+
except Exception as e:
229+
print('Error running Query: {}'.format(e))
229230
return None
230231

231232
# CV
@@ -384,15 +385,16 @@ def getVariables(self, ids=None, codes=None, sitecode=None, results=False):
384385
variables = [
385386
x[0] for x in
386387
self._session.query(distinct(Results.VariableID))
387-
.filter(Results.FeatureActionID == FeatureActions.FeatureActionID)
388-
.filter(FeatureActions.SamplingFeatureID == SamplingFeatures.SamplingFeatureID)
389-
.filter(SamplingFeatures.SamplingFeatureCode == sitecode).all()
388+
.filter(Results.FeatureActionID == FeatureActions.FeatureActionID)
389+
.filter(FeatureActions.SamplingFeatureID == SamplingFeatures.SamplingFeatureID)
390+
.filter(SamplingFeatures.SamplingFeatureCode == sitecode).all()
390391
]
391392
if ids:
392393
ids = list(set(ids).intersection(variables))
393394
else:
394395
ids = variables
395-
except:
396+
except Exception as e:
397+
print('Error running Query: {}'.format(e))
396398
pass
397399

398400
if results:
@@ -402,7 +404,8 @@ def getVariables(self, ids=None, codes=None, sitecode=None, results=False):
402404
ids = list(set(ids).intersection(variables))
403405
else:
404406
ids = variables
405-
except:
407+
except Exception as e:
408+
print('Error running Query: {}'.format(e))
406409
pass
407410

408411
query = self._session.query(Variables)
@@ -520,10 +523,10 @@ def getSamplingFeatures(self, ids=None, codes=None, uuids=None,
520523
if results:
521524
try:
522525
fas = [x[0] for x in self._session.query(distinct(Results.FeatureActionID)).all()]
523-
except:
526+
except Exception as e:
527+
print('Error running Query: {}'.format(e))
524528
return None
525-
sf = [x[0] for x in self._session.query(distinct(FeatureActions.SamplingFeatureID))
526-
.filter(FeatureActions.FeatureActionID.in_(fas)).all()]
529+
sf = [x[0] for x in self._session.query(distinct(FeatureActions.SamplingFeatureID)).filter(FeatureActions.FeatureActionID.in_(fas)).all()] # noqa
527530
if ids:
528531
ids = list(set(ids).intersection(sf))
529532
else:
@@ -557,8 +560,8 @@ def getRelatedSamplingFeatures(self, sfid=None, rfid=None, relationshiptype=None
557560
558561
"""
559562

560-
sf = self._session.query(distinct(SamplingFeatures.SamplingFeatureID))\
561-
.select_from(RelatedFeatures)
563+
sf = self._session.query(distinct(SamplingFeatures.SamplingFeatureID)) \
564+
.select_from(RelatedFeatures)
562565

563566
if sfid:
564567
sf = sf.join(RelatedFeatures.RelatedFeatureObj).filter(RelatedFeatures.SamplingFeatureID == sfid)
@@ -576,8 +579,6 @@ def getRelatedSamplingFeatures(self, sfid=None, rfid=None, relationshiptype=None
576579
print('Error running Query: {}'.format(e))
577580
return None
578581

579-
580-
581582
# Action
582583
def getActions(self, ids=None, acttype=None, sfid=None, **kwargs):
583584
"""
@@ -656,7 +657,6 @@ def getUnits(self, ids=None, name=None, unittype=None, **kwargs):
656657
print('Error running Query: {}'.format(e))
657658
return None
658659

659-
660660
# Organization
661661
def getOrganizations(self, ids=None, codes=None):
662662
"""
@@ -738,7 +738,7 @@ def getAffiliations(self, ids=None, personfirst=None, personlast=None, orgcode=N
738738
return None
739739

740740
# Results
741-
def getResults(self, ids=None, restype = None, uuids=None, actionid=None, simulationid=None,
741+
def getResults(self, ids=None, restype=None, uuids=None, actionid=None, simulationid=None,
742742
variableid=None, siteid=None, sfids=None, sfuuids=None, sfcodes=None, **kwargs):
743743

744744
# TODO what if user sends in both type and actionid vs just actionid
@@ -791,10 +791,10 @@ def getResults(self, ids=None, restype = None, uuids=None, actionid=None, simula
791791
if uuids:
792792
query = query.filter(Results.ResultUUID.in_(uuids))
793793
if simulationid:
794-
query = query.join(FeatureActions)\
795-
.join(Actions)\
796-
.join(Simulations)\
797-
.filter_by(SimulationID=simulationid)
794+
query = query.join(FeatureActions) \
795+
.join(Actions) \
796+
.join(Simulations) \
797+
.filter_by(SimulationID=simulationid)
798798
if actionid:
799799
query = query.join(FeatureActions).filter_by(ActionID=actionid)
800800
if 'sfid' in kwargs:
@@ -811,16 +811,15 @@ def getResults(self, ids=None, restype = None, uuids=None, actionid=None, simula
811811
query = query.join(FeatureActions).filter(FeatureActions.SamplingFeatureID.in_(sfids))
812812

813813
if siteid:
814-
815814
sfids = [x[0] for x in self._session.query(
816815
distinct(SamplingFeatures.SamplingFeatureID))
817816
.select_from(RelatedFeatures)
818817
.join(RelatedFeatures.SamplingFeatureObj)
819818
.filter(RelatedFeatures.RelatedFeatureID == siteid)
820819
.all()
821-
]
820+
]
822821

823-
#TODO does this code do the same thing as the code above?
822+
# TODO does this code do the same thing as the code above?
824823
# sf_list = self.getRelatedSamplingFeatures(rfid=siteid)
825824
# sfids = []
826825
# for sf in sf_list:
@@ -835,7 +834,7 @@ def getResults(self, ids=None, restype = None, uuids=None, actionid=None, simula
835834
return None
836835

837836
# Datasets
838-
def getDataSets(self, ids= None, codes=None, uuids=None, dstype=None):
837+
def getDataSets(self, ids=None, codes=None, uuids=None, dstype=None):
839838
"""
840839
Retrieve a list of Datasets
841840
@@ -907,7 +906,7 @@ def getDataSetsResults(self, ids=None, codes=None, uuids=None, dstype=None):
907906
if all(v is None for v in [ids, codes, uuids]):
908907
raise ValueError('Expected DataSetID OR DataSetUUID OR DataSetCode argument')
909908

910-
q = self._session.query(DataSetsResults)\
909+
q = self._session.query(DataSetsResults) \
911910
.join(DataSets)
912911
if ids:
913912
q = q.filter(DataSets.DataSetID.in_(ids))
@@ -956,12 +955,11 @@ def getDataSetsValues(self, ids=None, codes=None, uuids=None, dstype=None):
956955
resids.append(ds.ResultID)
957956

958957
try:
959-
return self.getResultValues(resultids = resids)
958+
return self.getResultValues(resultids=resids)
960959
except Exception as e:
961960
print('Error running Query {}'.format(e))
962961
return None
963962

964-
965963
def getSamplingFeatureDatasets(self, ids=None, codes=None, uuids=None, dstype=None, sftype=None):
966964
"""
967965
Retrieve a list of Datasets associated with the given sampling feature data.
@@ -991,11 +989,12 @@ def getSamplingFeatureDatasets(self, ids=None, codes=None, uuids=None, dstype=No
991989
992990
"""
993991

994-
995992
# make sure one of the three arguments has been sent in
996993
if all(v is None for v in [ids, codes, uuids, sftype]):
997-
raise ValueError('Expected samplingFeatureID OR samplingFeatureUUID OR samplingFeatureCode OR samplingFeatureType '
998-
'argument')
994+
raise ValueError(
995+
'Expected samplingFeatureID OR samplingFeatureUUID '
996+
'OR samplingFeatureCode OR samplingFeatureType '
997+
'argument')
999998

1000999
sf_query = self._session.query(SamplingFeatures)
10011000
if sftype:
@@ -1012,18 +1011,17 @@ def getSamplingFeatureDatasets(self, ids=None, codes=None, uuids=None, dstype=No
10121011
sf_list.append(sf)
10131012

10141013
try:
1015-
sfds=[]
1014+
sfds = []
10161015
for sf in sf_list:
10171016

1018-
q = self._session.query(DataSetsResults)\
1019-
.join(Results)\
1020-
.join(FeatureActions)\
1017+
q = self._session.query(DataSetsResults) \
1018+
.join(Results) \
1019+
.join(FeatureActions) \
10211020
.filter(FeatureActions.SamplingFeatureID == sf.SamplingFeatureID)
10221021

10231022
if dstype:
10241023
q = q.filter_by(DatasetTypeCV=dstype)
10251024

1026-
10271025
vals = q.all()
10281026

10291027
related = self.getRelatedSamplingFeatures(sf.SamplingFeatureID)
@@ -1082,17 +1080,21 @@ def getEquipment(self, codes=None, equiptype=None, sfid=None, actionid=None, **k
10821080
warnings.warn('The parameter \'type\' is deprecated. Please use the equiptype parameter instead.',
10831081
DeprecationWarning, stacklevel=2)
10841082
equiptype = kwargs['type']
1083+
1084+
# NOTE: Equiptype currently unused!
1085+
if equiptype:
1086+
pass
10851087
e = self._session.query(Equipment)
10861088
if sfid:
10871089
e = e.join(EquipmentUsed) \
1088-
.join(Actions) \
1089-
.join(FeatureActions) \
1090-
.filter(FeatureActions.SamplingFeatureID == sfid)
1090+
.join(Actions) \
1091+
.join(FeatureActions) \
1092+
.filter(FeatureActions.SamplingFeatureID == sfid)
10911093
if codes:
10921094
e = e.filter(Equipment.EquipmentCode.in_(codes))
10931095
if actionid:
10941096
e = e.join(EquipmentUsed).join(Actions) \
1095-
.filter(Actions.ActionID == actionid)
1097+
.filter(Actions.ActionID == actionid)
10961098
return e.all()
10971099

10981100
def CalibrationReferenceEquipment(self):

0 commit comments

Comments
 (0)