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
예제 #2
0
    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
예제 #3
0
 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):
        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()
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)
예제 #7
0
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)
예제 #8
0
    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()
예제 #9
0
    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()
예제 #10
0
    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()
예제 #11
0
    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()
예제 #12
0
    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
예제 #13
0
    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()
예제 #14
0
    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, 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()
예제 #18
0
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'
예제 #19
0
 def checkConnectingToSqlite(self):
     db_setup = DB_Setup()
     if not db_setup.get_session():
         return False
     return True
예제 #20
0
 def disconnect_DB(self):
     conn = DB_Setup()
     if conn.get_session():
         conn.close_db()
예제 #21
0
    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 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()
예제 #23
0
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
예제 #24
0
 def __init__(self):
     self.ConnectWEAP()
     self.setup = DB_Setup()
     self.session = self.setup.get_session()
     self.excel_pointer = None