Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/StreamingDataLoader.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,25 @@ def main(arguments):
parser = ArgumentParser(description="StreamingDataLoader")
parser.add_argument('-r', '--restart', action='store_true', help="Read the entire CSV file to ensure that data is correct and accounted for. This option affects performance. While the integrity of the data is checked each time the program executes, it is still recommended to use this option if you have manually modified your data file between executions.")
parser.add_argument('-v', '--verbose', action='store_true', help="Enable more verbose logging in the logfile.")
parser.add_argument('-c', '--config', nargs='+', dest="yamlFile", help="Specify a YAML configuration file in the form of one of these formats:\n1. A single YAML (.yaml) file.\n2. A list of YAML files (.yaml), deliminated by white space.\n3. A directory containing multiple YAML (.yaml) files.", required=True, action="store")
parser.add_argument('-c', '--config', nargs='+', dest="yamlFile", help="Specify a YAML configuration file in the form of one of these formats:\n1. A single YAML (.yaml) file.\n2. A list of YAML files (.yaml), deliminated by white space.\n3. A directory containing multiple YAML (.yaml) files.", required=False, action="store")
parser.add_argument('-f', '--file', dest="csvFile", help="Specify a single CSV data file to target instead of the one listed in the configuration file.", required=False, action="store")
args = parser.parse_args()


correct_path = ""
for path in args.yamlFile:
correct_path += path + " "

os.chdir(os.getcwd())
for filename in os.listdir('.'):
if filename.endswith('.yaml'):
correct_path = os.getcwd()
correct_path += filename
break;

if args.yamlFile is not None:
if args in args.yamlFile:
correct_path = ""
for path in args.yamlFile:
correct_path += path + " "

args.yamlFile = [correct_path.strip()]
start_time = time.time()
Expand Down
7 changes: 5 additions & 2 deletions src/controllers/Database.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,18 @@ def createConnection(self, Credentials):
print Credentials.host
print Credentials.db_name
print Credentials.uid
print Credentials.pwd
# print Credentials.pwd

self.session_factory = \
dbconnection.createConnection(Credentials.engine, Credentials.host,
Credentials.db_name,
Credentials.uid,
Credentials.pwd, 2.0)
if not self.session_factory:
logger.error("Unable to connect to database with host='%s', database='%s', user='%s', pwd='%s'." % (Credentials.host, Credentials.db_name, Credentials.uid, Credentials.pwd))
message = "Unable to connect to database with host='%s', database='%s', user='%s', pwd='%s'." % (Credentials.host, Credentials.db_name, Credentials.uid, Credentials.pwd)

logger.error(message)
print message
return False

return True
Expand Down
30 changes: 30 additions & 0 deletions src/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## Configuration file
## Last modified: 2017-07-11 13:39
---
test:
Database:
Address: localhost
DatabaseName: odm2
Engine: mysql
Password: bobrules
UserName: Bob
Mappings:
RelativeHumidity-%:
CalculateAggInterval: 'false'
IntendedTimeSpacing: 0
IntendedTimeSpacingUnitID: 136
LastByteRead: '127003'
ResultID: 22293
Schedule:
Beginning: 01/01/2014 12:00:00 AM
Frequency: Hour
LastUpdate: '2017-07-11 13:39:41'
Time: 1
Settings:
DataRowPosition: 21
DateTimeColumnName: DateTime
Delimiter: ','
FileLocation: C:\Sites\ODM2StreamingDataLoader\ODM2StreamingDataLoader\tests\test_handlers\test_csvHandler\csvFiles\Treeline_HrlySummary_2014.csv
FillGaps: 'false'
HeaderRowPosition: 20
UTCOffset: 0
55 changes: 37 additions & 18 deletions src/wizard/controller/frmAddNewActionsPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@ def onNewMethod(self, event):
newMethodPanel.setTypeFilter(str(self.action_type_combo.GetStringSelection()))
if dlg.ShowModal() == wx.ID_OK:
newMethod = newMethodPanel.method
self.methods = [{i.MethodName:i.MethodID}\
for i in [newMethod]]
self.methods = [{i.MethodName: i.MethodID} for i in [newMethod]]
self.method_combo.AppendItems([y for x in [i.keys() for i in self.methods] for y in x])
#self.m_comboBox134.SetValue(newMethod.MethodName)
# self.method_combo.SetValue(newMethod.MethodName)
i = self.method_combo.FindString(newMethod.MethodName)
self.method_combo.Select(i)
dlg.Destroy()
if self.method_combo.IsEmpty():
self.method_combo.Select(0)

event.Skip()

def onNewAffiliation(self, event):
Expand Down Expand Up @@ -91,11 +95,15 @@ def onOK(self, event):
MethodID=self.methodID,
BeginDateTime=self.beginDT,
BeginDateTimeUTCOffset=self.beginDTUTC,
EndDateTime=self.endDT,
EndDateTimeUTCOffset=self.endDTUTC,
ActionDescription=self.actionDesc,
ActionFileLink=self.actionLink
)
try:
action.EndDateTime = self.endDT,
action.EndDateTimeUTCOffset = self.endDTUTC,
action.ActionDescription = self.actionDesc,
action.ActionFileLink = self.actionLink
except Exception as error:
print error

action = write.createAction(action)

self.actionID = action.ActionID
Expand All @@ -121,33 +129,44 @@ def onOK(self, event):

def getFieldValues(self):

keys = [y for x in [i.keys() for i in self.methods] for y in x]
vals = [y for x in [i.values() for i in self.methods] for y in x]
keys = [y for x in [aff.keys() for aff in self.methods] for y in x]
vals = [y for x in [aff.values() for aff in self.methods] for y in x]
d = dict(zip(keys, vals))

# self.ActionType = str(self.action_type_combo.GetStringSelection())
# self.MethodID = d[str(self.method_combo.GetStringSelection())]
# self.BeginDT = self._getTime(self.m_datePicker5, self.m_timePicker1)
# self.BeginDTUTC = self.spinUTCBegin.GetValue()
# self.AffiliationList = [i.affiliationID for i in self.affList.GetSelectedObjects()]
#
# for i in self.affList.selected():
# if self.affList.IsChecked(i):
# self.actionLead = i.affiliationID
# # =======
self.actionType = str(self.action_type_combo.GetStringSelection())
self.methodID = d[str(self.method_combo.GetStringSelection())]
self.beginDT = self._getTime(self.m_datePicker5, self.m_timePicker1)
self.beginDT = self._getTime(self.dateBegin, self.m_timePicker1)
self.beginDTUTC = self.spinUTCBegin.GetValue()
self.affiliationList = [aff.AffiliationID for aff in self.affList.GetSelectedObjects()]

for i in self.affList.GetSelectedObjects():
if self.affList.IsChecked(i):
self.actionLead = i.affiliationID
for aff in self.affList.GetSelectedObjects():
if self.affList.IsChecked(aff):
self.actionLead = aff.AffiliationID
# >>>>>>> 302544e2537a81675971d89e1be2a758c65becd8
break
if self.m_datePicker51.GetValue().IsValid():
self.endDT = self._getTime(self.m_datePicker51, self.m_timePicker2)
else:
self.endDT = None
self.endDTUTC = self.beginDTUTC
self.EndDT = None
self.EndDTUTC = self.beginDTUTC
if str(self.m_textCtrl232.GetValue()) == '':
self.actionDesc = None
else:
self.actionDesc = str(self.m_textCtrl232.GetValue())
self.ActionDesc = str(self.m_textCtrl232.GetValue())
if str(self.m_textCtrl234.GetValue()) == '':
self.actionLink = None
self.ActionLink = None
else:
self.actionLink = str(self.m_textCtrl234.GetValue())
self.ActionLink = str(self.m_textCtrl234.GetValue())

def _getTime(self, d, t):
date = d.GetValue()
Expand Down
9 changes: 7 additions & 2 deletions src/wizard/controller/frmAddNewMethodPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ def __init__(self, daddy, db, **kwargs):
**kwargs)
self.parent = daddy
self.db = db

self.method = None# This is our method return value
self.methodCode = None
self.methodName = None
self.desc = None
self.populateFields()

def setTypeFilter(self, t):
Expand Down Expand Up @@ -42,8 +45,10 @@ def onOK(self, event):
OrganizationID=self.orgId,
MethodDescription=self.desc)
self.method = write.createMethod(meth)

except Exception as e:
wx.MessageBox(e, 'Error saving method to database.')
wx.MessageBox(e, "Error saving method to database")

event.Skip()

def getFieldValues(self):
Expand Down
66 changes: 37 additions & 29 deletions src/wizard/controller/frmDataConfigPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, daddy, **kwargs):

self.prev_data = {}
self.inputDict = {}
self.m_listCtrl3.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.rightClick)
self.lstMappings.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.rightClick)


def rightClick(self, event):
Expand All @@ -44,13 +44,13 @@ def rightClick(self, event):

def editMapping(self, event):
self.selectedColumn = \
self.m_listCtrl3.GetSelectedObject().variableName
self.lstMappings.GetSelectedObject().variableName
self.runSeriesSelectDialog()
event.Skip()

def deleteMapping(self, event):
names = [obj.variableName for obj in \
self.m_listCtrl3.GetSelectedObjects()]
self.lstMappings.GetSelectedObjects()]
for i in range(0, self.m_listCtrl1.GetNumberCols()):
if str(self.m_listCtrl1.GetColLabelValue(i)) in names:
self.m_listCtrl1.SetColLabelRenderer(\
Expand All @@ -61,14 +61,14 @@ def deleteMapping(self, event):
# Instead of deleting from mapping right now,
# add to a list that can be deleted when finish
# button is clicked.
for name in self.m_listCtrl3.GetSelectedObjects():
for name in self.lstMappings.GetSelectedObjects():
self.deletedMappings.append(name.variableName)
#for name in self.m_listCtrl3.GetSelectedObjects():
# self.inputDict['Mappings'].pop(name.variableName)

self.m_listCtrl3.RemoveObjects(\
self.m_listCtrl3.GetSelectedObjects())
self.m_listCtrl3.RepopulateList()
self.lstMappings.RemoveObjects(\
self.lstMappings.GetSelectedObjects())
self.lstMappings.RepopulateList()

event.Skip()

Expand Down Expand Up @@ -158,8 +158,8 @@ def setInputMappingList(self, existingData, read):
except KeyError:
existingData.update({"Mappings": {}})

self.m_listCtrl3.DeleteAllItems()
self.m_listCtrl3.RepopulateList()
self.lstMappings.DeleteAllItems()
self.lstMappings.RepopulateList()

popThese = []
# Iterate through the mappings
Expand All @@ -171,19 +171,21 @@ def setInputMappingList(self, existingData, read):
continue
# Add the variable name to the mapping list.
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.ProcessingLevelDefinition,
mapped.UnitsName,
variableName))

# mapped = mapping[0]
for mapped in mapping:
self.lstMappings.AddObject(
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." \
% (", ".join(popThese)),
Expand Down Expand Up @@ -263,13 +265,19 @@ def setInputUnit(self, read):
unitID = searchDict(self.inputDict['Mappings'],
'IntendedTimeSpacingUnitID')
#unit = read.getUnitById(int(unitID))
unit = read.getUnits(ids = [int(unitID)])[0]
i = self.choiceUnitID.FindString(unit.UnitsName)
self.choiceUnitID.SetSelection(i)
#unit = read.getUnits(ids = [int(unitID)])[0]
unit = read.getUnits(ids = [int(unitID)])
if(unit is not None and len(unit) > 0):
i = self.choiceUnitID.FindString(unit[0].UnitsName)
self.choiceUnitID.SetSelection(i)
else:
defaultTimeUnits = ['seconds', 'minutes', 'hours', 'days']
for unit in defaultTimeUnits:
self.choiceUnitID.Append(unit)
self.choiceUnitID.SetSelection(0)
except KeyError:
self.choiceUnitID.SetSelection(0)


def onAddNew(self, event):
self.runSeriesSelectDialog()
# event.Skip()
Expand Down Expand Up @@ -328,12 +336,12 @@ def runSeriesSelectDialog(self):
'CalculateAggInterval':'false'}})

#pprint.pprint(self.inputDict)
for m in self.m_listCtrl3.GetObjects():
for m in self.lstMappings.GetObjects():
if m.variableName == dlg.selectedResult.variableName:
self.m_listCtrl3.RemoveObjects([m])
self.lstMappings.RemoveObjects([m])
break

self.m_listCtrl3.AddObject(dlg.selectedResult)
self.lstMappings.AddObject(dlg.selectedResult)
dlg.Destroy()
return True
dlg.Destroy()
Expand Down
5 changes: 3 additions & 2 deletions src/wizard/controller/frmDatabaseConfigPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ def validateInput(self, conn_dict):
self.parent.nextButton.SetFocus()
else:
connected = False
except:
connected = False
except Exception as ex:
connected = False
print ex

wx.MessageBox(message=message,
caption=title,
Expand Down
20 changes: 10 additions & 10 deletions src/wizard/controller/frmResultSummaryPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ def createResult(self):
if str(self.comboSR.GetStringSelection()) != "":
sr = d[self.comboSR.GetStringSelection()]

timeSpacing = None
if str(self.txtIntended.GetValue()) != "":
timeSpacing = float(self.txtIntended.GetValue())
timeUnit = None
if str(self.comboIntendedUnits.GetStringSelection()) != "":
timeUnit = lunitsdict[str(self.comboIntendedUnits.GetStringSelection())]
# timeSpacing = None
# if str(self.txtIntended.GetValue()) != "":
# timeSpacing = float(self.txtIntended.GetValue())
# timeUnit = None
# if str(self.comboIntendedUnits.GetStringSelection()) != "":
# timeUnit = lunitsdict[str(self.comboIntendedUnits.GetStringSelection())]

print "X", x
print "Y", y
Expand All @@ -242,9 +242,9 @@ def createResult(self):
YLocationUnitsID=yUnit,
ZLocation=z,
ZLocationUnitsID=zUnit,
SpatialReferenceID=sr,
IntendedTimeSpacing=timeSpacing,
IntendedTimeSpacingUnitsID=timeUnit)
SpatialReferenceID=sr)
# IntendedTimeSpacing=timeSpacing,
# IntendedTimeSpacingUnitsID=timeUnit)
result = write.createResult(tsr)

print result
Expand Down Expand Up @@ -306,7 +306,7 @@ def populateFields(self):
self.comboXUnits.AppendItems(length_units_name)
self.comboYUnits.AppendItems(length_units_name)
self.comboZUnits.AppendItems(length_units_name)
self.comboIntendedUnits.AppendItems(time_units_name)
#self.comboIntendedUnits.AppendItems(time_units_name)

self.tax = [{i.TaxonomicClassifierName:i.TaxonomicClassifierID}\
for i in self.read_session.getTaxonomicClassifiers()]
Expand Down
2 changes: 1 addition & 1 deletion src/wizard/controller/frmSeriesDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def onNew(self, event):
wiz.result.ResultID)
r_id = r[0].ResultID ###DetailedResult instance has no attribute resultID

r_id = r[0].resultID
r_id = r[0].ResultID

detailedResults = read.getDetailedResultInfo("Time series coverage")
self.seriesSelectPanel.listCtrl.SetObjects(detailedResults)
Expand Down
Loading