>>> import datetime
Class for expression output, i.e. output variables defined with a syntax similar to optimisation task definitions
Creates the output class. fully inherited, executes self.run()
>>> from simo.output.test.init_objects import *
>>> from collections import defaultdict
>>> import datetime
>>> import numpy
>>> idata = InitData()
>>> idata.init()
>>> testdb = idata.testdb
>>> const_obj = idata.const_obj
>>> aggr_obj = idata.aggr_obj
>>> expr_obj = idata.expr_obj
>>> from simo.output.expression import OutputExpr
>>> out = OutputExpr(testdb, 'result', ['stand1'], 'stratum',
... 'optimized',
... 'output/test/expression.txt', TestLogger(),
... const_obj, 1, False, True, aggr_obj, expr_obj,
... ['cash_flow', 'Income', 'Scrapwood', 'Volume',
... 'BIOMASS_branches', 'BIOMASS_stumps'])
>>> try:
... f = open('output/test/expression.txt', 'r')
... for line in f:
... print line.rstrip('\n')
... finally:
... f.close()
level;unit;iteration;branch;1st expression;2nd expression
comp_unit;stand1;0;0;0.0;0.0
comp_unit;stand1;1;0;0.0;0.0
comp_unit;stand2;0;0;0.0;0.0
comp_unit;stand2;0;1;0.0;0.0
comp_unit;stand2;1;0;0.0;0.0
comp_unit;stand2;1;1;0.0;0.0
stratum;stratum1-1;0;0;0.0;0.0
stratum;stratum1-1;1;0;0.0;0.0
stratum;stratum1-2;0;0;0.0;0.0
stratum;stratum1-2;1;0;0.0;0.0
stratum;stratum2-1;0;0;31.0;0.0
stratum;stratum2-1;1;0;31.0;0.0
stratum;stratum2-2;0;0;0.0;0.0
stratum;stratum2-2;1;0;0.0;0.0
stratum;stratum2-3;0;1;0.0;0.0
stratum;stratum2-3;1;1;0.0;0.0
Uses data from init to run the class-specific output (self.expression)
Executes the given expression dictionary for all reporting periods and return the results in a list of lists of strings.
Executes the given aggregation set with the given values and returns results as a list of strings.
Go through expressions and input database and analyse some data properties.
Go through the expressions and try to deduce data levels and earliest and latest dates.
Create expression data tables, using Numpy arrays.
Fill expression data tables with values from input databases.
Get values for a single expression operand from either data or operation result database.
Parameters:
epxr -- subobjective or constraint expression in postfix form
array -- target Numpy array
Get value(s) for a single operand from data or operation result database.
Parameters:
operand -- expression operand, i.e. variable, value or operator
dates -- date range
norm -- boolean indicating whether a normal or condition operand
condition -- operand condition
forced_level -- forced level name, i.e. use this level for getting the data
Evaluate operand constraint and store only those objects for which the condition evaluated True.
Parameters:
dates -- date range
arr -- temporary data array
operand -- current operand
norm -- boolean indicating whether a normal or condition operand
Store a single value into a correct location in a matrix and update branch number container.
Parameters:
array -- Numpy array
it -- iteration, int
uid -- object id, str
br -- branch, int
i_e -- expression operand index, int
date -- datetime object
value -- value to store, float
Filter data so that only the values from the last recorded date of each iteration-branch-object combination are selected. This is needed when operand dates are defined as [-1:-1]
Parameters
data -- data generator object from datadb
>>> data = [
... ('1', 0, datetime.date(2000,12,31), 1000.),
... ('1', 0, datetime.date(2005,12,31), 1005.),
... ('1', 0, datetime.date(2010,12,31), 1010.),
... ('1', 1, datetime.date(2000,12,31), 1100.),
... ('1', 1, datetime.date(2005,12,31), 1105.),
... ('1', 1, datetime.date(2010,12,31), 1110.),
... ('2', 0, datetime.date(2000,12,31), 2000.),
... ('2', 0, datetime.date(2005,12,31), 2005.),
... ('2', 0, datetime.date(2010,12,31), 2010.),
... ('2', 1, datetime.date(2000,12,31), 2100.),
... ('2', 1, datetime.date(2005,12,31), 2105.),
... ('2', 1, datetime.date(2010,12,31), 2110.)]
>>> data = out._filter_data_by_last_date(data)
>>> for item in data: print item
('1', 1, datetime.date(2010, 12, 31), 1110.0)
('2', 0, datetime.date(2010, 12, 31), 2010.0)
('1', 0, datetime.date(2010, 12, 31), 1010.0)
('2', 1, datetime.date(2010, 12, 31), 2110.0)
Construct strings from expression value table contents for output.