Commit 5664bda0 authored by François Fortin's avatar François Fortin
Browse files

add code to write list in roadcast

output hardcoded value for now.
parent 1e7347a6
......@@ -238,6 +238,7 @@ class Metro_metro2dom( Metro_module ):
#
# Data creation
naMatrix = metro_data.get_matrix()
metro_xml.create_node_tree_from_matrix(domDoc, nodePrediction,
sPrediction_node_name,
lPrediction_keys,
......
......@@ -93,7 +93,8 @@ CFG_LONG_OPTIONS = ["help","version",
"generate-dtd-catalog",
"config=","generate-config=","log-file=","verbose-level=",
"selftest", "silent", "roadcast-start-date=", "lang=",
"use-solarflux-forecast", "use-infrared-forecast"]
"use-solarflux-forecast", "use-infrared-forecast",
"level"]
......@@ -394,6 +395,14 @@ def save_command_line_parameter( lArgv, sShort_opt, lLong_opt ):
'VALUE'].append(dSFDict)
if o == "--level":
dConfig['TL']['VALUE'] = True
dTLDict= {'NAME':"TL",
'XML_TAG':"tl",
'DATA_TYPE':"LIST_LEVEL_TEMP"}
dConfig['XML_ROADCAST_PREDICTION_EXTENDED_ITEMS'][\
'VALUE'].append(dTLDict)
# Selftest value
if o == "--selftest":
dConf['INIT_ROADCAST_START_DATE'] = "2004-01-30T20:00Z"
......@@ -574,7 +583,15 @@ def set_default_value( ):
'XML_TAG':"longitude",
'DATA_TYPE':'REAL'},
]},
'LIST_LEVEL_TEMP': \
{'READ' :"",
'WRITE':"metro_metro2dom_handler.write_list",
'CHILD':[{'NAME':"LEV-TEMP",
'XML_TAG':"lev-temp",
'DATA_TYPE':'REAL'}
]},
'ROADLAYER_TYPE': \
{'READ' :"metro_dom2metro_handler.read_roadlayer_type",
'WRITE':""},
......@@ -1004,6 +1021,7 @@ def set_default_value( ):
'XML_TAG':"sst",
'DATA_TYPE':"REAL",
'PRECISION':2},
],
'FROM' :CFG_INTERNAL,
......@@ -1172,6 +1190,12 @@ def set_default_value( ):
'FROM' :CFG_HARDCODED,
'COMMENTS':_("Use solar flux value from forecast")}
dConfig['TL'] = \
{'VALUE' :False,
'FROM' :CFG_HARDCODED,
'COMMENTS':_("Output levels (TL) in roadcast")}
# ---------------------------- observation ---------------------------------
......
......@@ -40,6 +40,7 @@ import string
import metro_config
from toolbox import metro_xml
from toolbox import metro_date
from toolbox import metro_util
def write_string( domDoc, sXml_tag, sString ):
return metro_xml.create_text_node(domDoc, sXml_tag, sString)
......@@ -54,6 +55,47 @@ def write_date( domDoc, sXml_tag, fDate ):
sDate = metro_date.seconds2iso8601(fDate)
return metro_xml.create_text_node(domDoc, sXml_tag, sDate)
def write_list( domDoc, sXml_list_tag, lChildList, lValues ):
lValues=[0.2,3.4]
listNode = metro_xml.create_node( domDoc, sXml_list_tag)
# print "domDoc=" + str(domDoc)
# print "xmltag=" + str(sXml_tag1)
# print "lChildList=" + str(lChildList)
# print "toto=" + str(lValues)
#
# Get handler
#
dDef = lChildList[0]
sWriteHandler = metro_xml.get_handler('WRITE', dDef)
sImportHandlerCode = metro_xml.get_handler_import_code(sWriteHandler)
exec sImportHandlerCode
sXml_tag = dDef['XML_TAG']
#
# Add value to listNode
#
for val in lValues:
# Construction of instruction doing the function call that will
# create the node
sCode = "nodeData = " + sWriteHandler + "(domDoc,sXml_tag,val)"
exec sCode
metro_xml.append_child(listNode,nodeData)
return listNode
def integer_to_string(iNumber, iWidth=0):
sNumber = str(iNumber)
if len(sNumber) < iWidth:
......
......@@ -199,6 +199,7 @@ def extract_data(lDefs, nodeItems):
for dDef in lDefs:
# Get the name and the type of the item
sTag = dDef['XML_TAG']
sData_type_name = dDef['DATA_TYPE']
if sData_type_name not in dData_type.keys():
......@@ -427,3 +428,40 @@ def create_node_tree_from_matrix( domDoc, nodeParent, sPrediction_xpath,
exec sCode
append_child(nodePrediction, nodeData)
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
def get_handler_import_code(sHandler):
# Creation of code needed to import the module in which we can find
# the function used to create the node.
lFunctionPart = string.split(sHandler,'.')
sFunction_module = string.join(lFunctionPart[:-1],".")
sCode = "import " +sFunction_module
return sCode
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment