## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  message = FALSE,
  warning = FALSE,
  fig.width = 7,
  fig.height = 4.5,
  out.width = "100%"
)

## ----setup--------------------------------------------------------------------
library(ambre)
set.seed(2024)

## ----signature, eval = FALSE--------------------------------------------------
#  run_economic_analysis(scenario, membership_fee,
#                        price_per_m3, grant, initialSituation = FALSE)

## ----cost-table---------------------------------------------------------------
config_ambre$economic$cost[, c("TreatmentName", "CostType", "value", "unit")] |>
  head(8)

## ----scenario-----------------------------------------------------------------
scenario <- create_scenario(
  system.file("input_1culture_2pop.xlsx", package = "ambre")
)

## ----run, results = "hide"----------------------------------------------------
plots <- run_economic_analysis(
  scenario,
  membership_fee = 200,   # €/ha/year
  price_per_m3   = 0.1,   # €/m3
  grant          = 0.5,    # half the capital cost is subsidised,
  initialSituation = FALSE # calcul the cost of Supplementary process
)

## ----annual-------------------------------------------------------------------
plots$annual

## ----capex--------------------------------------------------------------------
plots$total_investement

## ----allocation-key-----------------------------------------------------------
plots$allocation_key

## ----run-custom---------------------------------------------------------------

crop <- scenario$CropName
allocation_custom <- data.frame(CropName = crop,
                                allocation = c(0.5, 0.5))
run_economic_analysis(
  scenario,
  membership_fee = 200,   
  price_per_m3   = 0.1,   
  grant          = 0,   
  initialSituation = FALSE, 
  allocation_key = allocation_custom # No subvention, collective treatment price 50% for each crop
)

## ----numbers, results = "hide"------------------------------------------------
scenario_need <- irrigation_need_calculation(scenario)

water_price <- water_price(scenario = scenario_need,
                          price_per_m3 = 0.01,
                          membership_fee = 200)
supplementary_cost <- process_cost_calculation(scenario = scenario_need,
                                              membership_fee = 200,
                                              charge = 0.1,
                                              initialSituation = FALSE)


## ----numbers-cols-------------------------------------------------------------
setdiff(names(water_price), names(supplementary_cost))

