>>> from simo.builder.modelbase.modelbase import ModelbaseDef
>>> tdf = open('../../simulator/xml/schemas/Typedefs_SIMO.xsd')
>>> typedef = tdf.read()
>>> tdf.close()
>>> sf = open('../../simulator/xml/schemas/cash_flow_modelbase.xsd')
>>> schema = sf.read()
>>> sf.close()
>>> xml = u'''<cash_flow_modelbase 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/cash_flow_modelbase.xsd">
... <cash_flow_model>
... <name>random_prices</name>
... <implemented_at>cashflowmodels.py</implemented_at>
... <implemented_in>python</implemented_in>
... <reference_values>
... <cash_flow_tables>
... <cash_flow_table>timber_prices</cash_flow_table>
... </cash_flow_tables>
... </reference_values>
... <variables>
... <variable>
... <name>Testname</name>
... <level>Testlevel</level>
... </variable>
... </variables>
... </cash_flow_model>
... </cash_flow_modelbase>
... '''
>>> class Lexicon(object):
... def __init__(self):
... self.models = {}
... def get_variable_ind(self, level, variable, active=False):
... return (1, 1)
... def get_level_ind(self, level):
... return 1
... def add_model(self, mtype, mname):
... if mtype not in self.models:
... self.models[mtype] = set()
... self.models[mtype].add(mname)
>>> mb = ModelbaseDef(typedef)
>>> mb.schema = ('cash_flow', schema)
>>> mb.xml = ('testxml', xml, Lexicon(), '', 'cash_flow')
>>> mb.xml['cash_flow']['testxml'][:16]
u'<cash_flow_model'
cash flow model
Attributes:
-name -at: the model library name in which the model implementation is found -variables: a list of variable definitions
Parses the XML data into model instance attributes:
>>> cf = mb.obj['cash_flow']['testxml']['random_prices']
>>> cf.name
'random_prices'
>>> cf.language
'python'
>>> cf.variables
[(1, 1)]