Skip to content

Commit 0dfa0c7

Browse files
author
stephanie
committed
load series selector
1 parent 5bf036c commit 0dfa0c7

16 files changed

Lines changed: 946 additions & 1014 deletions

odmtools/common/taskServer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def worker(cls, dispatcher):
132132
connection = SeriesService("sqlite:///:memory:")
133133
df = task[1]
134134
logger.debug("Load series from db")
135-
df.to_sql(name="DataValues", con=connection._session_factory.engine, flavor='sqlite', index = False, chunksize = 10000)
135+
df.to_sql(name="DataValues", con=connection._connection.engine, flavor='sqlite', index = False, chunksize = 10000)
136136
logger.debug("done loading database")
137137
result = connection
138138
if task_type == "UpdateEditDF":

odmtools/controller/frmSeriesSelector.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ def initTableSeries(self):
6969
self.memDB.set_series_service(self.series_service)
7070

7171
object = self.series_service.get_all_series()
72-
72+
cols = object[0].__dict__.keys()
73+
self.tblSeries._buildColumns(cols)
7374
if object:
7475
self.tblSeries.SetObjects(object)
7576
else:
@@ -140,13 +141,13 @@ def initSVBoxes(self):
140141
try:
141142
self.siteList = self.series_service.get_used_sites()
142143
for site in self.siteList:
143-
self.cbSites.Append(site.code + '-' + site.name)
144+
self.cbSites.Append("%s-%s"%(site.SamplingFeatureCode, site.SamplingFeatureName))
144145
self.cbSites.SetSelection(0)
145-
self.site_code = self.siteList[0].code
146+
self.site_code = self.siteList[0].SamplingFeatureCode
146147

147148
self.varList = self.series_service.get_used_variables()
148149
for var in self.varList:
149-
self.cbVariables.Append(var.code + '-' + var.name)
150+
self.cbVariables.Append("%s-%s"%(var.VariableCode, var.VariableNameCV))
150151
self.cbVariables.SetSelection(0)
151152
except AttributeError as e:
152153
logger.error(e)
@@ -340,12 +341,12 @@ def onCbSitesCombobox(self, event):
340341
"""
341342

342343
if self.checkSite.GetValue():
343-
self.site_code = self.siteList[event.GetSelection()].code
344+
self.site_code = self.siteList[event.GetSelection()].SamplingFeatureCode
344345
self.varList = self.series_service.get_variables_by_site_code(self.site_code)
345346

346347
self.cbVariables.Clear()
347348
for var in self.varList:
348-
self.cbVariables.Append(var.code + '-' + var.name)
349+
self.cbVariables.Append("%s-%s"%(var.VariableCode, var.VariableNameCV))
349350
self.cbVariables.SetSelection(0)
350351

351352
if (self.checkSite.GetValue() and not self.checkVariable.GetValue()):
@@ -362,7 +363,7 @@ def onCbVariablesCombobox(self, event):
362363
"""
363364

364365
if self.checkVariable.GetValue():
365-
self.variable_code = self.varList[event.GetSelection()].code
366+
self.variable_code = self.varList[event.GetSelection()].VariableCode
366367
if (not self.checkSite.GetValue() and self.checkVariable.GetValue()):
367368
self.site_code = None
368369
self.setFilter(site_code=self.site_code, var_code=self.variable_code)
@@ -373,16 +374,16 @@ def siteAndVariables(self):
373374
374375
:return:
375376
"""
376-
self.site_code = self.siteList[self.cbSites.Selection].code
377+
self.site_code = self.siteList[self.cbSites.Selection].VariableCode
377378

378379
self.cbVariables.Clear()
379380
self.varList = self.series_service.get_variables_by_site_code(self.site_code)
380381
for var in self.varList:
381-
self.cbVariables.Append(var.code + '-' + var.name)
382+
self.cbVariables.Append("%s-%s"%(var.VariableCode, var.VariableNameCV))
382383
self.cbVariables.SetSelection(0)
383384

384385
try:
385-
self.variable_code = self.varList[self.cbVariables.Selection].code
386+
self.variable_code = self.varList[self.cbVariables.Selection].VariableCode
386387
self.setFilter(site_code=self.site_code, var_code=self.variable_code)
387388
self.cbVariables.Enabled = True
388389
self.cbSites.Enabled = True
@@ -411,12 +412,12 @@ def variableOnly(self):
411412
self.cbVariables.Clear()
412413
self.varList = self.series_service.get_used_variables()
413414
for var in self.varList:
414-
self.cbVariables.Append(var.code + '-' + var.name)
415+
self.cbVariables.Append("%s-%s"%(var.VariableCode, var.VariableNameCV))
415416
self.cbVariables.SetSelection(0)
416417
self.cbSites.Enabled = False
417418
self.cbVariables.Enabled = True
418419

419-
self.variable_code = self.varList[0].code
420+
self.variable_code = self.varList[0].VariableCode
420421

421422
self.setFilter(var_code=self.variable_code)
422423

odmtools/controller/olvSeriesSelector.py

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88

99
# from odmtools.common.logger import LoggerTool
10-
from odmtools.odmdata import series
1110

1211

1312
# tool = LoggerTool()
@@ -16,21 +15,25 @@
1615

1716
OvlCheckEvent, EVT_OVL_CHECK_EVENT = wx.lib.newevent.NewEvent()
1817
from collections import OrderedDict
19-
def returnDict():
20-
keys = ['SeriesID', 'SiteID', 'SiteCode', 'SiteName', 'VariableID', 'VariableCode', 'VariableName', 'Speciation',
21-
'VariableUnitsID', 'VariableUnitsName', 'SampleMedium', 'ValueType', 'TimeSupport', 'TimeUnitsID',
22-
'TimeUnitsName', 'DataType', 'GeneralCategory', 'MethodID', 'MethodDescription', 'SourceID',
23-
'SourceDescription', 'Organization', 'Citation', 'QualityControlLevelID', 'QualityControlLevelCode',
24-
'BeginDateTime', 'EndDateTime', 'BeginDateTimeUTC', 'EndDateTimeUTC', 'ValueCount'
25-
]
26-
values = ['id', 'site_id', 'site_code', 'site_name', 'variable_id', 'variable_code', 'variable_name', 'speciation',
27-
'variable_units_id', 'variable_units_name', 'sample_medium', 'value_type', 'time_support',
28-
'time_units_id', 'time_units_name', 'data_type', 'general_category', 'method_id', 'method_description',
29-
'source_id', 'source_description', 'organization', 'citation', 'quality_control_level_id',
30-
'quality_control_level_code', 'begin_date_time', 'end_date_time', 'begin_date_time_utc',
31-
'end_date_time_utc', 'value_count'
32-
]
33-
return OrderedDict(zip(keys, values))
18+
# def returnDict():
19+
# keys = ['SeriesID', 'SiteID', 'SiteCode', 'SiteName', 'VariableID', 'VariableCode', 'VariableName', 'Speciation',
20+
# 'VariableUnitsID', 'VariableUnitsName', 'SampleMedium', 'ValueType', 'TimeSupport', 'TimeUnitsID',
21+
# 'TimeUnitsName', 'DataType', 'GeneralCategory', 'MethodID', 'MethodDescription', 'SourceID',
22+
# 'SourceDescription', 'Organization', 'Citation', 'QualityControlLevelID', 'QualityControlLevelCode',
23+
# 'BeginDateTime', 'EndDateTime', 'BeginDateTimeUTC', 'EndDateTimeUTC', 'ValueCount'
24+
# ]
25+
# values = ['id', 'site_id', 'site_code', 'site_name', 'variable_id', 'variable_code', 'variable_name', 'speciation',
26+
# 'variable_units_id', 'variable_units_name', 'sample_medium', 'value_type', 'time_support',
27+
# 'time_units_id', 'time_units_name', 'data_type', 'general_category', 'method_id', 'method_description',
28+
# 'source_id', 'source_description', 'organization', 'citation', 'quality_control_level_id',
29+
# 'quality_control_level_code', 'begin_date_time', 'end_date_time', 'begin_date_time_utc',
30+
# 'end_date_time_utc', 'value_count'
31+
# ]
32+
# return OrderedDict(zip(keys, values))
33+
34+
35+
36+
# def returnDict():
3437

3538
class clsSeriesTable(FastObjectListView):
3639
def __init__(self, *args, **kwargs):
@@ -47,8 +50,8 @@ def __init__(self, *args, **kwargs):
4750
"""Object being edited"""
4851
self.editingObject = None
4952

50-
self._buildColumns()
51-
self.CreateCheckStateColumn()
53+
#self._buildColumns()
54+
5255

5356
def rowFormatter(listItem, point):
5457
listItem.SetFont(wx.Font(11, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False))
@@ -60,13 +63,16 @@ def onKeyPress(self, evt):
6063
"""Ignores Keypresses"""
6164
pass
6265

63-
def _buildColumns(self):
66+
def _buildColumns(self, columns):
6467
seriesColumns = [
65-
ColumnDefn(key, align="left", minimumWidth=100, valueGetter=value,
68+
ColumnDefn(key, align="left", minimumWidth=100, valueGetter=key,
6669
# stringConverter = '%s')
6770
stringConverter='%Y-%m-%d %H:%M:%S' if "date" in key.lower() else'%s')
68-
for key, value in returnDict().iteritems()]
71+
for key in columns]
72+
73+
6974
self.SetColumns(seriesColumns)
75+
self.CreateCheckStateColumn()
7076

7177
"""User can select series using the mouse to click on check boxes """
7278

odmtools/gui/pageMethod.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import wx
44
import wx.grid
55
import wx.richtext
6-
from odmtools.odmdata import ODM
6+
# from odmtools.odmdata import ODM
7+
from odm2api.ODM2.models import Methods
78

89

910
[wxID_PNLMETHOD, wxID_PNLMETHODSLISTCTRL1, wxID_PNLMETHODSRBCREATENEW,
@@ -119,8 +120,8 @@ def getMethod(self):
119120
m= self.series_service.get_method_by_description(genmethod)
120121
if m is None:
121122
logger.debug("assigning new method description")
122-
m = ODM.Method()
123-
m.description = genmethod
123+
m = Methods()
124+
m.MethodDescription = genmethod
124125

125126

126127
elif self.rbSelect.Value:

odmtools/odmdata/__init__.py

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,12 @@
11

22

33

4+
#from odm2api.ODM1_1_1.services import SeriesService#, refreshDB
45

5-
6-
7-
#from api.versionSwitcher import ODM, refreshDB
8-
9-
10-
# DataTypeCV=ODM.DataTypeCV
11-
# DataValue=ODM.DataValue
12-
# # GeneralCategoryCV=ODM.GeneralCategoryCV
13-
# ISOMetadata=ODM.ISOMetadata
14-
# LabMethod=ODM.LabMethod
15-
# Method=ODM.Method
16-
# OffsetType=ODM.OffsetType
17-
# Qualifier=ODM.Qualifier
18-
# QualityControlLevel=ODM.QualityControlLevel
19-
# Sample =ODM.Sample
20-
# SampledMediumCV= ODM.SampleMediumCV
21-
# # SampleTypeCV=ODM.SampleTypeCV
22-
# Series=ODM.Series
23-
# Site= ODM.Site
24-
# SiteType=ODM.SiteTypeCV
25-
# Source =ODM.Source
26-
# SpatialReferences=ODM.SpatialReference
27-
# SpeciationCV=ODM.SpeciationCV
28-
# # TopicCategoryCV=ODM.TopicCategoryCV
29-
# Unit= ODM.Unit
30-
# # ValueTypeCV=ODM.ValueTypeCV
31-
# Variable = ODM.Variable
32-
# VerticalDatumCV=ODM.VerticalDatumCV
33-
# returnDict = ODM.returnDict
34-
from odm2api.ODM1_1_1.services import SeriesService#, refreshDB
356
from odm2api.ODMconnection import SessionFactory, dbconnection
367
from odm2api.ODM2.models import _changeSchema as change_schema
378
from odmtools.odmdata.memory_database import MemoryDatabase
38-
ODM = SeriesService.ODM
9+
#ODM = SeriesService.ODM
3910

4011
from collections import OrderedDict
4112
def returnDict():
@@ -61,6 +32,7 @@ def returnDict():
6132
#'ODM',
6233
'MemoryDatabase',
6334
'returnDict'
64-
'SeriesService'
35+
#'SeriesService'
36+
'readService', 'createService', 'updateService', 'deleteService'
6537
'dbconnection'
6638
]

odmtools/odmdata/memory_database.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
from odmtools.common.logger import LoggerTool
66
from odmtools.odmservices import SeriesService
7-
from odmtools.odmservices import ServiceManager
8-
from odmtools.odmdata import SeriesService#ODM
9-
ODM = SeriesService.ODM
10-
# tool = LoggerTool()
11-
# logger = tool.setupLogger(__name__, __name__ + '.log', 'w', logging.DEBUG)
7+
from odmtools.odmservices import ServiceManager, SeriesService
8+
9+
# from odmtools.odmdata import SeriesService#ODM
10+
# ODM = SeriesService.ODM
11+
from odm2api.ODM2.models import TimeSeriesResultValues as DataValue
12+
13+
1214
logger =logging.getLogger('main')
1315

1416
class MemoryDatabase(object):
@@ -105,8 +107,8 @@ def update(self, updates):
105107
updates : list of dictionary that contains 2 items, id and value
106108
'''
107109

108-
stmt = (ODM.DataValue.__table__.update().
109-
where(ODM.DataValue.local_date_time == bindparam('id')).
110+
stmt = (DataValue.__table__.update().
111+
where(DataValue.ValueDateTime == bindparam('id')).
110112
values(DataValue=bindparam('value'))
111113
)
112114

@@ -118,20 +120,20 @@ def update(self, updates):
118120
def updateValue(self, ids, operator, value):
119121
# query = DataValue.data_value+value
120122
if operator == '+':
121-
query = ODM.DataValue.data_value + value
123+
query = DataValue.DataValue + value
122124
elif operator == '-':
123-
query = ODM.DataValue.data_value - value
125+
query = DataValue.DataValue - value
124126
elif operator == '*':
125-
query = ODM.DataValue.data_value * value
127+
query = DataValue.DataValue * value
126128
elif operator == '=':
127129
query = value
128130

129131

130132
#break into chunks to get around sqlites restriction. allowing user to send in only 999 arguments at once
131133
chunks=self.chunking(ids)
132134
for c in chunks:
133-
q=self.mem_service._session.query(ODM.DataValue).filter(ODM.DataValue.local_date_time.in_(c))
134-
q.update({ODM.DataValue.data_value: query}, False)
135+
q=self.mem_service._session.query(DataValue).filter(DataValue.ValueDateTime.in_(c))
136+
q.update({DataValue.DataValue: query}, False)
135137

136138
#self.updateDF()
137139

@@ -143,11 +145,12 @@ def chunking(self, data):
143145

144146

145147
#break into chunks to get around sqlite's restriction. allowing user to send in only 999 arguments at once
148+
#TODO update to work with odm2
146149
def updateFlag(self, ids, value):
147150
chunks=self.chunking(ids)
148151
for c in chunks:
149-
self.mem_service._session.query(ODM.DataValue).filter(ODM.DataValue.local_date_time.in_(c))\
150-
.update({ODM.DataValue.qualifier_id: value}, False)
152+
self.mem_service._session.query(DataValue).filter(DataValue.ValueDateTime.in_(c))\
153+
.update({DataValue.qualifier_id: value}, False)
151154

152155

153156
def delete(self, ids):
@@ -161,7 +164,7 @@ def addPoints(self, points):
161164
"""
162165
Takes in a list of points and loads each point into the database
163166
"""
164-
stmt = ODM.DataValue.__table__.insert()
167+
stmt = DataValue.__table__.insert()
165168

166169
if not isinstance(points, list):
167170
points = [points]
@@ -228,6 +231,8 @@ def initEditValues(self, seriesID):
228231
index=False)#,flavor='sqlite', chunksize=10000)
229232
logger.debug("done loading database")
230233

234+
235+
#TODO: update to work with ODM2
231236
def changeSeriesIDs(self, var=None, qcl=None, method=None):
232237
"""
233238
@@ -237,17 +242,17 @@ def changeSeriesIDs(self, var=None, qcl=None, method=None):
237242
:return:
238243
"""
239244

240-
query = self.mem_service._session.query(ODM.DataValue)
245+
query = self.mem_service._session.query(DataValue)
241246
if var is not None:
242247
logger.debug(var)
243-
query.update({ODM.DataValue.variable_id: var})
248+
query.update({DataValue.variable_id: var})
244249

245250
if method is not None:
246251
logger.debug(method)
247-
query.update({ODM.DataValue.method_id: method})
252+
query.update({DataValue.method_id: method})
248253
# check that the code is not zero
249254
# if qcl is not None and qcl.code != 0:
250255
if qcl is not None:
251256
logger.debug(qcl)
252-
query.update({ODM.DataValue.quality_control_level_id: qcl})
257+
query.update({DataValue.quality_control_level_id: qcl})
253258

0 commit comments

Comments
 (0)