Table Of Contents

Previous topic

aggrdef.py

Next topic

outputconstraint.py

This Page

exprdef.py

exprdef test definitions:

>>> from lxml import etree
>>> import datetime
>>> from pprint import pprint
>>> from simo.builder.output.exprdef import ExpressionOutputDef
>>> tdf = open('../../simulator/xml/schemas/Typedefs_SIMO.xsd')
>>> typedef = tdf.read()
>>> tdf.close()
>>> sf = open('../../simulator/xml/schemas/expression_definition.xsd')
>>> schema = sf.read()
>>> sf.close()
>>> xml = '''<?xml version="1.0" encoding="UTF-8"?>
... <expression_definition
...     xmlns="http://www.simo-project.org/simo"
...     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
...     xsi:schemaLocation="http://www.simo-project.org/simo
...         ../schemas/item_definition.xsd">
...     <initial_date>2009-01-01</initial_date>
...     <discount_rate>3.0</discount_rate>
...     <expressions>
...         <item>
...             <expression>sum[-1:-1](stratum:SP*stratum:HgM)</expression>
...             <label>1st item</label>
...         </item>
...         <item>
...             <expression>sum[-1:-1](operation:Volume)</expression>
...             <label>2nd item</label>
...         </item>
...     </expressions>
... </expression_definition>'''

class ExpressionOutputDef(XmlObject):

Expression output definitions.

def __init__(self, typedef):

>>> aodef = ExpressionOutputDef(typedef)
>>> aodef.schema = schema
>>> aodef.xml = ('test data', xml, None)

class ExpressionOutput(object):

Expressionoutput info.

def __init__(self, ns, root, validator):

>>> ao = aodef.obj['test data']
>>> pprint(ao.data) 
{'discount_rate': 3.0,
 'expression_variables': [{'expression': 'sum[-1:-1](stratum:SP*stratum:HgM)',
                           'label': '1st item'},
                          {'expression': 'sum[-1:-1](operation:Volume)',
                           'label': '2nd item'}],
 'initial_date': datetime.date(2009, 1, 1)}

def _parse(self, root):

Parses the agregation output instructions into self.data