@@ -72,6 +72,43 @@ def __init__(self, affiliation, person, org):
7272 self .Organization = '(' + org .OrganizationCode + ') ' + org .OrganizationName
7373
7474
75+ class SamplingFeatureDataSet ():
76+ datasets = {}
77+ def __init__ (self , samplingfeature , datasetresults ):
78+ sf = samplingfeature
79+
80+ self .SamplingFeatureID = sf .SamplingFeatureID
81+ self .SamplingFeatureUUID = sf .SamplingFeatureUUID
82+ self .SamplingFeatureTypeCV = sf .SamplingFeatureTypeCV
83+ self .SamplingFeatureCode = sf .SamplingFeatureCode
84+ self .SamplingFeatureName = sf .SamplingFeatureName
85+ self .SamplingFeatureDescription = sf .SamplingFeatureDescription
86+ self .SamplingFeatureGeotypeCV = sf .SamplingFeatureGeotypeCV
87+ self .Elevation_m = sf .Elevation_m
88+ self .ElevationDatumCV = sf .ElevationDatumCV
89+ self .FeatureGeometryWKT = sf .FeatureGeometryWKT
90+ self .assignDatasets (datasetresults )
91+
92+ print (self .datasets )
93+
94+
95+ def assignDatasets (self , datasetresults ):
96+ for dsr in datasetresults :
97+ if dsr .DataSetObj not in self .datasets :
98+ #if the dataset is not in the dictionary, add it and the first result
99+ self .datasets [dsr .DataSetObj ]= []
100+ res = dsr .ResultObj
101+ # res.FeatureActionObj = None
102+ self .datasets [dsr .DataSetObj ].append (res )
103+ else :
104+ #if the dataset is in the dictionary, append the result object to the list
105+ res = dsr .ResultObj
106+ # res.FeatureActionObj = None
107+ self .datasets [dsr .DataSetObj ].append (res )
108+
109+
110+
111+
75112class ReadODM2 (serviceBase ):
76113 # Exists functions
77114 def resultExists (self , result ):
@@ -871,7 +908,6 @@ def getSamplingFeatureDatasets(self, ids=None, codes=None, uuids=None, dstype=No
871908 raise ValueError ('Expected samplingFeatureID OR samplingFeatureUUID OR samplingFeatureCode argument' )
872909
873910 sf_query = self ._session .query (SamplingFeatures )
874-
875911 if ids :
876912 sf_query = sf_query .filter (SamplingFeatures .SamplingFeatureID .in_ (ids ))
877913 if codes :
@@ -880,21 +916,29 @@ def getSamplingFeatureDatasets(self, ids=None, codes=None, uuids=None, dstype=No
880916 sf_query = sf_query .filter (SamplingFeatures .SamplingFeatureUUID .in_ (uuids ))
881917 sf_list = []
882918 for sf in sf_query .all ():
883- sf_list .append (sf . SamplingFeatureID )
919+ sf_list .append (sf )
884920
885- q = self . _session . query ( DataSetsResults )\
886- . join ( Results )\
887- . join ( FeatureActions )\
888- . filter ( FeatureActions . SamplingFeatureID . in_ ( sf_list ))
921+ sfds = None
922+ try :
923+ sfds = []
924+ for sf in sf_list :
889925
890- if dstype :
891- q = q .filter_by (DatasetTypeCV = dstype )
926+ q = self ._session .query (DataSetsResults )\
927+ .join (Results )\
928+ .join (FeatureActions )\
929+ .filter (FeatureActions .SamplingFeatureID == sf .SamplingFeatureID )
892930
893- try :
894- return q .all ()
931+ if dstype :
932+ q = q .filter_by (DatasetTypeCV = dstype )
933+
934+
935+ vals = q .all ()
936+
937+ sfds .append (SamplingFeatureDataSet (sf , vals ))
895938 except Exception as e :
896939 print ('Error running Query: {}' .format (e ))
897940 return None
941+ return sfds
898942
899943 # Data Quality
900944 def getDataQuality (self ):
0 commit comments