else: orig_jobs = f.make_original_jobs_from_counts(jcnts_arr[0], eg_sequence, fur_sequence, num_of_job_levels).astype(int) # insert stovepipe job result into new column of proposal (month_form) # this indexes the jobs with empkeys (orig_jobs is an ndarray only) df_proposal['orig_job'] = orig_jobs # ASSIGN JOBS - flush and no flush option* # cmonths - career length in months for each employee. # length is equal to number of employees cmonths = f.career_months_df_in(df_proposal) # nonret_each_month: count of non-retired employees remaining # in each month until no more remain - # length is equal to longest career length nonret_each_month = f.count_per_month(cmonths) all_months = np.sum(nonret_each_month) cumulative = nonret_each_month.cumsum() np_low_limits = f.make_lower_slice_limits(cumulative) job_level_counts = np.array(jcnts_arr[1]) if cf.delayed_implementation: imp_month = cf.imp_month imp_low = np_low_limits[imp_month]
else: orig_jobs = f.make_original_jobs_from_counts( jcnts_arr[0], eg_sequence, fur_sequence, num_of_job_levels).astype(int) # insert stovepipe job result into new column of proposal (month_form) # this indexes the jobs with empkeys (orig_jobs is an ndarray only) df_proposal['orig_job'] = orig_jobs # ASSIGN JOBS - flush and no flush option* # cmonths - career length in months for each employee. # length is equal to number of employees cmonths = f.career_months_df_in(df_proposal) # nonret_each_month: count of non-retired employees remaining # in each month until no more remain - # length is equal to longest career length nonret_each_month = f.count_per_month(cmonths) all_months = np.sum(nonret_each_month) cumulative = nonret_each_month.cumsum() np_low_limits = f.make_lower_slice_limits(cumulative) job_level_counts = np.array(jcnts_arr[1]) if cf.delayed_implementation: imp_month = cf.imp_month imp_low = np_low_limits[imp_month]
ds_list = [ds1, ds2, ds3] short_ds_list = [short_ds1, short_ds2, short_ds3] for i in range(len(ds_list)): df_long = ds_list[i] df_short = short_ds_list[i] jcnts = jcnts_arr[0][i] # jcnts = np.take(jcnts, np.where(jcnts != 0)[0]) short_len = len(short_ds_list[i]) # ORIG_JOB* cmonths_this_ds = f.career_months_df_in(df_short) this_ds_nonret_each_month = f.count_per_month(cmonths_this_ds) uppers = this_ds_nonret_each_month.cumsum() lowers = f.make_lower_slice_limits(uppers) all_months = np.sum(this_ds_nonret_each_month) this_table = table[0][i] this_month_counts = table[1][i] df_align = df_long[['twa', 'fur']] fur_codes = np.array(df_align.fur) # if i == 0 and cf.apply_supc: # i == 0 >> eg1 from skeleton # twa_rights = np.array(cf.twa_rights) # twa_jobs = np.transpose(twa_rights)[1] # sup_c_counts = np.transpose(twa_rights)[2]
for date, add_months in ret_incr_dict.items(): master.loc[master.retdate > pd.to_datetime(date) + pd.offsets.MonthEnd(-1), 'retdate'] = \ master.retdate + pd.DateOffset(months=add_months) # only include employees who retire during or after the starting_month # (remove employees who retire prior to analysis period) master = master[master.retdate >= start_date - pd.DateOffset(months=1) + pd.DateOffset(days=1)] master.to_pickle('dill/master.pkl') # ACTIVE EACH MONTH (no consideration for job changes or recall, only # calculated on retirements of active employees as of start date) emps_to_calc = master[master.line == 1].copy() cmonths = f.career_months_df_in(emps_to_calc) nonret_each_month = f.count_per_month(cmonths) # code below subject to removal pending test period completion # actives = pd.DataFrame(nonret_each_month, columns=['count']) # actives.to_pickle('dill/active_each_month.pkl') # LIST ORDER PROPOSALS # Read the list ordering proposals from an Excel workbook, add an index # column ('idx'), and store each proposal as a dataframe in a pickled file. # The proposals are contained on separate worksheets. # The routine below will loop through the worksheets. # The worksheet tab names are important for the function. # The pickle files will be named like the workbook sheet names. xl = pd.ExcelFile('excel/' + case + '/proposals.xlsx')
start_date = pd.to_datetime(cf.starting_date) # only include pilots that are not retired prior to the starting_month df_proposal = df_proposal[df_proposal.retdate >= start_date - pd.DateOffset(months=1)] # include furloughees by default df = df_proposal[(df_proposal.line == 1) | (df_proposal.fur == 1)].copy() df_proposal = [] # MNUM* # calculate the number of career months for each employee (short_form) # cmonths is used for mnum, idx, and mth_pcnt calculations cmonths = f.career_months_df_in(df) # convert the python cmonths list to a numpy array and # use that array as input for the count_per_month function. # The count_per_month function output array is input for # other functions (month_form) nonret_each_month = f.count_per_month(cmonths) # calculate the total of all career months (sum) total_months = np.sum(nonret_each_month) # first long form data generation. # month numbers, same month number repeated for each month length (long_form)
else: orig_jobs = f.make_original_jobs_from_counts( jcnts_arr[0], eg_sequence, fur_sequence, num_of_job_levels).astype(int) # insert stovepipe job result into new column of proposal (month_form) # this indexes the jobs with empkeys (orig_jobs is an ndarray only) df_master['orig_job'] = orig_jobs # ASSIGN JOBS - flush and no flush option* # cmonths - career length in months for each employee. # length is equal to number of employees cmonths = f.career_months_df_in(df_master) # nonret_each_month: count of non-retired employees remaining # in each month until no more remain - # length is equal to longest career length nonret_each_month = f.count_per_month(cmonths) all_months = np.sum(nonret_each_month) cumulative = nonret_each_month.cumsum() np_low_limits = f.make_lower_slice_limits(cumulative) job_level_counts = np.array(jcnts_arr[1]) if cf.delayed_implementation: imp_month = cf.imp_month imp_low = np_low_limits[imp_month]
ds_dict[grp] = ds[ds.eg == grp].copy() for grp in egs: short_ds_dict[grp] = ds_dict[grp][ds_dict[grp].mnum == 0].copy() ds = pd.DataFrame() for i in egs - 1: df_long = ds_dict[i + 1] df_short = short_ds_dict[i + 1] jcnts = jcnts_arr[0][i] short_len = len(df_short) # ORIG_JOB* cmonths_this_ds = f.career_months_df_in(df_short) this_ds_nonret_each_month = f.count_per_month(cmonths_this_ds) uppers = this_ds_nonret_each_month.cumsum() lowers = f.make_lower_slice_limits(uppers) all_months = np.sum(this_ds_nonret_each_month) this_table = table[0][i] this_month_counts = table[1][i] df_align_cols = ['fur'] if 'sg' in df_long: df_align_cols.append('sg') df_align = df_long[df_align_cols] fur_codes = np.array(df_align.fur)