var rater =
;
rater.fromMap =
function(d,c){c(d);}
;
rater._retmap =
function(d,c){c(d);}
;
module.exports = function( args_base ) {
var ret; rater.fromMap( args_base, function( args ) {
var rater_result = rater( args );
// perf counter
var start = ( new Date() ).getTime();
rater._retmap( rater_result.vars, function( result )
{
// add the final premium
result.premium = rater_result.premium;
result.__classes = rater_result.classes;
// process the rating worksheet
try
{
result.__worksheet = process_worksheet(
rater.worksheet,
rater_result.vars,
rater_result.consts,
rater_result.debug,
rater_result.premium
);
}
catch ( e )
{
result.__worksheet = [ 'Failed: ' + e.message ];
}
ret = result;
} );
// add performance data
var end = ( new Date() ).getTime(),
time = ( ( new Date() ).getTime() - start );
ret.__perf = {
time: {
start: start,
end: end,
total: time
}
};
} );
return ret;
};
function process_worksheet( worksheet, vars, consts, debug, premium )
{
var ret = {};
for ( var name in worksheet )
{
var data = Array.prototype.slice.call( worksheet[ name ] ),
disp = data[0],
calc = data[1],
always = data[2];
ret[ name ] = [
disp,
process_wdisplay_set( [calc], vars, consts, debug ),
( ( name === 'yield' )
? premium
: ( vars[ name ] || consts[ name ] )
),
( always === 'true' )
];
}
return ret;
}
function process_wdisplay( data, vars, consts, debug )
{
if ( data === null )
{
return null;
}
var name = data[ 0 ],
desc = data[ 1 ],
sub = data[ 2 ],
val = data[ 3 ]; // may not exist
return [
name,
desc,
process_wdisplay_set( sub, vars, consts, debug ),
val || process_wval( name, desc, vars, consts, debug )
];
}
function process_wval( type, desc, vars, consts, debug )
{
if ( desc.runtime )
{
type = 'runtime';
}
switch ( type )
{
case 'apply':
case 'cases':
case 'case':
case 'otherwise':
case 'runtime':
return ( debug[ desc._id ] );
case 'value-of':
return ( vars[ desc.name ] || consts[ desc.name ] );
default:
return '';
}
}
function process_wdisplay_set( sub, vars, consts, debug )
{
var ret = [],
i = sub.length;
while ( i-- )
{
if ( sub[ i ] === undefined )
{
continue;
}
ret[ i ] = process_wdisplay( sub[ i ], vars, consts, debug );
}
return ret;
}
module.exports.rater = rater;