Skip to content

Commit 80837b5

Browse files
author
Stephanie Reeder
authored
Merge pull request #307 from ODM2/use_api2
Use api2
2 parents e503af9 + 1205414 commit 80837b5

File tree

86 files changed

+3124
-11408
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+3124
-11408
lines changed

ODMTools.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
#import psycopg2
2424

2525
tool = LoggerTool()
26-
logger = tool.setupLogger('main', 'odmtools.log', 'a', logging.INFO)
26+
# logger = tool.setupLogger('main', 'odmtools.log', 'a', logging.INFO)
27+
logger = tool.setupLogger('main', 'odmtools.log', 'a', logging.DEBUG)
2728
wx.Log.SetLogLevel(0)
2829

2930

@@ -56,6 +57,7 @@ def OnInit(self):
5657
kwargs['taskServer'] = self.taskserver
5758
kwargs['memdb']= self.memdb
5859
self.frame = frmODMToolsMain(**kwargs)
60+
self.frame.CenterOnScreen()
5961
self.frame.Show(True)
6062
app= self.frame
6163
return True

odmtools/common/taskServer.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,12 @@ def worker(cls, dispatcher):
130130
result = Statistics(task)
131131
if task_type == "InitEditValues":
132132
connection = SeriesService("sqlite:///:memory:")
133+
# connection._
133134
df = task[1]
134135
logger.debug("Load series from db")
135-
df.to_sql(name="DataValues", con=connection._connection.engine, flavor='sqlite', index = False, chunksize = 10000)
136-
# =======
137-
# logger.debug("Load series_service from db")
138-
# df.to_sql(name="DataValues", con=connection._session_factory.engine, flavor='sqlite', index = False, chunksize = 10000)
139-
# >>>>>>> origin/update_cvs
136+
#setSchema(self.mem_service._session_factory.engine)
137+
df.to_sql(name="timeseriesresultvalues", con=connection._connection.engine, flavor='sqlite', index = False, chunksize = 10000)
138+
140139
logger.debug("done loading database")
141140
result = connection
142141
if task_type == "UpdateEditDF":

odmtools/controller/frmBulkInsert.py renamed to odmtools/controller/BulkInsertController.py

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Bulk Insert of points
33
"""
44
import wx
5-
import odmtools.view.clsBulkInsert as clsBulkInsert
5+
import odmtools.view.BulkInsertView as clsBulkInsert
66
import odmtools.controller.olvAddPoint as olv
77
import pandas as pd
88
from pandas.parser import CParserError
@@ -13,13 +13,12 @@
1313
__author__ = 'Jacob'
1414

1515

16-
class BulkInsert(clsBulkInsert.BulkInsert):
16+
class BulkInsertController(clsBulkInsert.BulkInsertView):
1717
def __init__(self, parent):
18-
clsBulkInsert.BulkInsert.__init__(self, parent)
18+
clsBulkInsert.BulkInsertView.__init__(self, parent)
1919
self.parent = parent
2020

21-
self.col = ['DataValue', 'Date', 'Time', 'UTCOffSet', 'CensorCode', 'ValueAccuracy', 'OffSetValue',
22-
'OffSetType', 'QualifierCode', 'LabSampleCode']
21+
self.columns = ["DataValue", "Date", "Time", "UTFOffset", "CensorCode", "QualityCode", "TimeAggregationInterval", "TimeAggregationUnitID", "Annotation"]
2322

2423
def obtainFilePath(self):
2524
## Obtain CSV filepath
@@ -53,16 +52,10 @@ def readDataFromCSV(self, filepath):
5352

5453
try:
5554
#data = pd.read_csv(filepath, skiprows=[1], engine='c', lineterminator='\n')
56-
data = pd.read_csv(csv_data, skiprows=[1], engine='c', converters={0: str.strip,
57-
1: str.strip,
58-
2: str.strip,
59-
3: str.strip,
60-
4: str.strip,
61-
5: str.strip,
62-
6: str.strip,
63-
7: str.strip,
64-
8: str.strip,
65-
9: str.strip})
55+
data = pd.read_csv(csv_data, skiprows=[1], engine='c', converters={
56+
0: str.strip, 1: str.strip, 2: str.strip, 3: str.strip,
57+
4: str.strip, 5: str.strip, 6: str.strip, 7: str.strip,
58+
8: str.strip})
6659
except CParserError as e:
6760
message = "There was an issue trying to parse your file. "\
6861
"Please compare your csv with the template version as the file"\
@@ -112,6 +105,7 @@ def loadIntoDataFrame(self, data):
112105

113106
dlg.Destroy()
114107
return pointList
108+
115109
def onUpload(self, event):
116110
"""Reads csv into pandas object
117111
@@ -143,7 +137,7 @@ def onUpload(self, event):
143137
self.parent.Raise()
144138
event.Skip()
145139

146-
def onTemplate(self, event):
140+
def onDownloadTemplateButton(self, event):
147141
"""
148142
DataValues: Floats or -9999 (No data value)
149143
Date: --+ String
@@ -160,28 +154,25 @@ def onTemplate(self, event):
160154
:param event:
161155
:return:
162156
"""
163-
saveFileDialog = wx.FileDialog(self, "Save Bulk Insert Template", "", "", "CSV files (*.csv)|*.csv", wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
164-
value = saveFileDialog.ShowModal()
157+
158+
file_dialog = wx.FileDialog(self, "Save Bulk Insert Template", "", "", "CSV files (*.csv)|*.csv", wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
159+
value = file_dialog.ShowModal()
165160
if value == wx.ID_CANCEL:
166161
return
167-
filepath = saveFileDialog.GetPath()
168-
df = pd.DataFrame(columns=self.col)
162+
filepath = file_dialog.GetPath()
163+
df = pd.DataFrame(columns=self.columns)
169164
df.loc[0] = ['FLOAT|INT', 'YYYY-MM-DD', 'HH:MM:SS', 'INT', 'gt|nc|lt|nd|pnq', 'FLOAT', 'FLOAT',
170-
'String', 'String', 'String']
171-
df.loc[1] = ['-9999', '2005-06-29', '14:20:15', '-7', 'nc', "1.2", "1", "NULL", "NULL", "NULL"]
165+
'String', 'String']
166+
df.loc[1] = ['-9999', '2005-06-29', '14:20:15', '-7', 'nc', "1.2", "1", "NULL", "NULL"]
172167
df.to_csv(filepath, index=False)
173-
174-
self.EndModal(0) # Denver
175-
#self.Hide()
176-
self.parent.Raise()
168+
self.onClose(None)
177169

178170
def onClose(self, event):
179-
self.EndModal(0) # Denver
180-
#self.Hide()
171+
self.EndModal(0)
181172
self.parent.Raise()
182173

183174
if __name__ == '__main__':
184175
app = wx.App(useBestVisual=True)
185-
m = BulkInsert(None)
176+
m = BulkInsertController(None)
186177
m.Show()
187178
app.MainLoop()
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import wx
2+
from odmtools.view.NewFlagValuesView import NewFlagValuesView
3+
import odmtools.controller.olvAddPoint
4+
5+
6+
class NewFlagValuesController(NewFlagValuesView):
7+
def __init__(self, parent, series_service, qualifier_choice, record_service):
8+
9+
NewFlagValuesView.__init__(self, parent)
10+
self.parent = parent
11+
self.series_service = series_service
12+
self.qualifer_choice = qualifier_choice
13+
self.record_service = record_service
14+
self.__new_annotation = "New Annontation"
15+
16+
if self.qualifer_choice:
17+
annotations = self.series_service.get_all_annotations()
18+
self.append_items_to_annotation(annotations)
19+
20+
self.annotation_combo.Append(self.__new_annotation)
21+
self.annotation_combo.SetSelection(0)
22+
23+
self.cancel_button.Bind(wx.EVT_BUTTON, self.on_cancel)
24+
self.Bind(wx.EVT_CLOSE, self.on_cancel)
25+
self.ok_button.Bind(wx.EVT_BUTTON, self.on_ok)
26+
self.MakeModal(True)
27+
28+
def append_items_to_annotation(self, annotations):
29+
if not isinstance(annotations, list):
30+
print "type(annotations) must be list of annotations"
31+
return
32+
33+
for item in annotations:
34+
self.annotation_combo.Append(str(item.AnnotationCode + ":" + item.AnnotationText))
35+
36+
def on_cancel(self, event):
37+
self.MakeModal(False)
38+
self.Destroy()
39+
40+
if event:
41+
event.Skip()
42+
43+
def on_ok(self, event):
44+
selection = self.annotation_combo.GetValue()
45+
if selection == self.__new_annotation:
46+
code = self.code_textbox.GetValue()
47+
text = self.text_textbox.GetValue()
48+
49+
annotation = self.series_service.create_annotation(code, text)
50+
else:
51+
code = selection.split(':')[0]
52+
annotation = self.series_service.get_annotation_by_code(code)
53+
self.record_service.flag(annotation.AnnotationID)
54+
55+
if isinstance(self.parent, odmtools.controller.olvAddPoint.OLVAddPoint):
56+
self.parent.refresh_annotations()
57+
58+
self.on_cancel(event)
59+
60+
if __name__ == '__main__':
61+
app = wx.App(False)
62+
controller = NewFlagValuesController(None, None, None, None)
63+
controller.Show()
64+
app.MainLoop()
65+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import wx
2+
from odmtools.view.WizardActionView import WizardActionView
3+
from wx.wizard import WizardPageSimple
4+
from odm2api.ODM2.models import Affiliations
5+
6+
7+
# Should we rename this to Affiliations instead of actions? Action is created else where
8+
class WizardActionController(WizardPageSimple):
9+
def __init__(self, parent, affiliations):
10+
WizardPageSimple.__init__(self, parent)
11+
self.action_view = WizardActionView(self)
12+
self.affiliations = affiliations
13+
14+
master_sizer = wx.BoxSizer(wx.VERTICAL)
15+
master_sizer.Add(self.action_view, 1, wx.EXPAND | wx.RIGHT, 0)
16+
self.SetSizer(master_sizer)
17+
18+
if self.affiliations is None:
19+
return
20+
# Populate table with the affiliations
21+
self.populate_affiliations_table()
22+
23+
def populate_affiliations_table(self):
24+
"""
25+
self.affiliations must be a list affiliations
26+
:return:
27+
"""
28+
if not isinstance(self.affiliations, list):
29+
return
30+
if not len(self.affiliations) and not isinstance(self.affiliations[0], Affiliations):
31+
return
32+
33+
data = []
34+
for affiliation in self.affiliations:
35+
data.append([
36+
affiliation.PersonObj.PersonFirstName + " " + affiliation.PersonObj.PersonLastName,
37+
affiliation.OrganizationObj.OrganizationName
38+
])
39+
40+
columns = ["Person", "Organization"]
41+
self.action_view.affiliations_table.set_columns(columns)
42+
self.action_view.affiliations_table.set_table_content(data)
43+
44+
def get_affiliation(self):
45+
index = self.action_view.affiliations_table.GetFirstSelected()
46+
return self.affiliations[index]
47+
48+
49+
50+
51+
if __name__ == '__main__':
52+
app = wx.App(False)
53+
controller = WizardActionController(None, None)
54+
controller.Show()
55+
app.MainLoop()

0 commit comments

Comments
 (0)