def generate_summary_files(processrunid): flamingo_db_utils.generate_oasis_files_outputs(processrunid) prog_oasis_location = \ flamingo_db_utils.get_prog_oasis_location(processrunid) ts = values.get_timestamp() process_dir = "ProcessRun_" + str(processrunid) + "_" + ts input_location = str(prog_oasis_location) + "/" + str(process_dir) if not os.path.isdir(input_location): os.mkdir(input_location) for i in ("items", "coverages", "fm_programme", "fm_policytc", "fm_xref", "fm_profile"): source_file = "{}/{}.csv".format(prog_oasis_location, i) target_file = "{}/{}.csv".format(input_location, i) if not IS_WINDOWS_HOST: os.symlink(source_file, target_file) else: shutil.copy(source_file, target_file) db.bcp("OasisGULSUMMARYXREF", input_location + "/gulsummaryxref_temp.csv") db.bcp("OasisFMSUMMARYXREF", input_location + "/fmsummaryxref_temp.csv") gulsummaryxref = input_location + "/gulsummaryxref.csv" destination = open(gulsummaryxref, 'wb') destination.write("coverage_id,summary_id,summaryset_id\n") shutil.copyfileobj(open(input_location + "/gulsummaryxref_temp.csv", 'rb'), destination) destination.close() os.remove(input_location + "/gulsummaryxref_temp.csv") fmsummaryxref = input_location + "/fmsummaryxref.csv" destination = open(fmsummaryxref, 'wb') destination.write("output_id,summary_id,summaryset_id\n") shutil.copyfileobj(open(input_location + "/fmsummaryxref_temp.csv", 'rb'), destination) destination.close() os.remove(input_location + "/fmsummaryxref_temp.csv") process_run_locationid = flamingo_db_utils.get_process_run_locationid( prog_oasis_location, process_dir, processrunid) flamingo_db_utils.generate_oasis_files_records_outputs( processrunid, process_run_locationid) return input_location
def do_generate_oasis_files(progoasisid): location_id = -1 status = flamingo_db_utils.generate_oasis_files(progoasisid) if status != "Done": raise Exception("Failed to generate Oasis files") progoasis_dir = "ProgOasis_" + progoasisid input_location = OASIS_FILES_DIRECTORY + "/" + progoasis_dir if not os.path.isdir(input_location): os.mkdir(input_location) location_id = flamingo_db_utils.generate_location_record( OASIS_FILES_DIRECTORY, progoasis_dir, "ProgOasis_" + progoasisid)[0] logging.getLogger().info("location_id: {}".format(location_id)) if location_id == -1: raise Exception("Failed to generate location record") items = input_location + "/items.csv" coverages = input_location + "/coverages.csv" fm_programme = input_location + "/fm_programme.csv" fm_policytc = input_location + "/fm_policytc.csv" fm_xref = input_location + "/fm_xref.csv" fm_profile = input_location + "/fm_profile.csv" itemdict = input_location + "/ItemDict.csv" fmdict = input_location + "/FMDict.csv" db.bcp("OasisCOVERAGES", OASIS_FILES_DIRECTORY + "/Coverages_temp.csv") db.bcp("OasisITEMS", OASIS_FILES_DIRECTORY + "/Items_temp.csv") db.bcp("OasisFM_PROGRAMME", OASIS_FILES_DIRECTORY + "/FMProgramme_temp.csv") db.bcp("OasisFM_POLICYTC", OASIS_FILES_DIRECTORY + "/FMPolicyTC_temp.csv") db.bcp("OasisFM_PROFILE", OASIS_FILES_DIRECTORY + "/FMProfile_temp.csv") db.bcp("OasisFM_XREF", OASIS_FILES_DIRECTORY + "/FMXRef_temp.csv") db.bcp("OasisITEMDICT", OASIS_FILES_DIRECTORY + "/ItemDict_temp.csv") db.bcp("OasisFMDICT", OASIS_FILES_DIRECTORY + "/FMDict_temp.csv") destination = open(coverages, 'wb') destination.write("coverage_id,tiv\n") shutil.copyfileobj( open(OASIS_FILES_DIRECTORY + "/Coverages_temp.csv", 'rb'), destination) destination.close() os.remove(OASIS_FILES_DIRECTORY + "/Coverages_temp.csv") destination = open(items, 'wb') destination.write( "item_id,coverage_id,areaperil_id,vulnerability_id,group_id\n") shutil.copyfileobj(open(OASIS_FILES_DIRECTORY + "/Items_temp.csv", 'rb'), destination) destination.close() os.remove(OASIS_FILES_DIRECTORY + "/Items_temp.csv") destination = open(fm_programme, 'wb') destination.write("from_agg_id,level_id,to_agg_id\n") shutil.copyfileobj( open(OASIS_FILES_DIRECTORY + "/FMProgramme_temp.csv", 'rb'), destination) destination.close() os.remove(OASIS_FILES_DIRECTORY + "/FMProgramme_temp.csv") destination = open(fm_policytc, 'wb') destination.write("layer_id,level_id,agg_id,policytc_id\n") shutil.copyfileobj( open(OASIS_FILES_DIRECTORY + "/FMPolicyTC_temp.csv", 'rb'), destination) destination.close() os.remove(OASIS_FILES_DIRECTORY + "/FMPolicyTC_temp.csv") destination = open(fm_profile, 'wb') destination.write("policytc_id,calcrule_id,allocrule_id,ccy_id,deductible," + \ "limit,share_prop_of_lim,deductible_prop_of_loss,limit_prop_of_loss," + \ "deductible_prop_of_tiv,limit_prop_of_tiv,deductible_prop_of_limit\n") shutil.copyfileobj( open(OASIS_FILES_DIRECTORY + "/FMProfile_temp.csv", 'rb'), destination) destination.close() os.remove(OASIS_FILES_DIRECTORY + "/FMProfile_temp.csv") destination = open(fm_xref, 'wb') destination.write("output_id,agg_id,layer_id\n") shutil.copyfileobj(open(OASIS_FILES_DIRECTORY + "/FMXRef_temp.csv", 'rb'), destination) destination.close() os.remove(OASIS_FILES_DIRECTORY + "/FMXRef_temp.csv") destination = open(itemdict, 'wb') destination.write( "item_id,coverage_id,location_id,location_desc,lob_id,lob_desc,county_id,county_desc,state_id,state_desc\n" ) shutil.copyfileobj( open(OASIS_FILES_DIRECTORY + "/ItemDict_temp.csv", 'rb'), destination) destination.close() os.remove(OASIS_FILES_DIRECTORY + "/ItemDict_temp.csv") destination = open(fmdict, 'wb') destination.write( "output_id,item_id,agg_id,layer_id,policy_name,layer_name\n") shutil.copyfileobj(open(OASIS_FILES_DIRECTORY + "/FMDict_temp.csv", 'rb'), destination) destination.close() os.remove(OASIS_FILES_DIRECTORY + "/FMDict_temp.csv") flamingo_db_utils.generate_oasis_file_records(progoasisid, location_id)
def do_generate_oasis_files(progoasisid): location_id = -1 status = flamingo_db_utils.generate_oasis_files(progoasisid) if status != "Done": raise Exception("Failed to generate Oasis files") progoasis_dir = "ProgOasis_" + progoasisid input_location = OASIS_FILES_DIRECTORY + "/" + progoasis_dir if not os.path.isdir(input_location): os.mkdir(input_location) location_id = flamingo_db_utils.generate_location_record( OASIS_FILES_DIRECTORY, progoasis_dir, "ProgOasis_" + progoasisid)[0] logging.getLogger().info("location_id: {}".format(location_id)) if location_id == -1: raise Exception("Failed to generate location record") items = input_location + "/items.csv" coverages = input_location + "/coverages.csv" fm_programme = input_location + "/fm_programme.csv" fm_policytc = input_location + "/fm_policytc.csv" fm_xref = input_location + "/fm_xref.csv" fm_profile = input_location + "/fm_profile.csv" itemdict = input_location + "/ItemDict.csv" fmdict = input_location + "/FMDict.csv" db.bcp("OasisCOVERAGES", OASIS_FILES_DIRECTORY + "/Coverages_temp.csv") db.bcp("OasisITEMS", OASIS_FILES_DIRECTORY + "/Items_temp.csv") db.bcp("OasisFM_PROGRAMME", OASIS_FILES_DIRECTORY + "/FMProgramme_temp.csv") db.bcp("OasisFM_POLICYTC", OASIS_FILES_DIRECTORY + "/FMPolicyTC_temp.csv") db.bcp("OasisFM_PROFILE", OASIS_FILES_DIRECTORY + "/FMProfile_temp.csv") db.bcp("OasisFM_XREF", OASIS_FILES_DIRECTORY + "/FMXRef_temp.csv") db.bcp("OasisITEMDICT", OASIS_FILES_DIRECTORY + "/ItemDict_temp.csv") db.bcp("OasisFMDICT", OASIS_FILES_DIRECTORY + "/FMDict_temp.csv") destination = open(coverages, 'wb') destination.write("coverage_id,tiv\n") shutil.copyfileobj( open(OASIS_FILES_DIRECTORY + "/Coverages_temp.csv", 'rb'), destination) destination.close() os.remove(OASIS_FILES_DIRECTORY + "/Coverages_temp.csv") destination = open(items, 'wb') destination.write( "item_id,coverage_id,areaperil_id,vulnerability_id,group_id\n") shutil.copyfileobj(open(OASIS_FILES_DIRECTORY + "/Items_temp.csv", 'rb'), destination) destination.close() os.remove(OASIS_FILES_DIRECTORY + "/Items_temp.csv") destination = open(fm_programme, 'wb') destination.write("from_agg_id,level_id,to_agg_id\n") shutil.copyfileobj( open(OASIS_FILES_DIRECTORY + "/FMProgramme_temp.csv", 'rb'), destination) destination.close() os.remove(OASIS_FILES_DIRECTORY + "/FMProgramme_temp.csv") destination = open(fm_policytc, 'wb') destination.write("layer_id,level_id,agg_id,policytc_id\n") shutil.copyfileobj( open(OASIS_FILES_DIRECTORY + "/FMPolicyTC_temp.csv", 'rb'), destination) destination.close() os.remove(OASIS_FILES_DIRECTORY + "/FMPolicyTC_temp.csv") destination = open(fm_profile, 'wb') destination.write("policytc_id,calcrule_id,allocrule_id,ccy_id,deductible," + \ "limit,share_prop_of_lim,deductible_prop_of_loss,limit_prop_of_loss," + \ "deductible_prop_of_tiv,limit_prop_of_tiv,deductible_prop_of_limit\n") shutil.copyfileobj( open(OASIS_FILES_DIRECTORY + "/FMProfile_temp.csv", 'rb'), destination) destination.close() os.remove(OASIS_FILES_DIRECTORY + "/FMProfile_temp.csv") destination = open(fm_xref, 'wb') destination.write("output_id,agg_id,layer_id\n") shutil.copyfileobj(open(OASIS_FILES_DIRECTORY + "/FMXRef_temp.csv", 'rb'), destination) destination.close() os.remove(OASIS_FILES_DIRECTORY + "/FMXRef_temp.csv") destination = open(itemdict, 'wb') destination.write( "item_id,coverage_id,location_id,location_desc,lob_id,lob_desc,county_id,county_desc,state_id,state_desc\n" ) shutil.copyfileobj( open(OASIS_FILES_DIRECTORY + "/ItemDict_temp.csv", 'rb'), destination) destination.close() os.remove(OASIS_FILES_DIRECTORY + "/ItemDict_temp.csv") destination = open(fmdict, 'wb') destination.write( "output_id,item_id,agg_id,layer_id,policy_name,layer_name\n") shutil.copyfileobj(open(OASIS_FILES_DIRECTORY + "/FMDict_temp.csv", 'rb'), destination) destination.close() os.remove(OASIS_FILES_DIRECTORY + "/FMDict_temp.csv") flamingo_db_utils.generate_oasis_file_records(progoasisid, location_id) # oed files oed_location = input_location + '/oed_files' if not os.path.isdir(oed_location): os.mkdir(oed_location) progid = flamingo_db_utils.get_ProgId_For_ProgOasis(progoasisid)[0] # location location_file = flamingo_db_utils.get_source_loc_file_for_prog(progid)[0] source_file = "/var/www/oasis/Files/Exposures/{}".format(location_file) target_file = "{}/location.csv".format(oed_location) if not IS_WINDOWS_HOST: os.symlink(source_file, target_file) else: shutil.copy(source_file, target_file) # account account_file = flamingo_db_utils.get_source_acc_file_for_prog(progid)[0] source_file = "/var/www/oasis/Files/Exposures/{}".format(account_file) target_file = "{}/account.csv".format(oed_location) if not IS_WINDOWS_HOST: os.symlink(source_file, target_file) else: shutil.copy(source_file, target_file) # reinsurance info reins_info_file = flamingo_db_utils.get_source_reinsurance_file_for_prog( progid)[0] source_file = "/var/www/oasis/Files/Exposures/{}".format(reins_info_file) target_file = "{}/ri_info.csv".format(oed_location) if not IS_WINDOWS_HOST: os.symlink(source_file, target_file) else: shutil.copy(source_file, target_file) # reinsurance scope reins_scope_file = flamingo_db_utils.get_source_reinsurance_scope_file_for_prog( progid)[0] source_file = "/var/www/oasis/Files/Exposures/{}".format(reins_scope_file) target_file = "{}/ri_scope.csv".format(oed_location) if not IS_WINDOWS_HOST: os.symlink(source_file, target_file) else: shutil.copy(source_file, target_file) # xref description item_dict_file = input_location + '/ItemDict.csv' item_dict = pd.read_csv(item_dict_file) fm_dict_file = input_location + '/FMDict.csv' fm_dict = pd.read_csv(fm_dict_file) combined_dict = item_dict.merge(fm_dict, on=('item_id')) xref_description = combined_dict[[ 'layer_name', 'policy_name', 'location_desc' ]] xref_description.columns = [ 'policy_number', 'account_number', 'location_number' ] xref_description['xref_id'] = xref_description.index + 1 xref_description['coverage_type_id'] = 1 xref_description['peril_id'] = 1 xref_description['tiv'] = 1 xref_description = xref_description[[ 'xref_id', 'policy_number', 'account_number', 'location_number', 'coverage_type_id', 'peril_id', 'tiv' ]] xref_description_file = input_location + '/xref_descriptions.csv' xref_description.to_csv(xref_description_file, index=False) # generate dfs (account_df, location_df, ri_info_df, ri_scope_df, do_reinsurance) = load_oed_dfs(oed_location) # direct layers items = pd.read_csv(input_location + "/items.csv") coverages = pd.read_csv(input_location + "/coverages.csv") fm_xrefs = pd.read_csv(input_location + "/fm_xref.csv") xref_descriptions = pd.read_csv(input_location + "/xref_descriptions.csv") validate_inst = OedValidator() (main_is_valid, inuring_layers) = validate_inst.validate(account_df, location_df, ri_info_df, ri_scope_df) logging.getLogger().info("main_is_valid: {}".format(main_is_valid)) logging.getLogger().info("inuring_layers: {}".format(inuring_layers)) # if not main_is_valid: # print("Reinsuarnce structure not valid") # for inuring_layer in inuring_layers: # if not inuring_layers.is_valid: # print("Inuring layer {} invalid:".format( # inuring_layer.inuring_priority)) # for validation_message in inuring_layer.validation_messages: # print("\t{}".format(validation_message)) # exit(0) generate_files_for_reinsurance(account_df, location_df, items, coverages, fm_xrefs, xref_descriptions, ri_info_df, ri_scope_df, input_location)
def generate_summary_files(processrunid): flamingo_db_utils.generate_oasis_files_outputs(processrunid) prog_oasis_location = \ flamingo_db_utils.get_prog_oasis_location(processrunid) ts = values.get_timestamp() process_dir = "ProcessRun_" + str(processrunid) + "_" + ts input_location = str(prog_oasis_location) + "/" + str(process_dir) if not os.path.isdir(input_location): os.mkdir(input_location) for i in ("items", "coverages", "fm_programme", "fm_policytc", "fm_xref", "fm_profile"): source_file = "{}/{}.csv".format(prog_oasis_location, i) target_file = "{}/{}.csv".format(input_location, i) if not IS_WINDOWS_HOST: os.symlink(source_file, target_file) else: shutil.copy(source_file, target_file) input_dir_list = os.listdir(prog_oasis_location) ri_dir_list = [] for dirs in input_dir_list: if dirs.startswith('RI_'): ri_dir_list.append(dirs) for dirs in ri_dir_list: ri_full_path = prog_oasis_location + '/' + dirs ri_target_path = input_location + '/' + dirs if not IS_WINDOWS_HOST: os.symlink(ri_full_path, ri_target_path) else: shutil.copytree(ri_full_path, ri_target_path) db.bcp("OasisGULSUMMARYXREF", input_location + "/gulsummaryxref_temp.csv") db.bcp("OasisFMSUMMARYXREF", input_location + "/fmsummaryxref_temp.csv") db.bcp("OasisRISUMMARYXREF", input_location + "/risummaryxref_temp.csv") gulsummaryxref = input_location + "/gulsummaryxref.csv" destination = open(gulsummaryxref, 'wb') destination.write("coverage_id,summary_id,summaryset_id\n") shutil.copyfileobj(open(input_location + "/gulsummaryxref_temp.csv", 'rb'), destination) destination.close() os.remove(input_location + "/gulsummaryxref_temp.csv") fmsummaryxref = input_location + "/fmsummaryxref.csv" destination = open(fmsummaryxref, 'wb') destination.write("output_id,summary_id,summaryset_id\n") shutil.copyfileobj(open(input_location + "/fmsummaryxref_temp.csv", 'rb'), destination) destination.close() os.remove(input_location + "/fmsummaryxref_temp.csv") risummaryxref = input_location + "/risummaryxref.csv" destination = open(risummaryxref, 'wb') destination.write("output_id,summary_id,summaryset_id\n") shutil.copyfileobj(open(input_location + "/risummaryxref_temp.csv", 'rb'), destination) destination.close() os.remove(input_location + "/risummaryxref_temp.csv") dirs = os.listdir(input_location) ri_dirs = [] for dir in dirs: if dir.startswith('RI_'): ri_dirs.append(dir) for dir in ri_dirs: full_dir = os.path.join(input_location, dir) shutil.copy(os.path.join(input_location, "risummaryxref.csv"), os.path.join(full_dir, "fmsummaryxref.csv")) process_run_locationid = flamingo_db_utils.get_process_run_locationid( prog_oasis_location, process_dir, processrunid) flamingo_db_utils.generate_oasis_files_records_outputs( processrunid, process_run_locationid) return input_location