Skip to content

Commit 40b7118

Browse files
committed
Merge branch 'use_api2' of https://github.com/ODM2/ODMToolsPython into use_api2
2 parents f9d827a + 458b1cf commit 40b7118

6 files changed

Lines changed: 458 additions & 280 deletions

File tree

odmtools/controller/pageExisting.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,14 @@ def getSeries(self):
7272

7373
def initTable(self, dbservice, site_id):
7474
"""Set up columns and objects to be used in the objectlistview to be visible in the series_service selector"""
75-
76-
seriesColumns = [clsExisting.ColumnDefn(key, align="left",
77-
minimumWidth=-1, valueGetter=value,
78-
stringConverter= '%Y-%m-%d %H:%M:%S' if 'date' in key.lower() else '%s')
79-
for key, value in returnDict().iteritems()]
75+
objects = dbservice.get_all_series(siteid=site_id)
76+
seriesColumns = [
77+
clsExisting.ColumnDefn(key, align="left", minimumWidth=100, valueGetter=key,
78+
# stringConverter = '%s')
79+
stringConverter='%Y-%m-%d %H:%M:%S' if "date" in key.lower() else '%s')
80+
for key in objects[0].__dict__.keys()]
8081

8182
self.pnlExisting.olvSeriesList.SetColumns(seriesColumns)
82-
objects = dbservice.get_series_by_site(site_id=site_id)
83+
# objects = dbservice.get_series_by_site(site_id=site_id)
84+
8385
self.pnlExisting.olvSeriesList.SetObjects(objects)

odmtools/gui/wizSave.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import pageQCL
1010
import pageVariable
1111
import pageSummary
12-
from odm2api.ODM2.models import Actions
12+
from odm2api.ODM2.models import *
1313

1414
[wxID_PNLINTRO, wxID_PNLVARIABLE, wxID_PNLMETHOD, wxID_PNLQCL,
1515
wxID_PNLSUMMARY, wxID_WIZSAVE, wxID_PNLEXISTING,
@@ -226,7 +226,7 @@ def _init_ctrls(self, prnt):
226226

227227
def get_metadata(self):
228228
# method = self.currSeries.FeatureActionObj.ActionObj.MethodObj
229-
# processing_level = self.currSeries.quality_control_level
229+
# processing_level = self.currSeriefs.quality_control_level
230230
# variable = self.currSeries.variable
231231
# action =
232232

@@ -267,9 +267,11 @@ def get_metadata(self):
267267
# Create action
268268
action = Actions()
269269
action.MethodObj = method
270+
action.MethodID = method.MethodID
270271
action.ActionDescription = self.action_page.action_view.description_text_box.GetValue()
271272
action.ActionFileLink = self.action_page.action_view.action_file_link_text_box.GetValue()
272273
action.MethodObj.OrganizationObj = affiliation.OrganizationObj
274+
action.BeginDateTime = self.currSeries.ResultDateTime
273275

274276
return site, variable, method, action, processing_level
275277

@@ -442,8 +444,6 @@ def on_wizard_finished(self, event):
442444
else:
443445
method = self.series_service.get_method_by_code(method.MethodCode)
444446

445-
446-
447447
# initiate either "Save as" or "Save"
448448
'''
449449
if self.page1.pnlIntroduction.rbSave.GetValue():
@@ -452,19 +452,35 @@ def on_wizard_finished(self, event):
452452
result = self.record_service.saveAs(Variable, Method, QCL, True)
453453
'''
454454

455+
456+
#TODO: move all of this stuff into the edit_service file
455457
# Create action
456-
new_result = self.series_service.createResult(var=variable, meth=method, proc=proc_level)
458+
new_result = self.series_service.getResult(var=variable, meth=method, proc=proc_level)
459+
457460
# action = self.series_service.create.createAction(action)
458461

462+
affiliation = self.action_page.get_affiliation()
463+
464+
new_action_by = ActionBy()
465+
new_action_by.ActionID = action.ActionID
466+
new_action_by.RoleDescription = self.action_page.action_view.role_description_text_box.GetValue()
467+
new_action_by.AffiliationID = affiliation.AffiliationID
468+
new_action_by.AffiliationObj = affiliation
469+
470+
#TODO end
471+
459472
try:
460473
if rbSave:
461474
result = self.record_service.save()
462475
elif rbSaveAsNew:
476+
#TODO send in Action, and Actionby
463477
result = self.record_service.save_as(variable, method, proc_level)
464478
elif rbSaveAsExisting:
465479
if overwrite:
480+
#TODO send in just the result
466481
result = self.record_service.save_existing(variable, method, proc_level)
467482
elif append:
483+
#TODO send in just the result
468484
#def save_appending(self, var = None, method =None, qcl = None, overwrite = False):
469485
#TODO if i require that original or new is selected I can call once with overwrite = original
470486
if original:

odmtools/odmdata/memory_database.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def __init__(self, taskserver=None):
2929
# Memory_service handles in memory database
3030
sm = ServiceManager()
3131
self.mem_service = sm.get_series_service(conn_string="sqlite:///:memory:")
32+
3233
setSchema(self.mem_service._session_factory.engine)
3334

3435
# TODO clean up closing of program
@@ -68,13 +69,17 @@ def getDataValuesDF(self):
6869
#else:
6970
# self.updateDF()
7071
'''
72+
# TODO: fix me! this commit location is only temoporarily. should be flushing so that we can restore
73+
self.mem_service._session.commit()
7174
setSchema(self.mem_service._session_factory.engine)
7275
self.updateDF()
7376
# pick up thread here before it is needed
7477
logging.debug("done updating memory dataframe")
7578
return self.df
7679

7780
def getDataValues(self):
81+
# TODO: fix me! this commit location is only temoporarily. should be flushing so that we can restore
82+
self.mem_service._session.commit()
7883
setSchema(self.mem_service._session_factory.engine)
7984
return self.mem_service.get_all_values()
8085

@@ -97,6 +102,7 @@ def getEditDataValuesforGraph(self):
97102

98103
def commit(self):
99104
self.mem_service._session.commit()
105+
# self.mem_service._session.commit()
100106

101107
def rollback(self):
102108
self.mem_service._session.rollback()
@@ -143,6 +149,7 @@ def updateValue(self, ids, operator, value):
143149
q=self.mem_service._session.query(TSRV).filter(TSRV.ValueDateTime.in_(c))
144150
q.update({TSRV.DataValue: query}, False)
145151

152+
146153
#self.updateDF()
147154

148155
def chunking(self, data):
@@ -175,6 +182,7 @@ def updateFlag(self, ids, value):
175182
frames = [self.annotation_list, flags]
176183
self.annotation_list=pd.concat(frames)
177184
print self.annotation_list
185+
#todo: remove duplicates before saving
178186

179187

180188

@@ -199,9 +207,12 @@ def addPoints(self, points):
199207
vals = {"datavalue": point[0], "valuedatetime": point[1],
200208
"valuedatetimeutcoffset": point[3],
201209
"censorcodecv": point[4], "qualitycodecv": point[5],
202-
"timeaggregationinterval": point[6], "timeaggregationintervalunitsid": point[7]
210+
"timeaggregationinterval": point[6], "timeaggregationintervalunitsid": point[7],
211+
"resultid":self.df["resultid"][0]
203212
# todo: Add annotations
204213
}
214+
if point[8]:
215+
self.updateFlag(point[1], self.series_service.get_annotation_by_code(point[8].split(':')[0]).AnnotationID)
205216

206217
setSchema(self.mem_service._session_factory.engine)
207218
self.mem_service._session.execute(stmt, vals)

0 commit comments

Comments
 (0)