22 Bulk Insert of points
33"""
44import wx
5- import odmtools .view .clsBulkInsert as clsBulkInsert
5+ import odmtools .view .BulkInsertView as clsBulkInsert
66import odmtools .controller .olvAddPoint as olv
77import pandas as pd
88from pandas .parser import CParserError
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
183174if __name__ == '__main__' :
184175 app = wx .App (useBestVisual = True )
185- m = BulkInsert (None )
176+ m = BulkInsertController (None )
186177 m .Show ()
187178 app .MainLoop ()
0 commit comments