Exemplo n.º 1
0
    def test_policytc_ids(self, fm_items):

        fm_items.sort(key=lambda it: it['level_id'])

        for it in fm_items:
            it['attachment'] = 0 if it['level_id'] < 6 else it['deductible']
            it['calcrule_id'] = (get_sub_layer_calcrule_id(
                it['deductible'], it['deductible_min'], it['deductible_max'],
                it['limit']) if it['level_id'] < 6 else get_layer_calcrule_id(
                    it['attachment'], it['limit'], it['share'])) or -1

        term_combs = {}

        ptc_id = 0
        for i, it in enumerate(fm_items):
            t = (
                it['limit'],
                it['deductible'],
                it['deductible_min'],
                it['deductible_max'],
                it['attachment'],
                it['share'],
                it['calcrule_id'],
            )
            if t not in term_combs.values():
                ptc_id += 1
                term_combs[ptc_id] = t

        fm_items_df = pd.DataFrame(data=fm_items)

        policytc_ids = get_policytc_ids(fm_items_df)

        for policytc_id, policytc_comb in policytc_ids.items():
            t = dict(
                zip((
                    'limit',
                    'deductible',
                    'deductible_min',
                    'deductible_max',
                    'attachment',
                    'share',
                    'calcrule_id',
                ), term_combs[policytc_id]))
            self.assertEqual(t, policytc_comb)
Exemplo n.º 2
0
    def test_exposure_with_one_coverage_type_and_fm_terms_with_one_account_and_one_top_level_layer_per_account_and_model_lookup_supporting_single_peril_and_coverage_type__all_non_coverage_level_terms_generated(
            self, exposures, accounts, fm_items):
        ufcp = self.unified_canonical_profile

        for i, _ in enumerate(exposures):
            exposures[i]['cond1name'] = fm_items[i]['cond1name'] = 0

        levels = sorted(ufcp.keys())
        levels.remove(min(levels))

        cacc_it = accounts[0]

        for l in levels:
            lufcp = ufcp[l]

            lfmaggp = self.fm_agg_profile[l]

            ded_fld = lufcp[1].get('deductible')
            ded_elm = ded_fld['ProfileElementName'].lower(
            ) if ded_fld else None
            ded_min_fld = lufcp[1].get('deductiblemin')
            ded_min_elm = ded_min_fld['ProfileElementName'].lower(
            ) if ded_min_fld else None
            ded_max_fld = lufcp[1].get('deductiblemax')
            ded_max_elm = ded_max_fld['ProfileElementName'].lower(
            ) if ded_max_fld else None

            lim_fld = lufcp[1].get('limit')
            lim_elm = lim_fld['ProfileElementName'].lower(
            ) if lim_fld else None

            shr_fld = lufcp[1].get('share')
            shr_elm = shr_fld['ProfileElementName'].lower(
            ) if shr_fld else None

            for i, it in enumerate(fm_items):
                it['level_id'] = l
                it['index'] = i

                it['agg_id'] = i + 1 if l in [1, 2, 3] else 1

                cexp_it = exposures[it['canexp_id']]

                if ded_fld and ded_fld['ProfileType'].lower() == 'loc':
                    cexp_it[ded_elm] = 1
                elif ded_fld and ded_fld['ProfileType'].lower() == 'acc':
                    cacc_it[ded_elm] = 1

                if ded_min_fld and ded_min_fld['ProfileType'].lower() == 'loc':
                    cexp_it[ded_min_elm] = 0
                elif ded_min_fld and ded_min_fld['ProfileType'].lower(
                ) == 'acc':
                    cacc_it[ded_min_elm] = 0

                if ded_max_fld and ded_max_fld['ProfileType'].lower() == 'loc':
                    cexp_it[ded_max_elm] = 0
                elif ded_max_fld and ded_max_fld['ProfileType'].lower(
                ) == 'acc':
                    cacc_it[ded_max_elm] = 0

                it['attachment'] = 0 if l < max(levels) else cacc_it[ded_elm]

                if lim_fld and lim_fld['ProfileType'].lower() == 'loc':
                    cexp_it[lim_elm] = 1
                elif lim_fld and lim_fld['ProfileType'].lower() == 'acc':
                    cacc_it[lim_elm] = 1

                if shr_fld and shr_fld['ProfileType'].lower() == 'loc':
                    cexp_it[shr_elm] = 0
                elif shr_fld and shr_fld['ProfileType'].lower() == 'acc':
                    cacc_it[shr_elm] = 0

            level_fm_terms_func = get_sub_layer_non_coverage_level_fm_terms if l < max(
                levels) else get_layer_level_fm_terms

            results = [
                r for r in level_fm_terms_func(
                    lufcp,
                    lfmaggp,
                    {i: it
                     for i, it in enumerate(fm_items)},
                    pd.DataFrame(data=exposures),
                    pd.DataFrame(data=accounts),
                )
            ]

            self.assertEqual(len(fm_items), len(results))

            self.assertEqual(tuple(it['item_id'] for it in fm_items),
                             tuple(r['item_id'] for r in results))

            for i, res in enumerate(results):
                it = fm_items[i]

                self.assertEqual(it['level_id'], res['level_id'])
                self.assertEqual(it['index'], res['index'])
                self.assertEqual(it['item_id'], res['item_id'])
                self.assertEqual(it['gul_item_id'], res['gul_item_id'])

                self.assertEqual(it['canexp_id'], res['canexp_id'])
                self.assertEqual(it['canacc_id'], res['canacc_id'])

                self.assertEqual(it['peril_id'], res['peril_id'])
                self.assertEqual(it['coverage_type_id'],
                                 res['coverage_type_id'])

                self.assertEqual(it['layer_id'], res['layer_id'])
                self.assertEqual(it['agg_id'], res['agg_id'])

                self.assertEqual(it['tiv_elm'], res['tiv_elm'])
                self.assertEqual(it['tiv_tgid'], res['tiv_tgid'])

                self.assertEqual(it['ded_elm'], res['ded_elm'])
                self.assertEqual(it['ded_min_elm'], res['ded_min_elm'])
                self.assertEqual(it['ded_max_elm'], res['ded_max_elm'])

                self.assertEqual(it['lim_elm'], res['lim_elm'])

                self.assertEqual(it['shr_elm'], res['shr_elm'])

                self.assertEqual(it['tiv'], res['tiv'])

                self.assertEqual(it['deductible'], res['deductible'])
                self.assertEqual(it['deductible_min'], res['deductible_min'])
                self.assertEqual(it['deductible_max'], res['deductible_max'])

                self.assertEqual(it['attachment'],
                                 (0 if l < max(levels) else it['deductible']))

                self.assertEqual(it['limit'], res['limit'])

                self.assertEqual(it['share'], res['share'])

                calcrule_id = (get_sub_layer_calcrule_id(
                    it['deductible'], it['deductible_min'],
                    it['deductible_max'], it['limit'])
                               if l < max(levels) else get_layer_calcrule_id(
                                   it['attachment'], it['limit'], it['share']))
                self.assertEqual(calcrule_id, res['calcrule_id'])
Exemplo n.º 3
0
 def test_calcrule_id_2__with_positive_attachment_and_limit(
         self, attachment, limit, share):
     self.assertEqual(get_layer_calcrule_id(attachment, limit, share), 2)