dir.create('data') dir.create('output') source('libraries.R') source('R/LCE.R') download_emi_files(emi_sas = Sys.getenv("EMI_SAS"),emi_endpoint = "https://emidatasets.blob.core.windows.net/publicdata") df_branch_rentals = read.csv('data/pricing_year_20_21_transmission_rentals.csv') df_branch_regions = read.csv('data/final_branch_mapping.csv') #Get branch mapping of S1 investments #See https://www.emi.ea.govt.nz/Wholesale/Datasets/_AdditionalInformation/SupportingInformationAndAnalysis/2019/20190723_TPM_2019_IssuesPaper/2019_Proposal_Impacts_modelling df_s1_branch_mapping = read_excel('data/LCE rental refund module.xlsx', sheet = 'Branch_to_Projects') #Load scaling of rentals from LCE data df_tp_revenue = read_excel('data/Historic LCE Breakdown Jun 2021.xlsx', sheet = 'Monthly Data', range = 'b2:l269') %>% mutate(month_date = floor_date(Month, 'month') %>% as.Date) %>% select(month_date, scale_factor = `Scale Factor`) #Load allocators for simple method BBCs df_ipm_allocators = read.csv('data/indicative_pricing_allocators.csv') df_ipm_allocators<-df_ipm_allocators[,-c(2:8)] #Map rentals to simple method regions or historic investments df_branches_final = branch_rental_mapping(df_branch_rentals, df_s1_branch_mapping) #Create version that doesn't use S1 allocators df_non_s1_rentals_investment = calculate_non_s1_rentals(df_branches_final, df_tp_revenue) df_non_s1_rentals = rental_customer_allocation(df_non_s1_rentals_investment, df_tp_revenue, df_ipm_allocators) write_csv(df_non_s1_rentals, 'output/rental_attribution_to_customer_simpleBB_py2021.csv')