@@ -120,10 +120,23 @@ def assignRelatedFeatures(self, relatedfeatures):
120120 self .related_features = related
121121
122122
123+ class ReadODM2 (serviceBase ):
124+ def _get_columns (self , model ):
125+ """Internal helper function to get a dictionary of a model column properties.
123126
127+ Args:
128+ model (object): Sqlalchemy object, Ex. ODM2 model.
124129
130+ Returns:
131+ dict: Dictionary of column properties Ex. {'resultid': 'ResultID'}
132+
133+ """
134+ from sqlalchemy .orm .properties import ColumnProperty
135+ columns = [(prop .key .lower (), prop .key ) for prop in model .__mapper__ .iterate_properties if
136+ isinstance (prop , ColumnProperty )]
137+
138+ return dict (columns )
125139
126- class ReadODM2 (serviceBase ):
127140 # Exists functions
128141 def resultExists (self , result ):
129142 """
@@ -1275,25 +1288,25 @@ def getResultValues(self, resultids, starttime=None, endtime=None):
12751288 * Pass an endtime - Returns a dataframe with the values before the given end time
12761289
12771290 """
1278- type = self ._session .query (Results ).filter_by (ResultID = resultids [0 ]).first ().ResultTypeCV
1291+ restype = self ._session .query (Results ).filter_by (ResultID = resultids [0 ]).first ().ResultTypeCV
12791292 ResultType = TimeSeriesResultValues
1280- if 'categorical' in type .lower ():
1293+ if 'categorical' in restype .lower ():
12811294 ResultType = CategoricalResultValues
1282- elif 'measurement' in type .lower ():
1295+ elif 'measurement' in restype .lower ():
12831296 ResultType = MeasurementResultValues
1284- elif 'point' in type .lower ():
1297+ elif 'point' in restype .lower ():
12851298 ResultType = PointCoverageResultValues
1286- elif 'profile' in type .lower ():
1299+ elif 'profile' in restype .lower ():
12871300 ResultType = ProfileResultValues
1288- elif 'section' in type .lower ():
1301+ elif 'section' in restype .lower ():
12891302 ResultType = SectionResults
1290- elif 'spectra' in type .lower ():
1303+ elif 'spectra' in restype .lower ():
12911304 ResultType = SpectraResultValues
1292- elif 'time' in type .lower ():
1305+ elif 'time' in restype .lower ():
12931306 ResultType = TimeSeriesResultValues
1294- elif 'trajectory' in type .lower ():
1307+ elif 'trajectory' in restype .lower ():
12951308 ResultType = TrajectoryResultValues
1296- elif 'transect' in type .lower ():
1309+ elif 'transect' in restype .lower ():
12971310 ResultType = TransectResultValues
12981311
12991312 q = self ._session .query (ResultType ).filter (ResultType .ResultID .in_ (resultids ))
@@ -1310,6 +1323,7 @@ def getResultValues(self, resultids, starttime=None, endtime=None):
13101323 con = self ._session_factory .engine ,
13111324 params = query .params
13121325 )
1326+ df .columns = [self ._get_columns (ResultType )[c ] for c in df .columns ]
13131327 return df
13141328 except Exception as e :
13151329 print ('Error running Query: {}' .format (e ))
0 commit comments