complex_model/HailAUSKeysLookup.py
def create_uni_exposure(self, record, coverage_type: int):
        """This creates a uni_exposure object from an oasis loc object.
        The u_exposure table contains the following columns:

        loc_id, latitude, longitude, address_type, address_id, best_res, country_code, state, zone_type, zone_id,
        catchment_type, catchment_id, lrg_type, lrg_id, med_type, med_id, fine_type, fine_id, lob_id, props, modelled,
        origin_file_line

        :param record: a row from a OED portfolio
        :param coverage_type: is a either building [1], contents [3], other [3] (motor) or business interruption [4]
        :return: a uni_exposure object as per the Multi-Peril Workbench specification
        """

        self._pre_validate(record, coverage_type)

        uni_exposure = dict()
        uni_exposure['loc_id'] = str(record['loc_id'])
        uni_exposure['lob_id'] = self._get_lob_id(record)
        uni_exposure['cover_id'] = oed_to_rf_coverage(coverage_type, self._is_motor(record))

        # OED: country error_code is also required but we'll default to AU if missing
        try:
            uni_exposure['country_code'] = str(record["countrycode"]).lower()
        except (ValueError, KeyError):
            uni_exposure['country_code'] = COUNTRY_CODE

        # address, ICA zone and cresta
        uni_exposure['address_id'] = None
        uni_exposure['address_type'] = None
        uni_exposure['med_id'] = None
        uni_exposure['med_type'] = None
        uni_exposure['lrg_id'] = None
        uni_exposure['lrg_type'] = None
        uni_exposure['zone_id'] = None
        uni_exposure['zone_type'] = None
        for i in range(1, 6):
            geog_scheme_col = "geogscheme" + str(i)
            geog_name_col = "geogname" + str(i)
            try:
                if geog_scheme_col in record and geog_name_col in record:
                    uni_exposure = self._add_geog_name(uni_exposure, record[geog_scheme_col], record[geog_name_col])
            except (ValueError, TypeError):
                pass

        # overwrite postcode from 'postalcode' field
        if 'postalcode' in record and self.is_valid_postcode(record['postalcode']):
            postcode = int(record['postalcode'])
            if postcode in DELIVERY_POSTCODE_SET:
                postcode = POSTCODE_CONCORDANCE[str(postcode)]
            uni_exposure['med_id'] = postcode
            uni_exposure['med_type'] = EnumResolution.Postcode.value

        # lat/lon
        uni_exposure['latitude'] = None
        uni_exposure['longitude'] = None
        if 'longitude' in record and is_float(record['longitude']) \
                and 'latitude' in record and is_float(record['latitude']) \
                and not record['longitude'] == 0 and not record['latitude'] == 0 \
                and not math.isnan(record['longitude']) and not math.isnan(record['latitude']):
            if AU_BOUNDING_BOX['MIN'][0] <= record["longitude"] <= AU_BOUNDING_BOX['MAX'][0] \
                    and AU_BOUNDING_BOX['MIN'][1] <= record["latitude"] <= AU_BOUNDING_BOX['MAX'][1]:
                uni_exposure['latitude'] = record['latitude']
                uni_exposure['longitude'] = record['longitude']
                if (uni_exposure['med_id'] is None or uni_exposure['med_id'] == 0) and self._postcode_lookup:
                    uni_exposure['med_id'] = self._postcode_lookup.get_postcode(record["longitude"], record["latitude"])
                if uni_exposure['lrg_id'] is None or uni_exposure['lrg_id'] == 0:
                    pass  # not required at lat/lon level
            else:
                raise LocationLookupException("Location is not in Australia", error_code=121)

        # setting best res
        if uni_exposure['lrg_id'] is not None and uni_exposure['lrg_id'] > 0:
            uni_exposure['best_res'] = EnumResolution.IcaZone.value
        if uni_exposure['zone_id'] is not None and uni_exposure['zone_id'] > 0:
            uni_exposure['best_res'] = EnumResolution.Cresta.value
        if uni_exposure['med_id'] is not None and uni_exposure['med_id'] > 0:
            uni_exposure['best_res'] = EnumResolution.Postcode.value
        if uni_exposure['address_id'] is not None and \
                self.is_valid_address(uni_exposure['address_id'], uni_exposure['address_type']):
            uni_exposure['best_res'] = EnumResolution.Address.value
        if uni_exposure['latitude'] is not None and uni_exposure['longitude'] is not None:
            uni_exposure['best_res'] = EnumResolution.LatLong.value

        uni_exposure['state'] = None
        if 'areacode' in record and str(record["areacode"]).upper() in AU_STATES:
            uni_exposure['state'] = str(record["areacode"]).upper()

        # uni_exposure['catchment_type'] # todo: when implementing flood
        # uni_exposure['catchment_id']

        # uni_exposure['fine_type']
        # uni_exposure['fine_id']

        # uni_exposure["props"]
        props = {}
        try:
            props["YearBuilt"] = self.sanitize_year_built(int(record['yearbuilt']))
        except (ValueError, TypeError, KeyError):
            pass

        try:
            props['StaticMotor'] = self.sanitize_smv(record, to_bool(record['staticmotorvehicle']))
        except (ValueError, TypeError, KeyError):
            pass

        uni_exposure['props'] = props
        # uni_exposure['modelled'] # todo: when implementing flood, check that location is in flood zone

        return self._post_validate(uni_exposure, record)
This creates a uni_exposure object from an oasis loc object.
        The u_exposure table contains the following columns:

        loc_id, latitude, longitude, address_type, address_id, best_res, country_code, state, zone_type, zone_id,
        catchment_type, catchment_id, lrg_type, lrg_id, med_type, med_id, fine_type, fine_id, lob_id, props, modelled,
        origin_file_line

        :param record: a row from a OED portfolio
        :param coverage_type: is a either building [1], contents [3], other [3] (motor) or business interruption [4]
        :return: a uni_exposure object as per the Multi-Peril Workbench specification
        
This creates a uni_exposure object from an oasis loc object.
The u_exposure table contains the following columns.


This creates a uni_exposure object from an oasis loc object . The u_exposure table contains the following columns .
def create_uni_exposure(self, record, coverage_type: int):
        self._pre_validate(record, coverage_type)
        uni_exposure = dict()
        uni_exposure['loc_id'] = str(record['loc_id'])
        uni_exposure['lob_id'] = self._get_lob_id(record)
        uni_exposure['cover_id'] = oed_to_rf_coverage(coverage_type, self._is_motor(record))
        try:
            uni_exposure['country_code'] = str(record["countrycode"]).lower()
        except (ValueError, KeyError):
            uni_exposure['country_code'] = COUNTRY_CODE
        uni_exposure['address_id'] = None
        uni_exposure['address_type'] = None
        uni_exposure['med_id'] = None
        uni_exposure['med_type'] = None
        uni_exposure['lrg_id'] = None
        uni_exposure['lrg_type'] = None
        uni_exposure['zone_id'] = None
        uni_exposure['zone_type'] = None
        for i in range(1, 6):
            geog_scheme_col = "geogscheme" + str(i)
            geog_name_col = "geogname" + str(i)
            try:
                if geog_scheme_col in record and geog_name_col in record:
                    uni_exposure = self._add_geog_name(uni_exposure, record[geog_scheme_col], record[geog_name_col])
            except (ValueError, TypeError):
                pass
        if 'postalcode' in record and self.is_valid_postcode(record['postalcode']):
            postcode = int(record['postalcode'])
            if postcode in DELIVERY_POSTCODE_SET:
                postcode = POSTCODE_CONCORDANCE[str(postcode)]
            uni_exposure['med_id'] = postcode
            uni_exposure['med_type'] = EnumResolution.Postcode.value
        uni_exposure['latitude'] = None
        uni_exposure['longitude'] = None
        if 'longitude' in record and is_float(record['longitude']) \
                and 'latitude' in record and is_float(record['latitude']) \
                and not record['longitude'] == 0 and not record['latitude'] == 0 \
                and not math.isnan(record['longitude']) and not math.isnan(record['latitude']):
            if AU_BOUNDING_BOX['MIN'][0] <= record["longitude"] <= AU_BOUNDING_BOX['MAX'][0] \
                    and AU_BOUNDING_BOX['MIN'][1] <= record["latitude"] <= AU_BOUNDING_BOX['MAX'][1]:
                uni_exposure['latitude'] = record['latitude']
                uni_exposure['longitude'] = record['longitude']
                if (uni_exposure['med_id'] is None or uni_exposure['med_id'] == 0) and self._postcode_lookup:
                    uni_exposure['med_id'] = self._postcode_lookup.get_postcode(record["longitude"], record["latitude"])
                if uni_exposure['lrg_id'] is None or uni_exposure['lrg_id'] == 0:
                    pass  
            else:
                raise LocationLookupException("Location is not in Australia", error_code=121)
        if uni_exposure['lrg_id'] is not None and uni_exposure['lrg_id'] > 0:
            uni_exposure['best_res'] = EnumResolution.IcaZone.value
        if uni_exposure['zone_id'] is not None and uni_exposure['zone_id'] > 0:
            uni_exposure['best_res'] = EnumResolution.Cresta.value
        if uni_exposure['med_id'] is not None and uni_exposure['med_id'] > 0:
            uni_exposure['best_res'] = EnumResolution.Postcode.value
        if uni_exposure['address_id'] is not None and \
                self.is_valid_address(uni_exposure['address_id'], uni_exposure['address_type']):
            uni_exposure['best_res'] = EnumResolution.Address.value
        if uni_exposure['latitude'] is not None and uni_exposure['longitude'] is not None:
            uni_exposure['best_res'] = EnumResolution.LatLong.value
        uni_exposure['state'] = None
        if 'areacode' in record and str(record["areacode"]).upper() in AU_STATES:
            uni_exposure['state'] = str(record["areacode"]).upper()
        props = {}
        try:
            props["YearBuilt"] = self.sanitize_year_built(int(record['yearbuilt']))
        except (ValueError, TypeError, KeyError):
            pass
        try:
            props['StaticMotor'] = self.sanitize_smv(record, to_bool(record['staticmotorvehicle']))
        except (ValueError, TypeError, KeyError):
            pass
        uni_exposure['props'] = props
        return self._post_validate(uni_exposure, record)
def create_uni_exposure ( self , record , coverage_type : int ) : self . _pre_validate ( record , coverage_type ) uni_exposure = dict ( ) uni_exposure [ 'loc_id' ] = str ( record [ 'loc_id' ] ) uni_exposure [ 'lob_id' ] = self . _get_lob_id ( record ) uni_exposure [ 'cover_id' ] = oed_to_rf_coverage ( coverage_type , self . _is_motor ( record ) ) try : uni_exposure [ 'country_code' ] = str ( record [ "countrycode" ] ) . lower ( ) except ( ValueError , KeyError ) : uni_exposure [ 'country_code' ] = COUNTRY_CODE uni_exposure [ 'address_id' ] = None uni_exposure [ 'address_type' ] = None uni_exposure [ 'med_id' ] = None uni_exposure [ 'med_type' ] = None uni_exposure [ 'lrg_id' ] = None uni_exposure [ 'lrg_type' ] = None uni_exposure [ 'zone_id' ] = None uni_exposure [ 'zone_type' ] = None for i in range ( 1 , 6 ) : geog_scheme_col = "geogscheme" + str ( i ) geog_name_col = "geogname" + str ( i ) try : if geog_scheme_col in record and geog_name_col in record : uni_exposure = self . _add_geog_name ( uni_exposure , record [ geog_scheme_col ] , record [ geog_name_col ] ) except ( ValueError , TypeError ) : pass if 'postalcode' in record and self . is_valid_postcode ( record [ 'postalcode' ] ) : postcode = int ( record [ 'postalcode' ] ) if postcode in DELIVERY_POSTCODE_SET : postcode = POSTCODE_CONCORDANCE [ str ( postcode ) ] uni_exposure [ 'med_id' ] = postcode uni_exposure [ 'med_type' ] = EnumResolution . Postcode . value uni_exposure [ 'latitude' ] = None uni_exposure [ 'longitude' ] = None if 'longitude' in record and is_float ( record [ 'longitude' ] ) and 'latitude' in record and is_float ( record [ 'latitude' ] ) and not record [ 'longitude' ] == 0 and not record [ 'latitude' ] == 0 and not math . isnan ( record [ 'longitude' ] ) and not math . isnan ( record [ 'latitude' ] ) : if AU_BOUNDING_BOX [ 'MIN' ] [ 0 ] <= record [ "longitude" ] <= AU_BOUNDING_BOX [ 'MAX' ] [ 0 ] and AU_BOUNDING_BOX [ 'MIN' ] [ 1 ] <= record [ "latitude" ] <= AU_BOUNDING_BOX [ 'MAX' ] [ 1 ] : uni_exposure [ 'latitude' ] = record [ 'latitude' ] uni_exposure [ 'longitude' ] = record [ 'longitude' ] if ( uni_exposure [ 'med_id' ] is None or uni_exposure [ 'med_id' ] == 0 ) and self . _postcode_lookup : uni_exposure [ 'med_id' ] = self . _postcode_lookup . get_postcode ( record [ "longitude" ] , record [ "latitude" ] ) if uni_exposure [ 'lrg_id' ] is None or uni_exposure [ 'lrg_id' ] == 0 : pass else : raise LocationLookupException ( "Location is not in Australia" , error_code = 121 ) if uni_exposure [ 'lrg_id' ] is not None and uni_exposure [ 'lrg_id' ] > 0 : uni_exposure [ 'best_res' ] = EnumResolution . IcaZone . value if uni_exposure [ 'zone_id' ] is not None and uni_exposure [ 'zone_id' ] > 0 : uni_exposure [ 'best_res' ] = EnumResolution . Cresta . value if uni_exposure [ 'med_id' ] is not None and uni_exposure [ 'med_id' ] > 0 : uni_exposure [ 'best_res' ] = EnumResolution . Postcode . value if uni_exposure [ 'address_id' ] is not None and self . is_valid_address ( uni_exposure [ 'address_id' ] , uni_exposure [ 'address_type' ] ) : uni_exposure [ 'best_res' ] = EnumResolution . Address . value if uni_exposure [ 'latitude' ] is not None and uni_exposure [ 'longitude' ] is not None : uni_exposure [ 'best_res' ] = EnumResolution . LatLong . value uni_exposure [ 'state' ] = None if 'areacode' in record and str ( record [ "areacode" ] ) . upper ( ) in AU_STATES : uni_exposure [ 'state' ] = str ( record [ "areacode" ] ) . upper ( ) props = { } try : props [ "YearBuilt" ] = self . sanitize_year_built ( int ( record [ 'yearbuilt' ] ) ) except ( ValueError , TypeError , KeyError ) : pass try : props [ 'StaticMotor' ] = self . sanitize_smv ( record , to_bool ( record [ 'staticmotorvehicle' ] ) ) except ( ValueError , TypeError , KeyError ) : pass uni_exposure [ 'props' ] = props return self . _post_validate ( uni_exposure , record )
This creates a uni_exposure object from an oasis loc object.
This creates a uni_exposure object from an oasis loc object .
"""This creates a uni_exposure object from an oasis loc object.
        The u_exposure table contains the following columns:

        loc_id, latitude, longitude, address_type, address_id, best_res, country_code, state, zone_type, zone_id,
        catchment_type, catchment_id, lrg_type, lrg_id, med_type, med_id, fine_type, fine_id, lob_id, props, modelled,
        origin_file_line

        :param record: a row from a OED portfolio
        :param coverage_type: is a either building [1], contents [3], other [3] (motor) or business interruption [4]
        :return: a uni_exposure object as per the Multi-Peril Workbench specification
        """ # OED: country error_code is also required but we'll default to AU if missing # address, ICA zone and cresta # overwrite postcode from 'postalcode' field # lat/lon # not required at lat/lon level # setting best res # uni_exposure['catchment_type'] # todo: when implementing flood # uni_exposure['catchment_id'] # uni_exposure['fine_type'] # uni_exposure['fine_id'] # uni_exposure["props"] # uni_exposure['modelled'] # todo: when implementing flood, check that location is in flood zone
a uni_exposure object as per the Multi-Peril Workbench specification
a uni_exposure object as per the Multi - Peril Workbench specification
self
record
a row from a OED portfolio
a row from a OED portfolio
coverage_type
int
None