def main_wc_gc_model(): config = ConfigParser.ConfigParser() config.read('config/model_config.config') app_log = setup_logging('wc_gc_logger', config.get('logger', 'log_file_name')) app_log.info('Scoring DUNS number: %d' % user_duns_number) rate_lookup_table = read_rate_lookup( config.get('data_files', 'rate_lookup'), user_is_uslh) input_data['lookup_key'] = input_data['state'] + input_data['class_code'] avg_rates = merge_rate_lookup(input_data, rate_lookup_table) entered_ratios = calc_entered_payroll_ratios(input_data) inputs_valid, reason = check_inputs(input_data, entered_ratios) if not inputs_valid: return (numpy.NaN, numpy.NaN, numpy.NaN, reason) payrolls = calc_payroll_ratio(input_data) calc_allocate_clerical_payroll(payrolls, user_estimated_clerical_payroll) calc_clerical_class_premium(payrolls, rate_lookup_table) calc_standard_premium(payrolls, user_experience_mod) standard_premium_to_allocate = calc_missing_standard_premium( payrolls, avg_rates, user_experience_mod) calc_allocated_standard_premium(payrolls, standard_premium_to_allocate) calc_premium_discount(payrolls, config.getfloat('constants', 'other_loadings'), eval(config.get('data_files', 'ncci_tier_files'))) state_rate_data = merge_wcng_lr_rate_need( payrolls, user_division, user_effective_date, user_is_uslh, config.get('data_files', 'state_rate_need_lookup'), config.get('data_files', 'wcng_lr')) credit_scores = get_dnb_scores( user_duns_number, default_credit_score_pct=config.get('constants', 'default_duns_cs_pct'), default_financial_score_pct=config.get('constants', 'default_duns_fs_pct')) total_class_premium = input_data['class_premium'].sum() predom_state = input_data.groupby( by='state')['class_premium'].sum().idxmax(axis=1) model_inputs = calc_normalized_claim_counts( input_history, predom_state, eval(config.get('aqi', 'aqi_data')), total_class_premium, config.get('data_files', 'cdf_file')) model_inputs['credit_score_pct'] = credit_scores['credit_score_pct'] model_inputs['financial_score_pct'] = credit_scores['financial_score_pct'] model_inputs['payroll'] = user_total_projected_payroll model_inputs['major_group'] = get_sic_major_group(user_sic_code) predicted_lr = run_model( model_inputs, config.get('data_files', 'model_coefficients_file'), eval(config.get('model_rules', 'rules'))) state_rate_data['target_pricing_deviation_factor'] = ( ((predicted_lr / state_rate_data['avg_wcng_loss_ratio']) * state_rate_data['variable_rate_need']) + state_rate_data['fix_rate_need']) state_rate_data['estimated_premium'] = state_rate_data[ 'target_pricing_deviation_factor'] * state_rate_data[ 'manual_rate_pre_model'] output_midpoint = state_rate_data['estimated_premium'].sum() lower_ratio, upper_ratio = calc_diamond_bound_ratios( entered_ratios['clerical'], entered_ratios['non_clerical'], config.get('data_files', 'bound_ratios')) return (output_midpoint * lower_ratio, output_midpoint, output_midpoint * upper_ratio, '')
def test_string_dnb(self): with self.assertRaises(TypeError): get_dnb_scores('123')
def test_bad_dnb(self): scores = get_dnb_scores(123.456) # Have to use assertIn since NaN == NaN gives False self.assertIn(scores['credit_score_pct'], [NaN]) self.assertIN(scores['financial_score_pct'], [NaN])
def test_null_dnb(self): with self.assertRaises(TypeError): get_dnb_scores(None)
def test_vanilla(self): scores = get_dnb_scores(608201141) self.assertIn('credit_score_pct', scores) self.assertIn('financial_score_pct', scores) self.assertIsInstance(scores['credit_score_pct'], float) self.assertIsInstance(scores['financial_score_pct'], float)