def check_validation(self): # Check whether user select needed items correctly from viewer.Messages_forms.generalMsgDlg import messageDlg msg = "" if self.comboBox_Code.Value is None or self.comboBox_Code.Value == "": msg = "Warning!\n'Site Code' field can not be empty. Please provide CUAHSI Site Code." elif self.comboBox_VariableCode.Value is None or self.comboBox_VariableCode.Value == "": msg = "Warning!\n'Variable Code' field can not be empty. Please provide CUAHSI Variable Code." elif self.m_textCtrl24.Value is None or self.m_textCtrl24.Value == "": msg = "Warning!\n'Time Series Begin Date' field can not be empty. Please provide Time Series Begin Date [yyyy-mm-dd]." elif self.m_textCtrl25.Value is None or self.m_textCtrl25.Value == "": msg = "Warning!\n'Time Series End Date' field can not be empty. Please provide Time Series End Date [yyyy-mm-dd]." if msg != "": instance = messageDlg(None) instance.setMessage(msg) instance.ShowModal() instance.Destroy() return False #///////////////////////////////////////////////////////////////////////# # Check whether Sqlite db is connected. setup = DB_Setup() if not setup.get_session(): message = msg_somethigWrong( None, msg= '\n\n\nError, No Database Found, Please first connect to a database.' ) message.ShowModal() return False #///////////////////////////////////////////////////////////////////////# return True
def btn_yesOnButtonClick(self, event): conn = DB_Setup() if conn.get_session(): conn.close_db() if not conn.get_session(): topframe = wx.GetApp().GetTopWindow() topframe.SetTitle(topframe.GetTitle().split(':')[0]) self.disconnectResult = True from Messages_forms.msg_infos import msg_infos msg_infos(topframe, msg='\nDatabase disconnected successfully\n\n"' + define.dbName + '" session has been disconnected').Show() else: from Messages_forms.msg_somethigWrong import msg_somethigWrong msg_somethigWrong(None, msg='"' + define.dbName + '"database disconnection failed').Show() else: from Messages_forms.msg_somethigWrong import msg_somethigWrong msg_somethigWrong(None, msg='No "' + define.dbName + '" Connection Found').Show() self.Close()
def __init__(self, parent): ExportModels.dlg_ServeToWEAP.__init__(self, parent) try: if not DB_Setup().get_session(): msg = "\n\nWarning: Please connect to sqlite first." raise Exception(msg) ''' init combo model''' self.dataStructure = GetResourceStructure() self.datasets = self.dataStructure.GetResourceType() list_acromy = list() for index, row in self.datasets.iterrows(): list_acromy.append(row[0]) if list_acromy.__len__() > 0: self.Select_Model.SetItems(list_acromy) list_code = [] self.WEAP = win32com.client.Dispatch("WEAP.WEAPApplication") for area in self.WEAP.Areas: list_code.append(area.name) self.comboBox_SelectArea.SetItems(list_code) list_scen = [] for scen in self.WEAP.Scenarios: list_scen.append(scen.name) self.combo_selectWEAPScenario.SetItems(list_scen) except Exception as e: message = msg_somethigWrong(None, msg=e.message) message.Show() self.Destroy()
def check_validation(self): # Check whether user select needed item correctly from viewer.Messages_forms.generalMsgDlg import messageDlg msg = "" if self.path is None or self.path == "": msg = "Warning!\n Please select a valid wml file." elif self.wml_str is None or self.wml_str == "": msg = "Warning!\n The selected file could not be opened. Please select a valid wml file." if msg != "": instance = messageDlg(None) instance.setMessage(msg) instance.ShowModal() instance.Destroy() return False #///////////////////////////////////////////////////////////////////////# # Check whether Sqlite db is connected. setup = DB_Setup() if not setup.get_session(): message = msg_somethigWrong( None, msg= '\n\n\nError, No Database connection found, Please first connect to a database.' ) message.ShowModal() return False #///////////////////////////////////////////////////////////////////////# return True
def test_db_conn(self): setup = DB_Setup() if not setup.get_session(): message = msg_somethigWrong( None, msg= '\n\n\nError, No database Found. Please first connect to a database.' ) message.Show() return False return True
def __init__(self, textCtrl_AreaNameOnText, SelectedScenarioName,fileDir): self.textCtrl_AreaNameOnText = textCtrl_AreaNameOnText self.SelectedScenarioName = SelectedScenarioName self.fileDir = fileDir self.ConnectWEAP() self.NodesSheetList = None self.NodesSheetList = None self.LinksSheetList = None self.unique_object_types_value_list = None self.extract_network() self.setup = DB_Setup() self.session = self.setup.get_session() self.excel_pointer = None
def __init__(self, parent): viewer.WaMDaMWizard.dlg_query_metadata.__init__(self, parent) try: if not DB_Setup().get_session(): msg = "\n\nWarning: Please connect to sqlite first." raise Exception(msg) ''' get metadata qurey object''' self.getMetadata = GetMetadataByScenario() except Exception as e: message = msg_somethigWrong(None, msg=e.message) message.ShowModal() self.Destroy()
def btn_LoadDataGroupsOnButtonClick(self, event): # TODO: Implement btn_LoadDataGroupsOnButtonClick # Test DB connection if not self.test_db_conn(): return if not self.test_excel_file(): return # Backup the Database before loading any new data into it. if DB_Setup().getType() == 'sqlite': DB_Setup().backup_db() define.logger.info("Backing up the database before starting to \ load new data into it.") myobject = event.GetEventObject() myobject.Disable() self.msgDlg = msg_loading(None) self.msgDlg.guage.SetRange(14) self.msgDlg.guage.SetValue(1) self.msgDlg.btn_ok.Enabled = False self.msgDlg.btn_cancel.Bind(wx.EVT_BUTTON, self.stop_loading) define.logger.name = __name__ define.logger.info('Start data load') self.msgDlg.Show() ''' thread start: it is needed to show text in the Data loading window while the progress bar reports back the status of data loading steps''' # Will ask the thread to terminate itself, so the thread should always # check a condition if it should terminate itself and return self.our_thread = threading.Thread(None, self.load_data) self.our_thread.start()
def __init__(self, parent): viewer.WaMDaMWizard.dlg_query_model.__init__(self, parent) self.path = '' try: if not DB_Setup().get_session(): msg = "\n\nWarning: Please connect to sqlite first." raise Exception(msg) self.dataStructure = GetResourceStructure() self.datasets = self.dataStructure.GetResourceType() list_acromy = list() for row in self.datasets.values: list_acromy.append(row[0]) if list_acromy.__len__() > 0: self.comboBox_selectModel.SetItems(list_acromy) except Exception as e: message = msg_somethigWrong(None, msg=e.message) message.ShowModal() self.Destroy()
def __init__(self, parent): WaMDaMWizard.dlg_ExportScenarioDataToExcel.__init__(self, parent) self.path = '' try: if not DB_Setup().get_session(): msg = "\n\nWarning: Please connect to sqlite first." raise Exception(msg) ''' init combo model''' self.dataStructure = GetResourceStructure() self.datasets = self.dataStructure.GetResourceType() list_acromy = list() for index, row in self.datasets.iterrows(): list_acromy.append(row[0]) if list_acromy.__len__() > 0: self.comboBox_selectModel.SetItems(list_acromy) except Exception as e: message = msg_somethigWrong(None, msg=e.message) message.Show() self.Destroy()
def __init__(self, parent): viewer.WaMDaMWizard.dlg_SearchNodesLinks.__init__(self, parent) self.path = '' # self.textCtrl_X_min.Value = u'-112.4424' # self.textCtrl_X_Max.Value = u'-110.65833' # self.textCtrl_y_min.Value = u'41.00' # self.textCtrl_y_max.Value = u'42.700' try: if not DB_Setup().get_session(): msg = "\n\nWarning: Please connect to sqlite first." raise Exception(msg) ''' Get Controlled object type''' self.getNodeLinks = GetNodeLinks() list_acromy = self.getNodeLinks.GetCV_ObjectType() if list_acromy.__len__() > 0: self.comboBox_selectObjectType.SetItems(list_acromy) except Exception as e: message = msg_somethigWrong(None, msg=e.message) message.ShowModal() self.Destroy()
def __init__(self, weap, model, wamdam_network, wamdam_scenario, weap_area, weap_scenario, pathOfSqlite=''): self.weap = weap self.model = model self.wamdam_network = wamdam_network self.wamdam_scenario = wamdam_scenario self.weap_area = weap_area self.weap_scenario = weap_scenario self.WEAPAreasDirectory = self.weap.AreasDirectory + weap_area + "\\" + weap_scenario + "_ScenarioData" self.setup = DB_Setup() if self.setup.get_session() == None and pathOfSqlite != '': self.setup.connect(pathOfSqlite, db_type='sqlite') self.session = self.setup.get_session()
def check_validation(self): # Check whether user select needed items correctly from viewer.Messages_forms.generalMsgDlg import messageDlg msg = "" if self.comboBox_State.Value == None or self.comboBox_State.Value == "": msg = "Warning!\n'State' field can not be empty. Please select a state." elif self.comboBox_PlanningBasin.Value == None or self.comboBox_PlanningBasin.Value == "": msg = "Warning!\n'Planing Basin' field can not be empty. Please select a planing basin." elif self.comboBox_year1.Value == None or self.comboBox_year1.Value == "": msg = "Warning!\n'Year' field can not be empty. Please select begining year." elif self.comboBox_year2.Value == None or self.comboBox_year2.Value == "": msg = "Warning!\n'Year' field can not be empty. Please select end year." elif int(self.comboBox_year1.Value) > int(self.comboBox_year2.Value): msg = "Warning!\n'End Year' must be more than 'Begining Year'. Please select again." if msg != "": instance = messageDlg(None) instance.setMessage(msg) instance.ShowModal() instance.Destroy() return False #///////////////////////////////////////////////////////////////////////# # Check whether Sqlite db is connected. setup = DB_Setup() if not setup.get_session(): message = msg_somethigWrong( None, msg= '\n\n\nError, No Database connection found, Please first connect to a database.' ) message.ShowModal() return False #///////////////////////////////////////////////////////////////////////# return True
def __init__(self, parent): viewer.WaMDaMWizard.dlg_SearchDataValues.__init__(self, parent) try: if not DB_Setup().get_session(): msg = "\n\nWarning: Please connect to sqlite first." raise Exception(msg) ''' Get Controlled object type''' self.getDataValues = GetDataValues() '''Get C_VObjectType''' list_types = self.getDataValues.GetCV_ObjectType() if list_types.__len__() > 0: self.comboBox_ctrObjectType.SetItems(list_types) '''Get Attribute names''' list_attributes = self.getDataValues.getAttribute() if list_attributes.__len__() > 0: self.comboBox_ctrAttribute.SetItems(list_attributes) '''Get CV_Instance names''' list_InstanceNames = self.getDataValues.getCVinstanceName() if list_InstanceNames.__len__() > 0: self.comboBox_ctrlInstance.SetItems(list_InstanceNames) ''' check bok flag array''' self.typeCheck_list = { 'DualValues': False, 'DescriptorValues': False, 'NumericValues': False, 'ElectronicFiles': False, 'SeaonalNumericValues': False, 'TimeSeries': False, 'All': False, 'MultiVariableSeries': False } self.path = "" except Exception as e: message = msg_somethigWrong(None, msg=e.message) message.ShowModal() self.Destroy()
def btn_connectOnButtonClick(self, event): error = self.evaluator() if error: msg_somethigWrong(self.topframe, '\n\n' + error).Show() return else: setup = DB_Setup() # test if the user is already connected to a database, if so, user is asked to disconnect if setup.get_session(): msg_somethigWrong(None, msg='\n\nError: You are already connected to a database. \n\n to use another' ' database, you need to disconnect from the current one').Show() return # connects to mysql database given the sql_string setup.connect('', db_type='mysql', sql_string=self.sql_string) self.topframe.SetTitle(self.topframe.GetTitle() + ' ::: You are connected to MySQL DB ' + self.db_name) from Messages_forms.msg_connSQLiteSuccs import msg_connSQLiteSuccs msgdlg = msg_connSQLiteSuccs(self.topframe) msgdlg.setMessage(u"\n\nSuccessfully connected to mysql db with name \'" + self.db_name + u"\'") msgdlg.Show() # Create WaMDaMVersion table and fills it the version number declared in define.py file obj_cat = SqlAlchemy.WaMDaMVersion() try: qeury = setup.get_session().query(SqlAlchemy.WaMDaMVersion).first().VersionNumber except: obj_cat.VersionNumber = define.version setup.push_data(obj_cat) setup.add_data() self.Close()
def checkConnectingToSqlite(self): db_setup = DB_Setup() if not db_setup.get_session(): return False return True
def disconnect_DB(self): conn = DB_Setup() if conn.get_session(): conn.close_db()
def btn_connectOnButtonClick(self, event): topframe = wx.GetApp().GetTopWindow() dir_name = self.dirPicker_newDB.GetPath() db_name = self.m_textCtrl1.GetValue() # Check whether user select the file to write data correctly. fileCheck = False for root, dirs, files in os.walk(dir_name): for file in files: if file.endswith(".sqlite"): if file.split('.')[0] == db_name: from Messages_forms.generalMsgDlg import messageDlg errMsgDlg = messageDlg(topframe) errMsgDlg.SetTitle("Error") errMsgDlg.setMessage( "This database name already exists in this directory.\nPlease choose a different database name!") errMsgDlg.ShowModal() return # Report connecting to the db in the logfile define.logger = define.create_logger(db_name) define.logger.name = __name__ define.logger.info("Start database connection.") setup = DB_Setup() if setup.get_session(): define.logger.error( 'Failed database connection.\n\n Error: You are already connected to a database. \n\n to use another' 'database, you need to disconnect from the current one') msg_somethigWrong(topframe, msg='\n\n Error: You are already connected to a database. \n\n to use another' 'database, you need to disconnect from the current one').Show() return if not dir_name: define.logger.error( 'Failed database connection.\n\nError: Please select a directory. \n\nIf already so, try using the "other..." ' 'option in the Dir Dialog') msg_somethigWrong(topframe, msg='\n\nError: Please select a directory. \n\nIf already so, try using the "other..." ' 'option in the Dir Dialog').Show() return if not db_name: define.logger.error('Failed database connection.\n\nError: The database name is required.') msg_somethigWrong(topframe, msg='\n\n\nError: The database name is required.').Show() return if len(db_name.split('.')) > 1: if db_name.split('.')[-1] in ['sqlite']: pass else: db_name += '.sqlite' else: db_name += '.sqlite' # Get connection with db db_path = os.path.join(dir_name, db_name) db = DB_Setup() db.connect(db_path, db_type='sqlite') # Create WaMDaMVersion table and fills it the version number declared in define.py file obj_cat = SqlAlchemy.WaMDaMVersion() obj_cat.VersionNumber = define.version db.push_data(obj_cat) db.add_data() topframe.SetTitle(topframe.GetTitle() + ' ::: You are connected to ' + os.path.basename(db_name)) from Messages_forms.msg_connSQLiteSuccs import msg_connSQLiteSuccs msgdlg = msg_connSQLiteSuccs(topframe) msgdlg.setMessage(u"\n\n\n\n\n You are successfully connected to " + db_path.split('\\')[-1] + u".") msgdlg.Show() '''Report the connected db name to the logfile''' define.logger.info("'" + db_path.split('\\')[-1] + "'was connected successfully.\n") define.dbName = db_path.split('\\')[-1] self.Close()
def load_data(self): def metaData(msgDlg): define.logger.info("Start metaData load.") try: instance = LoadMetaData(obj) instance.load_data() msgDlg.guage.SetValue(3) define.logger.info("MetaData load was finished successfully.") return instance except Exception as e: define.logger.error('Failed metaData load.\n' + e.message) print(e) # message = messageDlg(None) # message.SetTitle("Sorry: something went wrong") # message.setMessage('{} \n\n [*] Could not Load MetaData'.format(e)) # message.Show() raise Exception(e.message) def cvData(msgDlg): define.logger.info("Start cvData load.") try: instance = Load_CV_To_DB(obj) instance.load_data() msgDlg.guage.SetValue(2) define.logger.info("CvData load was finished successfully.") return instance except Exception as e: define.logger.error('Failed cvData load.\n' + e.message) print(e) # message = messageDlg(None) # message.SetTitle(u"Sorry: something went wrong") # message.setMessage(u'{} \n\n [*] Could not Load DataValues Data'.format(e)) # message.Show() raise Exception(e.message) def structData(msgDlg): define.logger.info("Start structData load.") try: instance = Load_Struct_To_DB(obj) instance.load_data(struct_sheets_ordered) msgDlg.guage.SetValue(4) define.logger.info( "StructData load was finished successfully.") return instance except Exception as e: define.logger.error('Failed structData load.\n' + e.message) # message = messageDlg(None) # message.SetTitle(u"Sorry: something went wrong") # message.setMessage(u'{} \n\n [*] Could not Load Structure Data'.format(e)) # message.Show() raise Exception(e.message) def networksData(msgDlg): define.logger.info("Start networksData load.") try: instance = Load_Networks_Data(obj) instance.load_data() msgDlg.guage.SetValue(5) define.logger.info( "NetworksData load was finished successfully.") return instance except Exception as e: define.logger.error('Failed network Data load.\n' + e.message) print(e) # message = messageDlg(None) # message.SetTitle(u"Sorry: something went wrong") # message.setMessage(u'{} \n\n [*] Could not Load Network Data'.format(e)) # message.Show() raise Exception(e.message) def descriptorValues(msgDlg): define.logger.info("Start Categorical Data load.") try: instance = LoadCategoricalValues(obj) instance.load_data() msgDlg.guage.SetValue(6) define.logger.info( "Categorical data load was finished successfully.") return instance except Exception as e: define.logger.error('Failed Categorical data load.\n' + e.message) print(e) # message = messageDlg(None) # message.SetTitle(u"Sorry: something went wrong") # message.setMessage(u'{} \n\n [*] Could not Load TextFree Data'.format(e)) # message.Show() raise Exception(e.message) def freeText(msgDlg): define.logger.info("Start textFreeData load.") try: instance = LoadFreeTextValues(obj) instance.load_data() msgDlg.guage.SetValue(7) define.logger.info( "TextFreeData load was finished successfully.") return instance except Exception as e: define.logger.error('Failed textFreeData load.\n' + e.message) print(e) # message = messageDlg(None) # message.SetTitle(u"Sorry: something went wrong") # message.setMessage(u'{} \n\n [*] Could not Load TextFree Data'.format(e)) # message.Show() raise Exception(e.message) def numericValues(msgDlg): define.logger.info("Start paramsData load.") try: instance = LoadNumericValues(obj) instance.load_data() msgDlg.guage.SetValue(8) define.logger.info( "ParamsData load was finished successfully.") return instance except Exception as e: define.logger.error('Failed paramsData load.\n' + e.message) print(e) # message = messageDlg(None) # message.SetTitle(u"Sorry: something went wrong") # message.setMessage(u'{} \n\n [*] Could not Load Parameters Data'.format(e)) # message.Show() raise Exception(e.message) def seasonalNumericValues(msgDlg): define.logger.info("Start seasonParamsData load.") try: instance = LoadSeasonalNumericValues(obj) instance.load_data() msgDlg.guage.SetValue(9) define.logger.info( "SeasonParamsData load was finished successfully.") return instance except Exception as e: define.logger.error('Failed seasonParamsData load.\n' + e.message) print(e) # message = messageDlg(None) # message.SetTitle(u"Sorry: something went wrong") # message.setMessage(u'{} \n\n [*] Could not Load SeasonalParameters Data'.format(e)) # message.Show() raise Exception(e.message) def timeSeriesData(msgDlg): define.logger.info("Start timeSeriesData load.") try: instance = LoadTimeSeries(obj) instance.load_data() msgDlg.guage.SetValue(10) define.logger.info( "TimeSeriesData load was finished successfully.") return instance except Exception as e: define.logger.error('Failed timeSeriesData load.\n' + e.message) print(e) # message = messageDlg(None) # message.SetTitle(u"Sorry: something went wrong") # message.setMessage(u'{} \n\n [*] Could not Load TimeSeriesData Data'.format(e)) # message.Show() raise Exception(e.message) def timeSeriesValueData(msgDlg): define.logger.info("Start timeSeriesValueData load.") try: instance = LoadTimeSeriesValue(obj) instance.load_data() msgDlg.guage.SetValue(10) define.logger.info( "TimeSeriesValueData load was finished successfully.") return instance except Exception as e: define.logger.error('Failed TimeSeriesValueData load.\n' + e.message) print(e) # message = messageDlg(None) # message.SetTitle(u"Sorry: something went wrong") # message.setMessage(u'{} \n\n [*] Could not Load TimeSeriesValueData Data'.format(e)) # message.Show() raise Exception(e.message) def multiColumnArrayData(msgDlg): define.logger.info("Start MultiAttributeSeriesData load.") try: instance = LoadMultiCulumnArray(obj) instance.load_data() msgDlg.guage.SetValue(11) define.logger.info( "MultiAttributeSeriesData load was finished successfully.\n\n" ) return instance except Exception as e: define.logger.error('Failed MultiAttributeSeriesData load.\n' + e.message) print(e) # message = messageDlg(None) # message.SetTitle(u"Sorry: something went wrong") # message.setMessage(u'{} \n\n [*] Could not Load MultiAttributeSeries Data'.format(e)) # message.Show() raise Exception(e.message) def electronicFiles(msgDlg): define.logger.info("Start fileData load.") try: instance = LoadElectronicFiles(obj) instance.load_data() msgDlg.guage.SetValue(12) define.logger.info("FileData load was finished successfully.") return instance except Exception as e: define.logger.error('Failed fileData load.\n' + e.message) print(e) # message = messageDlg(None) # message.SetTitle(u"Sorry: something went wrong") # message.setMessage(u'{} \n\n [*] Could not Load File Data'.format(e)) # message.Show() raise Exception(e.message) if self.path: obj = excel.open_workbook(self.path) # Write various data form db to excel file try: instance_cvData = cvData(self.msgDlg) instance_cvData.add_data() self.data_pushed_to_db.append(instance_cvData) if all(value is True for value in self.active): instance_metaData = metaData(self.msgDlg) instance_structData = structData(self.msgDlg) instance_networksData = networksData(self.msgDlg) instance_DescriptorValuesData = descriptorValues( self.msgDlg) instance_freeText = freeText(self.msgDlg) instance_paramsData = numericValues(self.msgDlg) instance_seasonParamsData = seasonalNumericValues( self.msgDlg) instance_timeSeriesData = timeSeriesData(self.msgDlg) instance_timeSeriesValueData = timeSeriesValueData( self.msgDlg) instance_fileData = electronicFiles(self.msgDlg) instance_multiColumnArrayData = multiColumnArrayData( self.msgDlg) pass elif self.active[0] and all(value is False for value in self.active[1:]): instance_metaData = metaData() elif self.active[1] and all(value is False for value in self.active[2:]): if self.active[0]: instance_structData = structData(self.msgDlg) else: message = msg_somethigWrong( None, msg= 'Error, Structure Data Depends on MetaData, \n\n Please ' 'check MetaData box') message.Show() raise Exception elif self.active[2] and self.active[ 1] is False and self.active[3] is False: if self.active[0]: instance_networksData = networksData(self.msgDlg) else: message = msg_somethigWrong( None, msg= 'Error, Network Data Depends on MetaData, \n\n Please ' 'check MetaData box') message.Show() raise Exception() elif self.active[3] and all(value is False for value in self.active[:3]): # textFreeData() instance_DescriptorValuesData = descriptorValues( self.msgDlg) instance_freeText = freeText(self.msgDlg) instance_paramsData = numericValues(self.msgDlg) instance_seasonParamsData = seasonalNumericValues( self.msgDlg) instance_timeSeriesData = timeSeriesData(self.msgDlg) instance_timeSeriesValueData = timeSeriesValueData( self.msgDlg) instance_fileData = electronicFiles(self.msgDlg) instance_multiColumnArrayData = multiColumnArrayData( self.msgDlg) # instance_cvData.add_data() if all(value is True for value in self.active): instance_metaData.add_data() instance_structData.add_data() instance_networksData.add_data() instance_DescriptorValuesData.add_data() instance_freeText.add_data() instance_paramsData.add_data() instance_seasonParamsData.add_data() instance_timeSeriesData.add_data() instance_timeSeriesValueData.add_data() # instance_booleanData.add_data() instance_fileData.add_data() instance_multiColumnArrayData.add_data() pass elif self.active[0] and all(value is False for value in self.active[1:]): instance_metaData.add_data() elif self.active[1] and all(value is False for value in self.active[2:]): if self.active[0]: instance_structData.add_data() else: message = msg_somethigWrong( None, msg= 'Error, Data Structure Depends on MetaData, \n\n Please ' 'check MetaData box') message.Show() raise Exception elif self.active[2] and self.active[ 1] is False and self.active[3] is False: if self.active[0]: instance_networksData.add_data() else: message = msg_somethigWrong( None, msg= 'Error, Network Data Depends on MetaData, \n\n Please ' 'check MetaData box') message.Show() raise Exception() elif self.active[3] and all(value is False for value in self.active[:3]): # textFreeData() instance_paramsData.add_data() instance_seasonParamsData.add_data() instance_timeSeriesData.add_data() instance_timeSeriesValueData.add_data() instance_fileData.add_data() instance_DescriptorValuesData.add_data() instance_freeText.add_data() instance_multiColumnArrayData.add_data() # printing success message self.msgDlg.guage.SetValue(14) define.logger.info("All load was finished successfully.") wx.CallAfter(self.allDone) self.msgDlg.btn_ok.Enabled = True self.msgDlg.Close() except Exception as e: if e.message.startswith("The C++ part"): # Terminate thread. # Restore the Database first. define.logger.info("Data loading terminated, restoring \ the previous database backup.") DB_Setup().restore_db() return else: # Another exception happened define.logger.error( 'Failed data load.\n' + e.message + '\nThe loading of all data has been reverted, Please fix the error and load the file again.' ) self.errorMsg = e self.occuredError() return
def __init__(self): self.ConnectWEAP() self.setup = DB_Setup() self.session = self.setup.get_session() self.excel_pointer = None
def Read_provided_file_query_Required(): Network_input = pd.read_excel('./WASH_Network_input.xlsx', sheetname=None) sheetnames = Network_input.keys() sheet = Network_input[sheetnames[0]] keys = sheet.columns query_data_list = [] # for column in keys: # query_data_list[column] = [] for i in sheet.index: row = {} for column in keys: row[column] = sheet[column][i] query_data_list.append(row) # print query_data_list # based on the selected model (WEAP) or (WASH), ModelName = 'WASH' # Query WaMDaM db to get the list of Object types and their Attributes Model_required_attributes = ''' SELECT DISTINCT ObjectType as Required_ObjectType,ObjectTypeCV as Required_ObjectTypeCV , AttributeName as Required_AttributeName, AttributeNameCV Required_AttributeNameCV, AttributeDataTypeCV as Required_AttributeDataTypeCV, UnitName as Required_UnitName FROM ResourceTypes LEFT JOIN "ObjectTypes" ON "ObjectTypes"."ResourceTypeID"="ResourceTypes"."ResourceTypeID" LEFT JOIN "ObjectCategories" ON "ObjectCategories"."ObjectCategoryID"="ObjectTypes"."ObjectCategoryID" LEFT JOIN "Attributes" ON "Attributes"."ObjectTypeID"="ObjectTypes"."ObjectTypeID" LEFT JOIN "AttributeCategories" ON "AttributeCategories"."AttributeCategoryID"="Attributes"."AttributeCategoryID" -- Provide the model name WHERE "ResourceTypeAcronym"='%s' --exclude the dummy attributes that are just used to connect Object Types with their Instances. AND AttributeName!='ObjectTypeInstances' ''' % (ModelName) # df_Model_required_attributes = session.execute(Model_required_attributes) conn = sqlite3.connect("WaMDaM_db_WASH.sqlite") df_Model_required_attributes = pd.read_sql_query(Model_required_attributes, conn) # Model_required_attributes.keys() # # Required_ObjectType=df_Model_required_attributes['Required_ObjectType'] # Required_AttributeName=df_Model_required_attributes['Required_AttributeName'] # Required_AttributeDataTypeCV=df_Model_required_attributes['Required_AttributeDataTypeCV'] # Required_UnitName=df_Model_required_attributes['Required_UnitName'] Query_Load_params_list = [] # loop over the provided Object Types in Excel. # loop over the Required ObjectTypes from the db query # If the provided Object Type equals the required object type, then get the for prov_objs in query_data_list: for i, req_objs in enumerate( df_Model_required_attributes['Required_ObjectType'] ): # get the string value inside each column if prov_objs['Provided_ObjectType'] == req_objs: Query_Load_params = {} Query_Load_params[ 'Required_AttributeName'] = df_Model_required_attributes[ 'Required_AttributeName'][i] Query_Load_params[ 'Required_AttributeDataTypeCV'] = df_Model_required_attributes[ 'Required_AttributeDataTypeCV'][i] Query_Load_params[ 'Required_UnitName'] = df_Model_required_attributes[ 'Required_UnitName'][i] Query_Load_params['Required_ObjectType'] = req_objs Query_Load_params['Provided_ObjectType'] = prov_objs[ 'Provided_ObjectType'] # Query_Load_params['Provided_InstanceName'] = prov_objs[ 'Provided_InstanceName'] Query_Load_params['Provided_FullBranch'] = prov_objs[ 'Provided_FullBranch'] Query_Load_params_list.append(Query_Load_params) # print Query_Load_params_list # return Query_Load_params_list # iterate over the rows and get the string value of each Required_AttributeDataTypeCV setup = DB_Setup() session = setup.get_session() multi_timeseries = [] multi_AttributeSeries = [] multi_Seasonal = [] multi_Numeric = [] multi_Descriptor = [] for input_param in Query_Load_params_list: if input_param['Required_AttributeDataTypeCV'] == 'TimeSeries': #call the time series function #pass the input_param value to the time series function multi_timeseries.append(input_param) elif input_param[ 'Required_AttributeDataTypeCV'] == 'SeasonalNumericValues': multi_Seasonal.append(input_param) # elif input_param['Required_AttributeDataTypeCV'] == 'NumericValues': multi_Numeric.append(input_param) elif input_param['Required_AttributeDataTypeCV'] == 'DescriptorValues': multi_Descriptor.append(input_param) # # elif input_param[ 'Required_AttributeDataTypeCV'] == 'MultiAttributeSeries': multi_AttributeSeries.append(input_param) else: continue # Execute the time series function (for both the query and write csv) total_df_TimeSeries, Metadata_TimeSeries = execute_TimeSeries_query( conn, multi_timeseries) # Execute the seasonal query total_df_Seasonal, Metadata_seasonal = execute_Seasonal_query( conn, multi_Seasonal) # Execute the multi attributes series query total_df_MultiColumns, Metadata_multi_att = execute_MultiAtt_query( conn, multi_AttributeSeries) # Execute the numeric attributes query total_df_Numeric, Metadata_multi_numeric = execute_Numeric_query( conn, multi_Numeric) # Execute the descriptor attributes query total_df_Descriptor, Metadata_multi_descriptor = execute_Descriptor_query( conn, multi_Descriptor) # Execute the metadata file InputFile_list = execute_WriteMetadataFile( total_df_TimeSeries, total_df_Seasonal, total_df_MultiColumns, total_df_Numeric, total_df_Descriptor, Metadata_TimeSeries, Metadata_seasonal, Metadata_multi_att, Metadata_multi_numeric, Metadata_multi_descriptor) return total_df_Seasonal, total_df_MultiColumns, total_df_Descriptor, total_df_Numeric, total_df_TimeSeries # just these