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 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 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
class WEAP_export(object): WEAP = None def __init__(self): self.ConnectWEAP() self.setup = DB_Setup() self.session = self.setup.get_session() self.excel_pointer = None def ConnectWEAP(self): self.WEAP = win32com.client.Dispatch("WEAP.WEAPApplication") # make this dynamic active area self.WEAP.ActiveArea = "BearRiverFeb2017_V10.9" ActiveArea = self.WEAP.ActiveArea.Name Scenario = self.WEAP.ActiveScenario.Name WEAPAreasDirectory = self.WEAP.AreasDirectory print ActiveArea print Scenario print WEAPAreasDirectory SourceName = self.WEAP.ActiveArea.Name # 2. Extract the WEAP Network def QueryWaMDaMDataForWEAP(self): # call the function wich will run the query and write its output to excel # Time Series from controller.WEAP.ServeWaMDaMDataToWEAP.QueryTimeSeries import TimeSeries_query, Timeseries_csv_file df_TimeSeries = TimeSeries_query(self.session) csv_file_name_timeseries = Timeseries_csv_file(df_TimeSeries) # Multi Columns from controller.WEAP.ServeWaMDaMDataToWEAP.QueryMultiAttributes import MultiAttributes_query, MultiAttributes_csv_file df_MultiColumns = MultiAttributes_query(self.session) csv_file_path_or_value_multi = MultiAttributes_csv_file( df_MultiColumns) # Seasonal from controller.WEAP.ServeWaMDaMDataToWEAP.QuerySeasonal import Seasonal_query, Seasonal_csv_file df_Seasonal = Seasonal_query(self.session) csv_file_path_or_value_seasonal = Seasonal_csv_file(df_Seasonal) # Metadata for all the files together (pass all these to the function from controller.WEAP.ServeWaMDaMDataToWEAP.ExportWEAP_Inputfile import WriteMetadataFile WriteMetadataFile(df_TimeSeries, df_MultiColumns, df_Seasonal, csv_file_name_timeseries, csv_file_path_or_value_seasonal, csv_file_path_or_value_multi) WriteMetadataFile(self)
class WEAP_export(): WEAP = None 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 ConnectWEAP(self): self.WEAP=win32com.client.Dispatch("WEAP.WEAPApplication") self.WEAP.ActiveArea = self.textCtrl_AreaNameOnText ActiveArea=self.WEAP.ActiveArea.Name Scenario=self.WEAP.ActiveScenario.Name WEAPAreasDirectory= self.WEAP.AreasDirectory print ActiveArea print Scenario print WEAPAreasDirectory SourceName=self.WEAP.ActiveArea.Name # 2. Extract the WEAP Network def extract_network(self): from Extract_Network import Extract_Network self.NodesSheetList, self.LinksSheetList, self.unique_object_types_value_list,self.BranchesNew_list = Extract_Network(self.WEAP, self.SelectedScenarioName) def GetWEAPValues(self): from GetValues import GetValues_WEAP return GetValues_WEAP(self.WEAP, self.BranchesNew_list, self.unique_object_types_value_list) def SaveToExcel(self, result_list, UniqObjectAtt_list, Projection_source=''): from SaveWEAPToExcel import SaveExcel DateStamp = datetime.now().strftime('%m-%d-%Y') excel_filename = self.fileDir + '/' + self.textCtrl_AreaNameOnText + '_' + DateStamp + '.xlsx' SaveExcel(self.NodesSheetList, self.LinksSheetList, result_list, UniqObjectAtt_list, self.WEAP, excel_filename, Projection_source)
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 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 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 checkConnectingToSqlite(self): db_setup = DB_Setup() if not db_setup.get_session(): return False return True
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 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
def disconnect_DB(self): conn = DB_Setup() if conn.get_session(): conn.close_db()
class ServeWaMDaM_Data_to_WEAP: 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 load_data(self): self.QueryWaMDaMStructure_Instances(self.weap, self.model, self.wamdam_network, self.wamdam_scenario) #################################################### # Query WaMDaM list of object types, and their attributes # for the selected WEAP model #################################################### def QueryWaMDaMStructure_Instances(self, WEAP, model='', wamdam_network='', wamdam_scenario=''): WEAP_structure_instances_query = """ SELECT DISTINCT ObjectType,AttributeName,AttributeName_Abstract,AttributeDataTypeCV, UnitName,ScenarioName,InstanceName,Instances.Description as FullBranch 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 "Mappings" ON "Mappings"."AttributeID"= "Attributes"."AttributeID" LEFT JOIN "Instances" ON "Instances"."InstanceID"="Mappings"."InstanceID" LEFT JOIN "ScenarioMappings" ON "ScenarioMappings"."MappingID"="Mappings"."MappingID" LEFT JOIN "Scenarios" ON "Scenarios"."ScenarioID"="ScenarioMappings"."ScenarioID" LEFT JOIN "MasterNetworks" ON "MasterNetworks"."MasterNetworkID"="Scenarios"."MasterNetworkID" LEFT JOIN "ValuesMapper" ON "ValuesMapper"."ValuesMapperID"="Mappings"."ValuesMapperID" LEFT JOIN "NumericValues" ON "NumericValues"."ValuesMapperID"="ValuesMapper"."ValuesMapperID" WHERE InstanceName is not null --exclude the dummy attributes that are just used to connect Object Types with their Instances. AND AttributeName!='ObjectTypeInstances' AND NumericValue is not 0 AND ModelInputOrOutput is not "Output" and AttributeDataTypeCV is not "AttributeSeries" AND ResourceTypeAcronym='{}' AND MasterNetworkName='{}' AND ScenarioName='{}' Order by ObjectType,InstanceName,AttributeName_Abstract asc """.format(model, wamdam_network, wamdam_scenario) WEAP_structure_instances_df = pd.DataFrame( list(self.session.execute(WEAP_structure_instances_query))) WEAP_structure_instances_df_columns = list( self.session.execute(WEAP_structure_instances_query).keys()) WEAP_structure_instances_df.columns = WEAP_structure_instances_df_columns multi_timeseries = [] multi_AttributeSeries = [] multi_Seasonal = [] multi_Numeric = [] multi_Descriptor = [] for row in WEAP_structure_instances_df.iterrows(): if row[1]['AttributeDataTypeCV'] == 'TimeSeries': multi_timeseries.append(row) elif row[1]['AttributeDataTypeCV'] == 'SeasonalNumericValues': multi_Seasonal.append(row) # elif row[1]['AttributeDataTypeCV'] == 'NumericValues': multi_Numeric.append(row) elif row[1]['AttributeDataTypeCV'] == 'FreeText': multi_Descriptor.append(row) # # elif row[1]['AttributeDataTypeCV'] == 'MultiAttributeSeries': multi_AttributeSeries.append(row) else: continue conn = self.session WEAPAreasDirectory = self.WEAPAreasDirectory # Execute the time series function (for both the query and write csv) total_df_TimeSeries, Metadata_TimeSeries = self.execute_TimeSeries_query( conn, multi_timeseries) print 'exported time series' # Execute the seasonal query total_df_Seasonal, Metadata_seasonal = self.execute_Seasonal_query( conn, multi_Seasonal) print 'exported seasoal' # Execute the multi attributes series query total_df_MultiColumns, Metadata_multi_att = self.execute_MultiAtt_query( conn, multi_AttributeSeries) print 'exported multi' # Execute the numeric attributes query total_df_Numeric, Metadata_multi_numeric = self.execute_Numeric_query( conn, multi_Numeric) print 'exported numeric' # Execute the descriptor attributes query total_df_Descriptor, Metadata_multi_descriptor = self.execute_Descriptor_query( conn, multi_Descriptor) print 'exported descriptor' # Execute the metadata file # if you see this error message: TypeError: zip argument #1 must support iteration. Its because any of these is empty (no data) InputFile_list = self.execute_WriteMetadataFile( WEAPAreasDirectory, 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) self.load_InputTo_WEAP(WEAP, InputFile_list) def execute_TimeSeries_query(self, conn, multi_timeseries): # setup = DB_Setup() # session = setup.get_session() df_TimeSeries = TimeSeries_query(conn, multi_timeseries) if df_TimeSeries: total_df_TimeSeries, Metadata_TimeSeries = Timeseries_csv_file( df_TimeSeries, self.WEAPAreasDirectory) return (total_df_TimeSeries, Metadata_TimeSeries) else: return (None, None) #total_df_TimeSeries # def execute_MultiAtt_query(self, conn, multi_AttributeSeries): # setup = DB_Setup() # session = setup.get_session() df_MultiColumns = MultiAttributes_query(conn, multi_AttributeSeries) total_df_MultiColumns, Metadata_multi_att = MultiAttributes_csv_file( df_MultiColumns, self.WEAPAreasDirectory) return (total_df_MultiColumns, Metadata_multi_att) #total_df_Seasonal # csv_file_path_or_value_seasonal_all def execute_Seasonal_query(self, conn, multi_Seasonal): # setup = DB_Setup() # session = setup.get_session() df_Seasonal = Seasonal_query(conn, multi_Seasonal) total_df_Seasonal, Metadata_seasonal = Seasonal_csv_file( df_Seasonal, self.WEAPAreasDirectory) return (total_df_Seasonal, Metadata_seasonal) # def execute_Numeric_query(self, conn, multi_Numeric): # setup = DB_Setup() # session = setup.get_session() # df_Numeric = Numeric_query(session) total_df_Numeric, Metadata_multi_numeric = Numeric_query( conn, multi_Numeric) return (total_df_Numeric, Metadata_multi_numeric) # total_df_Numeric,Metadata_multi_descriptor = execute_Descriptor_query(conn, multi_Descriptor) # def execute_Descriptor_query(self, conn, multi_Descriptor): # setup = DB_Setup() # session = setup.get_session() # df_Descriptor = Descriptor_query(session) total_df_Descriptor, Metadata_multi_descriptor = Descriptor_query( conn, multi_Descriptor) return (total_df_Descriptor, Metadata_multi_descriptor) # store these as lists (matrix) then pass it to the write it all once into the input file or make def execute_WriteMetadataFile(self, WEAPAreasDirectory, total_df_TimeSeries, total_df_MultiColumns, total_df_Seasonal, total_df_Numeric, total_df_Descriptor, Metadata_TimeSeries, Metadata_seasonal, Metadata_multi_att, Metadata_multi_numeric, Metadata_multi_descriptor): # multi_AttributeSeries # from Read_provided_file_query_Required import * # from execute_TimeSeries_query import total_csv_file_name from ExportWEAP_Input_metadata_file import WriteMetadataFile return WriteMetadataFile(WEAPAreasDirectory, total_df_TimeSeries, total_df_MultiColumns, total_df_Seasonal, total_df_Numeric, total_df_Descriptor, Metadata_TimeSeries, Metadata_seasonal, Metadata_multi_att, Metadata_multi_numeric, Metadata_multi_descriptor) def load_InputTo_WEAP(self, WEAP, InputFile_list): # WEAP.Branch("Supply and Resources\River\Little Bear River\Reservoirs\Hyrum Reservoir").Variable("Volume Elevation Curve").Expression = "VolumeElevation(0.0,4590.0,130.0,4600.0,649.0,4610.0,1739.0,4620.0,3456.0,4630.0,5937.0,4640.0,9236.0,4650.0,13206.0,4660.0,17721.0,4670.0,18684.0,4672.0,22600.0,4680.0,28100.0,4690.0,34100.0,4700.0,40700.0,4710.0,47900.0,4720.0,55800.0,4730.0,64500.0,4740.0,73900.0,4750.0" # WEAP.Branch(BranchFullName).Variable(Required_AttributeName).Expression = InputFile for InputFile in InputFile_list: AttributeName = InputFile['VariableName'] Value = InputFile['Value'] InstanceName = InputFile['BranchName'] if "Headflow" in InstanceName: InstanceName = InstanceName.replace(" Headflow", "") ObjectType = InputFile['BranchType'] if ObjectType == 'River Headflow': ObjectType = 'River' # if ObjectType not in ('River','Reservoir','Demand Site','Flow Requirement','River Reach'): # if ObjectType in ('River Reach'): # and AttributeName in ('Groundwater Outflow','Surface Water Inflow') and \ # InstanceName in ('Below Bear River Canal Company Return','Below Last Chance Canal Co Return', # 'Below Logan River Inflow','Below Newton Creek Inflow'): # As an alternative to using the BranchName from WaMDaM, you can look up the full branch name from WEAP # using the existing Instance name (node or link in WEAP) # It would work fine for most of the Object types but could be tricky for the reaches if ObjectType == "WEAP Global Attributes": for Branch in WEAP.Branches: FullBranchName = Branch.FullName BranchName = Branch.Name if "Key\\" in FullBranchName: print FullBranchName if AttributeName == BranchName: for V in Branch.Variables: V.Expression = '0' V.Expression = Value WEAP.ActiveArea.Save else: for Branch in WEAP.Branches: FullBranchName = Branch.FullName WEAP_BranchTypeName = Branch.TypeName WEAP_BranchName = Branch.Name if WEAP_BranchTypeName == ObjectType and WEAP_BranchName == InstanceName: # and ('Central Bear' or 'Lower Bear' or 'Cub' or 'Malad' or 'Deep' or 'Mink') in FullBranchName: print FullBranchName # print Value if WEAP.Branch(FullBranchName).Variables.Exists( AttributeName): if not AttributeName == 'Method': WEAP.Branch(FullBranchName).Variable( AttributeName).Expression = '0' WEAP.Branch(FullBranchName).Variable( AttributeName).Expression = Value WEAP.ActiveArea.Save # Execute loading data to WEAP # load_InputTo_WEAP(WEAP,InputFile_list) Save = WEAP.ActiveArea.Save Save = WEAP.SaveArea print 'Done loading to WEAP' print 'Saved'