Skip to content

Commit

Permalink
Merge pull request #62 from ODM2/bug-fix
Browse files Browse the repository at this point in the history
Bug fix
  • Loading branch information
sreeder authored Feb 10, 2017
2 parents 93d9834 + 0473972 commit 4e03493
Show file tree
Hide file tree
Showing 23 changed files with 778 additions and 598 deletions.
6 changes: 6 additions & 0 deletions src/controllers/Database.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,9 @@ def getReadSession(self):
'''
_session = self.session_factory.getSession()
return ReadODM2(self.session_factory)

def getUpdateSession(self):
'''
'''
_session = self.session_factory.getSession()
return UpdateODM2(self.session_factory)
4 changes: 2 additions & 2 deletions src/controllers/Mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ def _buildTables(self):

# FIXME change to none when released.
# SDL Test Data is just for our testing purposes.
#df['QualityCodeCV'] = 'None'
df['QualityCodeCV'] = 'SDL Test Data'
df['QualityCodeCV'] = 'None'
# df['QualityCodeCV'] = 'SDL Test Data'
# TODO add unknown to database.
#df['CensorCodeCV'] = 'Unknown'
df['CensorCodeCV'] = 'Non-detect'
Expand Down
123 changes: 99 additions & 24 deletions src/wizard/controller/WizardDialog.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import wx
from src.wizard.controller.frmSampFeatSelectPanel \
import SampFeatSelectPanel
from src.wizard.controller.frmVariableSelectPanel \
import VariableSelectPanel
from src.wizard.controller.frmUnitSelectPanel \
import UnitSelectPanel
from src.wizard.controller.frmProcLevelSelectPanel \
import ProcLevelSelectPanel
#from src.wizard.controller.frmActionsSelectPanel \
# import ActionsSelectPanel
from src.wizard.view.clsResultPage import ResultPageView
from src.wizard.controller.frmSampFeatSelectPanel import SampFeatSelectPanel
from src.wizard.controller.frmVariableSelectPanel import VariableSelectPanel
from src.wizard.controller.frmUnitSelectPanel import UnitSelectPanel
from src.wizard.controller.frmProcLevelSelectPanel import ProcLevelSelectPanel
from src.wizard.controller.frmActionsSelectPanel import ActionsSelectPanel
# from src.wizard.view.clsResultPage import ResultPageView
from src.wizard.controller.frmResultSummaryPanel import ResultSummaryPanel
from datetime import datetime


class WizardDialog(wx.Dialog):
def __init__(self, parent, database=None, title="Wizard Dialog",
result=None,
size=wx.DefaultSize,
pos=wx.DefaultPosition,
style=wx.DEFAULT_DIALOG_STYLE):

self.existingResult = result
pre = wx.PreDialog()
pre.Create(parent, wx.ID_ANY, title, pos, size, style)
self.PostCreate(pre)
Expand All @@ -26,15 +26,21 @@ def __init__(self, parent, database=None, title="Wizard Dialog",
self.btnSizer = wx.BoxSizer(wx.HORIZONTAL)

self.pnlList = []
self.currentPnl = None;
self.currentPnl = None
self.database = database

self.addButtons()

self.centerSelf()
self.SetSizer(self.mainSizer)
self.mainSizer.Fit(self)

self.returnValue = wx.ID_ANY
self.Bind(wx.EVT_CLOSE, self.on_close)

def on_close(self, event):
self.Destroy()

def centerSelf(self):
self.CenterOnParent()

def addButtons(self):
self.btnCancel = wx.Button(self, wx.ID_CANCEL, "Cancel")
Expand All @@ -57,10 +63,11 @@ def addButtons(self):
self.btnPrev.Bind(wx.EVT_BUTTON, self.onPrev)

def addPage(self, pnl):
newPnl = pnl(self)
newPnl = pnl(self, self.existingResult)
newPnl.Hide()
self.pnlList.append(newPnl)
self.pnlSizer.Add(newPnl, 1, wx.ALL|wx.EXPAND, 5)
self.CenterOnParent()

if len(self.pnlList) == 1:
self.btnNext.Unbind(wx.EVT_BUTTON)
Expand All @@ -83,6 +90,7 @@ def ShowModal(self):
self.currentPnl = self.pnlList[0]
self.currentPnl.Show()
self.mainSizer.Fit(self)
self.CenterOnParent()
super(WizardDialog, self).ShowModal()
return self.returnValue

Expand All @@ -91,16 +99,81 @@ def ShowModal(self):
# ********************** #

def onFinish(self, event):
# self.result = self.pnlList[-1].createResult()
#
# if self.existingResult:
# print self.existingResult
# else:
# if self.result:
# self.returnValue = wx.ID_OK
# self.Close()
#
# event.Skip()
if self.existingResult is None:
self.__create_new_result()
else:
self.__update_existing_result()

def __create_new_result(self):
self.result = self.pnlList[-1].createResult()
if self.result:
self.returnValue = wx.ID_OK
self.Close()
event.Skip()

def __update_existing_result(self):

if not isinstance(self.currentPnl, ResultSummaryPanel):
raise Exception("self.currentPanel must be of type ResultSummaryPanel")

result = self.existingResult

result.SampledMediumCV = self.currentPnl.comboSamp.GetValue()
result.AggregationStatisticCV = self.currentPnl.comboAgg.GetValue()

if self.currentPnl.comboStatus.GetValue() != "":
result.StatusCV = self.currentPnl.comboStatus.GetValue()

for unit in self.currentPnl.length_units:
if unit.UnitsName == self.currentPnl.comboXUnits.GetValue():
result.XLocationUnitsID = unit.UnitsID

if unit.UnitsName == self.currentPnl.comboYUnits.GetValue():
result.YLocationUnitsID = unit.UnitsID

if unit.UnitsName == self.currentPnl.comboZUnits.GetValue():
result.ZLocationUnitsID = unit.UnitsID

for time in self.currentPnl.time_units:
if time.UnitsName == self.currentPnl.comboIntendedUnits.GetValue():
result.IntendedTimeSpacingUnitsID = time.UnitsID

date = self.currentPnl.datePickerResult.GetValue()
year = date.Year
month = date.Month
day = date.Day
date = self.currentPnl.timeResult.GetWxDateTime()
hour = date.Hour
minute = date.Minute
second = date.Second
date = datetime(year=year, month=month, day=day, hour=hour, minute=minute, second=second)
result.ResultDateTime = date

result.XLocation = self.currentPnl.txtX.GetValue()
result.YLocation = self.currentPnl.txtY.GetValue()
result.ZLocation = self.currentPnl.txtZ.GetValue()

result.IntendedTimeSpacing = self.currentPnl.txtIntended.GetValue()

# self.database.getUpdateSession().updateResult(pass in result object)
session = self.database.getUpdateSession()
session.updateResult(result=result)

self.returnValue = wx.ID_OK
self.Close()

def onPrev(self, event):
self.currentPnl.Hide()
self.currentPnl = self.pnlList[self.pnlList.index( \
self.currentPnl)-1]
self.currentPnl = self.pnlList[self.pnlList.index(self.currentPnl)-1]
self.currentPnl.Show()
self.Layout()
self.mainSizer.Fit(self)
Expand All @@ -109,6 +182,7 @@ def onPrev(self, event):
self.btnPrev.Enable(False)
else:
self.btnPrev.Enable(True)

if self.currentPnl == self.pnlList[-1]:
self.btnNext.SetLabel("Finish")
self.btnNext.Unbind(wx.EVT_BUTTON)
Expand All @@ -117,15 +191,13 @@ def onPrev(self, event):
self.btnNext.SetLabel("Next >")
self.btnNext.Unbind(wx.EVT_BUTTON)
self.btnNext.Bind(wx.EVT_BUTTON, self.onNext)



event.Skip()

def onNext(self, event):
self.btnNext.Enable(False)
self.currentPnl.Hide()
self.currentPnl = self.pnlList[self.pnlList.index( \
self.currentPnl)+1]
self.currentPnl = self.pnlList[self.pnlList.index(self.currentPnl)+1]
self.currentPnl.Show()
self.Layout()
self.mainSizer.Fit(self)
Expand All @@ -134,7 +206,10 @@ def onNext(self, event):
self.btnPrev.Enable(False)
else:
self.btnPrev.Enable(True)

if self.currentPnl == self.pnlList[-1]:
self.CenterOnParent()
self.currentPnl.check_required_fields()
self.btnNext.SetLabel("Finish")
self.btnNext.Unbind(wx.EVT_BUTTON)
self.btnNext.Bind(wx.EVT_BUTTON, self.onFinish)
Expand All @@ -143,7 +218,7 @@ def onNext(self, event):
self.btnNext.Unbind(wx.EVT_BUTTON)
self.btnNext.Bind(wx.EVT_BUTTON, self.onNext)

event.Skip()
event.Skip()


if __name__ == '__main__':
Expand All @@ -154,7 +229,7 @@ def onNext(self, event):
wiz.addPage(UnitSelectPanel)
wiz.addPage(ProcLevelSelectPanel)
wiz.addPage(ActionsSelectPanel)
wiz.addPage(ResultPageView)
# wiz.addPage(ResultPageView)
wiz.ShowModal()
app.MainLoop()

68 changes: 37 additions & 31 deletions src/wizard/controller/frmActionsSelectPanel.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,48 @@
import wx
from src.wizard.controller.frmNewSeriesDialog import NewSeriesDialog
from src.wizard.controller.frmAddNewActionsPanel import AddNewActionsPanelController
from src.wizard.controller.frmSeriesSelectPanel import SeriesSelectPanel
from ObjectListView import ColumnDefn

from odm2api.ODMconnection import dbconnection
#TODO get rid of *
from odm2api.ODM2.services.readService import *
from src.wizard.controller.frmNewSeriesDialog \
import NewSeriesDialog
from src.wizard.controller.frmAddNewActionsPanel \
import AddNewActionsPanelController
from src.wizard.controller.frmSeriesSelectPanel \
import SeriesSelectPanel

from ObjectListView import ObjectListView, ColumnDefn

class ActionsSelectPanel(SeriesSelectPanel):
def __init__( self, parent):
super(ActionsSelectPanel, self).__init__(parent,
"Action")
def __init__(self, parent, existing_result=None):
super(ActionsSelectPanel, self).__init__(parent, "Action")
self.parent = parent
self.existing_result = existing_result

self.list_ctrl.SetColumns([
ColumnDefn('Id', 'left', 70,
'ActionID'),
ColumnDefn('Type', 'left', 100,
'ActionTypeCV'),
ColumnDefn('Description', 'left', 500,
'ActionDescription'),
ColumnDefn('Method Id', 'left', 90,
'MethodID'),
ColumnDefn('Begin Time', 'left', 125,
'BeginDateTime'),
ColumnDefn('End Time', 'left', 125,
'EndDateTime'),
ColumnDefn('Id', 'left', 70, 'ActionID'),
ColumnDefn('Type', 'left', 100, 'ActionTypeCV'),
ColumnDefn('Description', 'left', 500, 'ActionDescription'),
ColumnDefn('Method Id', 'left', 90, 'MethodID'),
ColumnDefn('Begin Time', 'left', 125, 'BeginDateTime'),
ColumnDefn('End Time', 'left', 125, 'EndDateTime'),
])

self.list_ctrl.SetObjects(self.getSeriesData())
if not self.parent.database:
self.new_button.Enable(False)

self.select_existing_series()

self.list_ctrl.Bind(wx.EVT_LIST_ITEM_SELECTED, self.enable)
#self.list_ctrl.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.disable)
self.Bind(wx.EVT_SHOW, self.onShow)
self.list_ctrl.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.disable)

def select_existing_series(self):
if self.existing_result is None:
return

index = -1
data = self.list_ctrl.GetObjects()
for i in range(len(data)):
if self.existing_result.FeatureActionObj.ActionObj.ActionID == data[i].ActionID:
index = i
break

if index >= 0:
self.list_ctrl.Select(index)
self.list_ctrl.SetFocus()

def onShow(self, event):
if self.list_ctrl.GetSelectedObject():
Expand All @@ -46,12 +52,12 @@ def onShow(self, event):
event.Skip()

def enable(self, event):
if self.existing_result is not None:
self.existing_result.FeatureActionObj.ActionObj = self.list_ctrl.GetSelectedObject()
self.parent.btnNext.Enable(True)
event.Skip()


def disable(self, event):
self.parent.btnNext.Enable(False)
event.Skip()

def getSeriesData(self):
if self.parent.database:
Expand Down
5 changes: 2 additions & 3 deletions src/wizard/controller/frmAddNewUnitPanel.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@

import wx

from src.wizard.view.clsAddNewUnitPanel import AddNewUnitPanelView
from odm2api.ODM2.models import Units


class AddNewUnitPanelController(AddNewUnitPanelView):
def __init__(self, daddy, db, **kwargs):
super(AddNewUnitPanelController, self).__init__(daddy,
**kwargs)
super(AddNewUnitPanelController, self).__init__(daddy, **kwargs)
self.parent = daddy
self.db = db

Expand Down
27 changes: 12 additions & 15 deletions src/wizard/controller/frmDataConfigPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ def setInputGrid(self, data):
# Assign the table to the grid control.
self.m_listCtrl1.setTable(base)

for column in range(self.m_listCtrl1.GetNumberCols()):
self.m_listCtrl1.AutoSizeColLabelSize(column)
self.m_listCtrl1.AutoSizeColumns()

def setInputMappingList(self, existingData, read):
"""
Expand All @@ -171,21 +170,19 @@ def setInputMappingList(self, existingData, read):
popThese.append(variableName)
continue
# Add the variable name to the mapping list.
mapping = read.getDetailedResultInfo(\
"Time series coverage",
values['ResultID'])
mapping = read.getDetailedResultInfo("Time series coverage", values['ResultID'])
mapped = mapping[0]
self.m_listCtrl3.AddObject(
ResultMapping(mapped.resultID,
mapped.samplingFeatureCode,
mapped.samplingFeatureName,
mapped.methodCode,
mapped.methodName,
mapped.variableCode,
mapped.variableNameCV,
mapped.processingLevelCode,
mapped.processingLevelDef,
mapped.unitsName,
ResultMapping(mapped.ResultID,
mapped.SamplingFeatureCode,
mapped.SamplingFeatureName,
mapped.MethodCode,
mapped.MethodName,
mapped.VariableCode,
mapped.VariableNameCV,
mapped.ProcessingLevelCode,
mapped.ProcessingLevelDefinition,
mapped.UnitsName,
variableName))
if popThese:
wx.MessageBox("Mappings for the following variables exist, but do not appear in the selected data file:\n'%s'\n\nThese mappings will be deleted if you continue." \
Expand Down
Loading

0 comments on commit 4e03493

Please sign in to comment.