Ejemplo n.º 1
0
def validate_xml_file_def(dConf):

    # file definition to check
    lXML_files = [
        'XML_FORECAST_HEADER_STANDARD_ITEMS',
        'XML_FORECAST_HEADER_EXTENDED_ITEMS',
        'XML_FORECAST_PREDICTION_STANDARD_ITEMS',
        'XML_FORECAST_PREDICTION_EXTENDED_ITEMS',
        'XML_OBSERVATION_HEADER_STANDARD_ITEMS',
        'XML_OBSERVATION_HEADER_EXTENDED_ITEMS',
        'XML_OBSERVATION_MEASURE_STANDARD_ITEMS',
        'XML_OBSERVATION_MEASURE_EXTENDED_ITEMS',
        'XML_STATION_HEADER_STANDARD_ITEMS',
        'XML_STATION_HEADER_EXTENDED_ITEMS',
        'XML_STATION_ROADLAYER_STANDARD_ITEMS',
        'XML_STATION_ROADLAYER_EXTENDED_ITEMS',
        'XML_ROADCAST_HEADER_STANDARD_ITEMS',
        'XML_ROADCAST_HEADER_EXTENDED_ITEMS',
        'XML_ROADCAST_PREDICTION_STANDARD_ITEMS',
        'XML_ROADCAST_PREDICTION_EXTENDED_ITEMS',
    ]

    # extract all data type
    dStandard_data_type = metro_config.get_value('XML_DATATYPE_STANDARD')
    dExtended_data_type = metro_config.get_value('XML_DATATYPE_EXTENDED')
    dAll_data_type = metro_util.join_dictionaries(dStandard_data_type,
                                                  dExtended_data_type)

    for sXML_file in lXML_files:
        iFrom = dConf[sXML_file]['FROM']
        lXML_items = dConf[sXML_file]['VALUE']
        validate_xml_itemlist_def(sXML_file, iFrom, lXML_items, dAll_data_type)
Ejemplo n.º 2
0
def get_handler(sHandlerType, dDefData, dAllDefData=None):

    if dAllDefData == None:
        # Retrieve the informations about the data types
        dStandard_data_type = metro_config.get_value('XML_DATATYPE_STANDARD')
        dExtended_data_type = metro_config.get_value('XML_DATATYPE_EXTENDED')
        dAllDefData = metro_util.join_dictionaries(dStandard_data_type,
                                              dExtended_data_type)
    
    sTag = dDefData['NAME']
    sXml_tag = dDefData['XML_TAG']
    sData_type_name = dDefData['DATA_TYPE']

    if sData_type_name not in dAllDefData.keys():
        sMessage = _("Invalid data_type: (%s) for the following ") \
                   % (sData_type_name) +\
                   _("tag:(%s). Default data type will be used.") \
                   % (sTag)
        metro_logger.print_message(metro_logger.LOGGER_MSG_WARNING,
                                           sMessage)
        sData_type_name = 'DEFAULT'
                
    # The data type needs the call of a function to create the node
    sHandler = dAllDefData[sData_type_name][sHandlerType]

    return sHandler
Ejemplo n.º 3
0
def get_handler(sHandlerType, dDefData, dAllDefData=None):

    if dAllDefData == None:
        # Retrieve the informations about the data types
        dStandard_data_type = metro_config.get_value('XML_DATATYPE_STANDARD')
        dExtended_data_type = metro_config.get_value('XML_DATATYPE_EXTENDED')
        dAllDefData = metro_util.join_dictionaries(dStandard_data_type,
                                                   dExtended_data_type)

    sTag = dDefData['NAME']
    sXml_tag = dDefData['XML_TAG']
    sData_type_name = dDefData['DATA_TYPE']

    if sData_type_name not in dAllDefData.keys():
        sMessage = _("Invalid data_type: (%s) for the following ") \
                   % (sData_type_name) +\
                   _("tag:(%s). Default data type will be used.") \
                   % (sTag)
        metro_logger.print_message(metro_logger.LOGGER_MSG_WARNING, sMessage)
        sData_type_name = 'DEFAULT'

    # The data type needs the call of a function to create the node
    sHandler = dAllDefData[sData_type_name][sHandlerType]

    return sHandler
Ejemplo n.º 4
0
def create_node_tree_from_dict(domDoc, nodeParent, lDefs, dWriteHandlers,
                               dData):

    # Retrieve the informations on the data types
    dStandard_data_type = metro_config.get_value('XML_DATATYPE_STANDARD')
    dExtended_data_type = metro_config.get_value('XML_DATATYPE_EXTENDED')

    dData_type = metro_util.join_dictionaries(dStandard_data_type,
                                              dExtended_data_type)

    for dDef in lDefs:
        # Retrieve the name and the item type
        sTag = dDef['NAME']
        sXml_tag = dDef['XML_TAG']
        sData_type_name = dDef['DATA_TYPE']

        if dData_type[sData_type_name].has_key('CHILD'):
            #  create the node containing a list of "sub-node"
            lChildList = dData_type[sData_type_name]['CHILD']
            nodeData = dWriteHandlers[sData_type_name](sXml_tag, lChildList,
                                                       dData[sTag],
                                                       dWriteHandlers)
        else:
            #  create the node
            nodeData = dWriteHandlers[sData_type_name](sXml_tag, dData[sTag])

        append_child(nodeParent, nodeData)
Ejemplo n.º 5
0
def create_node_tree_from_matrix(domDoc, nodeParent, sPrediction_xpath, lDefs,
                                 dWriteHandlers, metro_data_object, npMatrix):
    """
    Each prediction will be contained in a node that will have the name
    given by sPrediction_xpath.
    """

    # Retrieve the informations about the data types
    dStandard_data_type = metro_config.get_value('XML_DATATYPE_STANDARD')
    dExtended_data_type = metro_config.get_value('XML_DATATYPE_EXTENDED')
    dData_type = metro_util.join_dictionaries(dStandard_data_type,
                                              dExtended_data_type)

    for npData in npMatrix:

        # If needed, creation of a node to contain the prediction
        if sPrediction_xpath != None and sPrediction_xpath != "":
            nodePrediction = mkdir_xpath(domDoc, nodeParent, sPrediction_xpath)
        else:
            nodePrediction = nodeParent

        for dDef in lDefs:
            # Get the name and the type of the item
            sTag = dDef['NAME']
            sXml_tag = dDef['XML_TAG']
            sData_type_name = dDef['DATA_TYPE']

            # Extraction of the data from the matrix
            lIndexList = metro_data_object.index_of_matrix_col(sTag)
            if not metro_data_object.is_multi_col(sTag):
                # single col
                val = npData[lIndexList[0]]
            else:
                # multi col
                # FFTODO good candidate for optimisation

                val = []

                for i in lIndexList:
                    val.append(npData[i])

            if dData_type[sData_type_name].has_key('CHILD'):
                #  create the node containing a list of "sub-node"
                lChildList = dData_type[sData_type_name]['CHILD']
                nodeData = dWriteHandlers[sData_type_name](sXml_tag,
                                                           lChildList, val,
                                                           dWriteHandlers)
            else:
                #  create the node
                nodeData = dWriteHandlers[sData_type_name](sXml_tag, val)

            append_child(nodePrediction, nodeData)
Ejemplo n.º 6
0
def extract_data(lDefs, dReadHandlers, nodeItems):
    """
    Name: extract_data

    Arguments:  [I] lDefs: list of dictionary containing the
                           definition of XML element in metro_config.py
                [I] dReadHandlers: dictionnay of read handler.
                                   key = data type name (ex: INTEGER),
                                   value = handler (ex: toolbox.metro_dom2metro_handler.read_integer)
                [I] nodeItems: fecth the elements in theses nodes

    Output:   lData :: list of values, one per definition in lDefs.

    Description: Extract the data from one node containing more nodes.
    """

    lData = []

    # Retrieve the informations about the data type
    dStandard_data_type = metro_config.get_value('XML_DATATYPE_STANDARD')
    dExtended_data_type = metro_config.get_value('XML_DATATYPE_EXTENDED')

    dData_type = metro_util.join_dictionaries(dStandard_data_type,
                                              dExtended_data_type)

    # For each definitions of item
    for dDef in lDefs:
        # Get the name and the type of the item
        sTag = dDef['XML_TAG']
        sData_type_name = dDef['DATA_TYPE']

        if dData_type[sData_type_name].has_key('CHILD'):
            #  extract the data containing a list of "sub-data"
            nodeTmp = metro_xml_lib.xpath(nodeItems, sTag)
            lChildList = dData_type[sData_type_name]['CHILD']
            data = dReadHandlers[sData_type_name](lChildList, nodeTmp,
                                                  dReadHandlers)
        else:
            #  extract the data
            data = dReadHandlers[sData_type_name](sTag, nodeItems)

        lData.append(data)

    # If there is only one definition of data (lDefs), it is an "array".
    #  In this case, we must extract the "array" from the list
    #  [[1,2,3,...,N]]  ==>  [1,2,3,...,N]
    if len(lDefs) == 1:
        if lData:
            lData = lData[0]

    return lData
Ejemplo n.º 7
0
def create_node_tree_from_matrix( domDoc, nodeParent, sPrediction_xpath,
                                  lDefs, dWriteHandlers, metro_data_object, npMatrix ):
    """
    Each prediction will be contained in a node that will have the name
    given by sPrediction_xpath.
    """


    # Retrieve the informations about the data types
    dStandard_data_type = metro_config.get_value('XML_DATATYPE_STANDARD')
    dExtended_data_type = metro_config.get_value('XML_DATATYPE_EXTENDED')
    dData_type = metro_util.join_dictionaries(dStandard_data_type,
                                              dExtended_data_type)

    for npData in npMatrix:

        # If needed, creation of a node to contain the prediction
        if sPrediction_xpath != None and sPrediction_xpath != "":
            nodePrediction = mkdir_xpath(domDoc, nodeParent, sPrediction_xpath)
        else:
            nodePrediction = nodeParent

        for dDef in lDefs:
            # Get the name and the type of the item
            sTag = dDef['NAME']
            sXml_tag = dDef['XML_TAG']
            sData_type_name = dDef['DATA_TYPE']

            # Extraction of the data from the matrix
            lIndexList = metro_data_object.index_of_matrix_col(sTag)
            if not metro_data_object.is_multi_col(sTag):
                # single col
                val = npData[lIndexList[0]]
            else:
                # multi col
                # FFTODO good candidate for optimisation
                
                val = []
                
                for i in lIndexList:
                    val.append(npData[i])
            
            if dData_type[sData_type_name].has_key('CHILD'):
                #  create the node containing a list of "sub-node"
                lChildList = dData_type[sData_type_name]['CHILD']
                nodeData = dWriteHandlers[sData_type_name](sXml_tag,lChildList,val,dWriteHandlers)
            else:
                #  create the node 
                nodeData = dWriteHandlers[sData_type_name](sXml_tag,val)

            append_child(nodePrediction, nodeData)
Ejemplo n.º 8
0
def extract_data(lDefs, dReadHandlers, nodeItems):
    """
    Name: extract_data

    Arguments:  [I] lDefs: list of dictionary containing the
                           definition of XML element in metro_config.py
                [I] dReadHandlers: dictionnay of read handler.
                                   key = data type name (ex: INTEGER),
                                   value = handler (ex: toolbox.metro_dom2metro_handler.read_integer)
                [I] nodeItems: fecth the elements in theses nodes

    Output:   lData :: list of values, one per definition in lDefs.

    Description: Extract the data from one node containing more nodes.
    """

    lData = []

    # Retrieve the informations about the data type
    dStandard_data_type = metro_config.get_value('XML_DATATYPE_STANDARD')
    dExtended_data_type = metro_config.get_value('XML_DATATYPE_EXTENDED')

    dData_type = metro_util.join_dictionaries(dStandard_data_type,
                                              dExtended_data_type)

    # For each definitions of item
    for dDef in lDefs:
        # Get the name and the type of the item
        sTag = dDef['XML_TAG']
        sData_type_name = dDef['DATA_TYPE']
        
        if dData_type[sData_type_name].has_key('CHILD'):
            #  extract the data containing a list of "sub-data"
            nodeTmp = metro_xml_lib.xpath(nodeItems,sTag)
            lChildList = dData_type[sData_type_name]['CHILD']
            data = dReadHandlers[sData_type_name](lChildList,nodeTmp,dReadHandlers)
        else:
            #  extract the data
            data = dReadHandlers[sData_type_name](sTag,nodeItems)

        lData.append(data)

    # If there is only one definition of data (lDefs), it is an "array".
    #  In this case, we must extract the "array" from the list
    #  [[1,2,3,...,N]]  ==>  [1,2,3,...,N]
    if len(lDefs) == 1:
        if lData:
            lData = lData[0]

    return lData
Ejemplo n.º 9
0
    def start(self):
        Metro_module.start(self)

        pRoadcast = self.get_infdata_reference('ROADCAST')
        roadcast_data = pRoadcast.get_data_collection()

        #
        # construct dictionnary of write handler
        #

        import toolbox.metro_metro2dom_handler

        # Retrieve the informations about the data type
        dStandard_data_type = metro_config.get_value('XML_DATATYPE_STANDARD')
        dExtended_data_type = metro_config.get_value('XML_DATATYPE_EXTENDED')

        dData_type = metro_util.join_dictionaries(dStandard_data_type,
                                                  dExtended_data_type)

        dWriteHandlers = {}

        # construct dictionnary of write handlers (only done once so not expensive)
        sMessage = _(
            "-------------------------- Write handlers available --------------------------\n"
        )
        for dType in dData_type:
            if dData_type[dType]['WRITE'] != "":
                sCode = "handler = " + dData_type[dType]['WRITE']
                exec sCode
                dWriteHandlers[dType] = handler
                sMessage += _("TYPE: %s , HANDLER: %s\n") % (
                    dType.ljust(15), dData_type[dType]['WRITE'])
        sMessage += "-----------------------------------------------------------------------------"
        metro_logger.print_message(metro_logger.LOGGER_MSG_DEBUG, sMessage)

        # Create roadcast
        if roadcast_data != None:
            domRoadcast = \
                self.__create_roadcast(roadcast_data.get_subsampled_data(),dWriteHandlers)

        else:
            metro_logger.print_message(
                metro_logger.LOGGER_MSG_WARNING,
                _("No roadcast, can't create DOM roadcast"))
            domRoadcast = None

        pRoadcast.set_output_information(domRoadcast)
Ejemplo n.º 10
0
    def start( self ):
        Metro_module.start(self)

        pRoadcast = self.get_infdata_reference('ROADCAST')
        roadcast_data = pRoadcast.get_data_collection()


        #
        # construct dictionnary of write handler
        #
        
        import toolbox.metro_metro2dom_handler 

        # Retrieve the informations about the data type
        dStandard_data_type = metro_config.get_value('XML_DATATYPE_STANDARD')
        dExtended_data_type = metro_config.get_value('XML_DATATYPE_EXTENDED')

        dData_type = metro_util.join_dictionaries(dStandard_data_type,
                                                  dExtended_data_type)

        dWriteHandlers = {}

        # construct dictionnary of write handlers (only done once so not expensive)
        sMessage = _("-------------------------- Write handlers available --------------------------\n")
        for dType in dData_type:
            if dData_type[dType]['WRITE'] != "":
                sCode = "handler = " + dData_type[dType]['WRITE']
                exec sCode
                dWriteHandlers[dType] = handler
                sMessage += _("TYPE: %s , HANDLER: %s\n") % (dType.ljust(15),dData_type[dType]['WRITE'])
        sMessage += "-----------------------------------------------------------------------------"        
        metro_logger.print_message(metro_logger.LOGGER_MSG_DEBUG,
                                   sMessage)                
        
        # Create roadcast
        if roadcast_data != None:
            domRoadcast = \
                self.__create_roadcast(roadcast_data.get_subsampled_data(),dWriteHandlers)

        else:
            metro_logger.print_message(metro_logger.LOGGER_MSG_WARNING,
                _("No roadcast, can't create DOM roadcast"))
            domRoadcast = None

        pRoadcast.set_output_information(domRoadcast)
Ejemplo n.º 11
0
def validate_datatype(dConf):

    # extract data type
    dStandard_data_type = metro_config.get_value('XML_DATATYPE_STANDARD')
    dExtended_data_type = metro_config.get_value('XML_DATATYPE_EXTENDED')
    dAll_data_type = metro_util.join_dictionaries(dStandard_data_type,
                                                  dExtended_data_type)

    # validate Metro standard data type
    sConfig_item = 'XML_DATATYPE_STANDARD'
    iFrom = dConf[sConfig_item]['FROM']
    validate_datatype_category(sConfig_item, iFrom, dStandard_data_type,
                               dAll_data_type)

    # validate User data type
    sConfig_item = 'XML_DATATYPE_EXTENDED'
    iFrom = dConf[sConfig_item]['FROM']
    validate_datatype_category(sConfig_item, iFrom, dExtended_data_type,
                               dAll_data_type)
Ejemplo n.º 12
0
def create_node_tree_from_dict( domDoc, nodeParent, lDefs, dWriteHandlers, dData ):

    # Retrieve the informations on the data types
    dStandard_data_type = metro_config.get_value('XML_DATATYPE_STANDARD')
    dExtended_data_type = metro_config.get_value('XML_DATATYPE_EXTENDED')

    dData_type = metro_util.join_dictionaries(dStandard_data_type,
                                              dExtended_data_type)

    for dDef in lDefs:
        # Retrieve the name and the item type
        sTag = dDef['NAME']
        sXml_tag = dDef['XML_TAG']
        sData_type_name = dDef['DATA_TYPE']

        if dData_type[sData_type_name].has_key('CHILD'):
            #  create the node containing a list of "sub-node"
            lChildList = dData_type[sData_type_name]['CHILD']
            nodeData = dWriteHandlers[sData_type_name](sXml_tag,lChildList,dData[sTag],dWriteHandlers)
        else:
            #  create the node 
            nodeData = dWriteHandlers[sData_type_name](sXml_tag,dData[sTag])

        append_child(nodeParent, nodeData)
Ejemplo n.º 13
0
    def start(self):
        Metro_module.start(self)

        pForecast        = self.get_infdata_reference('FORECAST')
        pObservation     = self.get_infdata_reference('OBSERVATION')
        pStation         = self.get_infdata_reference('STATION')
        if self.infdata_exist('OBSERVATION_REF'):
            pObservation_ref = self.get_infdata_reference('OBSERVATION_REF')
        else:
            pObservation_ref = None
            
        
        self.domForecast        = pForecast.get_input_information()
        self.domObservation     = pObservation.get_input_information()
        if pObservation_ref != None:
            self.domObservation_ref = pObservation_ref.get_input_information()
        else:
            self.domObservation_ref = None
        self.domStation         = pStation.get_input_information()

	if self.infdata_exist('HORIZON'):
            pHorizon = self.get_infdata_reference('HORIZON')
            self.domHorizon = self.domStation
            if metro_xml.xpath(self.domHorizon, \
                               metro_config.get_value('XML_STATION_XPATH_HORIZON')) \
                               == None:
                pHorizon.set_input_information(None)
            else:
                pHorizon.set_input_information(self.domHorizon)
        else:
            pHorizon = None


        #
        # construct dictionnary of read handler
        #
        
        import toolbox.metro_dom2metro_handler 

        # Retrieve the informations about the data type
        dStandard_data_type = metro_config.get_value('XML_DATATYPE_STANDARD')
        dExtended_data_type = metro_config.get_value('XML_DATATYPE_EXTENDED')

        dData_type = metro_util.join_dictionaries(dStandard_data_type,
                                                  dExtended_data_type)

        dReadHandlers = {}

        # construct dictionnary of read handlers (only done once so not expensive)
        sMessage = _("-------------------------- Read handlers available --------------------------\n")
        for dType in dData_type:
            if dData_type[dType]['READ'] != "":
                sCode = "handler = " + dData_type[dType]['READ']
                exec sCode
                dReadHandlers[dType] = handler
                sMessage += _("TYPE: %s , HANDLER: %s\n") % (dType.ljust(15),dData_type[dType]['READ'])
        sMessage += "-----------------------------------------------------------------------------"
        metro_logger.print_message(metro_logger.LOGGER_MSG_DEBUG,
                                   sMessage)           
        
        #
        # Forecast extraction
        #

        # validate version number
        sFilename = metro_config.get_value('FILE_FORECAST_IN_FILENAME')
        sFile_version = metro_xml.xpath(self.domForecast,"//version")

        sMin_version = metro_config.get_value('FILE_FORECAST_IN_MIN_VERSION')
        sMax_version = metro_config.get_value('FILE_FORECAST_IN_MAX_VERSION')
        self.validate_file_version_number(sFilename, sFile_version,
                                       sMin_version, sMax_version)
            
        try:
            # concatenation of all the keys of the header
            lHeader_keys = \
                metro_config.get_value('XML_FORECAST_HEADER_STANDARD_ITEMS') + \
                metro_config.get_value('XML_FORECAST_HEADER_EXTENDED_ITEMS')

            # xpath building
            sHeader_xpath = metro_config.get_value('XML_FORECAST_XPATH_HEADER')
            sData_xpath = \
                metro_config.get_value('XML_FORECAST_XPATH_PREDICTION')
            
            # concatenation of all forecast types
            lStandard_forecast = \
                metro_config.get_value('XML_FORECAST_PREDICTION_STANDARD_ITEMS')
            lExtended_forecast = \
                metro_config.get_value('XML_FORECAST_PREDICTION_EXTENDED_ITEMS')
            forecast_data = metro_data.Metro_data(lStandard_forecast,\
                                             lExtended_forecast)

            forecast_data = self.__extract_data_from_dom(forecast_data,
                                                         self.domForecast,
                                                         lHeader_keys,
                                                         sHeader_xpath,
                                                         lStandard_forecast,
                                                         lExtended_forecast,
                                                         dReadHandlers,
                                                         sData_xpath)
        except metro_error.Metro_xml_error:
            sXmlError = _("XML error in file '%s'.") % (sFilename)
            raise metro_error.Metro_xml_error(sXmlError)

        # create forecast collection
        lForecast_standard_attribute = metro_config.get_value(
            'DATA_ATTRIBUTE_FORECAST_STANDARD')
        lForecast_extended_attribute = metro_config.get_value(
            'DATA_ATTRIBUTE_FORECAST_EXTENDED')
        lForecast_attribute = lForecast_standard_attribute \
                              + lForecast_extended_attribute
        forecast = metro_data_collection_input.Metro_data_collection_input(
            forecast_data, lForecast_attribute)

        #
        # Observations extraction
        #
        
        # validate version number
        sFilename = metro_config.get_value('FILE_OBSERVATION_FILENAME')
        sFile_version = metro_xml.xpath(self.domObservation,"*/version/text()")
        sMin_version = metro_config.get_value('FILE_OBSERVATION_MIN_VERSION')
        sMax_version = metro_config.get_value('FILE_OBSERVATION_MAX_VERSION')
        self.validate_file_version_number(sFilename, sFile_version,
                                       sMin_version, sMax_version)

        try:
            # concatenation of all the header's keys
            lHeader_keys = \
                metro_config.get_value( 'XML_OBSERVATION_HEADER_STANDARD_ITEMS') + \
                metro_config.get_value('XML_OBSERVATION_HEADER_STANDARD_ITEMS')

            # xpath construction
            sHeader_xpath = metro_config.get_value('XML_OBSERVATION_XPATH_HEADER')
            sData_xpath = metro_config.get_value('XML_OBSERVATION_XPATH_MEASURE')
            
            # concatenation of all observations' type
            lStandard_observation = metro_config.get_value( \
            'XML_OBSERVATION_MEASURE_STANDARD_ITEMS')
            lExtended_observation = metro_config.get_value( \
            'XML_OBSERVATION_MEASURE_EXTENDED_ITEMS')        

            obs_data = metro_data.Metro_data(lStandard_observation, \
                                             lExtended_observation)

            observation_data = self.__extract_data_from_dom(obs_data,
                                                            self.domObservation,
                                                            lHeader_keys,
                                                            sHeader_xpath,
                                                            lStandard_observation,
                                                            lExtended_observation,
                                                            dReadHandlers,
                                                            sData_xpath)
        except :
            sXmlError = _("XML error in file '%s'.\n") % (sFilename) +\
                        sError
            raise metro_error.Metro_xml_error(sXmlError)

        # create observation collection
        lObservation_standard_attribute = metro_config.get_value(
            'DATA_ATTRIBUTE_OBSERVATION_STANDARD')
        lObservation_extended_attribute = metro_config.get_value(
            'DATA_ATTRIBUTE_OBSERVATION_EXTENDED')
        lObservation_attribute = lObservation_standard_attribute \
                                 + lObservation_extended_attribute
        observation = metro_data_collection_input.Metro_data_collection_input(
            observation_data, lObservation_attribute)


        #
        # observations_ref extraction
        #
        
        if self.domObservation_ref != None:

            # validate version number
            sFilename = metro_config.get_value('FILE_OBSERVATION_REF_FILENAME')
            sFile_version = \
                metro_xml.xpath(self.domObservation_ref,"*/version/text()")
            sMin_version = \
                metro_config.get_value('FILE_OBSERVATION_MIN_VERSION')
            sMax_version = \
                metro_config.get_value('FILE_OBSERVATION_MAX_VERSION')
            self.validate_file_version_number(sFilename, sFile_version,
                                           sMin_version, sMax_version)
            
            try:
                # concatenation of all header's keys
                lHeader_keys = \
                    metro_config.get_value('XML_OBSERVATION_HEADER_STANDARD_ITEMS') + \
                    metro_config.get_value('XML_OBSERVATION_HEADER_STANDARD_ITEMS')

                # xpath construction
                sHeader_xpath = metro_config.get_value('XML_OBSERVATION_XPATH_HEADER')
                sData_xpath = metro_config.get_value('XML_OBSERVATION_XPATH_MEASURE')
            
                # concatenation de tout les types d'observation
                lStandard_observation = metro_config.get_value( \
                    'XML_OBSERVATION_MEASURE_STANDARD_ITEMS')
                lExtended_observation = metro_config.get_value( \
                    'XML_OBSERVATION_MEASURE_EXTENDED_ITEMS')        

                obs_data = metro_data.Metro_data(lStandard_observation,\
                                                 lExtended_observation)

                observation_data = \
                    self.__extract_data_from_dom(obs_data,
                                                 self.domObservation_ref,
                                                 lHeader_keys,
                                                 sHeader_xpath,
                                                 lStandard_observation,
                                                 lExtended_observation,
                                                 dReadHandlers,
                                                 sData_xpath)
            except:
                sXmlError = _("XML error in file '%s'.") % (sFilename)
                raise metro_error.Metro_xml_error(sXmlError)

            # create observation collection
            lObservation_standard_attribute = metro_config.get_value(
                'DATA_ATTRIBUTE_OBSERVATION_STANDARD')
            lObservation_extended_attribute = metro_config.get_value(
                'DATA_ATTRIBUTE_OBSERVATION_EXTENDED')
            lObservation_attribute = lObservation_standard_attribute \
                                     + lObservation_extended_attribute
            observation_ref = \
                metro_data_collection_input.\
                Metro_data_collection_input(observation_data,
                                            lObservation_attribute)

            pObservation_ref.set_data_collection(observation_ref)

        #
        # station extraction
        #

        # validate version number
        sFilename = metro_config.get_value('FILE_STATION_FILENAME')
        sFile_version = metro_xml.xpath(self.domStation,"*/version/text()")
        sMin_version = metro_config.get_value('FILE_STATION_MIN_VERSION')
        sMax_version = metro_config.get_value('FILE_STATION_MAX_VERSION')
        self.validate_file_version_number(sFilename, sFile_version,
                                       sMin_version, sMax_version)

        try:
            # concatenation of all header's keys
            lHeader_defs = \
                metro_config.get_value('XML_STATION_HEADER_STANDARD_ITEMS') + \
                metro_config.get_value('XML_STATION_HEADER_EXTENDED_ITEMS')

            # xpath construction
            sHeader_xpath = metro_config.get_value('XML_STATION_XPATH_HEADER')
            sData_xpath = metro_config.get_value('XML_STATION_XPATH_ROADLAYER')

            # concatenation of all the roadlayer sections
            lStandard_roadlayer = metro_config.get_value( \
                'XML_STATION_ROADLAYER_STANDARD_ITEMS')
            lExtended_roadlayer = metro_config.get_value( \
                'XML_STATION_ROADLAYER_EXTENDED_ITEMS')        


            cs_data = metro_data_station.Metro_data_station(lStandard_roadlayer,\
                                                            lExtended_roadlayer)

            station_data = self.__extract_data_from_dom(cs_data,
                                                        self.domStation,
                                                        lHeader_defs,
                                                        sHeader_xpath,
                                                        lStandard_roadlayer,
                                                        lExtended_roadlayer,
                                                        dReadHandlers,
                                                        sData_xpath)

        except:
            sXmlError = _("XML error in file '%s'.") % (sFilename)
            raise  metro_error.Metro_xml_error(sXmlError)


        
	#
        # station horizon extraction
        #


        if ((pHorizon != None) and (pHorizon.get_input_information() != None)):
            try:
                # concatenation of all header's keys
                lHeader_defs = \
                    metro_config.get_value('XML_STATION_HEADER_STANDARD_ITEMS') + \
                    metro_config.get_value('XML_STATION_HEADER_EXTENDED_ITEMS')

                # xpath construction
                sHeader_xpath = metro_config.get_value('XML_STATION_XPATH_HEADER')
                # xpath construction
                sHorizon_xpath = metro_config.get_value('XML_STATION_XPATH_HORIZON')
	    
                # concatenation of all the horizon sections
                lStandard_horizon = metro_config.get_value( \
                    'XML_STATION_HORIZON_STANDARD_ITEMS')
                lExtended_horizon = metro_config.get_value( \
                    'XML_STATION_HORIZON_EXTENDED_ITEMS')
            
	        cs_horizon_data = metro_data_station.\
                                  Metro_data_station(lStandard_horizon,\
                                                     lExtended_horizon)
            
	        horizon_data = self.__extract_data_from_dom(cs_horizon_data,
                                                            self.domHorizon,
                                                            lHeader_defs,
                                                            sHeader_xpath,
                                                            lStandard_horizon,
                                                            lExtended_horizon,
                                                            dReadHandlers,
                                                            sHorizon_xpath)

            except:
               sXmlError = _("XML error in file '%s'.") % (sFilename)
               raise  metro_error.Metro_xml_error(sXmlError)
	    
	    pHorizon.set_data(horizon_data)



        pForecast.set_data_collection(forecast)
        pObservation.set_data_collection(observation)
        pStation.set_data(station_data)
Ejemplo n.º 14
0
    def start(self):
        Metro_module.start(self)

        pForecast = self.get_infdata_reference('FORECAST')
        pObservation = self.get_infdata_reference('OBSERVATION')
        pStation = self.get_infdata_reference('STATION')
        if self.infdata_exist('OBSERVATION_REF'):
            pObservation_ref = self.get_infdata_reference('OBSERVATION_REF')
        else:
            pObservation_ref = None

        self.domForecast = pForecast.get_input_information()
        self.domObservation = pObservation.get_input_information()
        if pObservation_ref != None:
            self.domObservation_ref = pObservation_ref.get_input_information()
        else:
            self.domObservation_ref = None
        self.domStation = pStation.get_input_information()

        if self.infdata_exist('HORIZON'):
            pHorizon = self.get_infdata_reference('HORIZON')
            self.domHorizon = self.domStation
            if metro_xml.xpath(self.domHorizon, \
                               metro_config.get_value('XML_STATION_XPATH_HORIZON')) \
                               == None:
                pHorizon.set_input_information(None)
            else:
                pHorizon.set_input_information(self.domHorizon)
        else:
            pHorizon = None

        #
        # construct dictionnary of read handler
        #

        import toolbox.metro_dom2metro_handler

        # Retrieve the informations about the data type
        dStandard_data_type = metro_config.get_value('XML_DATATYPE_STANDARD')
        dExtended_data_type = metro_config.get_value('XML_DATATYPE_EXTENDED')

        dData_type = metro_util.join_dictionaries(dStandard_data_type,
                                                  dExtended_data_type)

        dReadHandlers = {}

        # construct dictionnary of read handlers (only done once so not expensive)
        sMessage = _(
            "-------------------------- Read handlers available --------------------------\n"
        )
        for dType in dData_type:
            if dData_type[dType]['READ'] != "":
                sCode = "handler = " + dData_type[dType]['READ']
                exec sCode
                dReadHandlers[dType] = handler
                sMessage += _("TYPE: %s , HANDLER: %s\n") % (
                    dType.ljust(15), dData_type[dType]['READ'])
        sMessage += "-----------------------------------------------------------------------------"
        metro_logger.print_message(metro_logger.LOGGER_MSG_DEBUG, sMessage)

        #
        # Forecast extraction
        #

        # validate version number
        sFilename = metro_config.get_value('FILE_FORECAST_IN_FILENAME')
        sFile_version = metro_xml.xpath(self.domForecast, "//version")

        sMin_version = metro_config.get_value('FILE_FORECAST_IN_MIN_VERSION')
        sMax_version = metro_config.get_value('FILE_FORECAST_IN_MAX_VERSION')
        self.validate_file_version_number(sFilename, sFile_version,
                                          sMin_version, sMax_version)

        try:
            # concatenation of all the keys of the header
            lHeader_keys = \
                metro_config.get_value('XML_FORECAST_HEADER_STANDARD_ITEMS') + \
                metro_config.get_value('XML_FORECAST_HEADER_EXTENDED_ITEMS')

            # xpath building
            sHeader_xpath = metro_config.get_value('XML_FORECAST_XPATH_HEADER')
            sData_xpath = \
                metro_config.get_value('XML_FORECAST_XPATH_PREDICTION')

            # concatenation of all forecast types
            lStandard_forecast = \
                metro_config.get_value('XML_FORECAST_PREDICTION_STANDARD_ITEMS')
            lExtended_forecast = \
                metro_config.get_value('XML_FORECAST_PREDICTION_EXTENDED_ITEMS')
            forecast_data = metro_data.Metro_data(lStandard_forecast,\
                                             lExtended_forecast)

            forecast_data = self.__extract_data_from_dom(
                forecast_data, self.domForecast, lHeader_keys, sHeader_xpath,
                lStandard_forecast, lExtended_forecast, dReadHandlers,
                sData_xpath)
        except metro_error.Metro_xml_error:
            sXmlError = _("XML error in file '%s'.") % (sFilename)
            raise metro_error.Metro_xml_error(sXmlError)

        # create forecast collection
        lForecast_standard_attribute = metro_config.get_value(
            'DATA_ATTRIBUTE_FORECAST_STANDARD')
        lForecast_extended_attribute = metro_config.get_value(
            'DATA_ATTRIBUTE_FORECAST_EXTENDED')
        lForecast_attribute = lForecast_standard_attribute \
                              + lForecast_extended_attribute
        forecast = metro_data_collection_input.Metro_data_collection_input(
            forecast_data, lForecast_attribute)

        #
        # Observations extraction
        #

        # validate version number
        sFilename = metro_config.get_value('FILE_OBSERVATION_FILENAME')
        sFile_version = metro_xml.xpath(self.domObservation,
                                        "*/version/text()")
        sMin_version = metro_config.get_value('FILE_OBSERVATION_MIN_VERSION')
        sMax_version = metro_config.get_value('FILE_OBSERVATION_MAX_VERSION')
        self.validate_file_version_number(sFilename, sFile_version,
                                          sMin_version, sMax_version)

        try:
            # concatenation of all the header's keys
            lHeader_keys = \
                metro_config.get_value( 'XML_OBSERVATION_HEADER_STANDARD_ITEMS') + \
                metro_config.get_value('XML_OBSERVATION_HEADER_STANDARD_ITEMS')

            # xpath construction
            sHeader_xpath = metro_config.get_value(
                'XML_OBSERVATION_XPATH_HEADER')
            sData_xpath = metro_config.get_value(
                'XML_OBSERVATION_XPATH_MEASURE')

            # concatenation of all observations' type
            lStandard_observation = metro_config.get_value( \
            'XML_OBSERVATION_MEASURE_STANDARD_ITEMS')
            lExtended_observation = metro_config.get_value( \
            'XML_OBSERVATION_MEASURE_EXTENDED_ITEMS')

            obs_data = metro_data.Metro_data(lStandard_observation, \
                                             lExtended_observation)

            observation_data = self.__extract_data_from_dom(
                obs_data, self.domObservation, lHeader_keys, sHeader_xpath,
                lStandard_observation, lExtended_observation, dReadHandlers,
                sData_xpath)
        except:
            sXmlError = _("XML error in file '%s'.\n") % (sFilename) +\
                        sError
            raise metro_error.Metro_xml_error(sXmlError)

        # create observation collection
        lObservation_standard_attribute = metro_config.get_value(
            'DATA_ATTRIBUTE_OBSERVATION_STANDARD')
        lObservation_extended_attribute = metro_config.get_value(
            'DATA_ATTRIBUTE_OBSERVATION_EXTENDED')
        lObservation_attribute = lObservation_standard_attribute \
                                 + lObservation_extended_attribute
        observation = metro_data_collection_input.Metro_data_collection_input(
            observation_data, lObservation_attribute)

        #
        # observations_ref extraction
        #

        if self.domObservation_ref != None:

            # validate version number
            sFilename = metro_config.get_value('FILE_OBSERVATION_REF_FILENAME')
            sFile_version = \
                metro_xml.xpath(self.domObservation_ref,"*/version/text()")
            sMin_version = \
                metro_config.get_value('FILE_OBSERVATION_MIN_VERSION')
            sMax_version = \
                metro_config.get_value('FILE_OBSERVATION_MAX_VERSION')
            self.validate_file_version_number(sFilename, sFile_version,
                                              sMin_version, sMax_version)

            try:
                # concatenation of all header's keys
                lHeader_keys = \
                    metro_config.get_value('XML_OBSERVATION_HEADER_STANDARD_ITEMS') + \
                    metro_config.get_value('XML_OBSERVATION_HEADER_STANDARD_ITEMS')

                # xpath construction
                sHeader_xpath = metro_config.get_value(
                    'XML_OBSERVATION_XPATH_HEADER')
                sData_xpath = metro_config.get_value(
                    'XML_OBSERVATION_XPATH_MEASURE')

                # concatenation de tout les types d'observation
                lStandard_observation = metro_config.get_value( \
                    'XML_OBSERVATION_MEASURE_STANDARD_ITEMS')
                lExtended_observation = metro_config.get_value( \
                    'XML_OBSERVATION_MEASURE_EXTENDED_ITEMS')

                obs_data = metro_data.Metro_data(lStandard_observation,\
                                                 lExtended_observation)

                observation_data = \
                    self.__extract_data_from_dom(obs_data,
                                                 self.domObservation_ref,
                                                 lHeader_keys,
                                                 sHeader_xpath,
                                                 lStandard_observation,
                                                 lExtended_observation,
                                                 dReadHandlers,
                                                 sData_xpath)
            except:
                sXmlError = _("XML error in file '%s'.") % (sFilename)
                raise metro_error.Metro_xml_error(sXmlError)

            # create observation collection
            lObservation_standard_attribute = metro_config.get_value(
                'DATA_ATTRIBUTE_OBSERVATION_STANDARD')
            lObservation_extended_attribute = metro_config.get_value(
                'DATA_ATTRIBUTE_OBSERVATION_EXTENDED')
            lObservation_attribute = lObservation_standard_attribute \
                                     + lObservation_extended_attribute
            observation_ref = \
                metro_data_collection_input.\
                Metro_data_collection_input(observation_data,
                                            lObservation_attribute)

            pObservation_ref.set_data_collection(observation_ref)

        #
        # station extraction
        #

        # validate version number
        sFilename = metro_config.get_value('FILE_STATION_FILENAME')
        sFile_version = metro_xml.xpath(self.domStation, "*/version/text()")
        sMin_version = metro_config.get_value('FILE_STATION_MIN_VERSION')
        sMax_version = metro_config.get_value('FILE_STATION_MAX_VERSION')
        self.validate_file_version_number(sFilename, sFile_version,
                                          sMin_version, sMax_version)

        try:
            # concatenation of all header's keys
            lHeader_defs = \
                metro_config.get_value('XML_STATION_HEADER_STANDARD_ITEMS') + \
                metro_config.get_value('XML_STATION_HEADER_EXTENDED_ITEMS')

            # xpath construction
            sHeader_xpath = metro_config.get_value('XML_STATION_XPATH_HEADER')
            sData_xpath = metro_config.get_value('XML_STATION_XPATH_ROADLAYER')

            # concatenation of all the roadlayer sections
            lStandard_roadlayer = metro_config.get_value( \
                'XML_STATION_ROADLAYER_STANDARD_ITEMS')
            lExtended_roadlayer = metro_config.get_value( \
                'XML_STATION_ROADLAYER_EXTENDED_ITEMS')


            cs_data = metro_data_station.Metro_data_station(lStandard_roadlayer,\
                                                            lExtended_roadlayer)

            station_data = self.__extract_data_from_dom(
                cs_data, self.domStation, lHeader_defs, sHeader_xpath,
                lStandard_roadlayer, lExtended_roadlayer, dReadHandlers,
                sData_xpath)

        except:
            sXmlError = _("XML error in file '%s'.") % (sFilename)
            raise metro_error.Metro_xml_error(sXmlError)

#
# station horizon extraction
#

        if ((pHorizon != None) and (pHorizon.get_input_information() != None)):
            try:
                # concatenation of all header's keys
                lHeader_defs = \
                    metro_config.get_value('XML_STATION_HEADER_STANDARD_ITEMS') + \
                    metro_config.get_value('XML_STATION_HEADER_EXTENDED_ITEMS')

                # xpath construction
                sHeader_xpath = metro_config.get_value(
                    'XML_STATION_XPATH_HEADER')
                # xpath construction
                sHorizon_xpath = metro_config.get_value(
                    'XML_STATION_XPATH_HORIZON')

                # concatenation of all the horizon sections
                lStandard_horizon = metro_config.get_value( \
                    'XML_STATION_HORIZON_STANDARD_ITEMS')
                lExtended_horizon = metro_config.get_value( \
                    'XML_STATION_HORIZON_EXTENDED_ITEMS')

                cs_horizon_data = metro_data_station.\
                                         Metro_data_station(lStandard_horizon,\
                                                            lExtended_horizon)

                horizon_data = self.__extract_data_from_dom(
                    cs_horizon_data, self.domHorizon, lHeader_defs,
                    sHeader_xpath, lStandard_horizon, lExtended_horizon,
                    dReadHandlers, sHorizon_xpath)

            except:
                sXmlError = _("XML error in file '%s'.") % (sFilename)
                raise metro_error.Metro_xml_error(sXmlError)

            pHorizon.set_data(horizon_data)

        pForecast.set_data_collection(forecast)
        pObservation.set_data_collection(observation)
        pStation.set_data(station_data)