Parameters:
Importing operations from ‘text’ format; i.e. the data for each operation in a plain text file:
>>> from simo.input.importops import OperationImporter
>>> execfile('input/test/mock4importops.py')
>>> imp = OperationImporter(inputdb, fopsdb, 'text', opconv, op2mc, logger, logname, 100)
>>> imp.import_operations(textops, separator)
...
...
Called Logger.log_message('testlog', 'info', 'Importing forced operations...')
Called OperationDB.add_operation(
'stand1',
'comp_unit',
0,
0,
'clearcut',
'step',
2,
None,
'year',
['Cut', 'Cut some more'],
None,
ext_col_vals={'REGEN_SP': 3})
Called OperationDB.add_operation(
'stand2',
'comp_unit',
0,
0,
'first_thinning',
'step',
7,
None,
'year',
['Calculate thinning limits'],
None,
ext_col_vals={'TARGET_N': 500.0})
Called Logger.log_message('testlog', 'info', 'Forced operations imported!')
Called DataDB.db.commit()
Called OperationDB.db.commit()
Called OperationDB.db.vacuum_analyze()
Importing operations with timing type date and with defined operation id:
>>> imp.op_conv.op_id_rowpos = 8
>>> imp.op_conv.timing.type = 'date'
>>> imp.import_operations(textops2, separator)
...
...
Called Logger.log_message('testlog', 'info', 'Importing forced operations...')
Called OperationDB.add_operation(
'stand1',
'comp_unit',
0,
0,
'clearcut',
'date',
None,
datetime.date(2009, 5, 16),
None,
['Cut', 'Cut some more'],
'op1',
ext_col_vals={'REGEN_SP': 3})
Called OperationDB.add_operation(
'stand2',
'comp_unit',
0,
0,
'first_thinning',
'date',
None,
datetime.date(2009, 5, 6),
None,
['Calculate thinning limits'],
'op2',
ext_col_vals={'TARGET_N': 500.0})
Called Logger.log_message('testlog', 'info', 'Forced operations imported!')
Called DataDB.db.commit()
Called OperationDB.db.commit()
Called OperationDB.db.vacuum_analyze()
Importing operations from a database:
>>> imp.format = 'db'
>>> imp.import_operations(opdb, separator)
...
Called Logger.log_message('testlog', 'info', 'Importing forced operations...')
Called operation_DataDB.conn.execute(
'SELECT id, iteration, op_date, op_level, op_name FROM op_link ORDER BY id, op_date')
Called OperationDB.add_operation(
'stand1',
'comp_unit',
0,
0,
'clearcut',
'date',
None,
datetime.date(2009, 3, 27),
None,
['Cut', 'Cut some more'],
None,
ext_col_vals=None)
Called Logger.log_message('testlog', 'info', 'Forced operations imported!')
Called operation_DataDB.close()
Called DataDB.db.commit()
Called OperationDB.db.commit()
Called OperationDB.db.vacuum_analyze()
Checks that the current line is valid and then splits the line with the given separator
Parameters
line -- input data line, string
sep -- column separator, string or None
Split some valid rows
>>> imp._split_row('1;2;3;4;5', ';')
['1', '2', '3', '4', '5']
>>> imp._split_row('1 2 3 4 5', ' ')
['1', '2', '3', '4', '5']
>>> imp._split_row('1 2 3 4 5', ' ')
['1', '', '2', '', '3', '', '4', '', '5']
>>> imp._split_row('1 2 3 4 5', None)
['1', '2', '3', '4', '5']
>>> imp._split_row('1\t2\t3\t4\t5', '\t')
['1', '2', '3', '4', '5']
Try to split some rows with mismatching line content and separator
>>> imp._split_row('1\t2\t3\t4\t5', ' ')
>>> imp._split_row('1 2 3 4 5', '\t')
>>> imp._split_row('1;2;3;4;5', ' ')
>>> imp._split_row('1;2;3;4;5', ',')
Split some invalid rows
>>> imp._split_row(' THIS IS AN ERRONEUS ROW ', '\t')
>>> imp._split_row(' THIS IS AN ERRONEUS ROW ', ';')
>>> imp._split_row(' ', ' ')
Still, some rows might be invalid, but impossible to block
>>> imp._split_row(' THIS IS AN ERRONEUS ROW ', ' ')
['', 'THIS', 'IS', 'AN', 'ERRONEUS', 'ROW', '', '', '']