From 881b939e07c117ee8d28c3c86c2f1ec7078cf318 Mon Sep 17 00:00:00 2001 From: NicolaiHandreck Date: Thu, 21 Jul 2022 09:41:49 +0200 Subject: [PATCH 01/10] new --- R/plot.R | 76 +++++ R/pof_future_cables_60_30kv.R | 413 ++++++++++++++++++++++++ R/pof_future_tower_ohl_support_50kv.R | 319 +++++++++++++++++++ R/pof_ohl_cond_50kv.R | 442 ++++++++++++++++++++++++++ R/pof_ohl_fittings_50kv.R | 188 +++++++++++ R/pof_pillar_04kv.R | 185 +++++++++++ R/pof_poles_ohl_support_50kv.R | 209 ++++++++++++ R/pof_relay.R | 181 +++++++++++ R/pof_rtu.R | 181 +++++++++++ R/pof_serviceline.R | 265 +++++++++++++++ R/pof_submarine_cables_10kv_oil.R | 346 ++++++++++++++++++++ R/pof_submarine_cables_10kv_pex.R | 344 ++++++++++++++++++++ R/pof_submarine_cables_30_60kv_oil.R | 347 ++++++++++++++++++++ R/pof_submarine_cables_30_60kv_pex.R | 347 ++++++++++++++++++++ R/pof_switchgear_30_60kv.R | 204 ++++++++++++ 15 files changed, 4047 insertions(+) create mode 100644 R/plot.R create mode 100644 R/pof_future_cables_60_30kv.R create mode 100644 R/pof_future_tower_ohl_support_50kv.R create mode 100644 R/pof_ohl_cond_50kv.R create mode 100644 R/pof_ohl_fittings_50kv.R create mode 100644 R/pof_pillar_04kv.R create mode 100644 R/pof_poles_ohl_support_50kv.R create mode 100644 R/pof_relay.R create mode 100644 R/pof_rtu.R create mode 100644 R/pof_serviceline.R create mode 100644 R/pof_submarine_cables_10kv_oil.R create mode 100644 R/pof_submarine_cables_10kv_pex.R create mode 100644 R/pof_submarine_cables_30_60kv_oil.R create mode 100644 R/pof_submarine_cables_30_60kv_pex.R create mode 100644 R/pof_switchgear_30_60kv.R diff --git a/R/plot.R b/R/plot.R new file mode 100644 index 00000000..27216644 --- /dev/null +++ b/R/plot.R @@ -0,0 +1,76 @@ + + + +dat <- data.frame(matrix(ncol=4, nrow = 1000)) +names(dat) <- c("age", "pof","k", "c") +dat$age <- 1:100 + +dat$k[1:100] <- rep(0.0658,100) +dat$k[101:200] <- rep(0.0658,100) +dat$k[201:300] <- rep(0.0658,100) +dat$k[301:400] <- rep(0.0658,100) +dat$k[401:500] <- rep(0.0658,100) + +dat$k[501:600] <- rep(0.0658,100) +dat$k[601:700] <- rep(0.0658,100) +dat$k[701:800] <- rep(0.0658,100) +dat$k[801:900] <- rep(0.0658,100) +dat$k[901:1000] <- rep(0.0658,100) + + +dat$c[1:500] <- rep(1.087,100) +dat$c[501:1000] <- rep(2,100) + + +i = 1 +m = 1 +n = 2 + +for(n in 1:2) { + + cval <- unique(dat$c)[n] + + for(m in 1:5) { + + kval <- unique(dat$k)[m] + + for(i in 1:100) { + + + res <- pof_cables_04kv_pex( + utilisation_pct = "Default", + operating_voltage_pct = "Default", + sheath_test = "Default", + partial_discharge = "Default", + fault_hist = "Default", + reliability_factor = "Default", + age = i, + k_value = kval, + c_value = cval, + normal_expected_life = 80) + + + + + dat$pof[which(dat$c %in% cval & dat$k %in% kval & dat$age == i)] <- res + + } + } +} + +library(ggplot2) + +dat$k <- as.character(dat$k) +dat$c <- as.character(dat$c) +# +# ggplot(dat, aes(x=age, y=pof, color=k)) + +# geom_line() + + + +ggplot(dat, aes(x=age, y=pof, colour=k, shape = c, + group=interaction(k, c))) + + geom_point() + geom_line() + ggtitle("PoF for 0.4kV cable, normal expected life = 80" ) # for the main title + + + diff --git a/R/pof_future_cables_60_30kv.R b/R/pof_future_cables_60_30kv.R new file mode 100644 index 00000000..7505205a --- /dev/null +++ b/R/pof_future_cables_60_30kv.R @@ -0,0 +1,413 @@ +#' @importFrom magrittr %>% +#' @title Future Probability of Failure for 30-60kV Cables +#' @description This function calculates the future +#' annual probability of failure per kilometer for a 30-60kV cables. +#' The function is a cubic curve that is based on +#' the first three terms of the Taylor series for an +#' exponential function. +#' @inheritParams pof_cables_60_30kv +#' @param simulation_end_year Numeric. The last year of simulating probability +#' of failure. Default is 100. +#' @return Numeric array. Future probability of failure +#' per annum per kilometre for 30-60kV cables. +#' @export +#' @examples +#' # Future probability of failure for 60kV UG Cable (Non Pressurised) +# pof_60kV_non_pressurised <- +# pof_future_cables_60_30kv(cable_type = "60kV UG Cable (Non Pressurised)", +# sub_division = "Aluminium sheath - Aluminium conductor", +# utilisation_pct = 75, +# operating_voltage_pct = 50, +# sheath_test = "Default", +# partial_discharge = "Default", +# fault_hist = "Default", +# leakage = "Default", +# reliability_factor = "Default", +# age = 1, +# k_value = "Default", +# c_value = 1.087, +# normal_expected_life = "Default", +# simulation_end_year = 100) +#' # Plot +#'plot(pof_60kV_non_pressurised$PoF * 100, +#'type = "line", ylab = "%", xlab = "years", +#'main = "PoF per kilometre - 66kV UG Cable (Non Pressurised)") + +pof_future_cables_60_30kv <- + function(cable_type = "60kV UG Cable (Gas)", + sub_division = "Aluminium sheath - Aluminium conductor", + utilisation_pct = "Default", + operating_voltage_pct = "Default", + sheath_test = "Default", + partial_discharge = "Default", + fault_hist = "Default", + leakage = "Default", + reliability_factor = "Default", + age, + k_value = "Default", + c_value = 1.087, + normal_expected_life = "Default", + simulation_end_year = 100) { + + if (cable_type == "30kV UG Cable (Non Pressurised)" ) { + cable_type <- "33kV UG Cable (Non Pressurised)" + } else if ( cable_type == "30kV UG Cable (Oil)") { + cable_type <- "33kV UG Cable (Oil)" + } else if ( cable_type == "30kV UG Cable (Gas)") { + cable_type <- "33kV UG Cable (Gas)" + } else if ( cable_type == "60kV UG Cable (Non Pressurised)") { + cable_type <- "66kV UG Cable (Non Pressurised)" + } else if ( cable_type == "60kV UG Cable (Oil)") { + cable_type <- "66kV UG Cable (Oil)" + } else { + cable_type <- "66kV UG Cable (Gas)" + } + + + + `Asset Register Category` = `Health Index Asset Category` = + `Generic Term...1` = `Generic Term...2` = `Functional Failure Category` = + `K-Value (%)` = `C-Value` = `Asset Register Category` = + `Sub-division` = `Condition Criteria: Sheath Test Result` = + `Condition Criteria: Partial Discharge Test Result` = + `Condition Criteria: Leakage Rate` = NULL + # due to NSE notes in R CMD check + + # Ref. table Categorisation of Assets and Generic Terms for Assets -- + + asset_category <- gb_ref$categorisation_of_assets %>% + dplyr::filter(`Asset Register Category` == cable_type) %>% + dplyr::select(`Health Index Asset Category`) %>% dplyr::pull() + + generic_term_1 <- gb_ref$generic_terms_for_assets %>% + dplyr::filter(`Health Index Asset Category` == asset_category) %>% + dplyr::select(`Generic Term...1`) %>% dplyr::pull() + + generic_term_2 <- gb_ref$generic_terms_for_assets %>% + dplyr::filter(`Health Index Asset Category` == asset_category) %>% + dplyr::select(`Generic Term...2`) %>% dplyr::pull() + + # Normal expected life ------------------------- + + + if (normal_expected_life == "Default") { + normal_expected_life_cable <- gb_ref$normal_expected_life %>% + dplyr::filter(`Asset Register Category` == cable_type & + `Sub-division` == sub_division) %>% + dplyr::pull() + } else { + normal_expected_life_cable <- normal_expected_life + } + + + + # Constants C and K for PoF function -------------------------------------- + if (asset_category == "EHV UG Cable (Non Pressurised)") { + type_k_c <- + gb_ref$pof_curve_parameters$`Functional Failure Category`[which( + grepl("Non Pressurised", + gb_ref$pof_curve_parameters$`Functional Failure Category`, + fixed = TRUE) == TRUE + )] + } else { + + type_k_c <- + gb_ref$pof_curve_parameters$`Functional Failure Category`[which( + grepl(asset_category, + gb_ref$pof_curve_parameters$`Functional Failure Category`, + fixed = TRUE) == TRUE + )] + } + + if (k_value == "Default") { + k <- gb_ref$pof_curve_parameters %>% + dplyr::filter(`Functional Failure Category` == + type_k_c) %>% dplyr::select(`K-Value (%)`) %>% + dplyr::pull()/100 + } else { + k <- k_value/100 + } + + c <- c_value + + # Duty factor ------------------------------------------------------------- + + duty_factor_cable <- + duty_factor_cables(utilisation_pct, + operating_voltage_pct, + voltage_level = "EHV") + + # Expected life ------------------------------ + expected_life_years <- expected_life(normal_expected_life_cable, + duty_factor_cable, + location_factor = 1) + + # b1 (Initial Ageing Rate) ------------------------------------------------ + b1 <- beta_1(expected_life_years) + + # Initial health score ---------------------------------------------------- + initial_health_score <- initial_health(b1, age) + + ## NOTE + # Typically, the Health Score Collar is 0.5 and + # Health Score Cap is 10, implying no overriding + # of the Health Score. However, in some instances + # these parameters are set to other values in the + # Health Score Modifier calibration tables. + + + # Measured condition inputs --------------------------------------------- + asset_category_mmi <- stringr::str_remove(asset_category, pattern = "UG") + asset_category_mmi <- stringr::str_squish(asset_category_mmi) + + + mcm_mmi_cal_df <- + gb_ref$measured_cond_modifier_mmi_cal + + mmi_type <- mcm_mmi_cal_df$`Asset Category`[which( + grepl(asset_category_mmi, + mcm_mmi_cal_df$`Asset Category`, + fixed = TRUE) == TRUE + )] + + + mcm_mmi_cal_df <- + mcm_mmi_cal_df[which( + mcm_mmi_cal_df$`Asset Category` == asset_category_mmi), ] + + factor_divider_1 <- + as.numeric( + mcm_mmi_cal_df$ + `Parameters for Combination Using MMI Technique - Factor Divider 1`) + + factor_divider_2 <- + as.numeric( + mcm_mmi_cal_df$ + `Parameters for Combination Using MMI Technique - Factor Divider 2`) + + max_no_combined_factors <- + as.numeric( + mcm_mmi_cal_df$ + `Parameters for Combination Using MMI Technique - Max. No. of Combined Factors` + ) + + + # Sheath test ------------------------------------------------------------- + if (asset_category == "EHV UG Cable (Non Pressurised)") { + + mci_ehv_cbl_non_pr_sheath_test <- + gb_ref$mci_ehv_cbl_non_pr_sheath_test %>% dplyr::filter( + `Condition Criteria: Sheath Test Result` == sheath_test + ) + + ci_factor_sheath <- + mci_ehv_cbl_non_pr_sheath_test$`Condition Input Factor` + ci_cap_sheath <- + mci_ehv_cbl_non_pr_sheath_test$`Condition Input Cap` + ci_collar_sheath <- + mci_ehv_cbl_non_pr_sheath_test$`Condition Input Collar` + + + mci_ehv_cbl_non_pr_prtl_disch <- + gb_ref$mci_ehv_cbl_non_pr_prtl_disch %>% + dplyr::filter( + `Condition Criteria: Partial Discharge Test Result` == partial_discharge + ) + + # Partial discharge------------------------------------------------------- + + + ci_factor_partial <- + mci_ehv_cbl_non_pr_prtl_disch$`Condition Input Factor` + ci_cap_partial <- mci_ehv_cbl_non_pr_prtl_disch$`Condition Input Cap` + ci_collar_partial <- + mci_ehv_cbl_non_pr_prtl_disch$`Condition Input Collar` + + mci_ehv_cbl_non_pr_fault_hist <- + gb_ref$mci_ehv_cbl_non_pr_fault_hist + + + # Fault ------------------------------------------------------- + + for (n in 2:4) { + if (fault_hist == 'Default' || fault_hist == + 'No historic faults recorded') { + no_row <- which(mci_ehv_cbl_non_pr_fault_hist$Upper == fault_hist) + + ci_factor_fault <- + mci_ehv_cbl_non_pr_fault_hist$`Condition Input Factor`[no_row] + ci_cap_fault <- + mci_ehv_cbl_non_pr_fault_hist$`Condition Input Cap`[no_row] + ci_collar_fault <- + mci_ehv_cbl_non_pr_fault_hist$`Condition Input Collar`[no_row] + break + } else if (fault_hist >= + as.numeric(mci_ehv_cbl_non_pr_fault_hist$Lower[n]) & + fault_hist < + as.numeric(mci_ehv_cbl_non_pr_fault_hist$Upper[n])) { + + ci_factor_fault <- + mci_ehv_cbl_non_pr_fault_hist$`Condition Input Factor`[n] + ci_cap_fault <- + mci_ehv_cbl_non_pr_fault_hist$`Condition Input Cap`[n] + ci_collar_fault <- + mci_ehv_cbl_non_pr_fault_hist$`Condition Input Collar`[n] + + break + } + } + + # Measured conditions + + factors <- c(ci_factor_sheath, + ci_factor_partial, + ci_factor_fault) + + measured_condition_factor <- mmi(factors, + factor_divider_1, + factor_divider_2, + max_no_combined_factors) + + caps <- c(ci_cap_sheath, + ci_cap_partial, + ci_cap_fault) + measured_condition_cap <- min(caps) + + # Measured condition collar ---------------------------------------------- + collars <- c(ci_collar_sheath, + ci_collar_partial, + ci_collar_fault) + measured_condition_collar <- max(collars) + + } else if (asset_category == "EHV UG Cable (Oil)") { + + mci_ehv_cable_oil_leakage <- + gb_ref$mci_ehv_cable_oil_leakage %>% dplyr::filter( + `Condition Criteria: Leakage Rate` == leakage + ) + + ci_factor_leakage_oil <- + mci_ehv_cable_oil_leakage$`Condition Input Factor` + ci_cap_leakage_oil <- + mci_ehv_cable_oil_leakage$`Condition Input Cap` + ci_collar_leakage_oil <- + mci_ehv_cable_oil_leakage$`Condition Input Collar` + + # Measured conditions + + measured_condition_factor <- ci_factor_leakage_oil + measured_condition_cap <- ci_cap_leakage_oil + measured_condition_collar <- ci_collar_leakage_oil + + + } else if (asset_category == "EHV UG Cable (Gas)") { + + mci_ehv_cbl_gas <- + gb_ref$mci_ehv_cable_gas_leakage %>% dplyr::filter( + `Condition Criteria: Leakage Rate` == leakage + ) + + ci_factor_leakage_gas <- mci_ehv_cbl_gas$`Condition Input Factor` + ci_cap_leakage_gas <- mci_ehv_cbl_gas$`Condition Input Cap` + ci_collar_leakage_gas <- mci_ehv_cbl_gas$`Condition Input Collar` + + # Measured conditions + + measured_condition_factor <- ci_factor_leakage_gas + measured_condition_cap <- ci_cap_leakage_gas + measured_condition_collar <- ci_collar_leakage_gas + + } + + + # Measured condition modifier --------------------------------------------- + measured_condition_modifier <- data.frame(measured_condition_factor, + measured_condition_cap, + measured_condition_collar) + + + # Health score factor --------------------------------------------------- + health_score_factor <- measured_condition_modifier$measured_condition_factor + + # Health score cap -------------------------------------------------------- + health_score_cap <- measured_condition_modifier$measured_condition_cap + + # Health score collar ----------------------------------------------------- + health_score_collar <- measured_condition_modifier$measured_condition_collar + + # Health score modifier --------------------------------------------------- + health_score_modifier <- data.frame(health_score_factor, + health_score_cap, + health_score_collar) + + # Current health score ---------------------------------------------------- + current_health_score <- + current_health(initial_health_score, + health_score_modifier$health_score_factor, + health_score_modifier$health_score_cap, + health_score_modifier$health_score_collar, + reliability_factor = reliability_factor) + + # Probability of failure --------------------------------------------------- + probability_of_failure <- k * + (1 + (c * current_health_score) + + (((c * current_health_score)^2) / factorial(2)) + + (((c * current_health_score)^3) / factorial(3))) + + + # Future probability of failure ------------------------------------------- + + # the Health Score of a new asset + H_new <- 0.5 + + # the Health Score of the asset when it reaches its Expected Life + b2 <- beta_2(current_health_score, age) + print(b2) + if (b2 > 2*b1){ + b2 <- b1*2 + } else if (current_health_score == 0.5){ + b2 <- b1 + } + + if (current_health_score < 2) { + ageing_reduction_factor <- 1 + } else if (current_health_score <= 5.5) { + ageing_reduction_factor <- ((current_health_score - 2)/7) + 1 + } else { + ageing_reduction_factor <- 1.5 + } + + # Dynamic part + pof_year <- list() + year <- seq(from=0,to=simulation_end_year,by=1) + + for (y in 1:length(year)){ + t <- year[y] + + future_health_Score <- current_health_score*exp((b2/ageing_reduction_factor) * t) + + H <- future_health_Score + + future_health_score_limit <- 15 + if (H > future_health_score_limit){ + H <- future_health_score_limit + } else if (H < 4) { + H <- 4 + } + pof_year[[paste(y)]] <- k * (1 + (c * H) + + (((c * H)^2) / factorial(2)) + + (((c * H)^3) / factorial(3))) + } + + pof_future <- data.frame(year=year, PoF=as.numeric(unlist(pof_year))) + pof_future$age <- NA + pof_future$age[1] <- age + + for(i in 2:nrow(pof_future)) { + + pof_future$age[i] <- age + i -1 + + } + + return(pof_future) + } diff --git a/R/pof_future_tower_ohl_support_50kv.R b/R/pof_future_tower_ohl_support_50kv.R new file mode 100644 index 00000000..1864fdc5 --- /dev/null +++ b/R/pof_future_tower_ohl_support_50kv.R @@ -0,0 +1,319 @@ +#' @importFrom magrittr %>% +#' @title Future Probability of Failure for Towers OHL Support 50 kV +#' @description This function calculates the future +#' annual probability of failure per kilometer for a towers OHL support 50 kV. +#' The function is a cubic curve that is based on +#' the first three terms of the Taylor series for an +#' exponential function. +#' @inheritParams pof_tower_ohl_support_50kv +#' @param simulation_end_year Numeric. The last year of simulating probability +#' of failure. Default is 100. +#' @return Numeric array. Future probability of failure +#' per annum for Towers OHL support 50 kV. +#' @export +#' @examples +#' # Future annual probability of failure for Towers +# pof_future_tower_ohl_support_50kv( +# number_of_operations = "Default", +# placement = "Default", +# altitude_m = "Default", +# distance_from_coast_km = "Default", +# corrosion_category_index = "Default", +# age = 10, +# paint_type = "Paint System - Galvanising", +# foundation_type = "Foundation - Earth Grillage", +# observed_condition_inputs_steelwork = +# list("tower_legs" = list("Condition Criteria: Observed Condition" = "Default"), +# "tower_bracings" = list("Condition Criteria: Observed Condition" = "Default"), +# "tower_crossarms" = list("Condition Criteria: Observed Condition" = "Default"), +# "tower_peak" = list("Condition Criteria: Observed Condition" = "Default")), +# observed_condition_inputs_paint = +# list("paintwork_cond" = list("Condition Criteria: Observed Condition" = "Default")), +# observed_condition_inputs_foundation = +# list("foundation_cond" = list("Condition Criteria: Observed Condition" = "Default")), +# reliability_factor = "Default", +# k_value = 0.0545, +# c_value = 1.087, +# normal_expected_life = "Default", +# simulation_end_year = 100) + + +pof_future_tower_ohl_support_50kv <- + function(foundation_type = "Foundation - Fully Encased Concrete", + paint_type = "Paint System - Paint", + placement = "Default", + number_of_operations = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age, + observed_condition_inputs_steelwork, + observed_condition_inputs_paint, + observed_condition_inputs_foundation, + reliability_factor = "Default", + k_value = 0.0545, + c_value = 1.087, + normal_expected_life = "Default", + simulation_end_year = 100) { + + tower_asset_category <- "66kV Tower" + `Asset Register Category` = `Health Index Asset Category` = `Sub-division` = + `Generic Term...1` = `Generic Term...2` = `Functional Failure Category` = + `K-Value (%)` = `C-Value` = `Asset Register Category` = NULL + # due to NSE notes in R CMD check + + asset_category <- gb_ref$categorisation_of_assets %>% + dplyr::filter(`Asset Register Category` == + tower_asset_category) %>% + dplyr::select(`Health Index Asset Category`) %>% dplyr::pull() + + generic_term_1 <- gb_ref$generic_terms_for_assets %>% + dplyr::filter(`Health Index Asset Category` == asset_category) %>% + dplyr::select(`Generic Term...1`) %>% dplyr::pull() + + generic_term_2 <- gb_ref$generic_terms_for_assets %>% + dplyr::filter(`Health Index Asset Category` == asset_category) %>% + dplyr::select(`Generic Term...2`) %>% dplyr::pull() + + # Normal expected life ------------------------- + + if (normal_expected_life == "Default") { + normal_expected_life_steelwork <- gb_ref$normal_expected_life %>% + dplyr::filter(`Asset Register Category` == + tower_asset_category, `Sub-division` == "Steelwork") %>% + dplyr::pull() + + normal_expected_life_foundation <- gb_ref$normal_expected_life %>% + dplyr::filter(`Asset Register Category` == + tower_asset_category, `Sub-division` == foundation_type) %>% + dplyr::pull() + + normal_expected_life_paint <- gb_ref$normal_expected_life %>% + dplyr::filter(`Asset Register Category` == + tower_asset_category, `Sub-division` == paint_type) %>% + dplyr::pull() + } else { + normal_expected_life_steelwork <- normal_expected_life + normal_expected_life_foundation <- normal_expected_life + normal_expected_life_paint <- normal_expected_life + } + + + # Constants C and K for PoF function -------------------------------------- + k <- k_value/100 + c <- c_value + + # Duty factor ---------------------------------------------------- + duty_factor <- 1 + + # Location factor ---------------------------------------------------- + location_factor <- location_factor(placement, + altitude_m, + distance_from_coast_km, + corrosion_category_index, + asset_type = tower_asset_category) + + + # Expected life for structure ------------------------------ + expected_life_years_steelwork <- expected_life(normal_expected_life = + normal_expected_life_steelwork, + duty_factor, + location_factor) + + # Expected life for paint ------------------------------ + expected_life_years_foundation <- expected_life(normal_expected_life = + normal_expected_life_foundation, + duty_factor, + location_factor) + + # Expected life for paint ------------------------------ + expected_life_years_paint <- expected_life(normal_expected_life = + normal_expected_life_paint, + duty_factor, + location_factor) + + # b1 (Initial Ageing Rate) ------------------------------------------------ + b1_steelwork <- beta_1(expected_life_years_steelwork) + b1_foundation <- beta_1(expected_life_years_foundation) + b1_paint <- beta_1(expected_life_years_paint) + + # Initial health score ---------------------------------------------------- + initial_health_score_steelwork <- initial_health(b1_steelwork, age) + initial_health_score_foundation <- initial_health(b1_foundation, age) + initial_health_score_paint <- initial_health(b1_paint, age) + + + # Measured conditions + measured_condition_modifier <- data.frame(condition_factor = 1, + condition_cap = 10, + condition_collar = 0.5) + + # Observed conditions ----------------------------------------------------- + + # The table data is same for all towers category + oci_table_names_steelwork <- list("tower_legs" = "oci_ehv_tower_tower_legs", + "tower_bracings" = "oci_ehv_tower_bracings", + "tower_crossarms" = "oci_ehv_tower_crossarms", + "tower_peak" = "oci_ehv_tower_peak") + + oci_table_names_paint <- list("paintwork_cond" = "oci_ehv_tower_paintwork_cond") + + oci_table_names_foundation <- list("foundation_cond" = "oci_ehv_tower_foundation_cond") + + observed_condition_modifier_steelwork <- + get_observed_conditions_modifier_hv_switchgear("EHV Towers", + oci_table_names_steelwork, + observed_condition_inputs_steelwork, + "Tower Steelwork") + + observed_condition_modifier_paint <- + get_observed_conditions_modifier_hv_switchgear("EHV Towers", + oci_table_names_paint, + observed_condition_inputs_paint, + "Tower Paintwork") + + observed_condition_modifier_foundation <- + get_observed_conditions_modifier_hv_switchgear("EHV Towers", + oci_table_names_foundation, + observed_condition_inputs_foundation, + "Foundations") + + # Health score factor --------------------------------------------------- + health_score_factor_steelwork <- + health_score_excl_ehv_132kv_tf(observed_condition_modifier_steelwork$condition_factor, + measured_condition_modifier$condition_factor) + + health_score_factor_paint <- + health_score_excl_ehv_132kv_tf(observed_condition_modifier_paint$condition_factor, + measured_condition_modifier$condition_factor) + + health_score_factor_foundation <- + health_score_excl_ehv_132kv_tf(observed_condition_modifier_foundation$condition_factor, + measured_condition_modifier$condition_factor) + + # Health score cap -------------------------------------------------------- + health_score_cap_steelwork <- min(observed_condition_modifier_steelwork$condition_cap, + measured_condition_modifier$condition_cap) + + health_score_cap_paint <- min(observed_condition_modifier_paint$condition_cap, + measured_condition_modifier$condition_cap) + + health_score_cap_foundation <- min(observed_condition_modifier_foundation$condition_cap, + measured_condition_modifier$condition_cap) + + # Health score collar ----------------------------------------------------- + health_score_collar_steelowrk <- max(observed_condition_modifier_steelwork$condition_collar, + measured_condition_modifier$condition_collar) + + health_score_collar_paint <- max(observed_condition_modifier_paint$condition_collar, + measured_condition_modifier$condition_collar) + + health_score_collar_foundation <- max(observed_condition_modifier_foundation$condition_collar, + measured_condition_modifier$condition_collar) + + # Health score modifier --------------------------------------------------- + health_score_modifier_steelwork <- data.frame(health_score_factor_steelwork, + health_score_cap_steelwork, + health_score_collar_steelowrk) + + health_score_modifier_paint <- data.frame(health_score_factor_paint, + health_score_cap_paint, + health_score_collar_paint) + + health_score_modifier_foundation <- data.frame(health_score_factor_foundation, + health_score_cap_foundation, + health_score_collar_foundation) + + # Current health score ---------------------------------------------------- + current_health_score_steelwork <- + current_health(initial_health_score_steelwork, + health_score_modifier_steelwork$health_score_factor, + health_score_modifier_steelwork$health_score_cap, + health_score_modifier_steelwork$health_score_collar, + reliability_factor = reliability_factor) + + current_health_score_paint <- + current_health(initial_health_score_paint, + health_score_modifier_paint$health_score_factor, + health_score_modifier_paint$health_score_cap, + health_score_modifier_paint$health_score_collar, + reliability_factor = reliability_factor) + + current_health_score_foundation <- + current_health(initial_health_score_foundation, + health_score_modifier_foundation$health_score_factor, + health_score_modifier_foundation$health_score_cap, + health_score_modifier_foundation$health_score_collar, + reliability_factor = reliability_factor) + + current_health_score_paint <- min(current_health_score_paint, 6.4) + + current_health_score <- max(current_health_score_foundation, + current_health_score_steelwork, + current_health_score_paint) + + # Probability of failure --------------------------------------------------- + probability_of_failure <- k * + (1 + (c * current_health_score) + + (((c * current_health_score)^2) / factorial(2)) + + (((c * current_health_score)^3) / factorial(3))) + + + # Future probability of failure ------------------------------------------- + + # the Health Score of a new asset + H_new <- 0.5 + + # the Health Score of the asset when it reaches its Expected Life + b2 <- beta_2(current_health_score, age) + print(b2) + if (b2 > 2*b1){ + b2 <- b1*2 + } else if (current_health_score == 0.5){ + b2 <- b1 + } + + if (current_health_score < 2) { + ageing_reduction_factor <- 1 + } else if (current_health_score <= 5.5) { + ageing_reduction_factor <- ((current_health_score - 2)/7) + 1 + } else { + ageing_reduction_factor <- 1.5 + } + + # Dynamic part + pof_year <- list() + year <- seq(from=0,to=simulation_end_year,by=1) + + for (y in 1:length(year)){ + t <- year[y] + + future_health_Score <- current_health_score*exp((b2/ageing_reduction_factor) * t) + + H <- future_health_Score + + future_health_score_limit <- 15 + if (H > future_health_score_limit){ + H <- future_health_score_limit + } else if (H < 4) { + H <- 4 + } + pof_year[[paste(y)]] <- k * (1 + (c * H) + + (((c * H)^2) / factorial(2)) + + (((c * H)^3) / factorial(3))) + } + + pof_future <- data.frame(year=year, PoF=as.numeric(unlist(pof_year))) + pof_future$age <- NA + pof_future$age[1] <- age + + for(i in 2:nrow(pof_future)) { + + pof_future$age[i] <- age + i -1 + + } + + return(pof_future) + } + + diff --git a/R/pof_ohl_cond_50kv.R b/R/pof_ohl_cond_50kv.R new file mode 100644 index 00000000..2eafb2c7 --- /dev/null +++ b/R/pof_ohl_cond_50kv.R @@ -0,0 +1,442 @@ +#' @importFrom magrittr %>% +#' @title Current Probability of Failure for 50kV OHL Conductors +#' @description This function calculates the current +#' annual probability of failure per kilometer 50kV OHL conductors. +#' The function is a cubic curve that is based on +#' the first three terms of the Taylor series for an +#' exponential function. +#' @param sub_division String. Refers to material the conductor is +#' made of. Options: +#' \code{sub_division = c("ACSR - greased","ACSR - non-greased", "AAAC", +#' "Cad Cu", "Cu", "Other")}. +#' @inheritParams location_factor +#' @param altitude_m Numeric. Specify the altitude location for +#' the asset measured in meters from sea level.\code{altitude_m} +#' is used to derive the altitude factor. A setting of \code{"Default"} +#' will set the altitude factor to 1 independent of \code{asset_type}. +#' @param distance_from_coast_km Numeric. Specify the distance from the +#' coast measured in kilometers. \code{distance_from_coast_km} is used +#' to derive the distance from coast factor. A setting of \code{"Default"} will set the +#' distance from coast factor to 1 independent of \code{asset_type}. +#' @param corrosion_category_index Integer. +#' Specify the corrosion index category, 1-5. +#' @param age Numeric. The current age in years of the conductor. +#' @param conductor_samp String. Conductor sampling. Options: +#' \code{conductor_samp = c("Low","Medium/Normal","High","Default")}. +#' @param corr_mon_survey String. Corrosion monitoring survey. Options: +#' \code{corr_mon_survey = c("Low","Medium/Normal","High","Default")}. +#' @param visual_cond String. Visual condition. Options: +#' \code{visual_cond = c("No deterioration","Superficial/minor deterioration", +#' "Some Deterioration", +#' "Substantial Deterioration", "Default")}. +#' @param midspan_joints Integer. Number of midspan joints on the conductor. +#' A span includes all conductors in that span. +#' @inheritParams current_health +#' @param k_value Numeric. \code{k_value = 0.0080} by default. This number is +#' given in a percentage. The default value is accordingly to the CNAIM standard +#' on p. 110. +#' @param c_value Numeric. \code{c_value = 1.087} by default. +#' The default value is accordingly to the CNAIM standard see page 110 +#' @param normal_expected_life Numeric. \code{normal_expected_life = "Default"} by default. +#' The default value is accordingly to the CNAIM standard on page 107. +#' @return Numeric. Current probability of failure +#' per annum per kilometer. +#' @export +#' @examples +#' # Current annual probability of failure for 50kV OHL (Tower Line) Conductor +# pof_ohl_cond_50kV_res <- +# pof_ohl_cond_50kv( +# sub_division = "Cu", +# placement = "Default", +# altitude_m = "Default", +# distance_from_coast_km = "Default", +# corrosion_category_index = "Default", +# age = 10, +# conductor_samp = "Default", +# corr_mon_survey = "Default", +# visual_cond = "Default", +# midspan_joints = "Default", +# reliability_factor = "Default", +# k_value = 0.0080, +# c_value = 1.087, +# normal_expected_life = "Default") * 100 +# paste0(sprintf("Probability of failure %.4f", pof_ohl_cond_50kV_res), +# " percent per annum") + +pof_ohl_cond_50kv <- + function(sub_division = "Cu", + placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age, + conductor_samp = "Default", + corr_mon_survey = "Default", + visual_cond = "Default", + midspan_joints = "Default", + reliability_factor = "Default", + k_value = 0.0080, + c_value = 1.087, + normal_expected_life = "Default") { + + ohl_conductor <- "66kV OHL (Tower Line) Conductor" + + `Asset Register Category` = `Health Index Asset Category` = + `Generic Term...1` = `Generic Term...2` = `Functional Failure Category` = + `K-Value (%)` = `C-Value` = `Asset Register Category` = `Sub-division` = + `Condition Criteria: Conductor Sampling Result` = + `Condition Criteria: Corrosion Monitoring Survey Result` = + `Condition Criteria: Observed Condition` = + `Condition Criteria: No. of Midspan Joints` = NULL + # due to NSE notes in R CMD check + + # Ref. table Categorisation of Assets and Generic Terms for Assets -- + + asset_category <- gb_ref$categorisation_of_assets %>% + dplyr::filter(`Asset Register Category` == ohl_conductor) %>% + dplyr::select(`Health Index Asset Category`) %>% dplyr::pull() + + generic_term_1 <- gb_ref$generic_terms_for_assets %>% + dplyr::filter(`Health Index Asset Category` == asset_category) %>% + dplyr::select(`Generic Term...1`) %>% dplyr::pull() + + generic_term_2 <- gb_ref$generic_terms_for_assets %>% + dplyr::filter(`Health Index Asset Category` == asset_category) %>% + dplyr::select(`Generic Term...2`) %>% dplyr::pull() + + # Normal expected life ------------------------- + normal_expected_life_cond <- gb_ref$normal_expected_life %>% + dplyr::filter(`Asset Register Category` == ohl_conductor & + `Sub-division` == sub_division) %>% + dplyr::pull() + + if (normal_expected_life == "Default") { + normal_expected_life_cond <- gb_ref$normal_expected_life %>% + dplyr::filter(`Asset Register Category` == ohl_conductor & + `Sub-division` == sub_division) %>% + dplyr::pull() + } else { + normal_expected_life_cond <- normal_expected_life + } + + # Constants C and K for PoF function -------------------------------------- + + k <- k_value/100 + c <- c_value + + # Duty factor ------------------------------------------------------------- + + duty_factor_cond <- 1 + + # Location factor ---------------------------------------------------- + location_factor_cond <- location_factor(placement, + altitude_m, + distance_from_coast_km, + corrosion_category_index, + asset_type = ohl_conductor) + # Expected life ------------------------------ + expected_life_years <- expected_life(normal_expected_life_cond, + duty_factor_cond, + location_factor_cond) + + # b1 (Initial Ageing Rate) ------------------------------------------------ + b1 <- beta_1(expected_life_years) + + # Initial health score ---------------------------------------------------- + initial_health_score <- initial_health(b1, age) + + ## NOTE + # Typically, the Health Score Collar is 0.5 and + # Health Score Cap is 10, implying no overriding + # of the Health Score. However, in some instances + # these parameters are set to other values in the + # Health Score Modifier calibration tables. + + # Measured condition inputs --------------------------------------------- + if (asset_category == "EHV OHL Conductor (Tower Lines)") { + asset_category_mmi <- "EHV Tower Line Conductor" + } + if (asset_category == "132kV OHL Conductor (Tower Lines)") { + asset_category_mmi <- "132kV Tower Line Conductor" + } + + mcm_mmi_cal_df <- + gb_ref$measured_cond_modifier_mmi_cal + + mcm_mmi_cal_df <- + mcm_mmi_cal_df[which( + mcm_mmi_cal_df$`Asset Category` == asset_category_mmi), ] + + factor_divider_1 <- + as.numeric( + mcm_mmi_cal_df$ + `Parameters for Combination Using MMI Technique - Factor Divider 1`) + + factor_divider_2 <- + as.numeric( + mcm_mmi_cal_df$ + `Parameters for Combination Using MMI Technique - Factor Divider 2`) + + max_no_combined_factors <- + as.numeric( + mcm_mmi_cal_df$ + `Parameters for Combination Using MMI Technique - Max. No. of Combined Factors` + ) + + + # Measured inputs----------------------------------------------------------- + # Conductor sampling + + if (asset_category == "132kV OHL Conductor (Tower Lines)") { + + mci_132kv_twr_line_cond_sampl <- + gb_ref$mci_132kv_twr_line_cond_sampl %>% dplyr::filter( + `Condition Criteria: Conductor Sampling Result` == conductor_samp + ) + + ci_factor_cond_samp <- + mci_132kv_twr_line_cond_sampl$`Condition Input Factor` + ci_cap_cond_samp <- + mci_132kv_twr_line_cond_sampl$`Condition Input Cap` + ci_collar_cond_samp <- + mci_132kv_twr_line_cond_sampl$`Condition Input Collar` + + + # Corrosion monitoring survey + mci_132kv_twr_line_cond_srvy <- + gb_ref$mci_132kv_twr_line_cond_srvy %>% dplyr::filter( + `Condition Criteria: Corrosion Monitoring Survey Result` == + corr_mon_survey + ) + + + ci_factor_cond_srvy <- + mci_132kv_twr_line_cond_srvy$`Condition Input Factor` + ci_cap_cond_srvy <- mci_132kv_twr_line_cond_srvy$`Condition Input Cap` + ci_collar_cond_srvy <- + mci_132kv_twr_line_cond_srvy$`Condition Input Collar` + + } else { + + mci_ehv_twr_line_cond_sampl <- + gb_ref$mci_ehv_twr_line_cond_sampl %>% dplyr::filter( + `Condition Criteria: Conductor Sampling Result` == conductor_samp + ) + + ci_factor_cond_samp <- + mci_ehv_twr_line_cond_sampl$`Condition Input Factor` + ci_cap_cond_samp <- + mci_ehv_twr_line_cond_sampl$`Condition Input Cap` + ci_collar_cond_samp <- + mci_ehv_twr_line_cond_sampl$`Condition Input Collar` + + + # Corrosion monitoring survey + mci_ehv_twr_line_cond_srvy <- + gb_ref$mci_ehv_twr_line_cond_srvy %>% dplyr::filter( + `Condition Criteria: Corrosion Monitoring Survey Result` == + corr_mon_survey + ) + + + ci_factor_cond_srvy <- + mci_ehv_twr_line_cond_srvy$`Condition Input Factor` + ci_cap_cond_srvy <- mci_ehv_twr_line_cond_srvy$`Condition Input Cap` + ci_collar_cond_srvy <- + mci_ehv_twr_line_cond_srvy$`Condition Input Collar` + + } + + # Measured conditions + + factors <- c(ci_factor_cond_samp, + ci_factor_cond_srvy) + + measured_condition_factor <- mmi(factors, + factor_divider_1, + factor_divider_2, + max_no_combined_factors) + + caps <- c(ci_cap_cond_samp, + ci_cap_cond_srvy) + + measured_condition_cap <- min(caps) + + # Measured condition collar ---------------------------------------------- + collars <- c(ci_collar_cond_samp, + ci_collar_cond_srvy) + + measured_condition_collar <- max(collars) + + + # Measured condition modifier --------------------------------------------- + measured_condition_modifier <- data.frame(measured_condition_factor, + measured_condition_cap, + measured_condition_collar) + + + + # Observed conditions ----------------------------------------------------- + + oci_mmi_cal_df <- + gb_ref$observed_cond_modifier_mmi_cal + + oci_mmi_cal_df <- + oci_mmi_cal_df[which( + oci_mmi_cal_df$`Asset Category` == asset_category_mmi), ] + + factor_divider_1 <- + as.numeric( + oci_mmi_cal_df$`Parameters for Combination Using MMI Technique - Factor Divider 1`) + + factor_divider_2 <- + as.numeric( + oci_mmi_cal_df$`Parameters for Combination Using MMI Technique - Factor Divider 2`) + + max_no_combined_factors <- + as.numeric( + oci_mmi_cal_df$ + `Parameters for Combination Using MMI Technique - Max. No. of Combined Factors` + ) + + + # Observed inputs----------------------------------------------------------- + # Visual condition + + if (asset_category == "132kV OHL Conductor (Tower Lines)") { + + oci_132kv_twr_line_visual_cond <- + gb_ref$oci_132kv_twr_line_visual_cond %>% dplyr::filter( + `Condition Criteria: Observed Condition` == visual_cond + ) + + ci_factor_visual_cond <- + oci_132kv_twr_line_visual_cond$`Condition Input Factor` + ci_cap_visual_cond <- + oci_132kv_twr_line_visual_cond$`Condition Input Cap` + ci_collar_visual_cond <- + oci_132kv_twr_line_visual_cond$`Condition Input Collar` + + + # Midspan joints + + if (is.numeric(midspan_joints)) { + if(midspan_joints < 3) { + midspan_joints <- as.character(midspan_joints) + } else if (midspan_joints > 2){ + midspan_joints <- ">2" + } + + } + + oci_132kv_twr_line_cond_midspn <- + gb_ref$oci_132kv_twr_line_cond_midspn %>% dplyr::filter( + `Condition Criteria: No. of Midspan Joints` == midspan_joints + ) + + ci_factor_midspan_joints <- + oci_132kv_twr_line_cond_midspn$`Condition Input Factor` + ci_cap_midspan_joints <- oci_132kv_twr_line_cond_midspn$`Condition Input Cap` + ci_collar_midspan_joints <- + oci_132kv_twr_line_cond_midspn$`Condition Input Collar` + + } else { + + oci_ehv_twr_line_visal_cond <- + gb_ref$oci_ehv_twr_line_visal_cond %>% dplyr::filter( + `Condition Criteria: Observed Condition` == visual_cond + ) + + ci_factor_visual_cond <- + oci_ehv_twr_line_visal_cond$`Condition Input Factor` + ci_cap_visual_cond <- + oci_ehv_twr_line_visal_cond$`Condition Input Cap` + ci_collar_visual_cond <- + oci_ehv_twr_line_visal_cond$`Condition Input Collar` + + + # Midspan joints + + if (is.numeric(midspan_joints)) { + if(midspan_joints < 3) { + midspan_joints <- as.character(midspan_joints) + } else if (midspan_joints > 2){ + midspan_joints <- ">2" + } + + } + + oci_ehv_twr_cond_midspan_joint <- + gb_ref$oci_ehv_twr_cond_midspan_joint %>% dplyr::filter( + `Condition Criteria: No. of Midspan Joints` == midspan_joints + ) + + ci_factor_midspan_joints <- + oci_ehv_twr_cond_midspan_joint$`Condition Input Factor` + ci_cap_midspan_joints <- oci_ehv_twr_cond_midspan_joint$`Condition Input Cap` + ci_collar_midspan_joints <- + oci_ehv_twr_cond_midspan_joint$`Condition Input Collar` + } + + + # Observed conditions + + factors <- c(ci_factor_visual_cond, + ci_factor_midspan_joints) + + observed_condition_factor <- mmi(factors, + factor_divider_1, + factor_divider_2, + max_no_combined_factors) + + caps <- c(ci_cap_visual_cond, + ci_cap_midspan_joints) + + observed_condition_cap <- min(caps) + + # Observed condition collar ---------------------------------------------- + collars <- c(ci_collar_visual_cond, + ci_collar_midspan_joints) + + observed_condition_collar <- max(collars) + + + # Observed condition modifier --------------------------------------------- + observed_condition_modifier <- data.frame(observed_condition_factor, + observed_condition_cap, + observed_condition_collar) + + # Health score factor --------------------------------------------------- + health_score_factor <- + health_score_excl_ehv_132kv_tf(observed_condition_factor, + measured_condition_factor) + + # Health score cap -------------------------------------------------------- + health_score_cap <- min(observed_condition_cap, measured_condition_cap) + + # Health score collar ----------------------------------------------------- + health_score_collar <- max(observed_condition_collar, + measured_condition_collar) + + # Health score modifier --------------------------------------------------- + health_score_modifier <- data.frame(health_score_factor, + health_score_cap, + health_score_collar) + + # Current health score ---------------------------------------------------- + current_health_score <- + current_health(initial_health_score, + health_score_modifier$health_score_factor, + health_score_modifier$health_score_cap, + health_score_modifier$health_score_collar, + reliability_factor = reliability_factor) + + # Probability of failure --------------------------------------------------- + probability_of_failure <- k * + (1 + (c * current_health_score) + + (((c * current_health_score)^2) / factorial(2)) + + (((c * current_health_score)^3) / factorial(3))) + + + return(probability_of_failure) + } diff --git a/R/pof_ohl_fittings_50kv.R b/R/pof_ohl_fittings_50kv.R new file mode 100644 index 00000000..da2756f9 --- /dev/null +++ b/R/pof_ohl_fittings_50kv.R @@ -0,0 +1,188 @@ +#' @importFrom magrittr %>% +#' @title Current Probability of Failure for 50kV Fittings +#' @description This function calculates the current +#' annual probability of failure per kilometer 50kV Fittings +#' The function is a cubic curve that is based on +#' the first three terms of the Taylor series for an +#' exponential function. +#' @param placement String. Specify if the asset is located outdoor or indoor. +#' @param altitude_m Numeric. Specify the altitude location for +#' the asset measured in meters from sea level.\code{altitude_m} +#' is used to derive the altitude factor. A setting of \code{"Default"} +#' will set the altitude factor to 1 independent of \code{asset_type}. +#' @param distance_from_coast_km Numeric. Specify the distance from the +#' coast measured in kilometers. \code{distance_from_coast_km} is used +#' to derive the distance from coast factor. +#' A setting of \code{"Default"} will set the +#' distance from coast factor to 1 independent of \code{asset_type}. +#' @param corrosion_category_index Integer. +#' Specify the corrosion index category, 1-5. +#' @param age Numeric. The current age in years of the conductor. +#' @param measured_condition_inputs Named list observed_conditions_input +#' @param observed_condition_inputs Named list observed_conditions_input +#' \code{conductor_samp = c("Low","Medium/Normal","High","Default")}. +#' @inheritParams current_health +#' @param k_value Numeric. \code{k_value = 0.0096} by default. This number is +#' given in a percentage. The default value is accordingly to the CNAIM standard +#' on p. 110. +#' @param c_value Numeric. \code{c_value = 1.087} by default. +#' The default value is accordingly to the CNAIM standard see page 110 +#' @param normal_expected_life Numeric. \code{normal_expected_life = 40} by default. +#' The default value is accordingly to the CNAIM standard on page 107. +#' @return Numeric. Current probability of failure +#' per annum per kilometer. +#' @export +#' @examples +#' # Current annual probability of failure for 50kV fittings +# pof_ohl_fittings_50kV_res <- +# pof_ohl_fittings_50kv( +# placement = "Default", +# altitude_m = "Default", +# distance_from_coast_km = "Default", +# corrosion_category_index = "Default", +# age = 10, +# observed_condition_inputs = +# list("insulator_elec_cond" = +# list("Condition Criteria: Observed Condition" = "Default"), +# "insulator_mech_cond" = +# list("Condition Criteria: Observed Condition" = "Default"), +# "conductor_fitting_cond" = +# list("Condition Criteria: Observed Condition" = "Default"), +# "tower_fitting_cond" = +# list("Condition Criteria: Observed Condition" = "Default")), +# measured_condition_inputs = +# list("thermal_imaging" = +# list("Condition Criteria: Thermal Imaging Result" = "Default"), +# "ductor_test" = list("Condition Criteria: Ductor Test Result" = "Default")), +# reliability_factor = "Default", +# k_value = 0.0096, +# c_value = 1.087, +# normal_expected_life = 40) * 100 +# paste0(sprintf("Probability of failure %.4f", pof_ohl_fittings_50kV_res), +# " percent per annum") + +pof_ohl_fittings_50kv <- + function(placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age, + measured_condition_inputs, + observed_condition_inputs, + reliability_factor = "Default", + k_value = 0.0096, + c_value = 1.087, + normal_expected_life = 40) { + + + ehv_asset_category = "66kV Fittings" + `Asset Register Category` = `Health Index Asset Category` = + `Generic Term...1` = `Generic Term...2` = `Functional Failure Category` = + `K-Value (%)` = `C-Value` = `Asset Register Category` = NULL + # due to NSE notes in R CMD check + + asset_category <- gb_ref$categorisation_of_assets %>% + dplyr::filter(`Asset Register Category` == + ehv_asset_category) %>% + dplyr::select(`Health Index Asset Category`) %>% dplyr::pull() + + generic_term_1 <- gb_ref$generic_terms_for_assets %>% + dplyr::filter(`Health Index Asset Category` == asset_category) %>% + dplyr::select(`Generic Term...1`) %>% dplyr::pull() + + generic_term_2 <- gb_ref$generic_terms_for_assets %>% + dplyr::filter(`Health Index Asset Category` == asset_category) %>% + dplyr::select(`Generic Term...2`) %>% dplyr::pull() + + + + # Constants C and K for PoF function -------------------------------------- + + k <- k_value/100 + + c <- c_value + + # Duty factor ------------------------------------------------------------- + + duty_factor_cond <- 1 + + # Location factor ---------------------------------------------------- + location_factor_cond <- location_factor(placement, + altitude_m, + distance_from_coast_km, + corrosion_category_index, + asset_type = ehv_asset_category) + # Expected life ------------------------------ + expected_life_years <- expected_life(normal_expected_life, + duty_factor_cond, + location_factor_cond) + + # b1 (Initial Ageing Rate) ------------------------------------------------ + b1 <- beta_1(expected_life_years) + + # Initial health score ---------------------------------------------------- + initial_health_score <- initial_health(b1, age) + + # Measured conditions + mci_table_names <- list("thermal_imaging" = "mci_ehv_fittings_thrml_imaging", + "ductor_test" = "mci_ehv_fittings_ductor_test") + + asset_category_mmi <- "EHV Fittings" + + if(ehv_asset_category == "132kV Fittings"){ + asset_category_mmi <- "132kV Fittings" + } + + measured_condition_modifier <- + get_measured_conditions_modifier_hv_switchgear(asset_category_mmi, + mci_table_names, + measured_condition_inputs) + + # Observed conditions ----------------------------------------------------- + + oci_table_names <- list("insulator_elec_cond" = "oci_ehv_fitg_insltr_elect_cond", + "insulator_mech_cond" = "oci_ehv_fitg_insltr_mech_cond", + "conductor_fitting_cond" = "oci_ehv_cond_fitting_cond", + "tower_fitting_cond" = "oci_ehv_twr_fitting_cond") + + observed_condition_modifier <- + get_observed_conditions_modifier_hv_switchgear(asset_category_mmi, + oci_table_names, + observed_condition_inputs) + + # Health score factor --------------------------------------------------- + health_score_factor <- + health_score_excl_ehv_132kv_tf(observed_condition_modifier$condition_factor, + measured_condition_modifier$condition_factor) + + # Health score cap -------------------------------------------------------- + health_score_cap <- min(observed_condition_modifier$condition_cap, + measured_condition_modifier$condition_cap) + + # Health score collar ----------------------------------------------------- + health_score_collar <- max(observed_condition_modifier$condition_collar, + measured_condition_modifier$condition_collar) + + # Health score modifier --------------------------------------------------- + health_score_modifier <- data.frame(health_score_factor, + health_score_cap, + health_score_collar) + + # Current health score ---------------------------------------------------- + current_health_score <- + current_health(initial_health_score, + health_score_modifier$health_score_factor, + health_score_modifier$health_score_cap, + health_score_modifier$health_score_collar, + reliability_factor = reliability_factor) + + # Probability of failure --------------------------------------------------- + probability_of_failure <- k * + (1 + (c * current_health_score) + + (((c * current_health_score)^2) / factorial(2)) + + (((c * current_health_score)^3) / factorial(3))) + + + return(probability_of_failure) + } + diff --git a/R/pof_pillar_04kv.R b/R/pof_pillar_04kv.R new file mode 100644 index 00000000..a87fac72 --- /dev/null +++ b/R/pof_pillar_04kv.R @@ -0,0 +1,185 @@ +#' @importFrom magrittr %>% +#' @title Current Probability of Failure for 0.4kV Pillar +#' @description This function calculates the current +#' annual probability of failure for 0.4kV Pillar +#' The function is a cubic curve that is based on +#' the first three terms of the Taylor series for an +#' exponential function. +#' @param placement String. Specify if the asset is located outdoor or indoor. +#' @param altitude_m Numeric. Specify the altitude location for +#' the asset measured in meters from sea level.\code{altitude_m} +#' is used to derive the altitude factor. A setting of \code{"Default"} +#' will set the altitude factor to 1 independent of \code{asset_type}. +#' @param distance_from_coast_km Numeric. Specify the distance from the +#' coast measured in kilometers. \code{distance_from_coast_km} is used +#' to derive the distance from coast factor. +#' A setting of \code{"Default"} will set the +#' distance from coast factor to 1 independent of \code{asset_type}. +#' @param corrosion_category_index Integer. +#' Specify the corrosion index category, 1-5. +#' @param age Numeric. The current age in years of the conductor. +#' @param measured_condition_inputs Named list observed_conditions_input +#' @param observed_condition_inputs Named list observed_conditions_input +#' \code{conductor_samp = c("Low","Medium/Normal","High","Default")}. +#' @inheritParams current_health +#' @param k_value Numeric. \code{k_value = 0.0046} by default. This number is +#' given in a percentage. The default value is accordingly to the CNAIM standard +#' on p. 110. +#' @param c_value Numeric. \code{c_value = 1.087} by default. +#' The default value is accordingly to the CNAIM standard see page 110 +#' @param normal_expected_life Numeric. \code{normal_expected_life = 60} by default. +#' The default value is accordingly to the CNAIM standard on page 107. +#' @return Numeric. Current probability of failure +#' per annum per kilometer. +#' @export +#' @examples +#' # Current annual probability of failure for 0.4kV Pillar +# pof_pillar_04kv_res <- +# pof_pillar_04kv( +# placement = "Default", +# altitude_m = "Default", +# distance_from_coast_km = "Default", +# corrosion_category_index = "Default", +# age = 10, +# observed_condition_inputs = +# list("external_cond" = +# list("Condition Criteria: Observed Condition" = "Default"), +# "compound_leaks" = list("Condition Criteria: Observed Condition" = "Default"), +# "internal_cond" = list("Condition Criteria: Observed Condition" = "Default"), +# "insulation" = list("Condition Criteria: Observed Condition" = "Default"), +# "signs_heating" = list("Condition Criteria: Observed Condition" = "Default"), +# "phase_barriers" = list("Condition Criteria: Observed Condition" = "Default")), +# measured_condition_inputs = +# list("opsal_adequacy" = +# list("Condition Criteria: Operational Adequacy" = "Default")), +# reliability_factor = "Default", +# k_value = 0.0046, +# c_value = 1.087, +# normal_expected_life = 60) * 100 +# paste0(sprintf("Probability of failure %.4f", pof_pillar_04kv_res), +# " percent per annum") + +pof_pillar_04kv <- + function(placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age, + measured_condition_inputs, + observed_condition_inputs, + reliability_factor = "Default", + k_value = 0.0046, + c_value = 1.087, + normal_expected_life = 60) { + + lv_asset_category <- "LV Pillar (ID)" + `Asset Register Category` = `Health Index Asset Category` = + `Generic Term...1` = `Generic Term...2` = `Functional Failure Category` = + `K-Value (%)` = `C-Value` = `Asset Register Category` = NULL + # due to NSE notes in R CMD check + + asset_category <- gb_ref$categorisation_of_assets %>% + dplyr::filter(`Asset Register Category` == + lv_asset_category) %>% + dplyr::select(`Health Index Asset Category`) %>% dplyr::pull() + + generic_term_1 <- gb_ref$generic_terms_for_assets %>% + dplyr::filter(`Health Index Asset Category` == asset_category) %>% + dplyr::select(`Generic Term...1`) %>% dplyr::pull() + + generic_term_2 <- gb_ref$generic_terms_for_assets %>% + dplyr::filter(`Health Index Asset Category` == asset_category) %>% + dplyr::select(`Generic Term...2`) %>% dplyr::pull() + + + # Constants C and K for PoF function -------------------------------------- + + k <- k_value/100 + + c <- c_value + + # Duty factor ------------------------------------------------------------- + + duty_factor_cond <- 1 + + # Location factor ---------------------------------------------------- + location_factor_cond <- location_factor(placement, + altitude_m, + distance_from_coast_km, + corrosion_category_index, + asset_type = lv_asset_category) + # Expected life ------------------------------ + expected_life_years <- expected_life(normal_expected_life, + duty_factor_cond, + location_factor_cond) + + # b1 (Initial Ageing Rate) ------------------------------------------------ + b1 <- beta_1(expected_life_years) + + # Initial health score ---------------------------------------------------- + initial_health_score <- initial_health(b1, age) + + asset_category_mmi <- get_mmi_lv_switchgear_asset_category(lv_asset_category) + + # Measured conditions + mci_table_names <- list("opsal_adequacy" = "mci_lv_pillar_opsal_adequacy") + + measured_condition_modifier <- + get_measured_conditions_modifier_lv_switchgear(asset_category_mmi, + mci_table_names, + measured_condition_inputs) + + # Observed conditions ----------------------------------------------------- + + oci_table_names <- list( + "external_cond" = "oci_lv_pillar_swg_ext_cond", + "compound_leaks" = "oci_lv_pillar_compound_leak", + "internal_cond" = "oci_lv_pillar_swg_int_cond_op", + "insulation" = "oci_lv_pillar_insulation_cond", + "signs_heating" = "oci_lv_pillar_signs_heating", + "phase_barriers" = "oci_lv_pillar_phase_barrier" + ) + + observed_condition_modifier <- + get_observed_conditions_modifier_lv_switchgear(asset_category_mmi, + oci_table_names, + observed_condition_inputs) + + + # Health score factor --------------------------------------------------- + health_score_factor <- + health_score_excl_ehv_132kv_tf(observed_condition_modifier$condition_factor, + measured_condition_modifier$condition_factor) + + # Health score cap -------------------------------------------------------- + health_score_cap <- min(observed_condition_modifier$condition_cap, + measured_condition_modifier$condition_cap) + + # Health score collar ----------------------------------------------------- + health_score_collar <- max(observed_condition_modifier$condition_collar, + measured_condition_modifier$condition_collar) + + # Health score modifier --------------------------------------------------- + health_score_modifier <- data.frame(health_score_factor, + health_score_cap, + health_score_collar) + + # Current health score ---------------------------------------------------- + current_health_score <- + current_health(initial_health_score, + health_score_modifier$health_score_factor, + health_score_modifier$health_score_cap, + health_score_modifier$health_score_collar, + reliability_factor = reliability_factor) + + # Probability of failure --------------------------------------------------- + probability_of_failure <- k * + (1 + (c * current_health_score) + + (((c * current_health_score)^2) / factorial(2)) + + (((c * current_health_score)^3) / factorial(3))) + + + return(probability_of_failure) + } + + diff --git a/R/pof_poles_ohl_support_50kv.R b/R/pof_poles_ohl_support_50kv.R new file mode 100644 index 00000000..d6251aea --- /dev/null +++ b/R/pof_poles_ohl_support_50kv.R @@ -0,0 +1,209 @@ +#' @importFrom magrittr %>% +#' @title Current Probability of Failure for Poles OHL Support 50 kV +#' @description This function calculates the current +#' annual probability of failure per kilometer Poles +#' The function is a cubic curve that is based on +#' the first three terms of the Taylor series for an +#' exponential function. +#' @param sub_division String. Refers to material the pole is +#' made of. Options: +#' \code{sub_division = c("Concrete", "Steel", "Wood")}. +#' @param placement String. Specify if the asset is located outdoor or indoor. +#' @param altitude_m Numeric. Specify the altitude location for +#' the asset measured in meters from sea level.\code{altitude_m} +#' is used to derive the altitude factor. A setting of \code{"Default"} +#' will set the altitude factor to 1 independent of \code{asset_type}. +#' @param distance_from_coast_km Numeric. Specify the distance from the +#' coast measured in kilometers. \code{distance_from_coast_km} is used +#' to derive the distance from coast factor. +#' A setting of \code{"Default"} will set the +#' distance from coast factor to 1 independent of \code{asset_type}. +#' @param corrosion_category_index Integer. +#' Specify the corrosion index category, 1-5. +#' @param age Numeric. The current age in years of the conductor. +#' @param measured_condition_inputs Named list observed_conditions_input +#' @param observed_condition_inputs Named list observed_conditions_input +#' \code{conductor_samp = c("Low","Medium/Normal","High","Default")}. +#' See page 161, table 199 and 201 in CNAIM (2021). +#' @inheritParams current_health +#' @param k_value Numeric. \code{k_value = 0.0285} by default. This number is +#' given in a percentage. The default value is accordingly to the CNAIM standard +#' on p. 110. +#' @param c_value Numeric. \code{c_value = 1.087} by default. +#' The default value is accordingly to the CNAIM standard see page 110 +#' @param normal_expected_life Numeric. \code{normal_expected_life = "Default"} by default. +#' The default value is accordingly to the CNAIM standard on page 107. +#' @return Numeric. Current probability of failure +#' per annum per kilometer. +#' @export +#' @examples +#' # Current annual probability of failure for Poles OHL support 50 kV +# pof_poles_ohl_support_50kv_res <- +# pof_poles_ohl_support_50kv( +# sub_division = "Wood", +# placement = "Default", +# altitude_m = "Default", +# distance_from_coast_km = "Default", +# corrosion_category_index = "Default", +# age = 10, +# observed_condition_inputs = +# list("visual_pole_cond" = +# list("Condition Criteria: Pole Top Rot Present?" = "Default"), +# "pole_leaning" = list("Condition Criteria: Pole Leaning?" = "Default"), +# "bird_animal_damage" = +# list("Condition Criteria: Bird/Animal Damage?" = "Default"), +# "top_rot" = list("Condition Criteria: Pole Top Rot Present?" = "Default")), +# measured_condition_inputs = +# list("pole_decay" = +# list("Condition Criteria: Degree of Decay/Deterioration" = "Default")), +# reliability_factor = "Default", +# k_value = 0.0285, +# c_value = 1.087, +# normal_expected_life = "Default") * 100 +# paste0(sprintf("Probability of failure %.4f", pof_poles_ohl_support_50kv_res), +# " percent per annum") + +pof_poles_ohl_support_50kv <- + function(sub_division = "Wood", + placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age, + measured_condition_inputs, + observed_condition_inputs, + reliability_factor = "Default", + k_value = 0.0285, + c_value = 1.087, + normal_expected_life = "Default") { + + pole_asset_category <- "66kV Pole" + `Asset Register Category` = `Health Index Asset Category` = + `Generic Term...1` = `Generic Term...2` = `Functional Failure Category` = + `K-Value (%)` = `C-Value` = `Asset Register Category` = `Sub-division` = NULL + # due to NSE notes in R CMD check + + asset_category <- gb_ref$categorisation_of_assets %>% + dplyr::filter(`Asset Register Category` == + pole_asset_category) %>% + dplyr::select(`Health Index Asset Category`) %>% dplyr::pull() + + generic_term_1 <- gb_ref$generic_terms_for_assets %>% + dplyr::filter(`Health Index Asset Category` == asset_category) %>% + dplyr::select(`Generic Term...1`) %>% dplyr::pull() + + generic_term_2 <- gb_ref$generic_terms_for_assets %>% + dplyr::filter(`Health Index Asset Category` == asset_category) %>% + dplyr::select(`Generic Term...2`) %>% dplyr::pull() + + # Normal expected life ------------------------- + + normal_expected_life_cond <- gb_ref$normal_expected_life %>% + dplyr::filter(`Asset Register Category` == + pole_asset_category, + `Sub-division` == sub_division) %>% + dplyr::pull() + + if (normal_expected_life == "Default") { + normal_expected_life_cond <- gb_ref$normal_expected_life %>% + dplyr::filter(`Asset Register Category` == + pole_asset_category, + `Sub-division` == sub_division) %>% + dplyr::pull() + } else { + normal_expected_life_cond <- normal_expected_life + } + + # Constants C and K for PoF function -------------------------------------- + + # POF function asset category. + + pof_asset_category <- "Poles" + + k <- k_value/100 + + c <- c_value + + # Duty factor ------------------------------------------------------------- + + duty_factor_cond <- 1 + + # Location factor ---------------------------------------------------- + location_factor_cond <- location_factor(placement, + altitude_m, + distance_from_coast_km, + corrosion_category_index, + asset_type = pole_asset_category, + sub_division = sub_division) + # Expected life ------------------------------ + expected_life_years <- expected_life(normal_expected_life_cond, + duty_factor_cond, + location_factor_cond) + + # b1 (Initial Ageing Rate) ------------------------------------------------ + b1 <- beta_1(expected_life_years) + + # Initial health score ---------------------------------------------------- + initial_health_score <- initial_health(b1, age) + + # Measured conditions + # The table data is same for all poles category + mci_table_names <- list("pole_decay" = "mci_ehv_pole_pole_decay_deter") + + # The table data is same for all poles category + asset_category_mmi <- "EHV Poles" + + measured_condition_modifier <- + get_measured_conditions_modifier_hv_switchgear(asset_category_mmi, + mci_table_names, + measured_condition_inputs) + + # Observed conditions ----------------------------------------------------- + + # The table data is same for all poles category + oci_table_names <- list("visual_pole_cond" = "oci_ehv_pole_visual_pole_cond", + "pole_leaning" = "oci_ehv_pole_pole_leaning", + "bird_animal_damage" = "oci_ehv_pole_bird_animal_damag", + "top_rot" = "oci_ehv_pole_pole_top_rot") + + observed_condition_modifier <- + get_observed_conditions_modifier_hv_switchgear(asset_category_mmi, + oci_table_names, + observed_condition_inputs) + + # Health score factor --------------------------------------------------- + health_score_factor <- + health_score_excl_ehv_132kv_tf(observed_condition_modifier$condition_factor, + measured_condition_modifier$condition_factor) + + # Health score cap -------------------------------------------------------- + health_score_cap <- min(observed_condition_modifier$condition_cap, + measured_condition_modifier$condition_cap) + + # Health score collar ----------------------------------------------------- + health_score_collar <- max(observed_condition_modifier$condition_collar, + measured_condition_modifier$condition_collar) + + # Health score modifier --------------------------------------------------- + health_score_modifier <- data.frame(health_score_factor, + health_score_cap, + health_score_collar) + + # Current health score ---------------------------------------------------- + current_health_score <- + current_health(initial_health_score, + health_score_modifier$health_score_factor, + health_score_modifier$health_score_cap, + health_score_modifier$health_score_collar, + reliability_factor = reliability_factor) + + # Probability of failure --------------------------------------------------- + probability_of_failure <- k * + (1 + (c * current_health_score) + + (((c * current_health_score)^2) / factorial(2)) + + (((c * current_health_score)^3) / factorial(3))) + + + return(probability_of_failure) + } + diff --git a/R/pof_relay.R b/R/pof_relay.R new file mode 100644 index 00000000..4698a561 --- /dev/null +++ b/R/pof_relay.R @@ -0,0 +1,181 @@ +#' @importFrom magrittr %>% +#' @title Current Probability of Failure for Relay +#' @description This function calculates the current +#' annual probability of failure relay +#' The function is a cubic curve that is based on +#' the first three terms of the Taylor series for an +#' exponential function. +#' @param placement String. Specify if the asset is located outdoor or indoor. +#' @param altitude_m Numeric. Specify the altitude location for +#' the asset measured in meters from sea level.\code{altitude_m} +#' is used to derive the altitude factor. A setting of \code{"Default"} +#' will set the altitude factor to 1 independent of \code{asset_type}. +#' @param distance_from_coast_km Numeric. Specify the distance from the +#' coast measured in kilometers. \code{distance_from_coast_km} is used +#' to derive the distance from coast factor. A setting of \code{"Default"} will set the +#' distance from coast factor to 1 independent of \code{asset_type}. +#' @param corrosion_category_index Integer. +#' Specify the corrosion index category, 1-5. +#' @param age Numeric. The current age in years of the conductor. +#' @param measured_condition_inputs Named list observed_conditions_input +#' @param observed_condition_inputs Named list observed_conditions_input +#' \code{conductor_samp = c("Low","Medium/Normal","High","Default")}. +#' @inheritParams current_health +#' @param k_value Numeric. \code{k_value = 0.128} by default. This number is +#' given in a percentage. The default value is accordingly to the CNAIM standard +#' on p. 110. +#' @param c_value Numeric. \code{c_value = 1.087} by default. +#' The default value is accordingly to the CNAIM standard see page 110 +#' @param normal_expected_life Numeric. \code{normal_expected_life = 50} by default. +#' The default value is accordingly to the CNAIM standard on page 107. +#' @return Numeric. Current probability of failure per annum. +#' @export +#' @examples +#' # Current annual probability of failure for relay +# pof_relay_res <- +# pof_relay( +# placement = "Default", +# altitude_m = "Default", +# distance_from_coast_km = "Default", +# corrosion_category_index = "Default", +# age = 25, +# observed_condition_inputs = +# list("external_condition" = +# list("Condition Criteria: Observed Condition" = "Default"), +# "oil_gas" = list("Condition Criteria: Observed Condition" = "Default"), +# "thermo_assment" = list("Condition Criteria: Observed Condition" = "Default"), +# "internal_condition" = list("Condition Criteria: Observed Condition" = "Default"), +# "indoor_env" = list("Condition Criteria: Observed Condition" = "Default")), +# measured_condition_inputs = +# list("partial_discharge" = +# list("Condition Criteria: Partial Discharge Test Results" = "Default"), +# "ductor_test" = list("Condition Criteria: Ductor Test Results" = "Default"), +# "oil_test" = list("Condition Criteria: Oil Test Results" = "Default"), +# "temp_reading" = list("Condition Criteria: Temperature Readings" = "Default"), +# "trip_test" = list("Condition Criteria: Trip Timing Test Result" = "Default")), +# reliability_factor = "Default", +# k_value = 0.128, +# c_value = 1.087, +# normal_expected_life = 30) * 100 +# paste0(sprintf("Probability of failure %.4f", pof_relay_res), +# " percent per annum") + +pof_relay <- + function(placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age, + measured_condition_inputs, + observed_condition_inputs, + reliability_factor = "Default", + k_value = 0.128, + c_value = 1.087, + normal_expected_life = 30) { + + hv_asset_category <- "6.6/11kV CB (GM) Secondary" + `Asset Register Category` = `Health Index Asset Category` = + `Generic Term...1` = `Generic Term...2` = `Functional Failure Category` = + `K-Value (%)` = `C-Value` = `Asset Register Category` = NULL + # due to NSE notes in R CMD check + + asset_category <- gb_ref$categorisation_of_assets %>% + dplyr::filter(`Asset Register Category` == + hv_asset_category) %>% + dplyr::select(`Health Index Asset Category`) %>% dplyr::pull() + + generic_term_1 <- gb_ref$generic_terms_for_assets %>% + dplyr::filter(`Health Index Asset Category` == asset_category) %>% + dplyr::select(`Generic Term...1`) %>% dplyr::pull() + + generic_term_2 <- gb_ref$generic_terms_for_assets %>% + dplyr::filter(`Health Index Asset Category` == asset_category) %>% + dplyr::select(`Generic Term...2`) %>% dplyr::pull() + + + # Constants C and K for PoF function -------------------------------------- + k <- k_value/100 + c <- c_value + + # Duty factor ------------------------------------------------------------- + + duty_factor_cond <- 1 + + # Location factor ---------------------------------------------------- + location_factor_cond <- location_factor(placement, + altitude_m, + distance_from_coast_km, + corrosion_category_index, + asset_type = hv_asset_category) + + # Expected life ------------------------------ + expected_life_years <- expected_life(normal_expected_life, + duty_factor_cond, + location_factor_cond) + + # b1 (Initial Ageing Rate) ------------------------------------------------ + b1 <- beta_1(expected_life_years) + + # Initial health score ---------------------------------------------------- + initial_health_score <- initial_health(b1, age) + + # Measured conditions + mci_table_names <- list("partial_discharge" = "mci_hv_swg_distr_prtl_dischrg", + "ductor_test" = "mci_hv_swg_distr_ductor_test", + "oil_test" = "mci_hv_swg_distr_oil_test", + "temp_reading" = "mci_hv_swg_distr_temp_reading", + "trip_test" = "mci_hv_swg_distr_trip_test") + + measured_condition_modifier <- + get_measured_conditions_modifier_hv_switchgear(asset_category, + mci_table_names, + measured_condition_inputs) + + # Observed conditions ----------------------------------------------------- + + oci_table_names <- list("external_condition" = "oci_hv_swg_dist_swg_ext_cond", + "oil_gas" = "oci_hv_swg_dist_oil_lek_gas_pr", + "thermo_assment" = "oci_hv_swg_dist_thermo_assment", + "internal_condition" = "oci_hv_swg_dist_swg_int_cond", + "indoor_env" = "oci_hv_swg_dist_indoor_environ") + + observed_condition_modifier <- + get_observed_conditions_modifier_hv_switchgear(asset_category, + oci_table_names, + observed_condition_inputs) + + # Health score factor --------------------------------------------------- + health_score_factor <- + health_score_excl_ehv_132kv_tf(observed_condition_modifier$condition_factor, + measured_condition_modifier$condition_factor) + + # Health score cap -------------------------------------------------------- + health_score_cap <- min(observed_condition_modifier$condition_cap, + measured_condition_modifier$condition_cap) + + # Health score collar ----------------------------------------------------- + health_score_collar <- max(observed_condition_modifier$condition_collar, + measured_condition_modifier$condition_collar) + + # Health score modifier --------------------------------------------------- + health_score_modifier <- data.frame(health_score_factor, + health_score_cap, + health_score_collar) + + # Current health score ---------------------------------------------------- + current_health_score <- + current_health(initial_health_score, + health_score_modifier$health_score_factor, + health_score_modifier$health_score_cap, + health_score_modifier$health_score_collar, + reliability_factor = reliability_factor) + + # Probability of failure --------------------------------------------------- + probability_of_failure <- k * + (1 + (c * current_health_score) + + (((c * current_health_score)^2) / factorial(2)) + + (((c * current_health_score)^3) / factorial(3))) + + + return(probability_of_failure) + } diff --git a/R/pof_rtu.R b/R/pof_rtu.R new file mode 100644 index 00000000..2e2f77d3 --- /dev/null +++ b/R/pof_rtu.R @@ -0,0 +1,181 @@ +#' @importFrom magrittr %>% +#' @title Current Probability of Failure for RTU +#' @description This function calculates the current +#' annual probability of failure RTU +#' The function is a cubic curve that is based on +#' the first three terms of the Taylor series for an +#' exponential function. +#' @param placement String. Specify if the asset is located outdoor or indoor. +#' @param altitude_m Numeric. Specify the altitude location for +#' the asset measured in meters from sea level.\code{altitude_m} +#' is used to derive the altitude factor. A setting of \code{"Default"} +#' will set the altitude factor to 1 independent of \code{asset_type}. +#' @param distance_from_coast_km Numeric. Specify the distance from the +#' coast measured in kilometers. \code{distance_from_coast_km} is used +#' to derive the distance from coast factor. A setting of \code{"Default"} will set the +#' distance from coast factor to 1 independent of \code{asset_type}. +#' @param corrosion_category_index Integer. +#' Specify the corrosion index category, 1-5. +#' @param age Numeric. The current age in years of the conductor. +#' @param measured_condition_inputs Named list observed_conditions_input +#' @param observed_condition_inputs Named list observed_conditions_input +#' \code{conductor_samp = c("Low","Medium/Normal","High","Default")}. +#' @inheritParams current_health +#' @param k_value Numeric. \code{k_value = 0.0128} by default. This number is +#' given in a percentage. The default value is accordingly to the CNAIM standard +#' on p. 110. +#' @param c_value Numeric. \code{c_value = 1.087} by default. +#' The default value is accordingly to the CNAIM standard see page 110 +#' @param normal_expected_life Numeric. \code{normal_expected_life = 50} by default. +#' The default value is accordingly to the CNAIM standard on page 107. +#' @return Numeric. Current probability of failure per annum. +#' @export +#' @examples +#' # Current annual probability of failure for RTU +# pof_rtu_res <- +# pof_rtu( +# placement = "Default", +# altitude_m = "Default", +# distance_from_coast_km = "Default", +# corrosion_category_index = "Default", +# age = 10, +# observed_condition_inputs = +# list("external_condition" = +# list("Condition Criteria: Observed Condition" = "Default"), +# "oil_gas" = list("Condition Criteria: Observed Condition" = "Default"), +# "thermo_assment" = list("Condition Criteria: Observed Condition" = "Default"), +# "internal_condition" = list("Condition Criteria: Observed Condition" = "Default"), +# "indoor_env" = list("Condition Criteria: Observed Condition" = "Default")), +# measured_condition_inputs = +# list("partial_discharge" = +# list("Condition Criteria: Partial Discharge Test Results" = "Default"), +# "ductor_test" = list("Condition Criteria: Ductor Test Results" = "Default"), +# "oil_test" = list("Condition Criteria: Oil Test Results" = "Default"), +# "temp_reading" = list("Condition Criteria: Temperature Readings" = "Default"), +# "trip_test" = list("Condition Criteria: Trip Timing Test Result" = "Default")), +# reliability_factor = "Default", +# k_value = 0.128, +# c_value = 1.087, +# normal_expected_life = 20) * 100 +# paste0(sprintf("Probability of failure %.4f", pof_rtu_res), +# " percent per annum") + +pof_rtu <- + function(placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age, + measured_condition_inputs, + observed_condition_inputs, + reliability_factor = "Default", + k_value = 0.128, + c_value = 1.087, + normal_expected_life = 20) { + + hv_asset_category <- "6.6/11kV CB (GM) Secondary" + `Asset Register Category` = `Health Index Asset Category` = + `Generic Term...1` = `Generic Term...2` = `Functional Failure Category` = + `K-Value (%)` = `C-Value` = `Asset Register Category` = NULL + # due to NSE notes in R CMD check + + asset_category <- gb_ref$categorisation_of_assets %>% + dplyr::filter(`Asset Register Category` == + hv_asset_category) %>% + dplyr::select(`Health Index Asset Category`) %>% dplyr::pull() + + generic_term_1 <- gb_ref$generic_terms_for_assets %>% + dplyr::filter(`Health Index Asset Category` == asset_category) %>% + dplyr::select(`Generic Term...1`) %>% dplyr::pull() + + generic_term_2 <- gb_ref$generic_terms_for_assets %>% + dplyr::filter(`Health Index Asset Category` == asset_category) %>% + dplyr::select(`Generic Term...2`) %>% dplyr::pull() + + + # Constants C and K for PoF function -------------------------------------- + k <- k_value/100 + c <- c_value + + # Duty factor ------------------------------------------------------------- + + duty_factor_cond <- 1 + + # Location factor ---------------------------------------------------- + location_factor_cond <- location_factor(placement, + altitude_m, + distance_from_coast_km, + corrosion_category_index, + asset_type = hv_asset_category) + + # Expected life ------------------------------ + expected_life_years <- expected_life(normal_expected_life, + duty_factor_cond, + location_factor_cond) + + # b1 (Initial Ageing Rate) ------------------------------------------------ + b1 <- beta_1(expected_life_years) + + # Initial health score ---------------------------------------------------- + initial_health_score <- initial_health(b1, age) + + # Measured conditions + mci_table_names <- list("partial_discharge" = "mci_hv_swg_distr_prtl_dischrg", + "ductor_test" = "mci_hv_swg_distr_ductor_test", + "oil_test" = "mci_hv_swg_distr_oil_test", + "temp_reading" = "mci_hv_swg_distr_temp_reading", + "trip_test" = "mci_hv_swg_distr_trip_test") + + measured_condition_modifier <- + get_measured_conditions_modifier_hv_switchgear(asset_category, + mci_table_names, + measured_condition_inputs) + + # Observed conditions ----------------------------------------------------- + + oci_table_names <- list("external_condition" = "oci_hv_swg_dist_swg_ext_cond", + "oil_gas" = "oci_hv_swg_dist_oil_lek_gas_pr", + "thermo_assment" = "oci_hv_swg_dist_thermo_assment", + "internal_condition" = "oci_hv_swg_dist_swg_int_cond", + "indoor_env" = "oci_hv_swg_dist_indoor_environ") + + observed_condition_modifier <- + get_observed_conditions_modifier_hv_switchgear(asset_category, + oci_table_names, + observed_condition_inputs) + + # Health score factor --------------------------------------------------- + health_score_factor <- + health_score_excl_ehv_132kv_tf(observed_condition_modifier$condition_factor, + measured_condition_modifier$condition_factor) + + # Health score cap -------------------------------------------------------- + health_score_cap <- min(observed_condition_modifier$condition_cap, + measured_condition_modifier$condition_cap) + + # Health score collar ----------------------------------------------------- + health_score_collar <- max(observed_condition_modifier$condition_collar, + measured_condition_modifier$condition_collar) + + # Health score modifier --------------------------------------------------- + health_score_modifier <- data.frame(health_score_factor, + health_score_cap, + health_score_collar) + + # Current health score ---------------------------------------------------- + current_health_score <- + current_health(initial_health_score, + health_score_modifier$health_score_factor, + health_score_modifier$health_score_cap, + health_score_modifier$health_score_collar, + reliability_factor = reliability_factor) + + # Probability of failure --------------------------------------------------- + probability_of_failure <- k * + (1 + (c * current_health_score) + + (((c * current_health_score)^2) / factorial(2)) + + (((c * current_health_score)^3) / factorial(3))) + + + return(probability_of_failure) + } diff --git a/R/pof_serviceline.R b/R/pof_serviceline.R new file mode 100644 index 00000000..9154aeea --- /dev/null +++ b/R/pof_serviceline.R @@ -0,0 +1,265 @@ +#' @importFrom magrittr %>% +#' @title Current Probability of Failure for Service Lines +#' @description This function calculates the current +#' annual probability of failure per kilometer for a Service Line. +#' The function is a cubic curve that is based on +#' the first three terms of the Taylor series for an +#' exponential function. +#' @inheritParams duty_factor_cables +#' @param sheath_test String. Only applied for non pressurised cables. +#' Indicating the state of the sheath. Options: +#' \code{sheath_test = c("Pass", "Failed Minor", "Failed Major", +#' "Default")}. +#' @param partial_discharge String. Only applied for non pressurised cables. +#' Indicating the level of partial discharge. Options: +#' \code{partial_discharge = c("Low", "Medium", "High", +#' "Default")}. +#' @param fault_hist Numeric. Only applied for non pressurised cables. +#' The calculated fault rate for the cable in the period per kilometer. +#' A setting of \code{"No historic faults recorded"} +#' indicates no fault. +#' @inheritParams current_health +#' @param age Numeric. The current age in years of the cable. +#' @param k_value Numeric. \code{k_value = 0.0329} by default. +#' @param c_value Numeric. \code{c_value = 1.087} by default. +#' The default value is accordingly to the CNAIM standard see page 110 +#' @param normal_expected_life Numeric. \code{normal_expected_life = 75} by default. +#' @return Numeric. Current probability of failure +#' per annum for service line. +#' @export +#' @examples +#' # Current annual probability of failure for service line, 50 years old +# pof_serviceline_res <- +# pof_serviceline( +# utilisation_pct = 80, +# operating_voltage_pct = "Default", +# sheath_test = "Default", +# partial_discharge = "Default", +# fault_hist = "Default", +# reliability_factor = "Default", +# age = 50, +# k_value = 0.0329, +# c_value = 1.087, +# normal_expected_life = 75)*100 +# paste0(sprintf("Probability of failure %.4f", pof_serviceline_res), +# " percent per annum") + + +pof_serviceline <- function(utilisation_pct = "Default", + operating_voltage_pct = "Default", + sheath_test = "Default", + partial_discharge = "Default", + fault_hist = "Default", + reliability_factor = "Default", + age, + k_value = 0.0329, + c_value = 1.087, + normal_expected_life = 75) { + + # `Asset Register Category` = `Health Index Asset Category` = + # `Generic Term...1` = `Generic Term...2` = `Functional Failure Category` = + # `K-Value (%)` = `C-Value` = `Asset Register Category` = `Sub-division` = + # `Condition Criteria: Sheath Test Result` = + # `Condition Criteria: Partial Discharge Test Result` = + # NULL + + cable_type <- "33kV UG Cable (Non Pressurised)" + sub_division <- "Lead sheath - Copper conductor" + + + # Ref. table Categorisation of Assets and Generic Terms for Assets -- + asset_category <- gb_ref$categorisation_of_assets %>% + dplyr::filter(`Asset Register Category` == cable_type) %>% + dplyr::select(`Health Index Asset Category`) %>% dplyr::pull() + + generic_term_1 <- gb_ref$generic_terms_for_assets %>% + dplyr::filter(`Health Index Asset Category` == asset_category) %>% + dplyr::select(`Generic Term...1`) %>% dplyr::pull() + + generic_term_2 <- gb_ref$generic_terms_for_assets %>% + dplyr::filter(`Health Index Asset Category` == asset_category) %>% + dplyr::select(`Generic Term...2`) %>% dplyr::pull() + + + # Constants C and K for PoF function -------------------------------------- + + k <- k_value/100 + c <- c_value + + duty_factor_cable <- + duty_factor_cables(utilisation_pct, + operating_voltage_pct, + voltage_level = "HV") + + # Expected life ------------------------------ # the expected life set to 80 accordingly to p. 33 in "DE-10kV apb kabler CNAIM" + expected_life_years <- expected_life(normal_expected_life, + duty_factor_cable, + location_factor = 1) + + # b1 (Initial Ageing Rate) ------------------------------------------------ + b1 <- beta_1(expected_life_years) + + # Initial health score ---------------------------------------------------- + initial_health_score <- initial_health(b1, age) + + ## NOTE + # Typically, the Health Score Collar is 0.5 and + # Health Score Cap is 5.5, implying no overriding + # of the Health Score. However, in some instances + # these parameters are set to other values in the + # Health Score Modifier calibration tables. + + # Measured condition inputs --------------------------------------------- + asset_category_mmi <- stringr::str_remove(asset_category, pattern = "UG") + asset_category_mmi <- stringr::str_squish(asset_category_mmi) + + mcm_mmi_cal_df <- + gb_ref$measured_cond_modifier_mmi_cal + + mmi_type <- mcm_mmi_cal_df$`Asset Category`[which( + grepl(asset_category_mmi, + mcm_mmi_cal_df$`Asset Category`, + fixed = TRUE) == TRUE + )] + + + mcm_mmi_cal_df <- + mcm_mmi_cal_df[which( + mcm_mmi_cal_df$`Asset Category` == asset_category_mmi), ] + + factor_divider_1 <- + as.numeric( + mcm_mmi_cal_df$ + `Parameters for Combination Using MMI Technique - Factor Divider 1`) + + factor_divider_2 <- + as.numeric( + mcm_mmi_cal_df$ + `Parameters for Combination Using MMI Technique - Factor Divider 2`) + + max_no_combined_factors <- + as.numeric( + mcm_mmi_cal_df$ + `Parameters for Combination Using MMI Technique - Max. No. of Combined Factors` + ) + + + # Sheath test ------------------------------------------------------------- + mci_ehv_cbl_non_pr_sheath_test <- + gb_ref$mci_ehv_cbl_non_pr_sheath_test %>% dplyr::filter( + `Condition Criteria: Sheath Test Result` == sheath_test + ) + + ci_factor_sheath <- mci_ehv_cbl_non_pr_sheath_test$`Condition Input Factor` + ci_cap_sheath <- mci_ehv_cbl_non_pr_sheath_test$`Condition Input Cap` + ci_collar_sheath <- mci_ehv_cbl_non_pr_sheath_test$`Condition Input Collar` + + # Partial discharge------------------------------------------------------- + + mci_ehv_cbl_non_pr_prtl_disch <- + gb_ref$mci_ehv_cbl_non_pr_prtl_disch %>% dplyr::filter( + `Condition Criteria: Partial Discharge Test Result` == partial_discharge + ) + + + ci_factor_partial <- mci_ehv_cbl_non_pr_prtl_disch$`Condition Input Factor` + ci_cap_partial <- mci_ehv_cbl_non_pr_prtl_disch$`Condition Input Cap` + ci_collar_partial <- mci_ehv_cbl_non_pr_prtl_disch$`Condition Input Collar` + + + # Fault ------------------------------------------------------- + + mci_ehv_cbl_non_pr_fault_hist <- + gb_ref$mci_ehv_cbl_non_pr_fault_hist + + for (n in 2:4) { + if (fault_hist == 'Default' || fault_hist == + 'No historic faults recorded') { + no_row <- which(mci_ehv_cbl_non_pr_fault_hist$Upper == fault_hist) + + ci_factor_fault <- + mci_ehv_cbl_non_pr_fault_hist$`Condition Input Factor`[no_row] + ci_cap_fault <- + mci_ehv_cbl_non_pr_fault_hist$`Condition Input Cap`[no_row] + ci_collar_fault <- + mci_ehv_cbl_non_pr_fault_hist$`Condition Input Collar`[no_row] + break + } else if (fault_hist >= + as.numeric(mci_ehv_cbl_non_pr_fault_hist$Lower[n]) & + fault_hist < + as.numeric(mci_ehv_cbl_non_pr_fault_hist$Upper[n])) { + + ci_factor_fault <- + mci_ehv_cbl_non_pr_fault_hist$`Condition Input Factor`[n] + ci_cap_fault <- + mci_ehv_cbl_non_pr_fault_hist$`Condition Input Cap`[n] + ci_collar_fault <- + mci_ehv_cbl_non_pr_fault_hist$`Condition Input Collar`[n] + + break + } + } + + # Measured conditions + + factors <- c(ci_factor_sheath, + ci_factor_partial, + ci_factor_fault) + + measured_condition_factor <- mmi(factors, + factor_divider_1, + factor_divider_2, + max_no_combined_factors) + + caps <- c(ci_cap_sheath, + ci_cap_partial, + ci_cap_fault) + measured_condition_cap <- min(caps) + + # Measured condition collar ----------------------------------------------- + collars <- c(ci_collar_sheath, + ci_collar_partial, + ci_collar_fault) + measured_condition_collar <- max(collars) + + + # Measured condition modifier --------------------------------------------- + measured_condition_modifier <- data.frame(measured_condition_factor, + measured_condition_cap, + measured_condition_collar) + + + # Health score factor --------------------------------------------------- + health_score_factor <- measured_condition_modifier$measured_condition_factor + + # Health score cap -------------------------------------------------------- + health_score_cap <- measured_condition_modifier$measured_condition_cap + + # Health score collar ----------------------------------------------------- + health_score_collar <- measured_condition_modifier$measured_condition_collar + + # Health score modifier --------------------------------------------------- + health_score_modifier <- data.frame(health_score_factor, + health_score_cap, + health_score_collar) + + # Current health score ---------------------------------------------------- + current_health_score <- + current_health( + initial_health_score = initial_health_score, + health_score_factor= health_score_modifier$health_score_factor, + health_score_cap = health_score_modifier$health_score_cap, + health_score_collar = health_score_modifier$health_score_collar, + reliability_factor = reliability_factor) + + # Probability of failure --------------------------------------------------- + probability_of_failure <- k * + (1 + (c * current_health_score) + + (((c * current_health_score)^2) / factorial(2)) + + (((c * current_health_score)^3) / factorial(3))) + + return(probability_of_failure) +} + + + diff --git a/R/pof_submarine_cables_10kv_oil.R b/R/pof_submarine_cables_10kv_oil.R new file mode 100644 index 00000000..ada2390a --- /dev/null +++ b/R/pof_submarine_cables_10kv_oil.R @@ -0,0 +1,346 @@ +#' @importFrom magrittr %>% +#' @title Current Probability of Failure for 10kV Oil Submarine Cables +#' @description This function calculates the current +#' annual probability of failure per kilometer for submarine cables. +#' The function is a cubic curve that is based on +#' the first three terms of the Taylor series for an +#' exponential function. +#' @inheritParams duty_factor_cables +#' @inheritParams location_factor_sub +#' @param sheath_test String. Indicating the state of the sheath. Options: +#' \code{sheath_test = c("Pass", "Failed Minor", "Failed Major", +#' "Default")}. See page 158, table 189 in CNAIM (2021). +#' @param partial_discharge String. Indicating the level of partial discharge. +#' Options: +#' \code{partial_discharge = c("Low", "Medium", "High", +#' "Default")}. See page 158, table 190 in CNAIM (2021). +#' @param fault_hist Numeric. The calculated fault rate for the cable per annum +#' per kilometer. A setting of \code{"No historic faults recorded"} +#' indicates no fault. See page 158, table 191 in CNAIM (2021). +#' @param condition_armour String. Indicating the external condition of the +#' submarine cables armour. Options: +#' \code{condition_armour = c("Good","Poor","Critical","Default")} +#' @inheritParams current_health +#' @param k_value Numeric. \code{k_value = 0.0202} by default. This number is +#' given in a percentage. The default value is accordingly to the CNAIM standard +#' on p. 110. +#' @param c_value Numeric. \code{c_value = 1.087} by default. +#' The default value is accordingly to the CNAIM standard see page 110 +#' @param normal_expected_life Numeric. \code{normal_expected_life = 60} by default. +#' The default value is accordingly to the CNAIM standard on page 107. +#' @return Numeric. Current probability of failure +#' per annum per kilometer. +#' @param age Numeric. The current age in years of the cable. +#' @return Numeric. Current probability of failure +#' per annum per kilometre. +#' @source DNO Common Network Asset Indices Methodology (CNAIM), +#' Health & Criticality - Version 2.1, 2021: +#' \url{https://www.ofgem.gov.uk/sites/default/files/docs/2021/04/dno_common_network_asset_indices_methodology_v2.1_final_01-04-2021.pdf} +#' @export +#' @examples +#' # Current annual probability of failure for 1 km 10kV oil Sub Cable +# pof_submarine_cables_10kv_oil_res <- +# pof_submarine_cables_10kv_oil( +# utilisation_pct = "Default", +# operating_voltage_pct = "Default", +# topography = "Default", +# situation = "Default", +# wind_wave = "Default", +# intensity = "Default", +# landlocked = "no", +# sheath_test = "Default", +# partial_discharge = "Default", +# fault_hist = "Default", +# condition_armour = "Default", +# age = 10, +# reliability_factor = "Default", +# k_value = 2.0944, +# c_value = 1.087, +# normal_expected_life = 60) * 100 +# paste0(sprintf("Probability of failure %.4f", pof_submarine_cables_10kv_oil_res), +# " percent per annum") + + +pof_submarine_cables_10kv_oil <- + function(utilisation_pct = "Default", + operating_voltage_pct = "Default", + topography = "Default", + situation = "Default", + wind_wave = "Default", + intensity = "Default", + landlocked = "no", + sheath_test = "Default", + partial_discharge = "Default", + fault_hist = "Default", + condition_armour = "Default", + age, + reliability_factor = "Default", + k_value = 2.0944, + c_value = 1.087, + normal_expected_life = 60) { + + sub_cable_type <- "HV Sub Cable" + `Asset Register Category` = `Health Index Asset Category` = + `Generic Term...1` = `Generic Term...2` = + `Functional Failure Category`= `K-Value (%)` = + `C-Value` = `Condition Criteria: Sheath Test Result` = + `Condition Criteria: Partial Discharge Test Result` = + `Asset Category` = `Condition Criteria` = `Asset Register Category` = NULL + # due to NSE notes in R CMD check + + # Ref. table Categorisation of Assets and Generic Terms for Assets -- + + asset_category <- gb_ref$categorisation_of_assets %>% + dplyr::filter(`Asset Register Category` == sub_cable_type) %>% + dplyr::select(`Health Index Asset Category`) %>% dplyr::pull() + + generic_term_1 <- gb_ref$generic_terms_for_assets %>% + dplyr::filter(`Health Index Asset Category` == asset_category) %>% + dplyr::select(`Generic Term...1`) %>% dplyr::pull() + + generic_term_2 <- gb_ref$generic_terms_for_assets %>% + dplyr::filter(`Health Index Asset Category` == asset_category) %>% + dplyr::select(`Generic Term...2`) %>% dplyr::pull() + + + # Constants C and K for PoF function -------------------------------------- + k <- k_value/100 + + c <- c_value + + # Duty factor ------------------------------------------------------------- + sub_marine_col_level <- "HV" + + duty_factor_sub <- + duty_factor_cables( + utilisation_pct, + operating_voltage_pct, + voltage_level = sub_marine_col_level) + + + # # Location factor --------------------------------------------------------- + lf_submarine <- location_factor_sub(topography, + situation, + wind_wave, + intensity, + landlocked) + print(lf_submarine) + + + # Expected life ------------------------------ + expected_life_years <- expected_life(normal_expected_life, + duty_factor_sub, + lf_submarine) + + # b1 (Initial Ageing Rate) ------------------------------------------------ + b1 <- beta_1(expected_life_years) + + # Initial health score ---------------------------------------------------- + initial_health_score <- initial_health(b1, age) + + ## NOTE + # Typically, the Health Score Collar is 0.5 and + # Health Score Cap is 10, implying no overriding + # of the Health Score. However, in some instances + # these parameters are set to other values in the + # Health Score Modifier calibration tables. + # These overriding values are shown in Table 35 to Table 202 + # and Table 207 in Appendix B. + + # Measured condition inputs --------------------------------------------- + mcm_mmi_cal_df <- + gb_ref$measured_cond_modifier_mmi_cal + + + mcm_mmi_cal_df <- + mcm_mmi_cal_df[which( + mcm_mmi_cal_df$`Asset Category` == "Submarine Cable"), ] + + factor_divider_1 <- + as.numeric( + mcm_mmi_cal_df$ + `Parameters for Combination Using MMI Technique - Factor Divider 1`) + + factor_divider_2 <- + as.numeric( + mcm_mmi_cal_df$ + `Parameters for Combination Using MMI Technique - Factor Divider 2`) + + max_no_combined_factors <- + as.numeric( + mcm_mmi_cal_df$ + `Parameters for Combination Using MMI Technique - Max. No. of Combined Factors` + ) + + + # Sheath test ------------------------------------------------------------- + mci_submarine_cbl_sheath_test <- + gb_ref$mci_submarine_cbl_sheath_test %>% dplyr::filter( + `Condition Criteria: Sheath Test Result` == sheath_test + ) + + ci_factor_sheath <- + mci_submarine_cbl_sheath_test$`Condition Input Factor` + ci_cap_sheath <- + mci_submarine_cbl_sheath_test$`Condition Input Cap` + ci_collar_sheath <- + mci_submarine_cbl_sheath_test$`Condition Input Collar` + + # Partial discharge------------------------------------------------------- + mci_submarine_cable_prtl_disc <- + gb_ref$mci_submarine_cable_prtl_disc %>% + dplyr::filter( + `Condition Criteria: Partial Discharge Test Result` == partial_discharge + ) + + ci_factor_partial <- + mci_submarine_cable_prtl_disc$`Condition Input Factor` + ci_cap_partial <- mci_submarine_cable_prtl_disc$`Condition Input Cap` + ci_collar_partial <- + mci_submarine_cable_prtl_disc$`Condition Input Collar` + + + # Fault ------------------------------------------------------- + mci_submarine_cable_fault_hist <- + gb_ref$mci_submarine_cable_fault_hist + + for (n in 2:4) { + if (fault_hist == 'Default' || fault_hist == + 'No historic faults recorded') { + no_row <- which(mci_submarine_cable_fault_hist$Upper == fault_hist) + + ci_factor_fault <- + mci_submarine_cable_fault_hist$`Condition Input Factor`[no_row] + ci_cap_fault <- + mci_submarine_cable_fault_hist$`Condition Input Cap`[no_row] + ci_collar_fault <- + mci_submarine_cable_fault_hist$`Condition Input Collar`[no_row] + break + } else if (fault_hist >= + as.numeric(mci_submarine_cable_fault_hist$Lower[n]) & + fault_hist < + as.numeric(mci_submarine_cable_fault_hist$Upper[n])) { + + ci_factor_fault <- + mci_submarine_cable_fault_hist$`Condition Input Factor`[n] + ci_cap_fault <- + mci_submarine_cable_fault_hist$`Condition Input Cap`[n] + ci_collar_fault <- + mci_submarine_cable_fault_hist$`Condition Input Collar`[n] + + break + } + } + + # Measured conditions + + factors <- c(ci_factor_sheath, + ci_factor_partial, + ci_factor_fault) + + measured_condition_factor <- mmi(factors, + factor_divider_1, + factor_divider_2, + max_no_combined_factors) + + caps <- c(ci_cap_sheath, + ci_cap_partial, + ci_cap_fault) + measured_condition_cap <- min(caps) + + # Measured condition collar ---------------------------------------------- + collars <- c(ci_collar_sheath, + ci_collar_partial, + ci_collar_fault) + measured_condition_collar <- max(collars) + + + # Measured condition modifier --------------------------------------------- + measured_condition_modifier <- data.frame(measured_condition_factor, + measured_condition_cap, + measured_condition_collar) + + + + # Observed conditions ----------------------------------------------------- + + oci_mmi_cal_df <- + gb_ref$observed_cond_modifier_mmi_cal %>% + dplyr::filter(`Asset Category` == "Submarine Cable") + + factor_divider_1_oi <- + as.numeric(oci_mmi_cal_df$`Parameters for Combination Using MMI Technique - Factor Divider 1`) + + factor_divider_2_oi <- + as.numeric(oci_mmi_cal_df$`Parameters for Combination Using MMI Technique - Factor Divider 2`) + + max_no_combined_factors_oi <- + as.numeric(oci_mmi_cal_df$`Parameters for Combination Using MMI Technique - Max. No. of Combined Factors`) + + + + # External conditions of armour + oci_submrn_cable_ext_cond_armr <- + gb_ref$oci_submrn_cable_ext_cond_armr %>% + dplyr::filter( + `Condition Criteria` == condition_armour + ) + + oi_factor <- + oci_submrn_cable_ext_cond_armr$`Condition Input Factor` + oi_cap <- oci_submrn_cable_ext_cond_armr$`Condition Input Cap` + oi_collar <- + oci_submrn_cable_ext_cond_armr$`Condition Input Collar` + + + observed_condition_factor <- mmi(oi_factor, + factor_divider_1_oi, + factor_divider_2_oi, + max_no_combined_factors_oi) + + + observed_condition_cap <- oi_cap + observed_condition_collar <- oi_collar + + observed_condition_modifier <- data.frame(observed_condition_factor, + observed_condition_cap, + observed_condition_collar) + + # Health score factor --------------------------------------------------- + health_score_factor <- health_score_excl_ehv_132kv_tf( + observed_condition_modifier$observed_condition_factor, + measured_condition_modifier$measured_condition_factor) + + + # Health score cap -------------------------------------------------------- + health_score_cap <- + min(observed_condition_modifier$observed_condition_cap, + measured_condition_modifier$measured_condition_cap) + + # Health score collar ----------------------------------------------------- + health_score_collar <- + min(observed_condition_modifier$observed_condition_collar, + measured_condition_modifier$measured_condition_collar) + + # Health score modifier --------------------------------------------------- + health_score_modifier <- data.frame(health_score_factor, + health_score_cap, + health_score_collar) + + # Current health score ---------------------------------------------------- + current_health_score <- + current_health(initial_health_score, + health_score_modifier$health_score_factor, + health_score_modifier$health_score_cap, + health_score_modifier$health_score_collar, + reliability_factor = reliability_factor) + + # Probability of failure for the 6.6/11 kV transformer today --------------- + probability_of_failure <- k * + (1 + (c * current_health_score) + + (((c * current_health_score)^2) / factorial(2)) + + (((c * current_health_score)^3) / factorial(3))) + + + return(probability_of_failure) + } diff --git a/R/pof_submarine_cables_10kv_pex.R b/R/pof_submarine_cables_10kv_pex.R new file mode 100644 index 00000000..3a790b91 --- /dev/null +++ b/R/pof_submarine_cables_10kv_pex.R @@ -0,0 +1,344 @@ +#' @importFrom magrittr %>% +#' @title Current Probability of Failure for 10kV Non Pressurised Submarine Cables +#' @description This function calculates the current +#' annual probability of failure per kilometer for submarine cables. +#' The function is a cubic curve that is based on +#' the first three terms of the Taylor series for an +#' exponential function. +#' @inheritParams duty_factor_cables +#' @inheritParams location_factor_sub +#' @param sheath_test String. Indicating the state of the sheath. Options: +#' \code{sheath_test = c("Pass", "Failed Minor", "Failed Major", +#' "Default")}. See page 158, table 189 in CNAIM (2021). +#' @param partial_discharge String. Indicating the level of partial discharge. +#' Options: +#' \code{partial_discharge = c("Low", "Medium", "High", +#' "Default")}. See page 158, table 190 in CNAIM (2021). +#' @param fault_hist Numeric. The calculated fault rate for the cable per annum +#' per kilometer. A setting of \code{"No historic faults recorded"} +#' indicates no fault. See page 158, table 191 in CNAIM (2021). +#' @param condition_armour String. Indicating the external condition of the +#' submarine cables armour. Options: +#' \code{condition_armour = c("Good","Poor","Critical","Default")} +#' @inheritParams current_health +#' @param k_value Numeric. \code{k_value = 0.0202} by default. This number is +#' given in a percentage. The default value is accordingly to the CNAIM standard +#' on p. 110. +#' @param c_value Numeric. \code{c_value = 1.087} by default. +#' The default value is accordingly to the CNAIM standard see page 110 +#' @param normal_expected_life Numeric. \code{normal_expected_life = 60} by default. +#' The default value is accordingly to the CNAIM standard on page 107. +#' @return Numeric. Current probability of failure +#' per annum per kilometer. +#' @param age Numeric. The current age in years of the cable. +#' @return Numeric. Current probability of failure +#' per annum per kilometre. +#' @source DNO Common Network Asset Indices Methodology (CNAIM), +#' Health & Criticality - Version 2.1, 2021: +#' \url{https://www.ofgem.gov.uk/sites/default/files/docs/2021/04/dno_common_network_asset_indices_methodology_v2.1_final_01-04-2021.pdf} +#' @export +#' @examples +#' # Current annual probability of failure for 1 km 10kV pex Sub Cable +# pof_submarine_cables_10kv_pex_res <- +# pof_submarine_cables_10kv_pex( +# utilisation_pct = "Default", +# operating_voltage_pct = "Default", +# topography = "Default", +# situation = "Default", +# wind_wave = "Default", +# intensity = "Default", +# landlocked = "no", +# sheath_test = "Default", +# partial_discharge = "Default", +# fault_hist = "Default", +# condition_armour = "Default", +# age = 10, +# reliability_factor = "Default", +# k_value = 0.0202, +# c_value = 1.087, +# normal_expected_life = 60) * 100 +# paste0(sprintf("Probability of failure %.4f", pof_submarine_cables_10kv_pex_res), +# " percent per annum") + + +pof_submarine_cables_10kv_pex <- + function(utilisation_pct = "Default", + operating_voltage_pct = "Default", + topography = "Default", + situation = "Default", + wind_wave = "Default", + intensity = "Default", + landlocked = "no", + sheath_test = "Default", + partial_discharge = "Default", + fault_hist = "Default", + condition_armour = "Default", + age, + reliability_factor = "Default", + k_value = 0.0202, + c_value = 1.087, + normal_expected_life = 60) { + + sub_cable_type <- "HV Sub Cable" + `Asset Register Category` = `Health Index Asset Category` = + `Generic Term...1` = `Generic Term...2` = + `Functional Failure Category`= `K-Value (%)` = + `C-Value` = `Condition Criteria: Sheath Test Result` = + `Condition Criteria: Partial Discharge Test Result` = + `Asset Category` = `Condition Criteria` = `Asset Register Category` = NULL + # due to NSE notes in R CMD check + + # Ref. table Categorisation of Assets and Generic Terms for Assets -- + + asset_category <- gb_ref$categorisation_of_assets %>% + dplyr::filter(`Asset Register Category` == sub_cable_type) %>% + dplyr::select(`Health Index Asset Category`) %>% dplyr::pull() + + generic_term_1 <- gb_ref$generic_terms_for_assets %>% + dplyr::filter(`Health Index Asset Category` == asset_category) %>% + dplyr::select(`Generic Term...1`) %>% dplyr::pull() + + generic_term_2 <- gb_ref$generic_terms_for_assets %>% + dplyr::filter(`Health Index Asset Category` == asset_category) %>% + dplyr::select(`Generic Term...2`) %>% dplyr::pull() + + + # Constants C and K for PoF function -------------------------------------- + k <- k_value/100 + + c <- c_value + + # Duty factor ------------------------------------------------------------- + sub_marine_col_level <- "HV" + + duty_factor_sub <- + duty_factor_cables( + utilisation_pct, + operating_voltage_pct, + voltage_level = sub_marine_col_level) + + + # # Location factor --------------------------------------------------------- + lf_submarine <- location_factor_sub(topography, + situation, + wind_wave, + intensity, + landlocked) + + # Expected life ------------------------------ + expected_life_years <- expected_life(normal_expected_life, + duty_factor_sub, + lf_submarine) + + # b1 (Initial Ageing Rate) ------------------------------------------------ + b1 <- beta_1(expected_life_years) + + # Initial health score ---------------------------------------------------- + initial_health_score <- initial_health(b1, age) + + ## NOTE + # Typically, the Health Score Collar is 0.5 and + # Health Score Cap is 10, implying no overriding + # of the Health Score. However, in some instances + # these parameters are set to other values in the + # Health Score Modifier calibration tables. + # These overriding values are shown in Table 35 to Table 202 + # and Table 207 in Appendix B. + + # Measured condition inputs --------------------------------------------- + mcm_mmi_cal_df <- + gb_ref$measured_cond_modifier_mmi_cal + + + mcm_mmi_cal_df <- + mcm_mmi_cal_df[which( + mcm_mmi_cal_df$`Asset Category` == "Submarine Cable"), ] + + factor_divider_1 <- + as.numeric( + mcm_mmi_cal_df$ + `Parameters for Combination Using MMI Technique - Factor Divider 1`) + + factor_divider_2 <- + as.numeric( + mcm_mmi_cal_df$ + `Parameters for Combination Using MMI Technique - Factor Divider 2`) + + max_no_combined_factors <- + as.numeric( + mcm_mmi_cal_df$ + `Parameters for Combination Using MMI Technique - Max. No. of Combined Factors` + ) + + + # Sheath test ------------------------------------------------------------- + mci_submarine_cbl_sheath_test <- + gb_ref$mci_submarine_cbl_sheath_test %>% dplyr::filter( + `Condition Criteria: Sheath Test Result` == sheath_test + ) + + ci_factor_sheath <- + mci_submarine_cbl_sheath_test$`Condition Input Factor` + ci_cap_sheath <- + mci_submarine_cbl_sheath_test$`Condition Input Cap` + ci_collar_sheath <- + mci_submarine_cbl_sheath_test$`Condition Input Collar` + + # Partial discharge------------------------------------------------------- + mci_submarine_cable_prtl_disc <- + gb_ref$mci_submarine_cable_prtl_disc %>% + dplyr::filter( + `Condition Criteria: Partial Discharge Test Result` == partial_discharge + ) + + ci_factor_partial <- + mci_submarine_cable_prtl_disc$`Condition Input Factor` + ci_cap_partial <- mci_submarine_cable_prtl_disc$`Condition Input Cap` + ci_collar_partial <- + mci_submarine_cable_prtl_disc$`Condition Input Collar` + + + # Fault ------------------------------------------------------- + mci_submarine_cable_fault_hist <- + gb_ref$mci_submarine_cable_fault_hist + + for (n in 2:4) { + if (fault_hist == 'Default' || fault_hist == + 'No historic faults recorded') { + no_row <- which(mci_submarine_cable_fault_hist$Upper == fault_hist) + + ci_factor_fault <- + mci_submarine_cable_fault_hist$`Condition Input Factor`[no_row] + ci_cap_fault <- + mci_submarine_cable_fault_hist$`Condition Input Cap`[no_row] + ci_collar_fault <- + mci_submarine_cable_fault_hist$`Condition Input Collar`[no_row] + break + } else if (fault_hist >= + as.numeric(mci_submarine_cable_fault_hist$Lower[n]) & + fault_hist < + as.numeric(mci_submarine_cable_fault_hist$Upper[n])) { + + ci_factor_fault <- + mci_submarine_cable_fault_hist$`Condition Input Factor`[n] + ci_cap_fault <- + mci_submarine_cable_fault_hist$`Condition Input Cap`[n] + ci_collar_fault <- + mci_submarine_cable_fault_hist$`Condition Input Collar`[n] + + break + } + } + + # Measured conditions + + factors <- c(ci_factor_sheath, + ci_factor_partial, + ci_factor_fault) + + measured_condition_factor <- mmi(factors, + factor_divider_1, + factor_divider_2, + max_no_combined_factors) + + caps <- c(ci_cap_sheath, + ci_cap_partial, + ci_cap_fault) + measured_condition_cap <- min(caps) + + # Measured condition collar ---------------------------------------------- + collars <- c(ci_collar_sheath, + ci_collar_partial, + ci_collar_fault) + measured_condition_collar <- max(collars) + + + # Measured condition modifier --------------------------------------------- + measured_condition_modifier <- data.frame(measured_condition_factor, + measured_condition_cap, + measured_condition_collar) + + + + # Observed conditions ----------------------------------------------------- + + oci_mmi_cal_df <- + gb_ref$observed_cond_modifier_mmi_cal %>% + dplyr::filter(`Asset Category` == "Submarine Cable") + + factor_divider_1_oi <- + as.numeric(oci_mmi_cal_df$`Parameters for Combination Using MMI Technique - Factor Divider 1`) + + factor_divider_2_oi <- + as.numeric(oci_mmi_cal_df$`Parameters for Combination Using MMI Technique - Factor Divider 2`) + + max_no_combined_factors_oi <- + as.numeric(oci_mmi_cal_df$`Parameters for Combination Using MMI Technique - Max. No. of Combined Factors`) + + + + # External conditions of armour + oci_submrn_cable_ext_cond_armr <- + gb_ref$oci_submrn_cable_ext_cond_armr %>% + dplyr::filter( + `Condition Criteria` == condition_armour + ) + + oi_factor <- + oci_submrn_cable_ext_cond_armr$`Condition Input Factor` + oi_cap <- oci_submrn_cable_ext_cond_armr$`Condition Input Cap` + oi_collar <- + oci_submrn_cable_ext_cond_armr$`Condition Input Collar` + + + observed_condition_factor <- mmi(oi_factor, + factor_divider_1_oi, + factor_divider_2_oi, + max_no_combined_factors_oi) + + + observed_condition_cap <- oi_cap + observed_condition_collar <- oi_collar + + observed_condition_modifier <- data.frame(observed_condition_factor, + observed_condition_cap, + observed_condition_collar) + + # Health score factor --------------------------------------------------- + health_score_factor <- health_score_excl_ehv_132kv_tf( + observed_condition_modifier$observed_condition_factor, + measured_condition_modifier$measured_condition_factor) + + + # Health score cap -------------------------------------------------------- + health_score_cap <- + min(observed_condition_modifier$observed_condition_cap, + measured_condition_modifier$measured_condition_cap) + + # Health score collar ----------------------------------------------------- + health_score_collar <- + min(observed_condition_modifier$observed_condition_collar, + measured_condition_modifier$measured_condition_collar) + + # Health score modifier --------------------------------------------------- + health_score_modifier <- data.frame(health_score_factor, + health_score_cap, + health_score_collar) + + # Current health score ---------------------------------------------------- + current_health_score <- + current_health(initial_health_score, + health_score_modifier$health_score_factor, + health_score_modifier$health_score_cap, + health_score_modifier$health_score_collar, + reliability_factor = reliability_factor) + + # Probability of failure for the 6.6/11 kV transformer today --------------- + probability_of_failure <- k * + (1 + (c * current_health_score) + + (((c * current_health_score)^2) / factorial(2)) + + (((c * current_health_score)^3) / factorial(3))) + + + return(probability_of_failure) + } diff --git a/R/pof_submarine_cables_30_60kv_oil.R b/R/pof_submarine_cables_30_60kv_oil.R new file mode 100644 index 00000000..856efd6a --- /dev/null +++ b/R/pof_submarine_cables_30_60kv_oil.R @@ -0,0 +1,347 @@ +#' @importFrom magrittr %>% +#' @title Current Probability of Failure for 30kV and 60kV Oil Submarine Cables +#' @description This function calculates the current +#' annual probability of failure per kilometer for submarine cables. +#' The function is a cubic curve that is based on +#' the first three terms of the Taylor series for an +#' exponential function. For more information about the +#' probability of failure function see section 6 +#' on page 34 in CNAIM (2021). +#' @inheritParams duty_factor_cables +#' @inheritParams location_factor_sub +#' @param sheath_test String. Indicating the state of the sheath. Options: +#' \code{sheath_test = c("Pass", "Failed Minor", "Failed Major", +#' "Default")}. See page 158, table 189 in CNAIM (2021). +#' @param partial_discharge String. Indicating the level of partial discharge. +#' Options: +#' \code{partial_discharge = c("Low", "Medium", "High", +#' "Default")}. See page 158, table 190 in CNAIM (2021). +#' @param fault_hist Numeric. The calculated fault rate for the cable per annum +#' per kilometer. A setting of \code{"No historic faults recorded"} +#' indicates no fault. See page 158, table 191 in CNAIM (2021). +#' @param condition_armour String. Indicating the external condition of the +#' submarine cables armour. Options: +#' \code{condition_armour = c("Good","Poor","Critical","Default")} +#' @inheritParams current_health +#' @param k_value Numeric. \code{k_value = 0.0202} by default. This number is +#' given in a percentage. The default value is accordingly to the CNAIM standard +#' on p. 110. +#' @param c_value Numeric. \code{c_value = 1.087} by default. +#' The default value is accordingly to the CNAIM standard see page 110 +#' @param normal_expected_life Numeric. \code{normal_expected_life = 60} by default. +#' The default value is accordingly to the CNAIM standard on page 107. +#' @return Numeric. Current probability of failure +#' per annum per kilometer. +#' @param age Numeric. The current age in years of the cable. +#' @return Numeric. Current probability of failure +#' per annum per kilometre. +#' @source DNO Common Network Asset Indices Methodology (CNAIM), +#' Health & Criticality - Version 2.1, 2021: +#' \url{https://www.ofgem.gov.uk/sites/default/files/docs/2021/04/dno_common_network_asset_indices_methodology_v2.1_final_01-04-2021.pdf} +#' @export +#' @examples +#' # Current annual probability of failure for 1 km 30kV and 60kV Oil Sub Cable +# pof_submarine_cables_30_60kv_oil_res <- +# pof_submarine_cables_30_60kv_oil( +# utilisation_pct = "Default", +# operating_voltage_pct = "Default", +# topography = "Default", +# situation = "Default", +# wind_wave = "Default", +# intensity = "Default", +# landlocked = "no", +# sheath_test = "Default", +# partial_discharge = "Default", +# fault_hist = "Default", +# condition_armour = "Default", +# age = 10, +# reliability_factor = "Default", +# k_value = 2.0944, +# c_value = 1.087, +# normal_expected_life = 60)*100 +# paste0(sprintf("Probability of failure %.4f", pof_submarine_cables_30_60kv_oil_res), +# " percent per annum") + + +pof_submarine_cables_30_60kv_oil <- + function(utilisation_pct = "Default", + operating_voltage_pct = "Default", + topography = "Default", + situation = "Default", + wind_wave = "Default", + intensity = "Default", + landlocked = "no", + sheath_test = "Default", + partial_discharge = "Default", + fault_hist = "Default", + condition_armour = "Default", + age, + reliability_factor = "Default", + k_value = 2.0944, + c_value = 1.087, + normal_expected_life = 60) { + + sub_cable_type <- "EHV Sub Cable" + `Asset Register Category` = `Health Index Asset Category` = + `Generic Term...1` = `Generic Term...2` = + `Functional Failure Category`= `K-Value (%)` = + `C-Value` = `Condition Criteria: Sheath Test Result` = + `Condition Criteria: Partial Discharge Test Result` = + `Asset Category` = `Condition Criteria` = `Asset Register Category` = NULL + # due to NSE notes in R CMD check + + # Ref. table Categorisation of Assets and Generic Terms for Assets -- + + asset_category <- gb_ref$categorisation_of_assets %>% + dplyr::filter(`Asset Register Category` == sub_cable_type) %>% + dplyr::select(`Health Index Asset Category`) %>% dplyr::pull() + + generic_term_1 <- gb_ref$generic_terms_for_assets %>% + dplyr::filter(`Health Index Asset Category` == asset_category) %>% + dplyr::select(`Generic Term...1`) %>% dplyr::pull() + + generic_term_2 <- gb_ref$generic_terms_for_assets %>% + dplyr::filter(`Health Index Asset Category` == asset_category) %>% + dplyr::select(`Generic Term...2`) %>% dplyr::pull() + + + # Constants C and K for PoF function -------------------------------------- + k <- k_value/100 + + c <- c_value + + # Duty factor ------------------------------------------------------------- + sub_marine_col_level <- "EHV" + + + duty_factor_sub <- + duty_factor_cables( + utilisation_pct, + operating_voltage_pct, + voltage_level = sub_marine_col_level) + + + # # Location factor --------------------------------------------------------- + lf_submarine <- location_factor_sub(topography, + situation, + wind_wave, + intensity, + landlocked) + + # Expected life ------------------------------ + expected_life_years <- expected_life(normal_expected_life, + duty_factor_sub, + lf_submarine) + + # b1 (Initial Ageing Rate) ------------------------------------------------ + b1 <- beta_1(expected_life_years) + + # Initial health score ---------------------------------------------------- + initial_health_score <- initial_health(b1, age) + + ## NOTE + # Typically, the Health Score Collar is 0.5 and + # Health Score Cap is 10, implying no overriding + # of the Health Score. However, in some instances + # these parameters are set to other values in the + # Health Score Modifier calibration tables. + # These overriding values are shown in Table 35 to Table 202 + # and Table 207 in Appendix B. + + # Measured condition inputs --------------------------------------------- + mcm_mmi_cal_df <- + gb_ref$measured_cond_modifier_mmi_cal + + + mcm_mmi_cal_df <- + mcm_mmi_cal_df[which( + mcm_mmi_cal_df$`Asset Category` == "Submarine Cable"), ] + + factor_divider_1 <- + as.numeric( + mcm_mmi_cal_df$ + `Parameters for Combination Using MMI Technique - Factor Divider 1`) + + factor_divider_2 <- + as.numeric( + mcm_mmi_cal_df$ + `Parameters for Combination Using MMI Technique - Factor Divider 2`) + + max_no_combined_factors <- + as.numeric( + mcm_mmi_cal_df$ + `Parameters for Combination Using MMI Technique - Max. No. of Combined Factors` + ) + + + # Sheath test ------------------------------------------------------------- + mci_submarine_cbl_sheath_test <- + gb_ref$mci_submarine_cbl_sheath_test %>% dplyr::filter( + `Condition Criteria: Sheath Test Result` == sheath_test + ) + + ci_factor_sheath <- + mci_submarine_cbl_sheath_test$`Condition Input Factor` + ci_cap_sheath <- + mci_submarine_cbl_sheath_test$`Condition Input Cap` + ci_collar_sheath <- + mci_submarine_cbl_sheath_test$`Condition Input Collar` + + # Partial discharge------------------------------------------------------- + mci_submarine_cable_prtl_disc <- + gb_ref$mci_submarine_cable_prtl_disc %>% + dplyr::filter( + `Condition Criteria: Partial Discharge Test Result` == partial_discharge + ) + + ci_factor_partial <- + mci_submarine_cable_prtl_disc$`Condition Input Factor` + ci_cap_partial <- mci_submarine_cable_prtl_disc$`Condition Input Cap` + ci_collar_partial <- + mci_submarine_cable_prtl_disc$`Condition Input Collar` + + + # Fault ------------------------------------------------------- + mci_submarine_cable_fault_hist <- + gb_ref$mci_submarine_cable_fault_hist + + for (n in 2:4) { + if (fault_hist == 'Default' || fault_hist == + 'No historic faults recorded') { + no_row <- which(mci_submarine_cable_fault_hist$Upper == fault_hist) + + ci_factor_fault <- + mci_submarine_cable_fault_hist$`Condition Input Factor`[no_row] + ci_cap_fault <- + mci_submarine_cable_fault_hist$`Condition Input Cap`[no_row] + ci_collar_fault <- + mci_submarine_cable_fault_hist$`Condition Input Collar`[no_row] + break + } else if (fault_hist >= + as.numeric(mci_submarine_cable_fault_hist$Lower[n]) & + fault_hist < + as.numeric(mci_submarine_cable_fault_hist$Upper[n])) { + + ci_factor_fault <- + mci_submarine_cable_fault_hist$`Condition Input Factor`[n] + ci_cap_fault <- + mci_submarine_cable_fault_hist$`Condition Input Cap`[n] + ci_collar_fault <- + mci_submarine_cable_fault_hist$`Condition Input Collar`[n] + + break + } + } + + # Measured conditions + + factors <- c(ci_factor_sheath, + ci_factor_partial, + ci_factor_fault) + + measured_condition_factor <- mmi(factors, + factor_divider_1, + factor_divider_2, + max_no_combined_factors) + + caps <- c(ci_cap_sheath, + ci_cap_partial, + ci_cap_fault) + measured_condition_cap <- min(caps) + + # Measured condition collar ---------------------------------------------- + collars <- c(ci_collar_sheath, + ci_collar_partial, + ci_collar_fault) + measured_condition_collar <- max(collars) + + + # Measured condition modifier --------------------------------------------- + measured_condition_modifier <- data.frame(measured_condition_factor, + measured_condition_cap, + measured_condition_collar) + + + + # Observed conditions ----------------------------------------------------- + + oci_mmi_cal_df <- + gb_ref$observed_cond_modifier_mmi_cal %>% + dplyr::filter(`Asset Category` == "Submarine Cable") + + factor_divider_1_oi <- + as.numeric(oci_mmi_cal_df$`Parameters for Combination Using MMI Technique - Factor Divider 1`) + + factor_divider_2_oi <- + as.numeric(oci_mmi_cal_df$`Parameters for Combination Using MMI Technique - Factor Divider 2`) + + max_no_combined_factors_oi <- + as.numeric(oci_mmi_cal_df$`Parameters for Combination Using MMI Technique - Max. No. of Combined Factors`) + + + + # External conditions of armour + oci_submrn_cable_ext_cond_armr <- + gb_ref$oci_submrn_cable_ext_cond_armr %>% + dplyr::filter( + `Condition Criteria` == condition_armour + ) + + oi_factor <- + oci_submrn_cable_ext_cond_armr$`Condition Input Factor` + oi_cap <- oci_submrn_cable_ext_cond_armr$`Condition Input Cap` + oi_collar <- + oci_submrn_cable_ext_cond_armr$`Condition Input Collar` + + + observed_condition_factor <- mmi(oi_factor, + factor_divider_1_oi, + factor_divider_2_oi, + max_no_combined_factors_oi) + + + observed_condition_cap <- oi_cap + observed_condition_collar <- oi_collar + + observed_condition_modifier <- data.frame(observed_condition_factor, + observed_condition_cap, + observed_condition_collar) + + # Health score factor --------------------------------------------------- + health_score_factor <- health_score_excl_ehv_132kv_tf( + observed_condition_modifier$observed_condition_factor, + measured_condition_modifier$measured_condition_factor) + + + # Health score cap -------------------------------------------------------- + health_score_cap <- + min(observed_condition_modifier$observed_condition_cap, + measured_condition_modifier$measured_condition_cap) + + # Health score collar ----------------------------------------------------- + health_score_collar <- + min(observed_condition_modifier$observed_condition_collar, + measured_condition_modifier$measured_condition_collar) + + # Health score modifier --------------------------------------------------- + health_score_modifier <- data.frame(health_score_factor, + health_score_cap, + health_score_collar) + + # Current health score ---------------------------------------------------- + current_health_score <- + current_health(initial_health_score, + health_score_modifier$health_score_factor, + health_score_modifier$health_score_cap, + health_score_modifier$health_score_collar, + reliability_factor = reliability_factor) + + # Probability of failure for the 6.6/11 kV transformer today --------------- + probability_of_failure <- k * + (1 + (c * current_health_score) + + (((c * current_health_score)^2) / factorial(2)) + + (((c * current_health_score)^3) / factorial(3))) + + + return(probability_of_failure) + } diff --git a/R/pof_submarine_cables_30_60kv_pex.R b/R/pof_submarine_cables_30_60kv_pex.R new file mode 100644 index 00000000..80058f94 --- /dev/null +++ b/R/pof_submarine_cables_30_60kv_pex.R @@ -0,0 +1,347 @@ +#' @importFrom magrittr %>% +#' @title Current Probability of Failure for 30kV and 60kV Non Pressurised Submarine Cables +#' @description This function calculates the current +#' annual probability of failure per kilometer for submarine cables. +#' The function is a cubic curve that is based on +#' the first three terms of the Taylor series for an +#' exponential function. For more information about the +#' probability of failure function see section 6 +#' on page 34 in CNAIM (2021). +#' @inheritParams duty_factor_cables +#' @inheritParams location_factor_sub +#' @param sheath_test String. Indicating the state of the sheath. Options: +#' \code{sheath_test = c("Pass", "Failed Minor", "Failed Major", +#' "Default")}. See page 158, table 189 in CNAIM (2021). +#' @param partial_discharge String. Indicating the level of partial discharge. +#' Options: +#' \code{partial_discharge = c("Low", "Medium", "High", +#' "Default")}. See page 158, table 190 in CNAIM (2021). +#' @param fault_hist Numeric. The calculated fault rate for the cable per annum +#' per kilometer. A setting of \code{"No historic faults recorded"} +#' indicates no fault. See page 158, table 191 in CNAIM (2021). +#' @param condition_armour String. Indicating the external condition of the +#' submarine cables armour. Options: +#' \code{condition_armour = c("Good","Poor","Critical","Default")} +#' @inheritParams current_health +#' @param k_value Numeric. \code{k_value = 0.0202} by default. This number is +#' given in a percentage. The default value is accordingly to the CNAIM standard +#' on p. 110. +#' @param c_value Numeric. \code{c_value = 1.087} by default. +#' The default value is accordingly to the CNAIM standard see page 110 +#' @param normal_expected_life Numeric. \code{normal_expected_life = 60} by default. +#' The default value is accordingly to the CNAIM standard on page 107. +#' @return Numeric. Current probability of failure +#' per annum per kilometer. +#' @param age Numeric. The current age in years of the cable. +#' @return Numeric. Current probability of failure +#' per annum per kilometre. +#' @source DNO Common Network Asset Indices Methodology (CNAIM), +#' Health & Criticality - Version 2.1, 2021: +#' \url{https://www.ofgem.gov.uk/sites/default/files/docs/2021/04/dno_common_network_asset_indices_methodology_v2.1_final_01-04-2021.pdf} +#' @export +#' @examples +#' # Current annual probability of failure for 1 km 30kV and 60kV PEX Sub Cable +# pof_submarine_cables_30_60kv_pex_res <- +# pof_submarine_cables_30_60kv_pex( +# utilisation_pct = "Default", +# operating_voltage_pct = "Default", +# topography = "Default", +# situation = "Default", +# wind_wave = "Default", +# intensity = "Default", +# landlocked = "no", +# sheath_test = "Default", +# partial_discharge = "Default", +# fault_hist = "Default", +# condition_armour = "Default", +# age = 10, +# reliability_factor = "Default", +# k_value = 0.0202, +# c_value = 1.087, +# normal_expected_life = 60)*100 +# paste0(sprintf("Probability of failure %.4f", pof_submarine_cables_30_60kv_pex_res), +# " percent per annum") + + +pof_submarine_cables_30_60kv_pex <- + function(utilisation_pct = "Default", + operating_voltage_pct = "Default", + topography = "Default", + situation = "Default", + wind_wave = "Default", + intensity = "Default", + landlocked = "no", + sheath_test = "Default", + partial_discharge = "Default", + fault_hist = "Default", + condition_armour = "Default", + age, + reliability_factor = "Default", + k_value = 0.0202, + c_value = 1.087, + normal_expected_life = 60) { + + sub_cable_type <- "EHV Sub Cable" + `Asset Register Category` = `Health Index Asset Category` = + `Generic Term...1` = `Generic Term...2` = + `Functional Failure Category`= `K-Value (%)` = + `C-Value` = `Condition Criteria: Sheath Test Result` = + `Condition Criteria: Partial Discharge Test Result` = + `Asset Category` = `Condition Criteria` = `Asset Register Category` = NULL + # due to NSE notes in R CMD check + + # Ref. table Categorisation of Assets and Generic Terms for Assets -- + + asset_category <- gb_ref$categorisation_of_assets %>% + dplyr::filter(`Asset Register Category` == sub_cable_type) %>% + dplyr::select(`Health Index Asset Category`) %>% dplyr::pull() + + generic_term_1 <- gb_ref$generic_terms_for_assets %>% + dplyr::filter(`Health Index Asset Category` == asset_category) %>% + dplyr::select(`Generic Term...1`) %>% dplyr::pull() + + generic_term_2 <- gb_ref$generic_terms_for_assets %>% + dplyr::filter(`Health Index Asset Category` == asset_category) %>% + dplyr::select(`Generic Term...2`) %>% dplyr::pull() + + + # Constants C and K for PoF function -------------------------------------- + k <- k_value/100 + + c <- c_value + + # Duty factor ------------------------------------------------------------- + sub_marine_col_level <- "EHV" + + + duty_factor_sub <- + duty_factor_cables( + utilisation_pct, + operating_voltage_pct, + voltage_level = sub_marine_col_level) + + + # # Location factor --------------------------------------------------------- + lf_submarine <- location_factor_sub(topography, + situation, + wind_wave, + intensity, + landlocked) + + # Expected life ------------------------------ + expected_life_years <- expected_life(normal_expected_life, + duty_factor_sub, + lf_submarine) + + # b1 (Initial Ageing Rate) ------------------------------------------------ + b1 <- beta_1(expected_life_years) + + # Initial health score ---------------------------------------------------- + initial_health_score <- initial_health(b1, age) + + ## NOTE + # Typically, the Health Score Collar is 0.5 and + # Health Score Cap is 10, implying no overriding + # of the Health Score. However, in some instances + # these parameters are set to other values in the + # Health Score Modifier calibration tables. + # These overriding values are shown in Table 35 to Table 202 + # and Table 207 in Appendix B. + + # Measured condition inputs --------------------------------------------- + mcm_mmi_cal_df <- + gb_ref$measured_cond_modifier_mmi_cal + + + mcm_mmi_cal_df <- + mcm_mmi_cal_df[which( + mcm_mmi_cal_df$`Asset Category` == "Submarine Cable"), ] + + factor_divider_1 <- + as.numeric( + mcm_mmi_cal_df$ + `Parameters for Combination Using MMI Technique - Factor Divider 1`) + + factor_divider_2 <- + as.numeric( + mcm_mmi_cal_df$ + `Parameters for Combination Using MMI Technique - Factor Divider 2`) + + max_no_combined_factors <- + as.numeric( + mcm_mmi_cal_df$ + `Parameters for Combination Using MMI Technique - Max. No. of Combined Factors` + ) + + + # Sheath test ------------------------------------------------------------- + mci_submarine_cbl_sheath_test <- + gb_ref$mci_submarine_cbl_sheath_test %>% dplyr::filter( + `Condition Criteria: Sheath Test Result` == sheath_test + ) + + ci_factor_sheath <- + mci_submarine_cbl_sheath_test$`Condition Input Factor` + ci_cap_sheath <- + mci_submarine_cbl_sheath_test$`Condition Input Cap` + ci_collar_sheath <- + mci_submarine_cbl_sheath_test$`Condition Input Collar` + + # Partial discharge------------------------------------------------------- + mci_submarine_cable_prtl_disc <- + gb_ref$mci_submarine_cable_prtl_disc %>% + dplyr::filter( + `Condition Criteria: Partial Discharge Test Result` == partial_discharge + ) + + ci_factor_partial <- + mci_submarine_cable_prtl_disc$`Condition Input Factor` + ci_cap_partial <- mci_submarine_cable_prtl_disc$`Condition Input Cap` + ci_collar_partial <- + mci_submarine_cable_prtl_disc$`Condition Input Collar` + + + # Fault ------------------------------------------------------- + mci_submarine_cable_fault_hist <- + gb_ref$mci_submarine_cable_fault_hist + + for (n in 2:4) { + if (fault_hist == 'Default' || fault_hist == + 'No historic faults recorded') { + no_row <- which(mci_submarine_cable_fault_hist$Upper == fault_hist) + + ci_factor_fault <- + mci_submarine_cable_fault_hist$`Condition Input Factor`[no_row] + ci_cap_fault <- + mci_submarine_cable_fault_hist$`Condition Input Cap`[no_row] + ci_collar_fault <- + mci_submarine_cable_fault_hist$`Condition Input Collar`[no_row] + break + } else if (fault_hist >= + as.numeric(mci_submarine_cable_fault_hist$Lower[n]) & + fault_hist < + as.numeric(mci_submarine_cable_fault_hist$Upper[n])) { + + ci_factor_fault <- + mci_submarine_cable_fault_hist$`Condition Input Factor`[n] + ci_cap_fault <- + mci_submarine_cable_fault_hist$`Condition Input Cap`[n] + ci_collar_fault <- + mci_submarine_cable_fault_hist$`Condition Input Collar`[n] + + break + } + } + + # Measured conditions + + factors <- c(ci_factor_sheath, + ci_factor_partial, + ci_factor_fault) + + measured_condition_factor <- mmi(factors, + factor_divider_1, + factor_divider_2, + max_no_combined_factors) + + caps <- c(ci_cap_sheath, + ci_cap_partial, + ci_cap_fault) + measured_condition_cap <- min(caps) + + # Measured condition collar ---------------------------------------------- + collars <- c(ci_collar_sheath, + ci_collar_partial, + ci_collar_fault) + measured_condition_collar <- max(collars) + + + # Measured condition modifier --------------------------------------------- + measured_condition_modifier <- data.frame(measured_condition_factor, + measured_condition_cap, + measured_condition_collar) + + + + # Observed conditions ----------------------------------------------------- + + oci_mmi_cal_df <- + gb_ref$observed_cond_modifier_mmi_cal %>% + dplyr::filter(`Asset Category` == "Submarine Cable") + + factor_divider_1_oi <- + as.numeric(oci_mmi_cal_df$`Parameters for Combination Using MMI Technique - Factor Divider 1`) + + factor_divider_2_oi <- + as.numeric(oci_mmi_cal_df$`Parameters for Combination Using MMI Technique - Factor Divider 2`) + + max_no_combined_factors_oi <- + as.numeric(oci_mmi_cal_df$`Parameters for Combination Using MMI Technique - Max. No. of Combined Factors`) + + + + # External conditions of armour + oci_submrn_cable_ext_cond_armr <- + gb_ref$oci_submrn_cable_ext_cond_armr %>% + dplyr::filter( + `Condition Criteria` == condition_armour + ) + + oi_factor <- + oci_submrn_cable_ext_cond_armr$`Condition Input Factor` + oi_cap <- oci_submrn_cable_ext_cond_armr$`Condition Input Cap` + oi_collar <- + oci_submrn_cable_ext_cond_armr$`Condition Input Collar` + + + observed_condition_factor <- mmi(oi_factor, + factor_divider_1_oi, + factor_divider_2_oi, + max_no_combined_factors_oi) + + + observed_condition_cap <- oi_cap + observed_condition_collar <- oi_collar + + observed_condition_modifier <- data.frame(observed_condition_factor, + observed_condition_cap, + observed_condition_collar) + + # Health score factor --------------------------------------------------- + health_score_factor <- health_score_excl_ehv_132kv_tf( + observed_condition_modifier$observed_condition_factor, + measured_condition_modifier$measured_condition_factor) + + + # Health score cap -------------------------------------------------------- + health_score_cap <- + min(observed_condition_modifier$observed_condition_cap, + measured_condition_modifier$measured_condition_cap) + + # Health score collar ----------------------------------------------------- + health_score_collar <- + min(observed_condition_modifier$observed_condition_collar, + measured_condition_modifier$measured_condition_collar) + + # Health score modifier --------------------------------------------------- + health_score_modifier <- data.frame(health_score_factor, + health_score_cap, + health_score_collar) + + # Current health score ---------------------------------------------------- + current_health_score <- + current_health(initial_health_score, + health_score_modifier$health_score_factor, + health_score_modifier$health_score_cap, + health_score_modifier$health_score_collar, + reliability_factor = reliability_factor) + + # Probability of failure for the 6.6/11 kV transformer today --------------- + probability_of_failure <- k * + (1 + (c * current_health_score) + + (((c * current_health_score)^2) / factorial(2)) + + (((c * current_health_score)^3) / factorial(3))) + + + return(probability_of_failure) + } diff --git a/R/pof_switchgear_30_60kv.R b/R/pof_switchgear_30_60kv.R new file mode 100644 index 00000000..dedd50b5 --- /dev/null +++ b/R/pof_switchgear_30_60kv.R @@ -0,0 +1,204 @@ +#' @importFrom magrittr %>% +#' @title Current Probability of Failure for 30kv and 60kv Switchgear +#' @description This function calculates the current +#' annual probability of failure 30kv and 60kv Switchgear +#' The function is a cubic curve that is based on +#' the first three terms of the Taylor series for an +#' exponential function. +#' @param asset_type String The type of EHV asset type +#' can be set to 30kV or 60kV. \code{asset_type = c("30kV, "60kV")} +#' @param number_of_operations The number of operations for duty factor +#' @param placement String. Specify if the asset is located outdoor or indoor. +#' @param altitude_m Numeric. Specify the altitude location for +#' the asset measured in meters from sea level.\code{altitude_m} +#' is used to derive the altitude factor. +#' A setting of \code{"Default"} +#' will set the altitude factor to 1 independent of \code{asset_type}. +#' @param distance_from_coast_km Numeric. Specify the distance from the +#' coast measured in kilometers. \code{distance_from_coast_km} is used +#' to derive the distance from coast factor. +#' A setting of \code{"Default"} will set the +#' distance from coast factor to 1 independent of \code{asset_type}. +#' @param corrosion_category_index Integer. +#' Specify the corrosion index category, 1-5. +#' @param age Numeric. The current age in years of the conductor. +#' @param measured_condition_inputs Named list observed_conditions_input +#' @param observed_condition_inputs Named list observed_conditions_input +#' \code{conductor_samp = c("Low","Medium/Normal","High","Default")}. +#' @inheritParams current_health +#' @param k_value Numeric. \code{k_value = "Default"} by default. This number is +#' given in a percentage. The default value is accordingly to the CNAIM standard +#' on p. 110. k-value for 30kV would be 0.0223 % and 0.0512 % for 60kV. +#' @param c_value Numeric. \code{c_value = 1.087} by default. +#' The default value is accordingly to the CNAIM standard see page 110 +#' @param normal_expected_life Numeric. \code{normal_expected_life = 55} by default. +#' The default value is accordingly to the CNAIM standard on page 107. +#' @return Numeric. Current probability of failure per annum. +#' @export +#' @examples +#' # Current annual probability of failure for EHV Swicthgear +# pof_switchgear_30_60kv_res <- +# pof_switchgear_30_60kv( +# asset_type = "30kV", +# number_of_operations = "Default", +# placement = "Default", +# altitude_m = "Default", +# distance_from_coast_km = "Default", +# corrosion_category_index = "Default", +# age = 10, +# observed_condition_inputs = +# list("external_condition" = +# list("Condition Criteria: Observed Condition" = "Default"), +# "oil_gas" = list("Condition Criteria: Observed Condition" = "Default"), +# "thermo_assment" = list("Condition Criteria: Observed Condition" = "Default"), +# "internal_condition" = list("Condition Criteria: Observed Condition" = "Default"), +# "indoor_env" = list("Condition Criteria: Observed Condition" = "Default"), +# "support_structure" = list("Condition Criteria: Observed Condition" = "Default")), +# measured_condition_inputs = +# list("partial_discharge" = +# list("Condition Criteria: Partial Discharge Test Results" = "Default"), +# "ductor_test" = list("Condition Criteria: Ductor Test Results" = "Default"), +# "oil_test" = list("Condition Criteria: Oil Test Results" = "Default"), +# "temp_reading" = list("Condition Criteria: Temperature Readings" = "Default"), +# "trip_test" = list("Condition Criteria: Trip Timing Test Result" = "Default"), +# "ir_test" = list("Condition Criteria: IR Test Results" = "Default" )), +# reliability_factor = "Default", +# k_value = "Default", +# c_value = 1.087, +# normal_expected_life = 55) * 100 +# paste0(sprintf("Probability of failure %.4f", pof_switchgear_30_60kv_res), +# " percent per annum") + +pof_switchgear_30_60kv <- + function(asset_type = "30kV", + placement = "Default", + number_of_operations = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age, + measured_condition_inputs, + observed_condition_inputs, + reliability_factor = "Default", + k_value = "Default", + c_value = 1.087, + normal_expected_life = 55) { + + ehv_asset_category <- "33kV RMU" + `Asset Register Category` = `Health Index Asset Category` = + `Generic Term...1` = `Generic Term...2` = `Functional Failure Category` = + `K-Value (%)` = `C-Value` = `Asset Register Category` = NULL + # due to NSE notes in R CMD check + + asset_category <- gb_ref$categorisation_of_assets %>% + dplyr::filter(`Asset Register Category` == + ehv_asset_category) %>% + dplyr::select(`Health Index Asset Category`) %>% dplyr::pull() + + generic_term_1 <- gb_ref$generic_terms_for_assets %>% + dplyr::filter(`Health Index Asset Category` == asset_category) %>% + dplyr::select(`Generic Term...1`) %>% dplyr::pull() + + generic_term_2 <- gb_ref$generic_terms_for_assets %>% + dplyr::filter(`Health Index Asset Category` == asset_category) %>% + dplyr::select(`Generic Term...2`) %>% dplyr::pull() + + + + # Constants C and K for PoF function -------------------------------------- + + # POF function asset category. + if (k_value == "Default" && asset_type == "30kV" ) { + k <- 0.0223/100 + } else if (k_value == "Default" && asset_type == "60kV" ) { + k <- 0.0512/100 + } else { + k <- k_value/100 + } + + c <- c_value + + # Duty factor ------------------------------------------------------------- + + duty_factor_cond <- get_duty_factor_hv_switchgear_primary(number_of_operations) + + # Location factor ---------------------------------------------------- + location_factor_cond <- location_factor(placement, + altitude_m, + distance_from_coast_km, + corrosion_category_index, + asset_type = ehv_asset_category) + # Expected life ------------------------------ + expected_life_years <- expected_life(normal_expected_life, + duty_factor_cond, + location_factor_cond) + + # b1 (Initial Ageing Rate) ------------------------------------------------ + b1 <- beta_1(expected_life_years) + + # Initial health score ---------------------------------------------------- + initial_health_score <- initial_health(b1, age) + + # Measured conditions + mci_table_names <- list("partial_discharge" = "mci_ehv_swg_partial_discharge", + "ductor_test" = "mci_ehv_swg_ductor_test", + "oil_test" = "mci_ehv_swg_oil_tests_gas_test", + "temp_reading" = "mci_ehv_swg_temp_readings", + "trip_test" = "mci_ehv_swg_trip_test", + "ir_test"= "mci_ehv_swg_ir_test") + + measured_condition_modifier <- + get_measured_conditions_modifier_hv_switchgear(asset_category, + mci_table_names, + measured_condition_inputs) + + # Observed conditions ----------------------------------------------------- + + oci_table_names <- list("external_condition" = "oci_ehv_swg_swg_ext_cond", + "oil_gas" = "oci_ehv_swg_oil_leak_gas_pr", + "thermo_assment" = "oci_ehv_swg_thermo_assessment", + "internal_condition" = "oci_ehv_swg_swg_int_cond_ops", + "indoor_env" = "oci_ehv_swg_indoor_environ", + "support_structure" = "oci_ehv_swg_support_structure") + + observed_condition_modifier <- + get_observed_conditions_modifier_hv_switchgear(asset_category, + oci_table_names, + observed_condition_inputs) + + # Health score factor --------------------------------------------------- + health_score_factor <- + health_score_excl_ehv_132kv_tf(observed_condition_modifier$condition_factor, + measured_condition_modifier$condition_factor) + + # Health score cap -------------------------------------------------------- + health_score_cap <- min(observed_condition_modifier$condition_cap, + measured_condition_modifier$condition_cap) + + # Health score collar ----------------------------------------------------- + health_score_collar <- max(observed_condition_modifier$condition_collar, + measured_condition_modifier$condition_collar) + + # Health score modifier --------------------------------------------------- + health_score_modifier <- data.frame(health_score_factor, + health_score_cap, + health_score_collar) + + # Current health score ---------------------------------------------------- + current_health_score <- + current_health(initial_health_score, + health_score_modifier$health_score_factor, + health_score_modifier$health_score_cap, + health_score_modifier$health_score_collar, + reliability_factor = reliability_factor) + + # Probability of failure --------------------------------------------------- + probability_of_failure <- k * + (1 + (c * current_health_score) + + (((c * current_health_score)^2) / factorial(2)) + + (((c * current_health_score)^3) / factorial(3))) + + + return(probability_of_failure) + } + From 3e34a1e922dd4ce385fce32a2b5ece7b34f2fab1 Mon Sep 17 00:00:00 2001 From: NicolaiHandreck Date: Thu, 21 Jul 2022 11:34:56 +0200 Subject: [PATCH 02/10] added tests --- tests/testthat/test-cof_cables_04_10kv.R | 138 ++++++++++++++++++ tests/testthat/test-pof_cables_04kv_pex.R | 21 +++ tests/testthat/test-pof_cables_10kv_oil.R | 21 +++ tests/testthat/test-pof_cables_10kv_pex.R | 21 +++ .../test-pof_future_cables_04kv_pex.R | 22 +++ .../test-pof_future_cables_10kv_oil.R | 22 +++ .../test-pof_future_cables_10kv_pex.R | 22 +++ 7 files changed, 267 insertions(+) create mode 100644 tests/testthat/test-cof_cables_04_10kv.R create mode 100644 tests/testthat/test-pof_cables_04kv_pex.R create mode 100644 tests/testthat/test-pof_cables_10kv_oil.R create mode 100644 tests/testthat/test-pof_cables_10kv_pex.R create mode 100644 tests/testthat/test-pof_future_cables_04kv_pex.R create mode 100644 tests/testthat/test-pof_future_cables_10kv_oil.R create mode 100644 tests/testthat/test-pof_future_cables_10kv_pex.R diff --git a/tests/testthat/test-cof_cables_04_10kv.R b/tests/testthat/test-cof_cables_04_10kv.R new file mode 100644 index 00000000..3f037611 --- /dev/null +++ b/tests/testthat/test-cof_cables_04_10kv.R @@ -0,0 +1,138 @@ +library(testthat) +library(CNAIM) + +context("COF:Financial Cables: 10 kV UG Cable Oil") + +test_that("10kV UG Cable (Oil)", { + res <- financial_cof_ehv_cables(ehv_asset_category = "10kV UG Cable (Oil)") + + expected_value <- 1123.59 + + expect_equal(res, expected_value) +}) + +context("COF:Financial Cables: 10 kV UG Cable PEX") + +test_that("10kV UG Cable (Non Pressurised)", { + res <- financial_cof_ehv_cables(ehv_asset_category = "10kV UG Cable (Non Pressurised)") + + expected_value <- 275619.2 + + expect_equal(res, expected_value) +}) + +context("COF:Financial Cables: 0.4 kV UG Cable PEX") + +test_that("0.4kV UG Cable (Non Pressurised)", { + res <- financial_cof_ehv_cables(ehv_asset_category = "0.4kV UG Cable (Non Pressurised)") + + expected_value <- 275619.2 + + expect_equal(res, expected_value) +}) + + +#----------------------------------------- + +context("COF:Safety Cables: 10 kV UG Cable Oil") + +test_that("10kV UG Cable (Oil)", { + res <- safety_cof_ehv_cables(ehv_asset_category = "10kV UG Cable (Oil)") + + expected_value <- 17.42 + + expect_equal(res, expected_value) +}) + +context("COF:Safety Cables: 10 kV UG Cable PEX") + +test_that("10kV UG Cable (Non Pressurised)", { + res <- safety_cof_ehv_cables(ehv_asset_category = "10kV UG Cable (Non Pressurised)") + + expected_value <- 17.42 + + expect_equal(res, expected_value) +}) + +context("COF:Safety Cables: 0.4 kV UG Cable PEX") + +test_that("0.4kV UG Cable (Non Pressurised)", { + res <- safety_cof_ehv_cables(ehv_asset_category = "0.4kV UG Cable (Non Pressurised)") + + expected_value <- 17.42 + + expect_equal(res, expected_value) +}) + +#----------------------------------------- + +context("COF:Env Cables: 10 kV UG Cable Oil") + +test_that("10kV UG Cable (Oil)", { + res <- environmental_cof_ehv_cables(ehv_asset_category = "10kV UG Cable (Oil)", + prox_water = 95, + bunded = "Yes") + + expected_value <- 25629.18 + + expect_equal(res, expected_value) +}) + +context("COF:Env Cables: 10 kV UG Cable PEX") + +test_that("10kV UG Cable (Non Pressurised", { + res <- environmental_cof_ehv_cables(ehv_asset_category = "10kV UG Cable (Non Pressurised)", + prox_water = 95, + bunded = "Yes") + + expected_value <- 6323.46 + + expect_equal(res, expected_value) +}) + +context("COF:Env Cables: 0.4 kV UG Cable PEX") + +test_that("0.4kV UG Cable (Non Pressurised", { + res <- environmental_cof_ehv_cables(ehv_asset_category = "0.4kV UG Cable (Non Pressurised)", + prox_water = 95, + bunded = "Yes") + + expected_value <- 6323.46 + + expect_equal(res, expected_value) +}) + +#----------------------------------------- + +context("COF:Network Cables: 10 kV UG Cable Oil") + +test_that("10kV UG Cable (Oil)", { + res <- network_cof_ehv_cables(ehv_asset_category = "10kV UG Cable (Oil)", + actual_load_mva = 15, secure = T) %>% round(2) + expected_value <- 43.55 + + expect_equal(res, expected_value) +}) + +context("COF:Network Cables: 10 kV UG Cable PEX") + +test_that("10kV UG Cable (Non Pressurised)", { + res <- network_cof_ehv_cables(ehv_asset_category = "10kV UG Cable (Non Pressurised)", + actual_load_mva = 15, secure = T) %>% round(2) + + expected_value <- 38432.88 + + expect_equal(res, expected_value) +}) + + +context("COF:Network Cables: 0.4 kV UG Cable PEX") + +test_that("0.4kV UG Cable (Non Pressurised)", { + res <- network_cof_ehv_cables(ehv_asset_category = "0.4kV UG Cable (Non Pressurised)", + actual_load_mva = 15, secure = T) %>% round(2) + + expected_value <- 38432.88 + + expect_equal(res, expected_value) +}) diff --git a/tests/testthat/test-pof_cables_04kv_pex.R b/tests/testthat/test-pof_cables_04kv_pex.R new file mode 100644 index 00000000..f0e1a5cf --- /dev/null +++ b/tests/testthat/test-pof_cables_04kv_pex.R @@ -0,0 +1,21 @@ +library(testthat) +library(CNAIM) + +context("Current Probability of Failure for 0.4kV UG Cable (Non Pressurised)") + +test_that("pof_cables_04kv_pex", { + + res <- pof_cables_04kv_pex(utilisation_pct = 80, + operating_voltage_pct = "Default", + sheath_test = "Default", + partial_discharge = "Default", + fault_hist = "Default", + reliability_factor = "Default", + age = 50, + k_value = 0.0658, + c_value = 1.087, + normal_expected_life = 80) + + expect_equal(res, 0.005784159) + +}) diff --git a/tests/testthat/test-pof_cables_10kv_oil.R b/tests/testthat/test-pof_cables_10kv_oil.R new file mode 100644 index 00000000..c30e8132 --- /dev/null +++ b/tests/testthat/test-pof_cables_10kv_oil.R @@ -0,0 +1,21 @@ +library(testthat) +library(CNAIM) + +context("Current Probability of Failure for 10kV UG Cable (Oil)") + +test_that("pof_cables_10kv_oil", { + + res <- pof_cables_10kv_oil(utilisation_pct = 80, + operating_voltage_pct = "Default", + sheath_test = "Default", + partial_discharge = "Default", + fault_hist = "Default", + reliability_factor = "Default", + age = 50, + k_value = 0.24, + c_value = 1.087, + normal_expected_life = 80) + + expect_equal(res, 0.02109723) + +}) diff --git a/tests/testthat/test-pof_cables_10kv_pex.R b/tests/testthat/test-pof_cables_10kv_pex.R new file mode 100644 index 00000000..78b2b82f --- /dev/null +++ b/tests/testthat/test-pof_cables_10kv_pex.R @@ -0,0 +1,21 @@ +library(testthat) +library(CNAIM) + +context("Current Probability of Failure for 10kV UG Cable (Non Pressurised)") + +test_that("pof_cables_10kv_pex", { + + res <- pof_cables_10kv_pex(utilisation_pct = 80, + operating_voltage_pct = "Default", + sheath_test = "Default", + partial_discharge = "Default", + fault_hist = "Default", + reliability_factor = "Default", + age = 50, + k_value = 0.0658, + c_value = 1.087, + normal_expected_life = 80) + + expect_equal(res, 0.005784159) + +}) diff --git a/tests/testthat/test-pof_future_cables_04kv_pex.R b/tests/testthat/test-pof_future_cables_04kv_pex.R new file mode 100644 index 00000000..f8a62a9b --- /dev/null +++ b/tests/testthat/test-pof_future_cables_04kv_pex.R @@ -0,0 +1,22 @@ +library(testthat) +library(CNAIM) + +context("Future Probability of Failure for 0.4kV UG Cable (Non Pressurised)") + +test_that("pof_future_cables_04kv_pex", { + +res <- pof_future_cables_04kv_pex(utilisation_pct = 80, + operating_voltage_pct = 60, + sheath_test = "Default", + partial_discharge = "Default", + fault_hist = "Default", + reliability_factor = "Default", + age = 50, + k_value = 0.0658, + c_value = 1.087, + normal_expected_life = 80, + simulation_end_year = 100) + + expect_equal(res$PoF[which(res$year == 50)], 0.12098057) + +}) diff --git a/tests/testthat/test-pof_future_cables_10kv_oil.R b/tests/testthat/test-pof_future_cables_10kv_oil.R new file mode 100644 index 00000000..777ed717 --- /dev/null +++ b/tests/testthat/test-pof_future_cables_10kv_oil.R @@ -0,0 +1,22 @@ +library(testthat) +library(CNAIM) + +context("Future Probability of Failure for 10kV UG Cable (Oil)") + +test_that("pof_future_cables_10kv_oil", { + + res <- pof_future_cables_10kv_oil(utilisation_pct = 80, + operating_voltage_pct = 60, + sheath_test = "Default", + partial_discharge = "Default", + fault_hist = "Default", + reliability_factor = "Default", + age = 50, + k_value = 0.24, + c_value = 1.087, + normal_expected_life = 80, + simulation_end_year = 100) + + expect_equal(res$PoF[which(res$year == 50)], 0.44126651) + +}) diff --git a/tests/testthat/test-pof_future_cables_10kv_pex.R b/tests/testthat/test-pof_future_cables_10kv_pex.R new file mode 100644 index 00000000..0f30ce3e --- /dev/null +++ b/tests/testthat/test-pof_future_cables_10kv_pex.R @@ -0,0 +1,22 @@ +library(testthat) +library(CNAIM) + +context("Future Probability of Failure for 10kV UG Cable (Non Pressurised)") + +test_that("pof_future_cables_10kv_pex", { + + res <- pof_future_cables_10kv_pex(utilisation_pct = 80, + operating_voltage_pct = 60, + sheath_test = "Default", + partial_discharge = "Default", + fault_hist = "Default", + reliability_factor = "Default", + age = 50, + k_value = 0.0658, + c_value = 1.087, + normal_expected_life = 80, + simulation_end_year = 100) + + expect_equal(res$PoF[which(res$year == 50)], 0.12098057) + +}) From 7ffd3a2a3417cc5806615ecc4193dacdf04baead Mon Sep 17 00:00:00 2001 From: NicolaiHandreck Date: Mon, 25 Jul 2022 13:03:19 +0200 Subject: [PATCH 03/10] new tests added --- tests/testthat/test-cof_board_04kv.R | 45 +++++++++ tests/testthat/test-cof_cables_04_10kv.R | 42 ++++---- tests/testthat/test-cof_cables_60_30kv.R | 95 +++++++++++++++++++ tests/testthat/test-cof_ohl_cond_50kv.R | 49 ++++++++++ tests/testthat/test-cof_ohl_fittings_50kv.R | 45 +++++++++ tests/testthat/test-cof_pillar_04kv.R | 45 +++++++++ tests/testthat/test-cof_poles_support_50kv.R | 52 ++++++++++ tests/testthat/test-cof_relay.R | 52 ++++++++++ tests/testthat/test-cof_serviceline.R | 54 +++++++++++ .../testthat/test-cof_submarine_cables_10kv.R | 55 +++++++++++ .../test-cof_submarine_cables_30_60kv.R | 50 ++++++++++ tests/testthat/test-cof_switchgear_30_60kv.R | 56 +++++++++++ .../test-cof_switchgear_primary_10kv.R | 46 +++++++++ .../test-cof_switchgear_secondary_10kv.R | 46 +++++++++ .../test-cof_tower_ohl_support_50kv.R | 52 ++++++++++ tests/testthat/test-cof_transformer_04_10kv.R | 15 +++ tests/testthat/test-cof_transformer_30_60kv.R | 59 ++++++++++++ .../testthat/test-future_poles_support_50kv.R | 35 +++++++ tests/testthat/test-pof_building.R | 23 +++++ tests/testthat/test-pof_cables_60_30kv.R | 21 ++++ tests/testthat/test-pof_future_board_04kv.R | 35 +++++++ tests/testthat/test-pof_future_building.R | 28 ++++++ .../testthat/test-pof_future_cables_60_30kv.R | 25 +++++ tests/testthat/test-pof_future_meter.R | 37 ++++++++ .../testthat/test-pof_future_ohl_cond_50kv.R | 27 ++++++ .../test-pof_future_ohl_fittings_50kv.R | 37 ++++++++ tests/testthat/test-pof_future_pillar_04kv.R | 36 +++++++ tests/testthat/test-pof_future_rtu.R | 37 ++++++++ tests/testthat/test-pof_future_serviceline.R | 22 +++++ .../test-pof_future_submarine_30_60kv_oil.R | 29 ++++++ .../test-pof_future_submarine_30_60kv_pex.R | 29 ++++++ ...est-pof_future_submarine_cables_10kv_oil.R | 28 ++++++ ...est-pof_future_submarine_cables_10kv_pex.R | 28 ++++++ .../test-pof_future_switchgear_30_60kv.R | 42 ++++++++ .../test-pof_future_switchgear_primary_10kv.R | 40 ++++++++ ...est-pof_future_switchgear_secondary_10kv.R | 38 ++++++++ .../test-pof_future_transformer_04_10kv.R | 29 ++++++ .../test-pof_future_transformer_132kv.R | 23 +++++ .../test-pof_future_transformer_30_60kv.R | 55 +++++++++++ tests/testthat/test-pof_meter.R | 35 +++++++ tests/testthat/test-pof_ohl_cond_50kv.R | 25 +++++ tests/testthat/test-pof_ohl_support_50kv.R | 33 +++++++ tests/testthat/test-pof_serviceline.R | 21 ++++ .../test-pof_submarine_cables_10kv_oil.R | 27 ++++++ .../test-pof_submarine_cables_10kv_pex.R | 28 ++++++ .../test-pof_submarine_cables_30_60kv_oil.R | 27 ++++++ .../test-pof_submarine_cables_30_60kv_pex.R | 27 ++++++ tests/testthat/test-pof_transformer_04_10kv.R | 24 +++++ tests/testthat/test-pof_transformer_30_60kv.R | 52 ++++++++++ 49 files changed, 1840 insertions(+), 21 deletions(-) create mode 100644 tests/testthat/test-cof_board_04kv.R create mode 100644 tests/testthat/test-cof_cables_60_30kv.R create mode 100644 tests/testthat/test-cof_ohl_cond_50kv.R create mode 100644 tests/testthat/test-cof_ohl_fittings_50kv.R create mode 100644 tests/testthat/test-cof_pillar_04kv.R create mode 100644 tests/testthat/test-cof_poles_support_50kv.R create mode 100644 tests/testthat/test-cof_relay.R create mode 100644 tests/testthat/test-cof_serviceline.R create mode 100644 tests/testthat/test-cof_submarine_cables_10kv.R create mode 100644 tests/testthat/test-cof_submarine_cables_30_60kv.R create mode 100644 tests/testthat/test-cof_switchgear_30_60kv.R create mode 100644 tests/testthat/test-cof_switchgear_primary_10kv.R create mode 100644 tests/testthat/test-cof_switchgear_secondary_10kv.R create mode 100644 tests/testthat/test-cof_tower_ohl_support_50kv.R create mode 100644 tests/testthat/test-cof_transformer_04_10kv.R create mode 100644 tests/testthat/test-cof_transformer_30_60kv.R create mode 100644 tests/testthat/test-future_poles_support_50kv.R create mode 100644 tests/testthat/test-pof_building.R create mode 100644 tests/testthat/test-pof_cables_60_30kv.R create mode 100644 tests/testthat/test-pof_future_board_04kv.R create mode 100644 tests/testthat/test-pof_future_building.R create mode 100644 tests/testthat/test-pof_future_cables_60_30kv.R create mode 100644 tests/testthat/test-pof_future_meter.R create mode 100644 tests/testthat/test-pof_future_ohl_cond_50kv.R create mode 100644 tests/testthat/test-pof_future_ohl_fittings_50kv.R create mode 100644 tests/testthat/test-pof_future_pillar_04kv.R create mode 100644 tests/testthat/test-pof_future_rtu.R create mode 100644 tests/testthat/test-pof_future_serviceline.R create mode 100644 tests/testthat/test-pof_future_submarine_30_60kv_oil.R create mode 100644 tests/testthat/test-pof_future_submarine_30_60kv_pex.R create mode 100644 tests/testthat/test-pof_future_submarine_cables_10kv_oil.R create mode 100644 tests/testthat/test-pof_future_submarine_cables_10kv_pex.R create mode 100644 tests/testthat/test-pof_future_switchgear_30_60kv.R create mode 100644 tests/testthat/test-pof_future_switchgear_primary_10kv.R create mode 100644 tests/testthat/test-pof_future_switchgear_secondary_10kv.R create mode 100644 tests/testthat/test-pof_future_transformer_04_10kv.R create mode 100644 tests/testthat/test-pof_future_transformer_132kv.R create mode 100644 tests/testthat/test-pof_future_transformer_30_60kv.R create mode 100644 tests/testthat/test-pof_meter.R create mode 100644 tests/testthat/test-pof_ohl_cond_50kv.R create mode 100644 tests/testthat/test-pof_ohl_support_50kv.R create mode 100644 tests/testthat/test-pof_serviceline.R create mode 100644 tests/testthat/test-pof_submarine_cables_10kv_oil.R create mode 100644 tests/testthat/test-pof_submarine_cables_10kv_pex.R create mode 100644 tests/testthat/test-pof_submarine_cables_30_60kv_oil.R create mode 100644 tests/testthat/test-pof_submarine_cables_30_60kv_pex.R create mode 100644 tests/testthat/test-pof_transformer_04_10kv.R create mode 100644 tests/testthat/test-pof_transformer_30_60kv.R diff --git a/tests/testthat/test-cof_board_04kv.R b/tests/testthat/test-cof_board_04kv.R new file mode 100644 index 00000000..b3c881a9 --- /dev/null +++ b/tests/testthat/test-cof_board_04kv.R @@ -0,0 +1,45 @@ +library(testthat) +library(CNAIM) + +context("COF:Financial Board 0.4 kV") + +test_that("LV Board (WM)", { + res <- financial_cof_board_04kv(type_financial_factor_criteria = "Asbestos clad", + access_factor_criteria = "Type A") + + expected_value <- 68225.43 + + expect_equal(res, expected_value) +}) + + +context("COF:Safety Board 0.4 kV") + +test_that("LV Board (WM)", { + res <- safety_cof_board_04kv(location_risk = "Default", + type_risk = "Default") + expected_value <- 79339.39 + + expect_equal(res, expected_value) +}) + + +context("COF:Environmental Board 0.4 kV") + +test_that("LV Board(WM)", { + res <- environmental_cof_board_04kv() + expected_value <- 191.62 + + expect_equal(res, expected_value) +}) + + +context("COF:Network Board 0.4 kV") + +test_that("LV Board(WM)", { + res <- network_cof_board_04kv(no_customers = 750, + kva_per_customer = 51) + expected_value <- 6730924 + + expect_equal(res, expected_value) +}) diff --git a/tests/testthat/test-cof_cables_04_10kv.R b/tests/testthat/test-cof_cables_04_10kv.R index 3f037611..f66a9c4d 100644 --- a/tests/testthat/test-cof_cables_04_10kv.R +++ b/tests/testthat/test-cof_cables_04_10kv.R @@ -4,7 +4,7 @@ library(CNAIM) context("COF:Financial Cables: 10 kV UG Cable Oil") test_that("10kV UG Cable (Oil)", { - res <- financial_cof_ehv_cables(ehv_asset_category = "10kV UG Cable (Oil)") + res <- financial_cof_cables_04_10kv(hv_asset_category = "10kV UG Cable (Oil)") expected_value <- 1123.59 @@ -14,7 +14,7 @@ test_that("10kV UG Cable (Oil)", { context("COF:Financial Cables: 10 kV UG Cable PEX") test_that("10kV UG Cable (Non Pressurised)", { - res <- financial_cof_ehv_cables(ehv_asset_category = "10kV UG Cable (Non Pressurised)") + res <- financial_cof_cables_04_10kv(hv_asset_category = "10kV UG Cable (Non Pressurised)") expected_value <- 275619.2 @@ -24,7 +24,7 @@ test_that("10kV UG Cable (Non Pressurised)", { context("COF:Financial Cables: 0.4 kV UG Cable PEX") test_that("0.4kV UG Cable (Non Pressurised)", { - res <- financial_cof_ehv_cables(ehv_asset_category = "0.4kV UG Cable (Non Pressurised)") + res <- financial_cof_cables_04_10kv(hv_asset_category = "0.4kV UG Cable (Non Pressurised)") expected_value <- 275619.2 @@ -37,7 +37,7 @@ test_that("0.4kV UG Cable (Non Pressurised)", { context("COF:Safety Cables: 10 kV UG Cable Oil") test_that("10kV UG Cable (Oil)", { - res <- safety_cof_ehv_cables(ehv_asset_category = "10kV UG Cable (Oil)") + res <- safety_cof_cables_04_10kv(hv_asset_category = "10kV UG Cable (Oil)") expected_value <- 17.42 @@ -47,7 +47,7 @@ test_that("10kV UG Cable (Oil)", { context("COF:Safety Cables: 10 kV UG Cable PEX") test_that("10kV UG Cable (Non Pressurised)", { - res <- safety_cof_ehv_cables(ehv_asset_category = "10kV UG Cable (Non Pressurised)") + res <- safety_cof_cables_04_10kv(hv_asset_category = "10kV UG Cable (Non Pressurised)") expected_value <- 17.42 @@ -57,7 +57,7 @@ test_that("10kV UG Cable (Non Pressurised)", { context("COF:Safety Cables: 0.4 kV UG Cable PEX") test_that("0.4kV UG Cable (Non Pressurised)", { - res <- safety_cof_ehv_cables(ehv_asset_category = "0.4kV UG Cable (Non Pressurised)") + res <- safety_cof_cables_04_10kv(hv_asset_category = "0.4kV UG Cable (Non Pressurised)") expected_value <- 17.42 @@ -69,9 +69,9 @@ test_that("0.4kV UG Cable (Non Pressurised)", { context("COF:Env Cables: 10 kV UG Cable Oil") test_that("10kV UG Cable (Oil)", { - res <- environmental_cof_ehv_cables(ehv_asset_category = "10kV UG Cable (Oil)", - prox_water = 95, - bunded = "Yes") + res <- environmental_cof_cables_04_10kv(hv_asset_category = "10kV UG Cable (Oil)", + prox_water = 95, + bunded = "Yes") expected_value <- 25629.18 @@ -81,9 +81,9 @@ test_that("10kV UG Cable (Oil)", { context("COF:Env Cables: 10 kV UG Cable PEX") test_that("10kV UG Cable (Non Pressurised", { - res <- environmental_cof_ehv_cables(ehv_asset_category = "10kV UG Cable (Non Pressurised)", - prox_water = 95, - bunded = "Yes") + res <- environmental_cof_cables_04_10kv(hv_asset_category = "10kV UG Cable (Non Pressurised)", + prox_water = 95, + bunded = "Yes") expected_value <- 6323.46 @@ -93,9 +93,9 @@ test_that("10kV UG Cable (Non Pressurised", { context("COF:Env Cables: 0.4 kV UG Cable PEX") test_that("0.4kV UG Cable (Non Pressurised", { - res <- environmental_cof_ehv_cables(ehv_asset_category = "0.4kV UG Cable (Non Pressurised)", - prox_water = 95, - bunded = "Yes") + res <- environmental_cof_cables_04_10kv(hv_asset_category = "0.4kV UG Cable (Non Pressurised)", + prox_water = 95, + bunded = "Yes") expected_value <- 6323.46 @@ -107,8 +107,8 @@ test_that("0.4kV UG Cable (Non Pressurised", { context("COF:Network Cables: 10 kV UG Cable Oil") test_that("10kV UG Cable (Oil)", { - res <- network_cof_ehv_cables(ehv_asset_category = "10kV UG Cable (Oil)", - actual_load_mva = 15, secure = T) %>% round(2) + res <- network_cof_cables_04_10kv(hv_asset_category = "10kV UG Cable (Oil)", + actual_load_mva = 15, secure = T) %>% round(2) expected_value <- 43.55 expect_equal(res, expected_value) @@ -117,8 +117,8 @@ test_that("10kV UG Cable (Oil)", { context("COF:Network Cables: 10 kV UG Cable PEX") test_that("10kV UG Cable (Non Pressurised)", { - res <- network_cof_ehv_cables(ehv_asset_category = "10kV UG Cable (Non Pressurised)", - actual_load_mva = 15, secure = T) %>% round(2) + res <- network_cof_cables_04_10kv(hv_asset_category = "10kV UG Cable (Non Pressurised)", + actual_load_mva = 15, secure = T) %>% round(2) expected_value <- 38432.88 @@ -129,8 +129,8 @@ test_that("10kV UG Cable (Non Pressurised)", { context("COF:Network Cables: 0.4 kV UG Cable PEX") test_that("0.4kV UG Cable (Non Pressurised)", { - res <- network_cof_ehv_cables(ehv_asset_category = "0.4kV UG Cable (Non Pressurised)", - actual_load_mva = 15, secure = T) %>% round(2) + res <- network_cof_cof_cables_04_10kv(hv_asset_category = "0.4kV UG Cable (Non Pressurised)", + actual_load_mva = 15, secure = T) %>% round(2) expected_value <- 38432.88 diff --git a/tests/testthat/test-cof_cables_60_30kv.R b/tests/testthat/test-cof_cables_60_30kv.R new file mode 100644 index 00000000..02518ecd --- /dev/null +++ b/tests/testthat/test-cof_cables_60_30kv.R @@ -0,0 +1,95 @@ +library(testthat) +library(CNAIM) + +context("COF:Financial Cables: 30 kV") + +test_that("30kV UG Cable (Oil)", { + res <- financial_cof_cables_60_30kv(ehv_asset_category = "30kV UG Cable (Oil)") + + expected_value <- 1123.59 + + expect_equal(res, expected_value) +}) + +context("COF:Financial Cables: 60 kV") + +test_that("60kV UG Cable (Gas)", { + res <- financial_cof_cables_60_30kv(ehv_asset_category = "60kV UG Cable (Gas)") + + expected_value <- 4520.49 + + expect_equal(res, expected_value) +}) + + +#----------------------------------------- + +context("COF:Safety Cables: 30 kV") + +test_that("30kV UG Cable (Oil)", { + res <- safety_cof_cables_60_30kv(ehv_asset_category = "30kV UG Cable (Oil)") + + expected_value <- 17.42 + + expect_equal(res, expected_value) +}) + +context("COF:Safety Cables: 60 kV") + +test_that("60kV UG Cable (Gas)", { + res <- safety_cof_cables_60_30kv(ehv_asset_category = "60kV UG Cable (Gas)") + + expected_value <- 17.42 + + expect_equal(res, expected_value) +}) + +#----------------------------------------- + +context("COF:Env Cables: 30 kV") + +test_that("30kV UG Cable (Oil)", { + res <- environmental_cof_cables_60_30kv(ehv_asset_category = "30kV UG Cable (Oil)", + prox_water = 95, + bunded = "Yes") + + expected_value <- 25629.18 + + expect_equal(res, expected_value) +}) + +context("COF:Env Cables: 60 kV") + +test_that("60kV UG Cable (Gas)", { + res <- environmental_cof_cables_60_30kv(ehv_asset_category = "60kV UG Cable (Gas)", + prox_water = 95, + bunded = "Yes") + + expected_value <- 470.34 + + expect_equal(res, expected_value) +}) + +#----------------------------------------- + +context("COF:Network Cables: 30 kV") + +test_that("30kV UG Cable (Oil)", { + res <- network_cof_cables_60_30kv(ehv_asset_category = "30kV UG Cable (Oil)", + actual_load_mva = 15, secure = T) %>% round(2) + expected_value <- 43.55 + + expect_equal(res, expected_value) +}) + +context("COF:Network Cables: 60 kV") + +test_that("60kV UG Cable (Gas)", { + res <- network_cof_cables_60_30kv(ehv_asset_category = "60kV UG Cable (Gas)", + actual_load_mva = 15, secure = T) %>% round(2) + + expected_value <- 386.51 + + expect_equal(res, expected_value) +}) + diff --git a/tests/testthat/test-cof_ohl_cond_50kv.R b/tests/testthat/test-cof_ohl_cond_50kv.R new file mode 100644 index 00000000..c6d99283 --- /dev/null +++ b/tests/testthat/test-cof_ohl_cond_50kv.R @@ -0,0 +1,49 @@ +library(testthat) +library(CNAIM) + +context("COF:Financial Overhead Line conductor: 50 kV") + +test_that("50kV OHL (Tower Line) Conductor", { + res <- financial_cof_ohl_cond_50kv(access_factor_criteria = "Type A") + + expected_value <- 205556 + + expect_equal(res, expected_value) +}) + +#----------------------------------------- + +context("COF:Safety Overhead Line conductor: 50 kV") + +test_that("50kV OHL (Tower Line) Conductor", { + res <- safety_cof_ohl_cond_50kv(location_risk = "Default", + type_risk = "Default") + expected_value <- 13134.68 + + expect_equal(res, expected_value) +}) + + +#----------------------------------------- + +context("COF:Env Overhead Line conductor: 50 kV") + +test_that("50kV OHL (Tower Line) Conductor", { + res <- environmental_cof_ohl_cond_50kv() + expected_value <- 836.16 + + expect_equal(res, expected_value) +}) + + +#----------------------------------------- + +context("COF:Network Overhead Line conductor: 50 kV") + +test_that("50kV OHL (Tower Line) Conductor", { + res <- network_cof_ohl_cond_50kv(actual_load_mva = 15) + expected_value <- 14513.04 + + expect_equal(res, expected_value) +}) + diff --git a/tests/testthat/test-cof_ohl_fittings_50kv.R b/tests/testthat/test-cof_ohl_fittings_50kv.R new file mode 100644 index 00000000..1cc18eb2 --- /dev/null +++ b/tests/testthat/test-cof_ohl_fittings_50kv.R @@ -0,0 +1,45 @@ +library(testthat) +library(CNAIM) + +context("COF:Financial 50 kV OHL Fittings") + +test_that("50kV Fittings", { + res <- financial_cof_ohl_fittings_50kv(type_financial_factor_criteria = "Tension", + access_factor_criteria = "Type A") + + expected_value <- 5086.64 + + expect_equal(res, expected_value) +}) + + +context("COF:Safety 50 kV OHL Fittings") + +test_that("50kV Fittings", { + res <- safety_cof_ohl_fittings_50kv(location_risk = "Default", + type_risk = "Default") + expected_value <- 13134.68 + + expect_equal(res, expected_value) +}) + + +context("COF:Environmental 50 kV OHL Fittings") + +test_that("50kV Fittings", { + res <- environmental_cof_ohl_fittings_50kv() + expected_value <- 836.16 + + expect_equal(res, expected_value) +}) + + +context("COF:Network 50 kV OHL Fittings") + +test_that("50kV Fittings", { + res <- network_cof_ohl_fittings_50kv(actual_load_mva = 15) + expected_value <- 2901.519 + + expect_equal(res, expected_value) +}) + diff --git a/tests/testthat/test-cof_pillar_04kv.R b/tests/testthat/test-cof_pillar_04kv.R new file mode 100644 index 00000000..7130e651 --- /dev/null +++ b/tests/testthat/test-cof_pillar_04kv.R @@ -0,0 +1,45 @@ +library(testthat) +library(CNAIM) + +context("COF:Financial Pillar 0.4 kV") + +test_that("LV Pillar (ID)", { + res <- financial_cof_pillar_04kv(type_financial_factor_criteria = "Asbestos clad", + access_factor_criteria = "Type A") + + expected_value <- 49376.99 + + expect_equal(res, expected_value) +}) + + +context("COF:Safety Pillar 0.4 kV") + +test_that("LV Pillar (ID)", { + res <- safety_cof_pillar_04kv(location_risk = "Default", + type_risk = "Default") + expected_value <- 79339.39 + + expect_equal(res, expected_value) +}) + + +context("COF:Environmental Pillar 0.4 kV") + +test_that("LV Pillar (ID)", { + res <- environmental_cof_pillar_04kv() + expected_value <- 191.62 + + expect_equal(res, expected_value) +}) + + +context("COF:Network Pillar 0.4 kV") + +test_that("LV Pillar (ID)", { + res <- network_cof_pillar_04kv(no_customers = 750, + kva_per_customer = 51) + expected_value <- 6730924 + + expect_equal(res, expected_value) +}) diff --git a/tests/testthat/test-cof_poles_support_50kv.R b/tests/testthat/test-cof_poles_support_50kv.R new file mode 100644 index 00000000..7b8eb2af --- /dev/null +++ b/tests/testthat/test-cof_poles_support_50kv.R @@ -0,0 +1,52 @@ +library(testthat) +library(CNAIM) + +context("COF:Financial Poles: 50 kV") + +test_that("50kV Pole", { + res <- financial_cof_poles_ohl_support_50kv( + type_financial_factor_criteria = "Small footprint steel masts", + access_factor_criteria = "Type A") + + expected_value <- 64767.56 + + expect_equal(res, expected_value) +}) + + +#----------------------------------------- + +context("COF:Safety Poles: 50 kV") + +test_that("50kV Pole", { + res <- safety_cof_poles_ohl_support_50kv(location_risk = "Default", + type_risk = "Default") + expected_value <- 1742 + + expect_equal(res, expected_value) +}) + + +#----------------------------------------- + +context("COF:Env Poles: 50 kV") + +test_that("50kV pole", { + res <- environmental_cof_poles_ohl_support_50kv() + expected_value <- 783.9 + + expect_equal(res, expected_value) +}) + + +#----------------------------------------- + +context("COF:Network Poles: 50 kV") + +test_that("50kV Pole", { + res <- network_cof_poles_ohl_support_50kv(actual_load_mva = 15) + + expected_value <- 996.2063 + + expect_equal(res, expected_value) +}) diff --git a/tests/testthat/test-cof_relay.R b/tests/testthat/test-cof_relay.R new file mode 100644 index 00000000..44c71088 --- /dev/null +++ b/tests/testthat/test-cof_relay.R @@ -0,0 +1,52 @@ +library(testthat) +library(CNAIM) + +context("COF:Financial Relay") + +test_that("6.6/11kV CB (GM) Secondary", { + res <- financial_cof_relay(access_factor_criteria = "Type A") + + expected_value <- 30306.45 + + expect_equal(res, expected_value) +}) + + +# ---------------------------------------- + +context("COF:Safety Relay") + +test_that("6.6/11kV CB (GM) Secondary", { + res <- safety_cof_relay(location_risk = "Default", + type_risk = "Default") + + expected_value <- 21004.17 + + expect_equal(res, expected_value) +}) + + +# ---------------------------------------- + +context("COF:Environmental Relay") + +test_that("6.6/11kV CB (GM) Secondary", { + res <- environmental_cof_relay(type_env_factor = "Oil", + prox_water = 95, + bunded = "Yes") + expected_value <- 3171.05 + + expect_equal(res, expected_value) +}) + +# ---------------------------------------- + +context("COF:Network Relay") + +test_that("6.6/11kV CB (GM) Secondary", { + res <- network_cof_relay(no_customers = 100, kva_per_customer = 40) + + expected_value <- 6303.863 + + expect_equal(res, expected_value) +}) diff --git a/tests/testthat/test-cof_serviceline.R b/tests/testthat/test-cof_serviceline.R new file mode 100644 index 00000000..3341b10b --- /dev/null +++ b/tests/testthat/test-cof_serviceline.R @@ -0,0 +1,54 @@ +library(testthat) +library(CNAIM) + +context("COF:Financial Cables: Serviceline") + +test_that("serviceline" , { + res <- financial_cof_serviceline() + + expected_value <- 137809.6 + + expect_equal(res, expected_value) +}) + + +#----------------------------------------- + +context("COF:Safety Cables: Serviceline") + +test_that("serviceline", { + res <- safety_cof_serviceline() + + expected_value <- 8.71 + + expect_equal(res, expected_value) +}) + + +#----------------------------------------- + +context("COF:Env Cables: Serviceline") + +test_that("serviceline", { + res <- environmental_cof_serviceline(prox_water = 95, + bunded = "Yes") + + expected_value <- 3161.73 + + expect_equal(res, expected_value) +}) + + + +#----------------------------------------- + +context("COF:Network Cables: Service") + +test_that("service", { + res <- network_cof_serviceline(actual_load_mva = 0.5, secure = T) %>% round(2) + + expected_value <- 640.55 + + expect_equal(res, expected_value) +}) + diff --git a/tests/testthat/test-cof_submarine_cables_10kv.R b/tests/testthat/test-cof_submarine_cables_10kv.R new file mode 100644 index 00000000..66df84a2 --- /dev/null +++ b/tests/testthat/test-cof_submarine_cables_10kv.R @@ -0,0 +1,55 @@ +library(testthat) +library(CNAIM) + +context("COF:Financial Sub Cables: 10kV") + +test_that("HV Sub Cable", { + res <- financial_cof_submarine_cables_10kv() + expected_value <- 1585185 + + expect_equal(res, expected_value) +}) + + +#----------------------------------------- + +context("COF:Safety Sub Cables: 10kV") + +test_that("HV Sub Cable", { + res <- safety_cof_submarine_cables_10kv() + expected_value <- 17.42 + + expect_equal(res, expected_value) +}) + + + +#----------------------------------------- + +context("COF:Env Sub Cables: 10kV") + +test_that("HV Sub Cable", { + res <- environmental_cof_submarine_cables_10kv() + expected_value <- 31356 + + expect_equal(res, expected_value) +}) + + + +#----------------------------------------- + +context("COF:Network Sub Cables: 10kV") + +test_that("HV Sub Cable", { + res <- network_cof_submarine_cables_10kv(no_customers = 250, + kva_per_customer = 51) %>% round(0) + expected_value <- 12952314 + + expect_equal(res, expected_value) +}) + + + + + diff --git a/tests/testthat/test-cof_submarine_cables_30_60kv.R b/tests/testthat/test-cof_submarine_cables_30_60kv.R new file mode 100644 index 00000000..eb7e35fc --- /dev/null +++ b/tests/testthat/test-cof_submarine_cables_30_60kv.R @@ -0,0 +1,50 @@ +library(testthat) +library(CNAIM) + +context("COF:Financial Sub Cables: EHV") + +test_that("EHV Sub Cable", { + res <- financial_cof_submarine_cables_30_60kv() + expected_value <- 2485155 + + expect_equal(res, expected_value) +}) + + +#----------------------------------------- + +context("COF:Safety Sub Cables: EHV") + +test_that("EHV Sub Cable", { + res <- safety_cof_submarine_cables_30_60kv() + expected_value <- 17.42 + + expect_equal(res, expected_value) +}) + + +#----------------------------------------- + +context("COF:Env Sub Cables: EHV") + +test_that("EHV Sub Cable", { + res <- environmental_cof_submarine_cables_30_60kv() + expected_value <- 31356 + + expect_equal(res, expected_value) +}) + + +#----------------------------------------- + +context("COF:Network Sub Cables: EHV") + +test_that("EHV Sub Cable", { + res <- network_cof_submarine_cables_30_60kv(no_customers = 250, + kva_per_customer = 51) + + expected_value <- 12952314 + + expect_equal(res, expected_value) +}) + diff --git a/tests/testthat/test-cof_switchgear_30_60kv.R b/tests/testthat/test-cof_switchgear_30_60kv.R new file mode 100644 index 00000000..41d7b193 --- /dev/null +++ b/tests/testthat/test-cof_switchgear_30_60kv.R @@ -0,0 +1,56 @@ +library(testthat) +library(CNAIM) + +context("COF:Financial Switchgear 30/60 kV") + +test_that("30kV", { + res <- financial_cof_switchgear_30_60kv(ehv_asset_category = "30kV", + access_factor_criteria = "Type A") + + expected_value <- 126408.2 + + expect_equal(res, expected_value) +}) + + +# ---------------------------------------- + +context("COF:Safety Switchgear 30/60 kV") + +test_that("30kV", { + res <- safety_cof_switchgear_30_60kv(ehv_asset_category = "30kV", + location_risk = "Default", + type_risk = "Default") + expected_value <- 204702.4 + + expect_equal(res, expected_value) +}) + + +# ---------------------------------------- + +context("COF:Environmental Switchgear 30/60 kV") + +test_that("30kV", { + res <- environmental_cof_switchgear_30_60kv(ehv_asset_category = "30kV", + type_env_factor = "Oil", + prox_water = 95, + bunded = "Yes") + expected_value <- 17642.45 + + expect_equal(res, expected_value) +}) + +# ---------------------------------------- + +context("COF:Network Switchgear 30/60 kV") + +test_that("30kV", { + res <- network_cof_switchgear_30_60kv(ehv_asset_category = "30kV", + actual_load_mva = 15) + expected_value <- 126817.6 + + expect_equal(res, expected_value) +}) + + diff --git a/tests/testthat/test-cof_switchgear_primary_10kv.R b/tests/testthat/test-cof_switchgear_primary_10kv.R new file mode 100644 index 00000000..d10c3a80 --- /dev/null +++ b/tests/testthat/test-cof_switchgear_primary_10kv.R @@ -0,0 +1,46 @@ +library(testthat) +library(CNAIM) + +context("COF:Financial switchgear primary 10 kV") + +test_that("6.6/11kV CB (GM) Primary", { + res <- financial_cof_switchgear_primary_10kv(access_factor_criteria = "Type A") + + expected_value <- 66074.06 + + expect_equal(res, expected_value) +}) + + +context("COF:Safety switchgear primary 10 kV") + +test_that("6.6/11kV CB (GM) Primary", { + res <- safety_cof_switchgear_primary_10kv(location_risk = "Default", + type_risk = "Default") + expected_value <- 204702.4 + + expect_equal(res, expected_value) +}) + + +context("COF:Environmental switchgear primary 10 kV") + +test_that("6.6/11kV CB (GM) Primary", { + res <- environmental_cof_switchgear_primary_10kv(type_env_factor = "Oil", + prox_water = 95, + bunded = "Yes") + expected_value <- 6535.069 + + expect_equal(res, expected_value) +}) + + +context("COF:Network switchgear primary 10 kV") + +test_that("6.6/11kV CB (GM) Primary", { + res <- network_cof_switchgear_primary_10kv(no_customers = 750, + kva_per_customer = 51) + expected_value <- 6619056 + + expect_equal(res, expected_value) +}) diff --git a/tests/testthat/test-cof_switchgear_secondary_10kv.R b/tests/testthat/test-cof_switchgear_secondary_10kv.R new file mode 100644 index 00000000..da618175 --- /dev/null +++ b/tests/testthat/test-cof_switchgear_secondary_10kv.R @@ -0,0 +1,46 @@ +library(testthat) +library(CNAIM) + +context("COF:Financial switchgear secondary 10 kV") + +test_that("6.6/11kV CB (GM) Secondary", { + res <- financial_cof_switchgear_secondary_10kv(access_factor_criteria = "Type A") + + expected_value <- 60612.89 + + expect_equal(res, expected_value) +}) + + +context("COF:Safety switchgear secondary 10 kV") + +test_that("6.6/11kV CB (GM) Secondary", { + res <- safety_cof_switchgear_secondary_10kv(location_risk = "Default", + type_risk = "Default") + expected_value <- 42008.33 + + expect_equal(res, expected_value) +}) + + +context("COF:Environmental switchgear secondary 10 kV") + +test_that("6.6/11kV CB (GM) Secondary", { + res <- environmental_cof_switchgear_secondary_10kv(type_env_factor = "Oil", + prox_water = 95, + bunded = "Yes") + expected_value <- 6342.099 + + expect_equal(res, expected_value) +}) + + +context("COF:Network switchgear secondary 10 kV") + +test_that("6.6/11kV CB (GM) Secondary", { + res <- network_cof_switchgear_secondary_10kv(no_customers = 250, + kva_per_customer = 51) + expected_value <- 787982.8 + + expect_equal(res, expected_value) +}) diff --git a/tests/testthat/test-cof_tower_ohl_support_50kv.R b/tests/testthat/test-cof_tower_ohl_support_50kv.R new file mode 100644 index 00000000..5a0a6cab --- /dev/null +++ b/tests/testthat/test-cof_tower_ohl_support_50kv.R @@ -0,0 +1,52 @@ +library(testthat) +library(CNAIM) + +context("COF:Financial Tower: 50 kV") + +test_that("50kV Tower", { + res <- financial_cof_tower_ohl_support_50kv(type_financial_factor_criteria = "Suspension", + access_factor_criteria = "Type A") + + expected_value <- 110155.4 + + expect_equal(res, expected_value) +}) + + + +#----------------------------------------- + +context("COF:Safety Tower: 50 kV") + +test_that("50kV Tower", { + res <- safety_cof_tower_ohl_support_50kv(location_risk = "Default", + type_risk = "Default") + expected_value <- 3283.67 + + expect_equal(res, expected_value) +}) + + +#----------------------------------------- + +context("COF:Env Tower: 50 kV") + +test_that("50kV Tower", { + res <- environmental_cof_tower_ohl_support_50kv() + expected_value <- 1620.06 + + expect_equal(res, expected_value) +}) + + +#----------------------------------------- + +context("COF:Network Tower: 50 kV") + +test_that("50kV Tower", { + res <- network_cof_tower_ohl_support_50kv(actual_load_mva = 15) + expected_value <- 9052.956 + + expect_equal(res, expected_value) +}) + diff --git a/tests/testthat/test-cof_transformer_04_10kv.R b/tests/testthat/test-cof_transformer_04_10kv.R new file mode 100644 index 00000000..43733fd7 --- /dev/null +++ b/tests/testthat/test-cof_transformer_04_10kv.R @@ -0,0 +1,15 @@ +library(testthat) +library(CNAIM) + +context("consequences of a failure of a 0.4/10kV transformer") + +test_that("cof_transformer_04_10kv", { + expect_equal(cof_transformer_04_10kv(kva = 500, + type = "Type C", + type_risk = "High", + location_risk = "High", + prox_water = 50, bunded = "No", + no_customers = 500, + kva_per_customer = 1), 373500.5) + +}) diff --git a/tests/testthat/test-cof_transformer_30_60kv.R b/tests/testthat/test-cof_transformer_30_60kv.R new file mode 100644 index 00000000..8b74fd23 --- /dev/null +++ b/tests/testthat/test-cof_transformer_30_60kv.R @@ -0,0 +1,59 @@ +library(testthat) +library(CNAIM) + +context("COF:Financial Transformers: 30/10kv and 60/10kv") + +test_that("30kV Transformer (GM)", { + res <- financial_cof_transformer_30_60kv(tf_asset_category = "30kV Transformer (GM)", + type_financial_factor_kva_mva = 20, + access_factor_criteria = "Type A") + + expected_value <- 1291480 + + expect_equal(res, expected_value) +}) + + +#----------------------------------------- + +context("COF:Safety Transformers: 30/10kv and 60/10kv") + +test_that("30kV Transformer (GM)", { + res <- safety_cof_transformer_30_60kv(tf_asset_category = "30kV Transformer (GM)", + location_risk = "Default", + type_risk = "Default") + expected_value <- 204702.4 + + expect_equal(res, expected_value) +}) + + +#----------------------------------------- + +context("COF:Env Transformers: 30/10kv and 60/10kv") + +test_that("30kV Transformer (GM)", { + res <- environmental_cof_transformer_30_60kv(tf_asset_category = "30kV Transformer (GM)", + prox_water = 95, + bunded = "Yes", + size_kva_mva = 20) + + expected_value <- 118790.5 + + expect_equal(res, expected_value) +}) + + +#----------------------------------------- + +context("COF:Network Transformers: 30/10kv and 60/10kv") + +test_that("30kV Transformer", { + res <- network_cof_transformer_30_60kv(tf_asset_category = "30kV Transformer (GM)", + actual_load_mva = 15) + expected_value <- 252067.4 + + expect_equal(res, expected_value) +}) + + diff --git a/tests/testthat/test-future_poles_support_50kv.R b/tests/testthat/test-future_poles_support_50kv.R new file mode 100644 index 00000000..42a01738 --- /dev/null +++ b/tests/testthat/test-future_poles_support_50kv.R @@ -0,0 +1,35 @@ +library(testthat) +library(CNAIM) + +context("Future Probability of Failure for a 50 kV OHL support poles") + +test_that("pof_future_poles_support_50kv", { + + res <- + pof_future_poles_ohl_support_50kv( + sub_division = "Wood", + placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age = 10, + observed_condition_inputs = + list("visual_pole_cond" = + list("Condition Criteria: Pole Top Rot Present?" = "Default"), + "pole_leaning" = list("Condition Criteria: Pole Leaning?" = "Default"), + "bird_animal_damage" = + list("Condition Criteria: Bird/Animal Damage?" = "Default"), + "top_rot" = list("Condition Criteria: Pole Top Rot Present?" = "Default")), + measured_condition_inputs = + list("pole_decay" = + list("Condition Criteria: Degree of Decay/Deterioration" = "Default")), + reliability_factor = "Default", + k_value = 0.0285, + c_value = 1.087, + normal_expected_life = "Default", + simulation_end_year = 100) + + + expect_equal(res$PoF[which(res$year == 20)], 0.008122628) + +}) diff --git a/tests/testthat/test-pof_building.R b/tests/testthat/test-pof_building.R new file mode 100644 index 00000000..83773cab --- /dev/null +++ b/tests/testthat/test-pof_building.R @@ -0,0 +1,23 @@ +library(testthat) +library(CNAIM) + +context("Current Probability of Failure for a Building") + +test_that("pof_building", { + expect_equal(pof_building(substation_type = "Secondary", + material_type = "Wood", + placement = "Outdoor", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age = 43, + temperature_reading = "Default", + coolers_radiator = "Default", + kiosk = "Default", + cable_boxes = "Default", + reliability_factor = "Default", + k_value = "Default", + c_value = 1.087, + normal_expected_life_building = "Default"), 0.01076914) +}) + diff --git a/tests/testthat/test-pof_cables_60_30kv.R b/tests/testthat/test-pof_cables_60_30kv.R new file mode 100644 index 00000000..1782c4a8 --- /dev/null +++ b/tests/testthat/test-pof_cables_60_30kv.R @@ -0,0 +1,21 @@ +library(testthat) +library(CNAIM) + +context("Current Probability of Failure for 60kV UG Cable (Non Pressurised)") + +test_that("pof_cables_60_30kv", { + + res <- pof_cables_60_30kv(cable_type = "60kV UG Cable (Non Pressurised)", + sub_division = "Lead sheath - Copper conductor", + utilisation_pct = 80, + operating_voltage_pct = 60, + sheath_test = "Default", + partial_discharge = "Default", + fault_hist = "Default", + leakage = "Default", + reliability_factor = "Default", + age = 50) + + expect_equal(res, 0.004274284) + +}) diff --git a/tests/testthat/test-pof_future_board_04kv.R b/tests/testthat/test-pof_future_board_04kv.R new file mode 100644 index 00000000..3c87d90a --- /dev/null +++ b/tests/testthat/test-pof_future_board_04kv.R @@ -0,0 +1,35 @@ +library(testthat) +library(CNAIM) + +context("Future Probability of Failure for a Board 0.4 kV)") + +test_that("pof_future_board_04kv", { + + res <- + pof_future_board_04kv( + placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age = 10, + observed_condition_inputs = + list("external_cond" = + list("Condition Criteria: Observed Condition" = "Default"), + "compound_leaks" = list("Condition Criteria: Observed Condition" = "Default"), + "internal_cond" = list("Condition Criteria: Observed Condition" = "Default"), + "insulation" = list("Condition Criteria: Observed Condition" = "Default"), + "signs_heating" = list("Condition Criteria: Observed Condition" = "Default"), + "phase_barriers" = list("Condition Criteria: Observed Condition" = "Default")), + measured_condition_inputs = + list("opsal_adequacy" = + list("Condition Criteria: Operational Adequacy" = "Default")), + reliability_factor = "Default", + k_value = 0.0069, + c_value = 1.087, + normal_expected_life = 60, + simulation_end_year = 100) + + + expect_equal(res$PoF[which(res$year == 12)], 0.001966531) + +}) diff --git a/tests/testthat/test-pof_future_building.R b/tests/testthat/test-pof_future_building.R new file mode 100644 index 00000000..c892e0f9 --- /dev/null +++ b/tests/testthat/test-pof_future_building.R @@ -0,0 +1,28 @@ + +library(testthat) +library(CNAIM) + +context("Future Probability of Failure for a Building") + +test_that("pof_future_building", { + + res <- pof_future_building(substation_type = "Secondary", + material_type = "Wood", + placement = "Outdoor", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age = 1, + temperature_reading = "Default", + coolers_radiator = "Default", + kiosk = "Default", + cable_boxes = "Default", + reliability_factor = "Default", + k_value = "Default", + c_value = 1.087, + normal_expected_life_building = "Default", + simulation_end_year = 100) + + expect_equal(res$PoF[which(res$year == 12)], 0.1140018) + +}) diff --git a/tests/testthat/test-pof_future_cables_60_30kv.R b/tests/testthat/test-pof_future_cables_60_30kv.R new file mode 100644 index 00000000..fbf273fc --- /dev/null +++ b/tests/testthat/test-pof_future_cables_60_30kv.R @@ -0,0 +1,25 @@ +library(testthat) +library(CNAIM) + +context("Future Probability of Failure for 30/60kV UG Cable (Non Pressurised)") + +test_that("pof_future_cables_60_30kv", { + + res <- pof_future_cables_60_30kv(cable_type = "60kV UG Cable (Non Pressurised)", + sub_division = "Aluminium sheath - Aluminium conductor", + utilisation_pct = 75, + operating_voltage_pct = 50, + sheath_test = "Default", + partial_discharge = "Default", + fault_hist = "Default", + leakage = "Default", + reliability_factor = "Default", + age = 1, + k_value = "Default", + c_value = 1.087, + normal_expected_life = "Default", + simulation_end_year = 100) + + expect_equal(res$PoF[which(res$year == 50)], 0.01875330) + +}) diff --git a/tests/testthat/test-pof_future_meter.R b/tests/testthat/test-pof_future_meter.R new file mode 100644 index 00000000..a5bbd8cd --- /dev/null +++ b/tests/testthat/test-pof_future_meter.R @@ -0,0 +1,37 @@ +library(testthat) +library(CNAIM) + +context("Future Probability of Failure for a Meter") + +test_that("pof_future_meter", { + + res <- + pof_future_meter( + placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age = 1, + observed_condition_inputs = + list("external_condition" = + list("Condition Criteria: Observed Condition" = "Default"), + "oil_gas" = list("Condition Criteria: Observed Condition" = "Default"), + "thermo_assment" = list("Condition Criteria: Observed Condition" = "Default"), + "internal_condition" = list("Condition Criteria: Observed Condition" = "Default"), + "indoor_env" = list("Condition Criteria: Observed Condition" = "Default")), + measured_condition_inputs = + list("partial_discharge" = + list("Condition Criteria: Partial Discharge Test Results" = "Default"), + "ductor_test" = list("Condition Criteria: Ductor Test Results" = "Default"), + "oil_test" = list("Condition Criteria: Oil Test Results" = "Default"), + "temp_reading" = list("Condition Criteria: Temperature Readings" = "Default"), + "trip_test" = list("Condition Criteria: Trip Timing Test Result" = "Default")), + reliability_factor = "Default", + k_value = 0.128, + c_value = 1.087, + normal_expected_life = 25, + simulation_end_year = 100) + + expect_equal(res$PoF[which(res$year == 25)], 0.06201321) + +}) diff --git a/tests/testthat/test-pof_future_ohl_cond_50kv.R b/tests/testthat/test-pof_future_ohl_cond_50kv.R new file mode 100644 index 00000000..3b8203ff --- /dev/null +++ b/tests/testthat/test-pof_future_ohl_cond_50kv.R @@ -0,0 +1,27 @@ +library(testthat) +library(CNAIM) + +context("Future Probability of Failure for 50kV OHL (Tower Line) Conductor") + +test_that("pof_future_ohl_cond_50kv", { + + res <- pof_future_ohl_cond_50kv(sub_division = "Cu", + placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age = 10, + conductor_samp = "Default", + corr_mon_survey = "Default", + visual_cond = "Default", + midspan_joints = "Default", + reliability_factor = "Default", + k_value = 0.0080, + c_value = 1.087, + normal_expected_life = "Default", + simulation_end_year = 100) + + expect_equal(res$PoF[6], 0.002280036) + +}) + diff --git a/tests/testthat/test-pof_future_ohl_fittings_50kv.R b/tests/testthat/test-pof_future_ohl_fittings_50kv.R new file mode 100644 index 00000000..c550e931 --- /dev/null +++ b/tests/testthat/test-pof_future_ohl_fittings_50kv.R @@ -0,0 +1,37 @@ +library(testthat) +library(CNAIM) + +context("Future Probability of Failure for a OHL fittings 50 kV") + +test_that("pof_future_ohl_fittings_50kv", { + + res <- + pof_future_ohl_fittings_50kv( + placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age = 10, + observed_condition_inputs = + list("insulator_elec_cond" = + list("Condition Criteria: Observed Condition" = "Default"), + "insulator_mech_cond" = + list("Condition Criteria: Observed Condition" = "Default"), + "conductor_fitting_cond" = + list("Condition Criteria: Observed Condition" = "Default"), + "tower_fitting_cond" = + list("Condition Criteria: Observed Condition" = "Default")), + measured_condition_inputs = + list("thermal_imaging" = + list("Condition Criteria: Thermal Imaging Result" = "Default"), + "ductor_test" = list("Condition Criteria: Ductor Test Result" = "Default")), + reliability_factor = "Default", + k_value = 0.0096, + c_value = 1.087, + normal_expected_life = 40, + simulation_end_year = 100) + + + expect_equal(res$PoF[which(res$year == 20)], 0.002736043) + +}) diff --git a/tests/testthat/test-pof_future_pillar_04kv.R b/tests/testthat/test-pof_future_pillar_04kv.R new file mode 100644 index 00000000..5dff5891 --- /dev/null +++ b/tests/testthat/test-pof_future_pillar_04kv.R @@ -0,0 +1,36 @@ +library(testthat) +library(CNAIM) + +context("Future Probability of Failure for a Pillar 0.4 kV)") + +test_that("pof_future_pillar_04kv", { + + res <- + pof_future_pillar_04kv( + placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age = 10, + observed_condition_inputs = + list("external_cond" = + list("Condition Criteria: Observed Condition" = "Default"), + "compound_leaks" = list("Condition Criteria: Observed Condition" = "Default"), + "internal_cond" = list("Condition Criteria: Observed Condition" = "Default"), + "insulation" = list("Condition Criteria: Observed Condition" = "Default"), + "signs_heating" = list("Condition Criteria: Observed Condition" = "Default"), + "phase_barriers" = list("Condition Criteria: Observed Condition" = "Default")), + measured_condition_inputs = + list("opsal_adequacy" = + list("Condition Criteria: Operational Adequacy" = "Default")), + reliability_factor = "Default", + k_value = 0.0046, + c_value = 1.087, + normal_expected_life = 60, + simulation_end_year = 100) + + + + expect_equal(res$PoF[which(res$year == 12)], 0.001311021) + +}) diff --git a/tests/testthat/test-pof_future_rtu.R b/tests/testthat/test-pof_future_rtu.R new file mode 100644 index 00000000..1364379b --- /dev/null +++ b/tests/testthat/test-pof_future_rtu.R @@ -0,0 +1,37 @@ +library(testthat) +library(CNAIM) + +context("Future Probability of Failure for a RTU") + +test_that("pof_future_rtu", { + + res <- + pof_future_rtu( + placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age = 1, + observed_condition_inputs = + list("external_condition" = + list("Condition Criteria: Observed Condition" = "Default"), + "oil_gas" = list("Condition Criteria: Observed Condition" = "Default"), + "thermo_assment" = list("Condition Criteria: Observed Condition" = "Default"), + "internal_condition" = list("Condition Criteria: Observed Condition" = "Default"), + "indoor_env" = list("Condition Criteria: Observed Condition" = "Default")), + measured_condition_inputs = + list("partial_discharge" = + list("Condition Criteria: Partial Discharge Test Results" = "Default"), + "ductor_test" = list("Condition Criteria: Ductor Test Results" = "Default"), + "oil_test" = list("Condition Criteria: Oil Test Results" = "Default"), + "temp_reading" = list("Condition Criteria: Temperature Readings" = "Default"), + "trip_test" = list("Condition Criteria: Trip Timing Test Result" = "Default")), + reliability_factor = "Default", + k_value = 0.128, + c_value = 1.087, + normal_expected_life = 20, + simulation_end_year = 100) + + expect_equal(res$PoF[which(res$year == 25)], 0.26977956) + +}) diff --git a/tests/testthat/test-pof_future_serviceline.R b/tests/testthat/test-pof_future_serviceline.R new file mode 100644 index 00000000..66a256c8 --- /dev/null +++ b/tests/testthat/test-pof_future_serviceline.R @@ -0,0 +1,22 @@ +library(testthat) +library(CNAIM) + +context("Future Probability of Failure for Serviceline") + +test_that("pof_future_serviceline", { + + res <- pof_future_serviceline(utilisation_pct = 80, + operating_voltage_pct = 60, + sheath_test = "Default", + partial_discharge = "Default", + fault_hist = "Default", + reliability_factor = "Default", + age = 50, + k_value = 0.0329, + c_value = 1.087, + normal_expected_life = 75, + simulation_end_year = 100) + + expect_equal(res$PoF[which(res$year == 50)], 0.089454008) + +}) diff --git a/tests/testthat/test-pof_future_submarine_30_60kv_oil.R b/tests/testthat/test-pof_future_submarine_30_60kv_oil.R new file mode 100644 index 00000000..ef1fbe68 --- /dev/null +++ b/tests/testthat/test-pof_future_submarine_30_60kv_oil.R @@ -0,0 +1,29 @@ +library(testthat) +library(CNAIM) + +context("Future Probability of Failure for 30/60kV submarine cable (Oil)") + +test_that("pof_future_submarine_cables_30_60kv_oil", { + + res <- pof_future_submarine_cables_30_60kv_oil( + utilisation_pct = "Default", + operating_voltage_pct = "Default", + topography = "Default", + sitution = "Default", + wind_wave = "Default", + intensity = "Default", + landlocked = "no", + sheath_test = "Default", + partial_discharge = "Default", + fault_hist = "Default", + condition_armour = "Default", + age = 10, + reliability_factor = "Default", + k_value = 2.0944, + c_value = 1.087, + normal_expected_life = 60, + simulation_end_year = 100) + + expect_equal(res$PoF[which(res$year == 1)], 0.5969134) + +}) diff --git a/tests/testthat/test-pof_future_submarine_30_60kv_pex.R b/tests/testthat/test-pof_future_submarine_30_60kv_pex.R new file mode 100644 index 00000000..7ca08e1e --- /dev/null +++ b/tests/testthat/test-pof_future_submarine_30_60kv_pex.R @@ -0,0 +1,29 @@ +library(testthat) +library(CNAIM) + +context("Future Probability of Failure for 30/60kV submarine cable (PEX)") + +test_that("pof_future_submarine_cables_30_60kv_pex", { + + res <- pof_future_submarine_cables_30_60kv_pex( + utilisation_pct = "Default", + operating_voltage_pct = "Default", + topography = "Default", + sitution = "Default", + wind_wave = "Default", + intensity = "Default", + landlocked = "no", + sheath_test = "Default", + partial_discharge = "Default", + fault_hist = "Default", + condition_armour = "Default", + age = 10, + reliability_factor = "Default", + k_value = 0.0202, + c_value = 1.087, + normal_expected_life = 60, + simulation_end_year = 100) + + expect_equal(res$PoF[which(res$year == 1)], 0.005757091) + +}) diff --git a/tests/testthat/test-pof_future_submarine_cables_10kv_oil.R b/tests/testthat/test-pof_future_submarine_cables_10kv_oil.R new file mode 100644 index 00000000..037b7b9e --- /dev/null +++ b/tests/testthat/test-pof_future_submarine_cables_10kv_oil.R @@ -0,0 +1,28 @@ +library(testthat) +library(CNAIM) + +context("Future Probability of Failure for 10kV submarine cable (Oil)") + +test_that("pof_future_submarine_cables_10kv_oil", { + + res <- pof_future_submarine_cables_10kv_oil(utilisation_pct = "Default", + operating_voltage_pct = "Default", + topography = "Default", + sitution = "Default", + wind_wave = "Default", + intensity = "Default", + landlocked = "no", + sheath_test = "Default", + partial_discharge = "Default", + fault_hist = "Default", + condition_armour = "Default", + age = 10, + reliability_factor = "Default", + k_value = 2.0944, + c_value = 1.087, + normal_expected_life = 60, + simulation_end_year = 100) + + expect_equal(res$PoF[which(res$year == 1)], 0.5969134) + +}) diff --git a/tests/testthat/test-pof_future_submarine_cables_10kv_pex.R b/tests/testthat/test-pof_future_submarine_cables_10kv_pex.R new file mode 100644 index 00000000..1519a9a3 --- /dev/null +++ b/tests/testthat/test-pof_future_submarine_cables_10kv_pex.R @@ -0,0 +1,28 @@ +library(testthat) +library(CNAIM) + +context("Future Probability of Failure for 10kV submarine cable (PEX)") + +test_that("pof_future_submarine_cables_10kv_pex", { + + res <- pof_future_submarine_cables_10kv_pex(utilisation_pct = "Default", + operating_voltage_pct = "Default", + topography = "Default", + sitution = "Default", + wind_wave = "Default", + intensity = "Default", + landlocked = "no", + sheath_test = "Default", + partial_discharge = "Default", + fault_hist = "Default", + condition_armour = "Default", + age = 10, + reliability_factor = "Default", + k_value = 0.0202, + c_value = 1.087, + normal_expected_life = 60, + simulation_end_year = 100) + + expect_equal(res$PoF[which(res$year == 1)], 0.005757091 ) + +}) diff --git a/tests/testthat/test-pof_future_switchgear_30_60kv.R b/tests/testthat/test-pof_future_switchgear_30_60kv.R new file mode 100644 index 00000000..5dd7f345 --- /dev/null +++ b/tests/testthat/test-pof_future_switchgear_30_60kv.R @@ -0,0 +1,42 @@ +library(testthat) +library(CNAIM) + +context("Future Probability of Failure for 30kV Switchgear)") + +test_that("pof_future_switchgear_30_60kv", { + + res <- + pof_future_switchgear_30_60kv( + asset_type = "30kV", + number_of_operations = "Default", + placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age = 10, + observed_condition_inputs = + list("external_condition" = + list("Condition Criteria: Observed Condition" = "Default"), + "oil_gas" = list("Condition Criteria: Observed Condition" = "Default"), + "thermo_assment" = list("Condition Criteria: Observed Condition" = "Default"), + "internal_condition" = list("Condition Criteria: Observed Condition" = "Default"), + "indoor_env" = list("Condition Criteria: Observed Condition" = "Default"), + "support_structure" = list("Condition Criteria: Observed Condition" = "Default")), + measured_condition_inputs = + list("partial_discharge" = + list("Condition Criteria: Partial Discharge Test Results" = "Default"), + "ductor_test" = list("Condition Criteria: Ductor Test Results" = "Default"), + "oil_test" = list("Condition Criteria: Oil Test Results" = "Default"), + "temp_reading" = list("Condition Criteria: Temperature Readings" = "Default"), + "trip_test" = list("Condition Criteria: Trip Timing Test Result" = "Default"), + "ir_test" = list("Condition Criteria: IR Test Results" = "Default" )), + reliability_factor = "Default", + k_value = "Default", + c_value = 1.087, + normal_expected_life = 55, + simulation_end_year = 100) + + + expect_equal(res$PoF[which(res$year == 12)], 0.006355601) + +}) diff --git a/tests/testthat/test-pof_future_switchgear_primary_10kv.R b/tests/testthat/test-pof_future_switchgear_primary_10kv.R new file mode 100644 index 00000000..014c8fe6 --- /dev/null +++ b/tests/testthat/test-pof_future_switchgear_primary_10kv.R @@ -0,0 +1,40 @@ +library(testthat) +library(CNAIM) + +context("Future Probability of Failure for a Switchgear primary 10 kv)") + +test_that("pof_future_switchgear_primary_10kv", { + + res <- + pof_future_switchgear_primary_10kv( + number_of_operations = "Default", + placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age = 10, + observed_condition_inputs = + list("external_condition" = + list("Condition Criteria: Observed Condition" = "Default"), + "oil_gas" = list("Condition Criteria: Observed Condition" = "Default"), + "thermo_assment" = list("Condition Criteria: Observed Condition" = "Default"), + "internal_condition" = list("Condition Criteria: Observed Condition" = "Default"), + "indoor_env" = list("Condition Criteria: Observed Condition" = "Default")), + measured_condition_inputs = + list("partial_discharge" = + list("Condition Criteria: Partial Discharge Test Results" = "Default"), + "ductor_test" = list("Condition Criteria: Ductor Test Results" = "Default"), + "oil_test" = list("Condition Criteria: Oil Test Results" = "Default"), + "temp_reading" = list("Condition Criteria: Temperature Readings" = "Default"), + "trip_test" = list("Condition Criteria: Trip Timing Test Result" = "Default"), + "ir_test" = list("Condition Criteria: IR Test Results" = "Default" )), + reliability_factor = "Default", + k_value = 0.0052, + c_value = 1.087, + normal_expected_life = 55, + simulation_end_year = 100) + + + expect_equal(res$PoF[which(res$year == 12)], 0.001482023) + +}) diff --git a/tests/testthat/test-pof_future_switchgear_secondary_10kv.R b/tests/testthat/test-pof_future_switchgear_secondary_10kv.R new file mode 100644 index 00000000..faa2da41 --- /dev/null +++ b/tests/testthat/test-pof_future_switchgear_secondary_10kv.R @@ -0,0 +1,38 @@ +library(testthat) +library(CNAIM) + +context("Future Probability of Failure for a Switchgear secondary 10 kv)") + +test_that("pof_future_switchgear_secondary_10kv", { + + res <- + pof_future_switchgear_secondary_10kv( + placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age = 10, + observed_condition_inputs = + list("external_condition" = + list("Condition Criteria: Observed Condition" = "Default"), + "oil_gas" = list("Condition Criteria: Observed Condition" = "Default"), + "thermo_assment" = list("Condition Criteria: Observed Condition" = "Default"), + "internal_condition" = list("Condition Criteria: Observed Condition" = "Default"), + "indoor_env" = list("Condition Criteria: Observed Condition" = "Default")), + measured_condition_inputs = + list("partial_discharge" = + list("Condition Criteria: Partial Discharge Test Results" = "Default"), + "ductor_test" = list("Condition Criteria: Ductor Test Results" = "Default"), + "oil_test" = list("Condition Criteria: Oil Test Results" = "Default"), + "temp_reading" = list("Condition Criteria: Temperature Readings" = "Default"), + "trip_test" = list("Condition Criteria: Trip Timing Test Result" = "Default")), + reliability_factor = "Default", + k_value = 0.0067, + c_value = 1.087, + normal_expected_life = 55, + simulation_end_year = 100) + + + expect_equal(res$PoF[which(res$year == 12)], 0.001909530) + +}) diff --git a/tests/testthat/test-pof_future_transformer_04_10kv.R b/tests/testthat/test-pof_future_transformer_04_10kv.R new file mode 100644 index 00000000..7da65dcd --- /dev/null +++ b/tests/testthat/test-pof_future_transformer_04_10kv.R @@ -0,0 +1,29 @@ +library(testthat) +library(CNAIM) + +context("Future Probability of Failure for a Transformer") + +test_that("pof_future_transformer_04_10kv", { + + res <- + pof_future_transformer_04_10kv(utilisation_pct = "Default", + placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age = 20, + partial_discharge = "Default", + temperature_reading = "Default", + observed_condition = "Default", + reliability_factor = "Default", + moisture = "Default", + acidity = "Default", + bd_strength = "Default", + k_value = 0.0077, + c_value = 1.087, + normal_expected_life = 55, + simulation_end_year = 100) + + expect_equal(res$PoF[which(res$year == 50)], 0.002194535) + +}) diff --git a/tests/testthat/test-pof_future_transformer_132kv.R b/tests/testthat/test-pof_future_transformer_132kv.R new file mode 100644 index 00000000..7b3bc51b --- /dev/null +++ b/tests/testthat/test-pof_future_transformer_132kv.R @@ -0,0 +1,23 @@ +library(testthat) +library(CNAIM) + +context("Future Probability of Failure for 132kV Transformer (GM)") + +test_that("pof_future_transformer_132kv", { + + res <- + pof_future_transformer_132kv(transformer_type = "132kV Transformer (GM)", + year_of_manufacture = 1980, + utilisation_pct = "Default", + no_taps = "Default", + placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age_tf = 43, + age_tc = 43,simulation_end_year = 100) + + expect_equal(res$PoF[which(res$year == 12)], 0.03657150) + +}) + diff --git a/tests/testthat/test-pof_future_transformer_30_60kv.R b/tests/testthat/test-pof_future_transformer_30_60kv.R new file mode 100644 index 00000000..9ab0b4e2 --- /dev/null +++ b/tests/testthat/test-pof_future_transformer_30_60kv.R @@ -0,0 +1,55 @@ +library(testthat) +library(CNAIM) + +context("Future Probability of Failure for 60kV Transformer (GM)") + +test_that("pof_future_transformer_30_60kv", { + + res <- + pof_future_transformer_30_60kv(transformer_type = "60kV Transformer (GM)", + year_of_manufacture = 1980, + utilisation_pct = "Default", + no_taps = "Default", + placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age_tf = 43, + age_tc = 43, + partial_discharge_tf = "Default", + partial_discharge_tc = "Default", + temperature_reading = "Default", + main_tank = "Default", + coolers_radiator = "Default", + bushings = "Default", + kiosk = "Default", + cable_boxes = "Default", + external_tap = "Default", + internal_tap = "Default", + mechnism_cond = "Default", + diverter_contacts = "Default", + diverter_braids = "Default", + moisture = "Default", + acidity = "Default", + bd_strength = "Default", + hydrogen = "Default", + methane = "Default", + ethylene = "Default", + ethane = "Default", + acetylene = "Default", + hydrogen_pre = "Default", + methane_pre = "Default", + ethylene_pre = "Default", + ethane_pre = "Default", + acetylene_pre = "Default", + furfuraldehyde = "Default", + reliability_factor = "Default", + k_value = 0.454, + c_value = 1.087, + normal_expected_life_tf = "Default", + normal_expected_life_tc = "Default", + simulation_end_year = 100) + + expect_equal(res$PoF[which(res$year == 12)], 0.3657150) + +}) diff --git a/tests/testthat/test-pof_meter.R b/tests/testthat/test-pof_meter.R new file mode 100644 index 00000000..9200c24c --- /dev/null +++ b/tests/testthat/test-pof_meter.R @@ -0,0 +1,35 @@ +library(testthat) +library(CNAIM) + +context("POF Meter") + +test_that("Default case", { + res <- pof_meter( + placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age = 10, + observed_condition_inputs = + list("external_condition" = + list("Condition Criteria: Observed Condition" = "Default"), + "oil_gas" = list("Condition Criteria: Observed Condition" = "Default"), + "thermo_assment" = list("Condition Criteria: Observed Condition" = "Default"), + "internal_condition" = list("Condition Criteria: Observed Condition" = "Default"), + "indoor_env" = list("Condition Criteria: Observed Condition" = "Default")), + measured_condition_inputs = + list("partial_discharge" = + list("Condition Criteria: Partial Discharge Test Results" = "Default"), + "ductor_test" = list("Condition Criteria: Ductor Test Results" = "Default"), + "oil_test" = list("Condition Criteria: Oil Test Results" = "Default"), + "temp_reading" = list("Condition Criteria: Temperature Readings" = "Default"), + "trip_test" = list("Condition Criteria: Trip Timing Test Result" = "Default")), + reliability_factor = "Default", + k_value = 0.128, + c_value = 1.087, + normal_expected_life = 25) + + expected_val <- 0.004574662 + + expect_equal(res, expected_val) +}) diff --git a/tests/testthat/test-pof_ohl_cond_50kv.R b/tests/testthat/test-pof_ohl_cond_50kv.R new file mode 100644 index 00000000..054a8211 --- /dev/null +++ b/tests/testthat/test-pof_ohl_cond_50kv.R @@ -0,0 +1,25 @@ +library(testthat) +library(CNAIM) + +context("Current Probability of Failure for 50kV OHL (Tower Line) Conductor") + +test_that("pof_ohl_cond_50kv", { + + res <- pof_ohl_cond_50kv(sub_division = "Cu", + placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age = 10, + conductor_samp = "Default", + corr_mon_survey = "Default", + visual_cond = "Default", + midspan_joints = "Default", + reliability_factor = "Default", + k_value = 0.0080, + c_value = 1.087, + normal_expected_life = "Default") + + expect_equal(res, 0.0001706678) + +}) diff --git a/tests/testthat/test-pof_ohl_support_50kv.R b/tests/testthat/test-pof_ohl_support_50kv.R new file mode 100644 index 00000000..f796922d --- /dev/null +++ b/tests/testthat/test-pof_ohl_support_50kv.R @@ -0,0 +1,33 @@ +library(testthat) +library(CNAIM) + +context("POF Towers : 50 kV") + +test_that("50kV case", { + res <- pof_tower_ohl_support_50kv( + number_of_operations = "Default", + placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age = 10, + paint_type = "Paint System - Galvanising", + foundation_type = "Foundation - Earth Grillage", + observed_condition_inputs_steelwork = + list("tower_legs" = list("Condition Criteria: Observed Condition" = "Default"), + "tower_bracings" = list("Condition Criteria: Observed Condition" = "Default"), + "tower_crossarms" = list("Condition Criteria: Observed Condition" = "Default"), + "tower_peak" = list("Condition Criteria: Observed Condition" = "Default")), + observed_condition_inputs_paint = + list("paintwork_cond" = list("Condition Criteria: Observed Condition" = "Default")), + observed_condition_inputs_foundation = + list("foundation_cond" = list("Condition Criteria: Observed Condition" = "Default")), + reliability_factor = "Default", + k_value = 0.0545, + c_value = 1.087, + normal_expected_life = "Default") + + expected_val <- 0.001127166 + + expect_equal(res, expected_val) +}) diff --git a/tests/testthat/test-pof_serviceline.R b/tests/testthat/test-pof_serviceline.R new file mode 100644 index 00000000..3a3872c6 --- /dev/null +++ b/tests/testthat/test-pof_serviceline.R @@ -0,0 +1,21 @@ +library(testthat) +library(CNAIM) + +context("Current Probability of Failure for Serviceline") + +test_that("pof_serviceline", { + + res <- pof_serviceline(utilisation_pct = 80, + operating_voltage_pct = "Default", + sheath_test = "Default", + partial_discharge = "Default", + fault_hist = "Default", + reliability_factor = "Default", + age = 50, + k_value = 0.0329, + c_value = 1.087, + normal_expected_life = 75) + + expect_equal(res, 0.003467356) + +}) diff --git a/tests/testthat/test-pof_submarine_cables_10kv_oil.R b/tests/testthat/test-pof_submarine_cables_10kv_oil.R new file mode 100644 index 00000000..3713cd9e --- /dev/null +++ b/tests/testthat/test-pof_submarine_cables_10kv_oil.R @@ -0,0 +1,27 @@ +library(testthat) +library(CNAIM) + +context("Current Probability of Failure for 10kV Sub Cable (Oil)") + +test_that("pof_submarine_cables_10kv_oil", { + + res <- pof_submarine_cables_10kv_oil(utilisation_pct = "Default", + operating_voltage_pct = "Default", + topography = "Default", + situation = "Default", + wind_wave = "Default", + intensity = "Default", + landlocked = "no", + sheath_test = "Default", + partial_discharge = "Default", + fault_hist = "Default", + condition_armour = "Default", + age = 10, + reliability_factor = "Default", + k_value = 2.0944, + c_value = 1.087, + normal_expected_life = 60) + + expect_equal(res, 0.03598082) + +}) diff --git a/tests/testthat/test-pof_submarine_cables_10kv_pex.R b/tests/testthat/test-pof_submarine_cables_10kv_pex.R new file mode 100644 index 00000000..9800a45e --- /dev/null +++ b/tests/testthat/test-pof_submarine_cables_10kv_pex.R @@ -0,0 +1,28 @@ +library(testthat) +library(CNAIM) + +context("Current Probability of Failure for 10kV Sub Cable (PEX)") + +test_that("pof_submarine_cables_10kv_pex", { + + res <- pof_submarine_cables_10kv_pex(utilisation_pct = "Default", + operating_voltage_pct = "Default", + topography = "Default", + situation = "Default", + wind_wave = "Default", + intensity = "Default", + landlocked = "no", + sheath_test = "Default", + partial_discharge = "Default", + fault_hist = "Default", + condition_armour = "Default", + age = 10, + reliability_factor = "Default", + k_value = 0.0202, + c_value = 1.087, + normal_expected_life = 60) + + expect_equal(res, 0.0003470267) + +}) + diff --git a/tests/testthat/test-pof_submarine_cables_30_60kv_oil.R b/tests/testthat/test-pof_submarine_cables_30_60kv_oil.R new file mode 100644 index 00000000..ab09ee2b --- /dev/null +++ b/tests/testthat/test-pof_submarine_cables_30_60kv_oil.R @@ -0,0 +1,27 @@ +library(testthat) +library(CNAIM) + +context("Current Probability of Failure for 30/60kV Sub Cable") + +test_that("pof_submarine_cables_30_60kv-oil", { + + res <- pof_submarine_cables_30_60kv_oil(utilisation_pct = "Default", + operating_voltage_pct = "Default", + topography = "Default", + situation = "Default", + wind_wave = "Default", + intensity = "Default", + landlocked = "no", + sheath_test = "Default", + partial_discharge = "Default", + fault_hist = "Default", + condition_armour = "Default", + age = 10, + reliability_factor = "Default", + k_value = 2.0944, + c_value = 1.087, + normal_expected_life = 60) + + expect_equal(res, 0.03598082) + +}) diff --git a/tests/testthat/test-pof_submarine_cables_30_60kv_pex.R b/tests/testthat/test-pof_submarine_cables_30_60kv_pex.R new file mode 100644 index 00000000..6037f3e1 --- /dev/null +++ b/tests/testthat/test-pof_submarine_cables_30_60kv_pex.R @@ -0,0 +1,27 @@ +library(testthat) +library(CNAIM) + +context("Current Probability of Failure for 30/60kV Sub Cable (PEX)") + +test_that("pof_submarine_cables_30_60kv_pex", { + + res <- pof_submarine_cables_30_60kv_pex(utilisation_pct = "Default", + operating_voltage_pct = "Default", + topography = "Default", + situation = "Default", + wind_wave = "Default", + intensity = "Default", + landlocked = "no", + sheath_test = "Default", + partial_discharge = "Default", + fault_hist = "Default", + condition_armour = "Default", + age = 10, + reliability_factor = "Default", + k_value = 0.0202, + c_value = 1.087, + normal_expected_life = 60) + + expect_equal(res, 0.0003470267) + +}) diff --git a/tests/testthat/test-pof_transformer_04_10kv.R b/tests/testthat/test-pof_transformer_04_10kv.R new file mode 100644 index 00000000..38c2d352 --- /dev/null +++ b/tests/testthat/test-pof_transformer_04_10kv.R @@ -0,0 +1,24 @@ +library(testthat) +library(CNAIM) + +context("Current Probability of Failure for a 0.4/10kV Transformer") + +test_that("pof_transformer_04_10kv", { + expect_equal(pof_transformer_04_10kv(utilisation_pct = "Default", + placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age = 10, + partial_discharge = "Default", + temperature_reading = "Default", + observed_condition = "Default", + reliability_factor = "Default", + moisture = "Default", + acidity = "Default", + bd_strength = "Default", + k_value = 0.0077, + c_value = 1.087, + normal_expected_life = 55), 0.0001322824) +}) + diff --git a/tests/testthat/test-pof_transformer_30_60kv.R b/tests/testthat/test-pof_transformer_30_60kv.R new file mode 100644 index 00000000..5a1b9de7 --- /dev/null +++ b/tests/testthat/test-pof_transformer_30_60kv.R @@ -0,0 +1,52 @@ +library(testthat) +library(CNAIM) + +context("Current Probability of Failure for a 60kV Transformer (GM)") + +test_that("pof_transformer_30_60kv", { + expect_equel(pof_transformer_30_60kv(transformer_type = "60kV Transformer (GM)", + year_of_manufacture = 1980, + utilisation_pct = "Default", + no_taps = "Default", + placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age_tf = 43, + age_tc = 43, + partial_discharge_tf = "Default", + partial_discharge_tc = "Default", + temperature_reading = "Default", + main_tank = "Default", + coolers_radiator = "Default", + bushings = "Default", + kiosk = "Default", + cable_boxes = "Default", + external_tap = "Default", + internal_tap = "Default", + mechnism_cond = "Default", + diverter_contacts = "Default", + diverter_braids = "Default", + moisture = "Default", + acidity = "Default", + bd_strength = "Default", + hydrogen = "Default", + methane = "Default", + ethylene = "Default", + ethane = "Default", + acetylene = "Default", + hydrogen_pre = "Default", + methane_pre = "Default", + ethylene_pre = "Default", + ethane_pre = "Default", + acetylene_pre = "Default", + furfuraldehyde = "Default", + reliability_factor = "Default", + k_value = 0.454, + c_value = 1.087, + normal_expected_life_tf = "Default", + normal_expected_life_tc = "Default") ,0.1244618) + + }) + + From 7608288e02422513ce3eeabda9666cea0ed857d7 Mon Sep 17 00:00:00 2001 From: NicolaiHandreck Date: Mon, 25 Jul 2022 15:38:14 +0200 Subject: [PATCH 04/10] more added --- tests/testthat/test-pof_board_04kv.R | 32 ++++++++++++++++ .../test-pof_future_poles_ohl_support_50kv.R | 35 ++++++++++++++++++ tests/testthat/test-pof_future_relay.R | 37 +++++++++++++++++++ .../test-pof_future_tower_ohl_support_50kv.R | 35 ++++++++++++++++++ tests/testthat/test-pof_ohl_fittings_50kv.R | 37 +++++++++++++++++++ tests/testthat/test-pof_pillar_04kv.R | 33 +++++++++++++++++ .../test-pof_poles_ohl_support_50kv.R | 33 +++++++++++++++++ tests/testthat/test-pof_relay.R | 35 ++++++++++++++++++ tests/testthat/test-pof_rtu.R | 35 ++++++++++++++++++ .../test-pof_switchgear_secondary_10kv.R | 35 ++++++++++++++++++ 10 files changed, 347 insertions(+) create mode 100644 tests/testthat/test-pof_board_04kv.R create mode 100644 tests/testthat/test-pof_future_poles_ohl_support_50kv.R create mode 100644 tests/testthat/test-pof_future_relay.R create mode 100644 tests/testthat/test-pof_future_tower_ohl_support_50kv.R create mode 100644 tests/testthat/test-pof_ohl_fittings_50kv.R create mode 100644 tests/testthat/test-pof_pillar_04kv.R create mode 100644 tests/testthat/test-pof_poles_ohl_support_50kv.R create mode 100644 tests/testthat/test-pof_relay.R create mode 100644 tests/testthat/test-pof_rtu.R create mode 100644 tests/testthat/test-pof_switchgear_secondary_10kv.R diff --git a/tests/testthat/test-pof_board_04kv.R b/tests/testthat/test-pof_board_04kv.R new file mode 100644 index 00000000..a2a84d54 --- /dev/null +++ b/tests/testthat/test-pof_board_04kv.R @@ -0,0 +1,32 @@ +library(testthat) +library(CNAIM) + +context("POF Board 0.4 kV") + +test_that("LV Board(WM)", { + res <- pof_board_04kv( + placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age = 10, + observed_condition_inputs = + list("external_cond" = + list("Condition Criteria: Observed Condition" = "Default"), + "compound_leaks" = list("Condition Criteria: Observed Condition" = "Default"), + "internal_cond" = list("Condition Criteria: Observed Condition" = "Default"), + "insulation" = list("Condition Criteria: Observed Condition" = "Default"), + "signs_heating" = list("Condition Criteria: Observed Condition" = "Default"), + "phase_barriers" = list("Condition Criteria: Observed Condition" = "Default")), + measured_condition_inputs = + list("opsal_adequacy" = + list("Condition Criteria: Operational Adequacy" = "Default")), + reliability_factor = "Default", + k_value = 0.0069, + c_value = 1.087, + normal_expected_life = 60) + + expected_value <- 0.0001185388 + + expect_equal(res, expected_value) +}) diff --git a/tests/testthat/test-pof_future_poles_ohl_support_50kv.R b/tests/testthat/test-pof_future_poles_ohl_support_50kv.R new file mode 100644 index 00000000..00fa5971 --- /dev/null +++ b/tests/testthat/test-pof_future_poles_ohl_support_50kv.R @@ -0,0 +1,35 @@ +library(testthat) +library(CNAIM) + +context("Future Probability of Failure for 50 kV OHL support poles") + +test_that("pof_future_poles_ohl_support_50kv", { + + res <- + pof_future_poles_ohl_support_50kv( + sub_division = "Wood", + placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age = 10, + observed_condition_inputs = + list("visual_pole_cond" = + list("Condition Criteria: Pole Top Rot Present?" = "Default"), + "pole_leaning" = list("Condition Criteria: Pole Leaning?" = "Default"), + "bird_animal_damage" = + list("Condition Criteria: Bird/Animal Damage?" = "Default"), + "top_rot" = list("Condition Criteria: Pole Top Rot Present?" = "Default")), + measured_condition_inputs = + list("pole_decay" = + list("Condition Criteria: Degree of Decay/Deterioration" = "Default")), + reliability_factor = "Default", + k_value = 0.0285, + c_value = 1.087, + normal_expected_life = "Default", + simulation_end_year = 100) + + + expect_equal(res$PoF[which(res$year == 25)], 0.008122628) + +}) diff --git a/tests/testthat/test-pof_future_relay.R b/tests/testthat/test-pof_future_relay.R new file mode 100644 index 00000000..2b377aba --- /dev/null +++ b/tests/testthat/test-pof_future_relay.R @@ -0,0 +1,37 @@ +library(testthat) +library(CNAIM) + +context("Future Probability of Failure for Relay") + +test_that("pof_future_relay", { + + res <- + pof_future_relay( + placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age = 10, + observed_condition_inputs = + list("external_condition" = + list("Condition Criteria: Observed Condition" = "Default"), + "oil_gas" = list("Condition Criteria: Observed Condition" = "Default"), + "thermo_assment" = list("Condition Criteria: Observed Condition" = "Default"), + "internal_condition" = list("Condition Criteria: Observed Condition" = "Default"), + "indoor_env" = list("Condition Criteria: Observed Condition" = "Default")), + measured_condition_inputs = + list("partial_discharge" = + list("Condition Criteria: Partial Discharge Test Results" = "Default"), + "ductor_test" = list("Condition Criteria: Ductor Test Results" = "Default"), + "oil_test" = list("Condition Criteria: Oil Test Results" = "Default"), + "temp_reading" = list("Condition Criteria: Temperature Readings" = "Default"), + "trip_test" = list("Condition Criteria: Trip Timing Test Result" = "Default")), + reliability_factor = "Default", + k_value = 0.128, + c_value = 1.087, + normal_expected_life = 30, + simulation_end_year = 100) + + expect_equal(res$PoF[which(res$year == 25)], 0.12453976) + +}) diff --git a/tests/testthat/test-pof_future_tower_ohl_support_50kv.R b/tests/testthat/test-pof_future_tower_ohl_support_50kv.R new file mode 100644 index 00000000..1a672fd3 --- /dev/null +++ b/tests/testthat/test-pof_future_tower_ohl_support_50kv.R @@ -0,0 +1,35 @@ +library(testthat) +library(CNAIM) + +context("Future Probability of Failure for 50 kV OHL support tower") + +test_that("pof_future_tower_ohl_support_50kv", { + + res <- + pof_future_tower_ohl_support_50kv( + number_of_operations = "Default", + placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age = 10, + paint_type = "Paint System - Galvanising", + foundation_type = "Foundation - Earth Grillage", + observed_condition_inputs_steelwork = + list("tower_legs" = list("Condition Criteria: Observed Condition" = "Default"), + "tower_bracings" = list("Condition Criteria: Observed Condition" = "Default"), + "tower_crossarms" = list("Condition Criteria: Observed Condition" = "Default"), + "tower_peak" = list("Condition Criteria: Observed Condition" = "Default")), + observed_condition_inputs_paint = + list("paintwork_cond" = list("Condition Criteria: Observed Condition" = "Default")), + observed_condition_inputs_foundation = + list("foundation_cond" = list("Condition Criteria: Observed Condition" = "Default")), + reliability_factor = "Default", + k_value = 0.0545, + c_value = 1.087, + normal_expected_life = "Default", + simulation_end_year = 100) + + expect_equal(res$PoF[which(res$year == 25)], 0.01553275) + +}) diff --git a/tests/testthat/test-pof_ohl_fittings_50kv.R b/tests/testthat/test-pof_ohl_fittings_50kv.R new file mode 100644 index 00000000..77e6bd31 --- /dev/null +++ b/tests/testthat/test-pof_ohl_fittings_50kv.R @@ -0,0 +1,37 @@ +library(testthat) +library(CNAIM) + +context("POF 50 kV OHL Fittings") + +test_that("50kV Fittings", { + res <- pof_ohl_fittings_50kv( + placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age = 10, + observed_condition_inputs = + list("insulator_elec_cond" = + list("Condition Criteria: Observed Condition" = "Default"), + "insulator_mech_cond" = + list("Condition Criteria: Observed Condition" = "Default"), + "conductor_fitting_cond" = + list("Condition Criteria: Observed Condition" = "Default"), + "tower_fitting_cond" = + list("Condition Criteria: Observed Condition" = "Default")), + measured_condition_inputs = + list("thermal_imaging" = + list("Condition Criteria: Thermal Imaging Result" = "Default"), + "ductor_test" = list("Condition Criteria: Ductor Test Result" = "Default")), + reliability_factor = "Default", + k_value = 0.0096, + c_value = 1.087, + normal_expected_life = 40) + + expected_val <- 0.0002535621 + + expect_equal(res, expected_val) +}) + + + diff --git a/tests/testthat/test-pof_pillar_04kv.R b/tests/testthat/test-pof_pillar_04kv.R new file mode 100644 index 00000000..3c06141c --- /dev/null +++ b/tests/testthat/test-pof_pillar_04kv.R @@ -0,0 +1,33 @@ +library(testthat) +library(CNAIM) + +context("POF Pillars 0.4 kV") + +test_that("LV Pillars", { + + res <- pof_pillar_04kv( + placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age = 10, + observed_condition_inputs = + list("external_cond" = + list("Condition Criteria: Observed Condition" = "Default"), + "compound_leaks" = list("Condition Criteria: Observed Condition" = "Default"), + "internal_cond" = list("Condition Criteria: Observed Condition" = "Default"), + "insulation" = list("Condition Criteria: Observed Condition" = "Default"), + "signs_heating" = list("Condition Criteria: Observed Condition" = "Default"), + "phase_barriers" = list("Condition Criteria: Observed Condition" = "Default")), + measured_condition_inputs = + list("opsal_adequacy" = + list("Condition Criteria: Operational Adequacy" = "Default")), + reliability_factor = "Default", + k_value = 0.0046, + c_value = 1.087, + normal_expected_life = 60) + + expected_value <- 0.00007902587 + + expect_equal(res, expected_value) +}) diff --git a/tests/testthat/test-pof_poles_ohl_support_50kv.R b/tests/testthat/test-pof_poles_ohl_support_50kv.R new file mode 100644 index 00000000..e5db2ed8 --- /dev/null +++ b/tests/testthat/test-pof_poles_ohl_support_50kv.R @@ -0,0 +1,33 @@ +library(testthat) +library(CNAIM) + +context("POF 50 kV Support Poles") + +test_that("50kV case", { + res <- pof_poles_ohl_support_50kv( + sub_division = "Wood", + placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age = 10, + observed_condition_inputs = + list("visual_pole_cond" = + list("Condition Criteria: Pole Top Rot Present?" = "Default"), + "pole_leaning" = list("Condition Criteria: Pole Leaning?" = "Default"), + "bird_animal_damage" = + list("Condition Criteria: Bird/Animal Damage?" = "Default"), + "top_rot" = list("Condition Criteria: Pole Top Rot Present?" = "Default")), + measured_condition_inputs = + list("pole_decay" = + list("Condition Criteria: Degree of Decay/Deterioration" = "Default")), + reliability_factor = "Default", + k_value = 0.0285, + c_value = 1.087, + normal_expected_life = "Default") + + expected_val <- 0.0004896168 + + expect_equal(res, expected_val) +}) + diff --git a/tests/testthat/test-pof_relay.R b/tests/testthat/test-pof_relay.R new file mode 100644 index 00000000..cb9bb3b3 --- /dev/null +++ b/tests/testthat/test-pof_relay.R @@ -0,0 +1,35 @@ +library(testthat) +library(CNAIM) + +context("POF Relay") + +test_that("Default case", { + res <- pof_relay( + placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age = 25, + observed_condition_inputs = + list("external_condition" = + list("Condition Criteria: Observed Condition" = "Default"), + "oil_gas" = list("Condition Criteria: Observed Condition" = "Default"), + "thermo_assment" = list("Condition Criteria: Observed Condition" = "Default"), + "internal_condition" = list("Condition Criteria: Observed Condition" = "Default"), + "indoor_env" = list("Condition Criteria: Observed Condition" = "Default")), + measured_condition_inputs = + list("partial_discharge" = + list("Condition Criteria: Partial Discharge Test Results" = "Default"), + "ductor_test" = list("Condition Criteria: Ductor Test Results" = "Default"), + "oil_test" = list("Condition Criteria: Oil Test Results" = "Default"), + "temp_reading" = list("Condition Criteria: Temperature Readings" = "Default"), + "trip_test" = list("Condition Criteria: Trip Timing Test Result" = "Default")), + reliability_factor = "Default", + k_value = 0.128, + c_value = 1.087, + normal_expected_life = 30) + + expected_val <- 0.0220866 + + expect_equal(res, expected_val) +}) diff --git a/tests/testthat/test-pof_rtu.R b/tests/testthat/test-pof_rtu.R new file mode 100644 index 00000000..af85f607 --- /dev/null +++ b/tests/testthat/test-pof_rtu.R @@ -0,0 +1,35 @@ +library(testthat) +library(CNAIM) + +context("POF RTU") + +test_that("Default case", { + res <- pof_rtu( + placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age = 10, + observed_condition_inputs = + list("external_condition" = + list("Condition Criteria: Observed Condition" = "Default"), + "oil_gas" = list("Condition Criteria: Observed Condition" = "Default"), + "thermo_assment" = list("Condition Criteria: Observed Condition" = "Default"), + "internal_condition" = list("Condition Criteria: Observed Condition" = "Default"), + "indoor_env" = list("Condition Criteria: Observed Condition" = "Default")), + measured_condition_inputs = + list("partial_discharge" = + list("Condition Criteria: Partial Discharge Test Results" = "Default"), + "ductor_test" = list("Condition Criteria: Ductor Test Results" = "Default"), + "oil_test" = list("Condition Criteria: Oil Test Results" = "Default"), + "temp_reading" = list("Condition Criteria: Temperature Readings" = "Default"), + "trip_test" = list("Condition Criteria: Trip Timing Test Result" = "Default")), + reliability_factor = "Default", + k_value = 0.128, + c_value = 1.087, + normal_expected_life = 20) + + expected_val <- 0.006080249 + + expect_equal(res, expected_val) +}) diff --git a/tests/testthat/test-pof_switchgear_secondary_10kv.R b/tests/testthat/test-pof_switchgear_secondary_10kv.R new file mode 100644 index 00000000..65242211 --- /dev/null +++ b/tests/testthat/test-pof_switchgear_secondary_10kv.R @@ -0,0 +1,35 @@ +library(testthat) +library(CNAIM) + +context("POF switchgear secondary 10 kV") + +test_that("Default case", { + res <- pof_switchgear_secondary_10kV( + placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age = 10, + observed_condition_inputs = + list("external_condition" = + list("Condition Criteria: Observed Condition" = "Default"), + "oil_gas" = list("Condition Criteria: Observed Condition" = "Default"), + "thermo_assment" = list("Condition Criteria: Observed Condition" = "Default"), + "internal_condition" = list("Condition Criteria: Observed Condition" = "Default"), + "indoor_env" = list("Condition Criteria: Observed Condition" = "Default")), + measured_condition_inputs = + list("partial_discharge" = + list("Condition Criteria: Partial Discharge Test Results" = "Default"), + "ductor_test" = list("Condition Criteria: Ductor Test Results" = "Default"), + "oil_test" = list("Condition Criteria: Oil Test Results" = "Default"), + "temp_reading" = list("Condition Criteria: Temperature Readings" = "Default"), + "trip_test" = list("Condition Criteria: Trip Timing Test Result" = "Default")), + reliability_factor = "Default", + k_value = 0.0067, + c_value = 1.087, + normal_expected_life = 55) * 100 + + expected_val <- 0.0001496819 + + expect_equal(res, expected_val) +}) From 00675fe50421cc4b30ad3c97f9ee8cfa4deb3bf9 Mon Sep 17 00:00:00 2001 From: NicolaiHandreck Date: Tue, 26 Jul 2022 08:35:45 +0200 Subject: [PATCH 05/10] last tests added --- tests/testthat/test-pof_switchgear_30_60kv.R | 62 ++++++++++++++++++++ tests/testthat/test-pof_switchgear_primary.R | 30 ++++++++++ 2 files changed, 92 insertions(+) create mode 100644 tests/testthat/test-pof_switchgear_30_60kv.R create mode 100644 tests/testthat/test-pof_switchgear_primary.R diff --git a/tests/testthat/test-pof_switchgear_30_60kv.R b/tests/testthat/test-pof_switchgear_30_60kv.R new file mode 100644 index 00000000..2899071a --- /dev/null +++ b/tests/testthat/test-pof_switchgear_30_60kv.R @@ -0,0 +1,62 @@ +library(testthat) +library(CNAIM) + +context("POF switchgear 30 and 60 kV") + +test_that("30 kV category", { + res <- pof_ehv_switchgear( + ehv_asset_category = "30kV", + placement = "Default", + number_of_operations = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age = 10, + observed_condition_inputs =list("external_condition" = list("Condition Criteria: Observed Condition" = "Default"), + "oil_gas" = list("Condition Criteria: Observed Condition" = "Default"), + "thermo_assment" = list("Condition Criteria: Observed Condition" = "Default"), + "internal_condition" = list("Condition Criteria: Observed Condition" = "Default"), + "indoor_env" = list("Condition Criteria: Observed Condition" = "Default"), + "support_structure" = list("Condition Criteria: Observed Condition" = "Default")), + measured_condition_inputs = list("partial_discharge" = list("Condition Criteria: Partial Discharge Test Results" = "Default"), + "ductor_test" = list("Condition Criteria: Ductor Test Results" = "Default"), + "oil_test" = list("Condition Criteria: Oil Test Results" = "Default"), + "temp_reading" = list("Condition Criteria: Temperature Readings" = "Default"), + "trip_test" = list("Condition Criteria: Trip Timing Test Result" = "Default"), + "ir_test" = list("Condition Criteria: IR Test Results" = "Default" )), + reliability_factor = "Default") %>% round(5) + + expected_val <- 0.0005 + + expect_equal(res, expected_val) +}) + + + +test_that("60 kV category", { + res <- pof_ehv_switchgear( + ehv_asset_category = "60kV", + placement = "Default", + number_of_operations = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age = 10, + observed_condition_inputs =list("external_condition" = list("Condition Criteria: Observed Condition" = "Default"), + "oil_gas" = list("Condition Criteria: Observed Condition" = "Default"), + "thermo_assment" = list("Condition Criteria: Observed Condition" = "Default"), + "internal_condition" = list("Condition Criteria: Observed Condition" = "Default"), + "indoor_env" = list("Condition Criteria: Observed Condition" = "Default"), + "support_structure" = list("Condition Criteria: Observed Condition" = "Default")), + measured_condition_inputs = list("partial_discharge" = list("Condition Criteria: Partial Discharge Test Results" = "Default"), + "ductor_test" = list("Condition Criteria: Ductor Test Results" = "Default"), + "oil_test" = list("Condition Criteria: Oil Test Results" = "Default"), + "temp_reading" = list("Condition Criteria: Temperature Readings" = "Default"), + "trip_test" = list("Condition Criteria: Trip Timing Test Result" = "Default"), + "ir_test" = list("Condition Criteria: IR Test Results" = "Default" )), + reliability_factor = "Default") %>% round(5) + + expected_val <- 0.00118 + + expect_equal(res, expected_val) +}) diff --git a/tests/testthat/test-pof_switchgear_primary.R b/tests/testthat/test-pof_switchgear_primary.R new file mode 100644 index 00000000..5fa2800e --- /dev/null +++ b/tests/testthat/test-pof_switchgear_primary.R @@ -0,0 +1,30 @@ +library(testthat) +library(CNAIM) + +context("POF switchgear primary 10kV") + +test_that("Default case", { + res <- pof_hv_switchgear_primary( + number_of_operations = "Default", + placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age = 10, + observed_condition_inputs =list("external_condition" = list("Condition Criteria: Observed Condition" = "Default"), + "oil_gas" = list("Condition Criteria: Observed Condition" = "Default"), + "thermo_assment" = list("Condition Criteria: Observed Condition" = "Default"), + "internal_condition" = list("Condition Criteria: Observed Condition" = "Default"), + "indoor_env" = list("Condition Criteria: Observed Condition" = "Default")), + measured_condition_inputs = list("partial_discharge" = list("Condition Criteria: Partial Discharge Test Results" = "Default"), + "ductor_test" = list("Condition Criteria: Ductor Test Results" = "Default"), + "oil_test" = list("Condition Criteria: Oil Test Results" = "Default"), + "temp_reading" = list("Condition Criteria: Temperature Readings" = "Default"), + "trip_test" = list("Condition Criteria: Trip Timing Test Result" = "Default"), + "ir_test" = list("Condition Criteria: IR Test Results" = "Default" )), + reliability_factor = "Default") %>% round(5) + + expected_val <- 0.00012 + + expect_equal(res, expected_val) +}) From 08b69f2880cfff958205b6fd92d904e3344c7cf6 Mon Sep 17 00:00:00 2001 From: NicolaiHandreck Date: Wed, 3 Aug 2022 15:24:43 +0200 Subject: [PATCH 06/10] updated --- R/pof_future_tower_ohl_support_50kv.R | 1 + tests/testthat/test-cof_board_04kv.R | 4 +- tests/testthat/test-cof_cables_04_10kv.R | 18 ++-- tests/testthat/test-cof_cables_60_30kv.R | 4 +- tests/testthat/test-cof_ohl_cond_50kv.R | 2 +- tests/testthat/test-cof_ohl_fittings_50kv.R | 4 +- tests/testthat/test-cof_pillar_04kv.R | 4 +- tests/testthat/test-cof_poles_support_50kv.R | 4 +- tests/testthat/test-cof_relay.R | 10 +- tests/testthat/test-cof_serviceline.R | 2 +- .../testthat/test-cof_submarine_cables_10kv.R | 4 +- .../test-cof_submarine_cables_30_60kv.R | 6 +- tests/testthat/test-cof_switchgear_30_60kv.R | 8 +- .../test-cof_switchgear_primary_10kv.R | 10 +- .../test-cof_switchgear_secondary_10kv.R | 10 +- .../test-cof_tower_ohl_support_50kv.R | 10 +- tests/testthat/test-cof_transformer_04_10kv.R | 2 +- tests/testthat/test-cof_transformer_30_60kv.R | 8 +- .../test-pof_future_poles_support_50kv.R | 35 +++++++ .../test-pof_future_submarine_30_60kv_oil.R | 2 +- ...est-pof_future_submarine_cables_10kv_oil.R | 2 +- .../test-pof_future_tower_ohl_support_50kv.R | 4 +- tests/testthat/test-pof_switchgear_30_60kv.R | 96 +++++++++++-------- .../test-pof_switchgear_secondary_10kv.R | 2 +- tests/testthat/test-pof_transformer_30_60kv.R | 4 +- 25 files changed, 154 insertions(+), 102 deletions(-) create mode 100644 tests/testthat/test-pof_future_poles_support_50kv.R diff --git a/R/pof_future_tower_ohl_support_50kv.R b/R/pof_future_tower_ohl_support_50kv.R index 1864fdc5..4631079e 100644 --- a/R/pof_future_tower_ohl_support_50kv.R +++ b/R/pof_future_tower_ohl_support_50kv.R @@ -263,6 +263,7 @@ pof_future_tower_ohl_support_50kv <- # the Health Score of a new asset H_new <- 0.5 + b1 <- 0.5 # the Health Score of the asset when it reaches its Expected Life b2 <- beta_2(current_health_score, age) diff --git a/tests/testthat/test-cof_board_04kv.R b/tests/testthat/test-cof_board_04kv.R index b3c881a9..b77d35e3 100644 --- a/tests/testthat/test-cof_board_04kv.R +++ b/tests/testthat/test-cof_board_04kv.R @@ -34,12 +34,14 @@ test_that("LV Board(WM)", { }) +#something wrong with the network cof context("COF:Network Board 0.4 kV") test_that("LV Board(WM)", { res <- network_cof_board_04kv(no_customers = 750, kva_per_customer = 51) - expected_value <- 6730924 + expected_value <- 6730924.69 %>% round(2) expect_equal(res, expected_value) }) + diff --git a/tests/testthat/test-cof_cables_04_10kv.R b/tests/testthat/test-cof_cables_04_10kv.R index f66a9c4d..72f06e49 100644 --- a/tests/testthat/test-cof_cables_04_10kv.R +++ b/tests/testthat/test-cof_cables_04_10kv.R @@ -14,9 +14,9 @@ test_that("10kV UG Cable (Oil)", { context("COF:Financial Cables: 10 kV UG Cable PEX") test_that("10kV UG Cable (Non Pressurised)", { - res <- financial_cof_cables_04_10kv(hv_asset_category = "10kV UG Cable (Non Pressurised)") + res <- round(financial_cof_cables_04_10kv(hv_asset_category = "10kV UG Cable (Non Pressurised)"), digits=0) - expected_value <- 275619.2 + expected_value <- 275619 expect_equal(res, expected_value) }) @@ -24,9 +24,9 @@ test_that("10kV UG Cable (Non Pressurised)", { context("COF:Financial Cables: 0.4 kV UG Cable PEX") test_that("0.4kV UG Cable (Non Pressurised)", { - res <- financial_cof_cables_04_10kv(hv_asset_category = "0.4kV UG Cable (Non Pressurised)") + res <- round(financial_cof_cables_04_10kv(hv_asset_category = "0.4kV UG Cable (Non Pressurised)"), digits=0) - expected_value <- 275619.2 + expected_value <- 275619 expect_equal(res, expected_value) }) @@ -69,11 +69,11 @@ test_that("0.4kV UG Cable (Non Pressurised)", { context("COF:Env Cables: 10 kV UG Cable Oil") test_that("10kV UG Cable (Oil)", { - res <- environmental_cof_cables_04_10kv(hv_asset_category = "10kV UG Cable (Oil)", + res <- round(environmental_cof_cables_04_10kv(hv_asset_category = "10kV UG Cable (Oil)", prox_water = 95, - bunded = "Yes") + bunded = "Yes"), digits=1) - expected_value <- 25629.18 + expected_value <- 25629.2 expect_equal(res, expected_value) }) @@ -129,8 +129,8 @@ test_that("10kV UG Cable (Non Pressurised)", { context("COF:Network Cables: 0.4 kV UG Cable PEX") test_that("0.4kV UG Cable (Non Pressurised)", { - res <- network_cof_cof_cables_04_10kv(hv_asset_category = "0.4kV UG Cable (Non Pressurised)", - actual_load_mva = 15, secure = T) %>% round(2) + res <- network_cof_cables_04_10kv(hv_asset_category = "0.4kV UG Cable (Non Pressurised)", + actual_load_mva = 15, secure = T) %>% round(2) expected_value <- 38432.88 diff --git a/tests/testthat/test-cof_cables_60_30kv.R b/tests/testthat/test-cof_cables_60_30kv.R index 02518ecd..7ba1ce29 100644 --- a/tests/testthat/test-cof_cables_60_30kv.R +++ b/tests/testthat/test-cof_cables_60_30kv.R @@ -51,9 +51,9 @@ context("COF:Env Cables: 30 kV") test_that("30kV UG Cable (Oil)", { res <- environmental_cof_cables_60_30kv(ehv_asset_category = "30kV UG Cable (Oil)", prox_water = 95, - bunded = "Yes") + bunded = "Yes") %>% round(0) - expected_value <- 25629.18 + expected_value <- 25629 expect_equal(res, expected_value) }) diff --git a/tests/testthat/test-cof_ohl_cond_50kv.R b/tests/testthat/test-cof_ohl_cond_50kv.R index c6d99283..926dd22a 100644 --- a/tests/testthat/test-cof_ohl_cond_50kv.R +++ b/tests/testthat/test-cof_ohl_cond_50kv.R @@ -41,7 +41,7 @@ test_that("50kV OHL (Tower Line) Conductor", { context("COF:Network Overhead Line conductor: 50 kV") test_that("50kV OHL (Tower Line) Conductor", { - res <- network_cof_ohl_cond_50kv(actual_load_mva = 15) + res <- network_cof_ohl_cond_50kv(actual_load_mva = 15) %>% round(2) expected_value <- 14513.04 expect_equal(res, expected_value) diff --git a/tests/testthat/test-cof_ohl_fittings_50kv.R b/tests/testthat/test-cof_ohl_fittings_50kv.R index 1cc18eb2..c2176f9d 100644 --- a/tests/testthat/test-cof_ohl_fittings_50kv.R +++ b/tests/testthat/test-cof_ohl_fittings_50kv.R @@ -37,8 +37,8 @@ test_that("50kV Fittings", { context("COF:Network 50 kV OHL Fittings") test_that("50kV Fittings", { - res <- network_cof_ohl_fittings_50kv(actual_load_mva = 15) - expected_value <- 2901.519 + res <- network_cof_ohl_fittings_50kv(actual_load_mva = 15) %>% round(2) + expected_value <- 2901.52 expect_equal(res, expected_value) }) diff --git a/tests/testthat/test-cof_pillar_04kv.R b/tests/testthat/test-cof_pillar_04kv.R index 7130e651..00a1cb2c 100644 --- a/tests/testthat/test-cof_pillar_04kv.R +++ b/tests/testthat/test-cof_pillar_04kv.R @@ -38,8 +38,8 @@ context("COF:Network Pillar 0.4 kV") test_that("LV Pillar (ID)", { res <- network_cof_pillar_04kv(no_customers = 750, - kva_per_customer = 51) - expected_value <- 6730924 + kva_per_customer = 51) %>% round(2) + expected_value <- 6730924.69 expect_equal(res, expected_value) }) diff --git a/tests/testthat/test-cof_poles_support_50kv.R b/tests/testthat/test-cof_poles_support_50kv.R index 7b8eb2af..202e2f77 100644 --- a/tests/testthat/test-cof_poles_support_50kv.R +++ b/tests/testthat/test-cof_poles_support_50kv.R @@ -44,9 +44,9 @@ test_that("50kV pole", { context("COF:Network Poles: 50 kV") test_that("50kV Pole", { - res <- network_cof_poles_ohl_support_50kv(actual_load_mva = 15) + res <- network_cof_poles_ohl_support_50kv(actual_load_mva = 15) %>% round(2) - expected_value <- 996.2063 + expected_value <- 996.21 expect_equal(res, expected_value) }) diff --git a/tests/testthat/test-cof_relay.R b/tests/testthat/test-cof_relay.R index 44c71088..e7b5f3d6 100644 --- a/tests/testthat/test-cof_relay.R +++ b/tests/testthat/test-cof_relay.R @@ -4,7 +4,7 @@ library(CNAIM) context("COF:Financial Relay") test_that("6.6/11kV CB (GM) Secondary", { - res <- financial_cof_relay(access_factor_criteria = "Type A") + res <- financial_cof_relay(access_factor_criteria = "Type A") %>% round(2) expected_value <- 30306.45 @@ -18,7 +18,7 @@ context("COF:Safety Relay") test_that("6.6/11kV CB (GM) Secondary", { res <- safety_cof_relay(location_risk = "Default", - type_risk = "Default") + type_risk = "Default") %>% round(2) expected_value <- 21004.17 @@ -33,7 +33,7 @@ context("COF:Environmental Relay") test_that("6.6/11kV CB (GM) Secondary", { res <- environmental_cof_relay(type_env_factor = "Oil", prox_water = 95, - bunded = "Yes") + bunded = "Yes") %>% round(2) expected_value <- 3171.05 expect_equal(res, expected_value) @@ -44,9 +44,9 @@ test_that("6.6/11kV CB (GM) Secondary", { context("COF:Network Relay") test_that("6.6/11kV CB (GM) Secondary", { - res <- network_cof_relay(no_customers = 100, kva_per_customer = 40) + res <- network_cof_relay(no_customers = 100, kva_per_customer = 40) %>% round(2) - expected_value <- 6303.863 + expected_value <- 6303.86 expect_equal(res, expected_value) }) diff --git a/tests/testthat/test-cof_serviceline.R b/tests/testthat/test-cof_serviceline.R index 3341b10b..8b2ea99c 100644 --- a/tests/testthat/test-cof_serviceline.R +++ b/tests/testthat/test-cof_serviceline.R @@ -4,7 +4,7 @@ library(CNAIM) context("COF:Financial Cables: Serviceline") test_that("serviceline" , { - res <- financial_cof_serviceline() + res <- financial_cof_serviceline() %>% round(1) expected_value <- 137809.6 diff --git a/tests/testthat/test-cof_submarine_cables_10kv.R b/tests/testthat/test-cof_submarine_cables_10kv.R index 66df84a2..918d791c 100644 --- a/tests/testthat/test-cof_submarine_cables_10kv.R +++ b/tests/testthat/test-cof_submarine_cables_10kv.R @@ -4,7 +4,7 @@ library(CNAIM) context("COF:Financial Sub Cables: 10kV") test_that("HV Sub Cable", { - res <- financial_cof_submarine_cables_10kv() + res <- financial_cof_submarine_cables_10kv() %>% round(0) expected_value <- 1585185 expect_equal(res, expected_value) @@ -29,7 +29,7 @@ test_that("HV Sub Cable", { context("COF:Env Sub Cables: 10kV") test_that("HV Sub Cable", { - res <- environmental_cof_submarine_cables_10kv() + res <- environmental_cof_submarine_10kv() expected_value <- 31356 expect_equal(res, expected_value) diff --git a/tests/testthat/test-cof_submarine_cables_30_60kv.R b/tests/testthat/test-cof_submarine_cables_30_60kv.R index eb7e35fc..ebf2db30 100644 --- a/tests/testthat/test-cof_submarine_cables_30_60kv.R +++ b/tests/testthat/test-cof_submarine_cables_30_60kv.R @@ -4,7 +4,7 @@ library(CNAIM) context("COF:Financial Sub Cables: EHV") test_that("EHV Sub Cable", { - res <- financial_cof_submarine_cables_30_60kv() + res <- financial_cof_submarine_cables_30_60kv() %>% round(0) expected_value <- 2485155 expect_equal(res, expected_value) @@ -28,7 +28,7 @@ test_that("EHV Sub Cable", { context("COF:Env Sub Cables: EHV") test_that("EHV Sub Cable", { - res <- environmental_cof_submarine_cables_30_60kv() + res <- environmental_cof_submarine_30_60kv() expected_value <- 31356 expect_equal(res, expected_value) @@ -41,7 +41,7 @@ context("COF:Network Sub Cables: EHV") test_that("EHV Sub Cable", { res <- network_cof_submarine_cables_30_60kv(no_customers = 250, - kva_per_customer = 51) + kva_per_customer = 51) %>% round(0) expected_value <- 12952314 diff --git a/tests/testthat/test-cof_switchgear_30_60kv.R b/tests/testthat/test-cof_switchgear_30_60kv.R index 41d7b193..bccdd776 100644 --- a/tests/testthat/test-cof_switchgear_30_60kv.R +++ b/tests/testthat/test-cof_switchgear_30_60kv.R @@ -5,7 +5,7 @@ context("COF:Financial Switchgear 30/60 kV") test_that("30kV", { res <- financial_cof_switchgear_30_60kv(ehv_asset_category = "30kV", - access_factor_criteria = "Type A") + access_factor_criteria = "Type A") %>% round(1) expected_value <- 126408.2 @@ -20,7 +20,7 @@ context("COF:Safety Switchgear 30/60 kV") test_that("30kV", { res <- safety_cof_switchgear_30_60kv(ehv_asset_category = "30kV", location_risk = "Default", - type_risk = "Default") + type_risk = "Default") %>% round(1) expected_value <- 204702.4 expect_equal(res, expected_value) @@ -35,7 +35,7 @@ test_that("30kV", { res <- environmental_cof_switchgear_30_60kv(ehv_asset_category = "30kV", type_env_factor = "Oil", prox_water = 95, - bunded = "Yes") + bunded = "Yes") %>% round(2) expected_value <- 17642.45 expect_equal(res, expected_value) @@ -47,7 +47,7 @@ context("COF:Network Switchgear 30/60 kV") test_that("30kV", { res <- network_cof_switchgear_30_60kv(ehv_asset_category = "30kV", - actual_load_mva = 15) + actual_load_mva = 15) %>% round(1) expected_value <- 126817.6 expect_equal(res, expected_value) diff --git a/tests/testthat/test-cof_switchgear_primary_10kv.R b/tests/testthat/test-cof_switchgear_primary_10kv.R index d10c3a80..19df6b2a 100644 --- a/tests/testthat/test-cof_switchgear_primary_10kv.R +++ b/tests/testthat/test-cof_switchgear_primary_10kv.R @@ -4,7 +4,7 @@ library(CNAIM) context("COF:Financial switchgear primary 10 kV") test_that("6.6/11kV CB (GM) Primary", { - res <- financial_cof_switchgear_primary_10kv(access_factor_criteria = "Type A") + res <- financial_cof_switchgear_primary_10kv(access_factor_criteria = "Type A") %>% round(2) expected_value <- 66074.06 @@ -16,7 +16,7 @@ context("COF:Safety switchgear primary 10 kV") test_that("6.6/11kV CB (GM) Primary", { res <- safety_cof_switchgear_primary_10kv(location_risk = "Default", - type_risk = "Default") + type_risk = "Default") %>% round(1) expected_value <- 204702.4 expect_equal(res, expected_value) @@ -28,8 +28,8 @@ context("COF:Environmental switchgear primary 10 kV") test_that("6.6/11kV CB (GM) Primary", { res <- environmental_cof_switchgear_primary_10kv(type_env_factor = "Oil", prox_water = 95, - bunded = "Yes") - expected_value <- 6535.069 + bunded = "Yes") %>% round(2) + expected_value <- 6535.07 expect_equal(res, expected_value) }) @@ -39,7 +39,7 @@ context("COF:Network switchgear primary 10 kV") test_that("6.6/11kV CB (GM) Primary", { res <- network_cof_switchgear_primary_10kv(no_customers = 750, - kva_per_customer = 51) + kva_per_customer = 51) %>% round(0) expected_value <- 6619056 expect_equal(res, expected_value) diff --git a/tests/testthat/test-cof_switchgear_secondary_10kv.R b/tests/testthat/test-cof_switchgear_secondary_10kv.R index da618175..854e4d29 100644 --- a/tests/testthat/test-cof_switchgear_secondary_10kv.R +++ b/tests/testthat/test-cof_switchgear_secondary_10kv.R @@ -4,7 +4,7 @@ library(CNAIM) context("COF:Financial switchgear secondary 10 kV") test_that("6.6/11kV CB (GM) Secondary", { - res <- financial_cof_switchgear_secondary_10kv(access_factor_criteria = "Type A") + res <- financial_cof_switchgear_secondary_10kv(access_factor_criteria = "Type A") %>% round(2) expected_value <- 60612.89 @@ -16,7 +16,7 @@ context("COF:Safety switchgear secondary 10 kV") test_that("6.6/11kV CB (GM) Secondary", { res <- safety_cof_switchgear_secondary_10kv(location_risk = "Default", - type_risk = "Default") + type_risk = "Default") %>% round(2) expected_value <- 42008.33 expect_equal(res, expected_value) @@ -28,8 +28,8 @@ context("COF:Environmental switchgear secondary 10 kV") test_that("6.6/11kV CB (GM) Secondary", { res <- environmental_cof_switchgear_secondary_10kv(type_env_factor = "Oil", prox_water = 95, - bunded = "Yes") - expected_value <- 6342.099 + bunded = "Yes") %>% round(2) + expected_value <- 6342.10 expect_equal(res, expected_value) }) @@ -39,7 +39,7 @@ context("COF:Network switchgear secondary 10 kV") test_that("6.6/11kV CB (GM) Secondary", { res <- network_cof_switchgear_secondary_10kv(no_customers = 250, - kva_per_customer = 51) + kva_per_customer = 51) %>% round(1) expected_value <- 787982.8 expect_equal(res, expected_value) diff --git a/tests/testthat/test-cof_tower_ohl_support_50kv.R b/tests/testthat/test-cof_tower_ohl_support_50kv.R index 5a0a6cab..7ce480f8 100644 --- a/tests/testthat/test-cof_tower_ohl_support_50kv.R +++ b/tests/testthat/test-cof_tower_ohl_support_50kv.R @@ -5,7 +5,7 @@ context("COF:Financial Tower: 50 kV") test_that("50kV Tower", { res <- financial_cof_tower_ohl_support_50kv(type_financial_factor_criteria = "Suspension", - access_factor_criteria = "Type A") + access_factor_criteria = "Type A") %>% round(1) expected_value <- 110155.4 @@ -20,7 +20,7 @@ context("COF:Safety Tower: 50 kV") test_that("50kV Tower", { res <- safety_cof_tower_ohl_support_50kv(location_risk = "Default", - type_risk = "Default") + type_risk = "Default") %>% round(2) expected_value <- 3283.67 expect_equal(res, expected_value) @@ -32,7 +32,7 @@ test_that("50kV Tower", { context("COF:Env Tower: 50 kV") test_that("50kV Tower", { - res <- environmental_cof_tower_ohl_support_50kv() + res <- environmental_cof_tower_ohl_support_50kv() %>% round(2) expected_value <- 1620.06 expect_equal(res, expected_value) @@ -44,8 +44,8 @@ test_that("50kV Tower", { context("COF:Network Tower: 50 kV") test_that("50kV Tower", { - res <- network_cof_tower_ohl_support_50kv(actual_load_mva = 15) - expected_value <- 9052.956 + res <- network_cof_tower_ohl_support_50kv(actual_load_mva = 15) %>% round(2) + expected_value <- 9052.96 expect_equal(res, expected_value) }) diff --git a/tests/testthat/test-cof_transformer_04_10kv.R b/tests/testthat/test-cof_transformer_04_10kv.R index 43733fd7..faae9977 100644 --- a/tests/testthat/test-cof_transformer_04_10kv.R +++ b/tests/testthat/test-cof_transformer_04_10kv.R @@ -10,6 +10,6 @@ test_that("cof_transformer_04_10kv", { location_risk = "High", prox_water = 50, bunded = "No", no_customers = 500, - kva_per_customer = 1), 373500.5) + kva_per_customer = 1) %>% round(1), 373500.5) }) diff --git a/tests/testthat/test-cof_transformer_30_60kv.R b/tests/testthat/test-cof_transformer_30_60kv.R index 8b74fd23..fc5409c5 100644 --- a/tests/testthat/test-cof_transformer_30_60kv.R +++ b/tests/testthat/test-cof_transformer_30_60kv.R @@ -6,7 +6,7 @@ context("COF:Financial Transformers: 30/10kv and 60/10kv") test_that("30kV Transformer (GM)", { res <- financial_cof_transformer_30_60kv(tf_asset_category = "30kV Transformer (GM)", type_financial_factor_kva_mva = 20, - access_factor_criteria = "Type A") + access_factor_criteria = "Type A") %>% round(0) expected_value <- 1291480 @@ -21,7 +21,7 @@ context("COF:Safety Transformers: 30/10kv and 60/10kv") test_that("30kV Transformer (GM)", { res <- safety_cof_transformer_30_60kv(tf_asset_category = "30kV Transformer (GM)", location_risk = "Default", - type_risk = "Default") + type_risk = "Default") %>% round(1) expected_value <- 204702.4 expect_equal(res, expected_value) @@ -36,7 +36,7 @@ test_that("30kV Transformer (GM)", { res <- environmental_cof_transformer_30_60kv(tf_asset_category = "30kV Transformer (GM)", prox_water = 95, bunded = "Yes", - size_kva_mva = 20) + size_kva_mva = 20) %>% round(1) expected_value <- 118790.5 @@ -50,7 +50,7 @@ context("COF:Network Transformers: 30/10kv and 60/10kv") test_that("30kV Transformer", { res <- network_cof_transformer_30_60kv(tf_asset_category = "30kV Transformer (GM)", - actual_load_mva = 15) + actual_load_mva = 15) %>% round(1) expected_value <- 252067.4 expect_equal(res, expected_value) diff --git a/tests/testthat/test-pof_future_poles_support_50kv.R b/tests/testthat/test-pof_future_poles_support_50kv.R new file mode 100644 index 00000000..42a01738 --- /dev/null +++ b/tests/testthat/test-pof_future_poles_support_50kv.R @@ -0,0 +1,35 @@ +library(testthat) +library(CNAIM) + +context("Future Probability of Failure for a 50 kV OHL support poles") + +test_that("pof_future_poles_support_50kv", { + + res <- + pof_future_poles_ohl_support_50kv( + sub_division = "Wood", + placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age = 10, + observed_condition_inputs = + list("visual_pole_cond" = + list("Condition Criteria: Pole Top Rot Present?" = "Default"), + "pole_leaning" = list("Condition Criteria: Pole Leaning?" = "Default"), + "bird_animal_damage" = + list("Condition Criteria: Bird/Animal Damage?" = "Default"), + "top_rot" = list("Condition Criteria: Pole Top Rot Present?" = "Default")), + measured_condition_inputs = + list("pole_decay" = + list("Condition Criteria: Degree of Decay/Deterioration" = "Default")), + reliability_factor = "Default", + k_value = 0.0285, + c_value = 1.087, + normal_expected_life = "Default", + simulation_end_year = 100) + + + expect_equal(res$PoF[which(res$year == 20)], 0.008122628) + +}) diff --git a/tests/testthat/test-pof_future_submarine_30_60kv_oil.R b/tests/testthat/test-pof_future_submarine_30_60kv_oil.R index ef1fbe68..250b715a 100644 --- a/tests/testthat/test-pof_future_submarine_30_60kv_oil.R +++ b/tests/testthat/test-pof_future_submarine_30_60kv_oil.R @@ -22,7 +22,7 @@ test_that("pof_future_submarine_cables_30_60kv_oil", { k_value = 2.0944, c_value = 1.087, normal_expected_life = 60, - simulation_end_year = 100) + simulation_end_year = 100) %>% round(7) expect_equal(res$PoF[which(res$year == 1)], 0.5969134) diff --git a/tests/testthat/test-pof_future_submarine_cables_10kv_oil.R b/tests/testthat/test-pof_future_submarine_cables_10kv_oil.R index 037b7b9e..b91143ba 100644 --- a/tests/testthat/test-pof_future_submarine_cables_10kv_oil.R +++ b/tests/testthat/test-pof_future_submarine_cables_10kv_oil.R @@ -21,7 +21,7 @@ test_that("pof_future_submarine_cables_10kv_oil", { k_value = 2.0944, c_value = 1.087, normal_expected_life = 60, - simulation_end_year = 100) + simulation_end_year = 100) %>% round(7) expect_equal(res$PoF[which(res$year == 1)], 0.5969134) diff --git a/tests/testthat/test-pof_future_tower_ohl_support_50kv.R b/tests/testthat/test-pof_future_tower_ohl_support_50kv.R index 1a672fd3..de1d87cb 100644 --- a/tests/testthat/test-pof_future_tower_ohl_support_50kv.R +++ b/tests/testthat/test-pof_future_tower_ohl_support_50kv.R @@ -28,8 +28,8 @@ test_that("pof_future_tower_ohl_support_50kv", { k_value = 0.0545, c_value = 1.087, normal_expected_life = "Default", - simulation_end_year = 100) + simulation_end_year = 100) %>% round(4) - expect_equal(res$PoF[which(res$year == 25)], 0.01553275) + expect_equal(res$PoF[which(res$year == 25)], 0.0155) }) diff --git a/tests/testthat/test-pof_switchgear_30_60kv.R b/tests/testthat/test-pof_switchgear_30_60kv.R index 2899071a..c63fe6e2 100644 --- a/tests/testthat/test-pof_switchgear_30_60kv.R +++ b/tests/testthat/test-pof_switchgear_30_60kv.R @@ -4,29 +4,36 @@ library(CNAIM) context("POF switchgear 30 and 60 kV") test_that("30 kV category", { - res <- pof_ehv_switchgear( - ehv_asset_category = "30kV", - placement = "Default", + res <- pof_switchgear_30_60kv( + asset_type = "30kV", number_of_operations = "Default", + placement = "Default", altitude_m = "Default", distance_from_coast_km = "Default", corrosion_category_index = "Default", age = 10, - observed_condition_inputs =list("external_condition" = list("Condition Criteria: Observed Condition" = "Default"), - "oil_gas" = list("Condition Criteria: Observed Condition" = "Default"), - "thermo_assment" = list("Condition Criteria: Observed Condition" = "Default"), - "internal_condition" = list("Condition Criteria: Observed Condition" = "Default"), - "indoor_env" = list("Condition Criteria: Observed Condition" = "Default"), - "support_structure" = list("Condition Criteria: Observed Condition" = "Default")), - measured_condition_inputs = list("partial_discharge" = list("Condition Criteria: Partial Discharge Test Results" = "Default"), - "ductor_test" = list("Condition Criteria: Ductor Test Results" = "Default"), - "oil_test" = list("Condition Criteria: Oil Test Results" = "Default"), - "temp_reading" = list("Condition Criteria: Temperature Readings" = "Default"), - "trip_test" = list("Condition Criteria: Trip Timing Test Result" = "Default"), - "ir_test" = list("Condition Criteria: IR Test Results" = "Default" )), - reliability_factor = "Default") %>% round(5) - - expected_val <- 0.0005 + observed_condition_inputs = + list("external_condition" = + list("Condition Criteria: Observed Condition" = "Default"), + "oil_gas" = list("Condition Criteria: Observed Condition" = "Default"), + "thermo_assment" = list("Condition Criteria: Observed Condition" = "Default"), + "internal_condition" = list("Condition Criteria: Observed Condition" = "Default"), + "indoor_env" = list("Condition Criteria: Observed Condition" = "Default"), + "support_structure" = list("Condition Criteria: Observed Condition" = "Default")), + measured_condition_inputs = + list("partial_discharge" = + list("Condition Criteria: Partial Discharge Test Results" = "Default"), + "ductor_test" = list("Condition Criteria: Ductor Test Results" = "Default"), + "oil_test" = list("Condition Criteria: Oil Test Results" = "Default"), + "temp_reading" = list("Condition Criteria: Temperature Readings" = "Default"), + "trip_test" = list("Condition Criteria: Trip Timing Test Result" = "Default"), + "ir_test" = list("Condition Criteria: IR Test Results" = "Default" )), + reliability_factor = "Default", + k_value = "Default", + c_value = 1.087, + normal_expected_life = 55) %>% round(6) + + expected_val <- 0.000498 expect_equal(res, expected_val) }) @@ -34,29 +41,36 @@ test_that("30 kV category", { test_that("60 kV category", { - res <- pof_ehv_switchgear( - ehv_asset_category = "60kV", - placement = "Default", - number_of_operations = "Default", - altitude_m = "Default", - distance_from_coast_km = "Default", - corrosion_category_index = "Default", - age = 10, - observed_condition_inputs =list("external_condition" = list("Condition Criteria: Observed Condition" = "Default"), - "oil_gas" = list("Condition Criteria: Observed Condition" = "Default"), - "thermo_assment" = list("Condition Criteria: Observed Condition" = "Default"), - "internal_condition" = list("Condition Criteria: Observed Condition" = "Default"), - "indoor_env" = list("Condition Criteria: Observed Condition" = "Default"), - "support_structure" = list("Condition Criteria: Observed Condition" = "Default")), - measured_condition_inputs = list("partial_discharge" = list("Condition Criteria: Partial Discharge Test Results" = "Default"), - "ductor_test" = list("Condition Criteria: Ductor Test Results" = "Default"), - "oil_test" = list("Condition Criteria: Oil Test Results" = "Default"), - "temp_reading" = list("Condition Criteria: Temperature Readings" = "Default"), - "trip_test" = list("Condition Criteria: Trip Timing Test Result" = "Default"), - "ir_test" = list("Condition Criteria: IR Test Results" = "Default" )), - reliability_factor = "Default") %>% round(5) - - expected_val <- 0.00118 + res <- pof_switchgear_30_60kv( + asset_type = "60kV", + number_of_operations = "Default", + placement = "Default", + altitude_m = "Default", + distance_from_coast_km = "Default", + corrosion_category_index = "Default", + age = 10, + observed_condition_inputs = + list("external_condition" = + list("Condition Criteria: Observed Condition" = "Default"), + "oil_gas" = list("Condition Criteria: Observed Condition" = "Default"), + "thermo_assment" = list("Condition Criteria: Observed Condition" = "Default"), + "internal_condition" = list("Condition Criteria: Observed Condition" = "Default"), + "indoor_env" = list("Condition Criteria: Observed Condition" = "Default"), + "support_structure" = list("Condition Criteria: Observed Condition" = "Default")), + measured_condition_inputs = + list("partial_discharge" = + list("Condition Criteria: Partial Discharge Test Results" = "Default"), + "ductor_test" = list("Condition Criteria: Ductor Test Results" = "Default"), + "oil_test" = list("Condition Criteria: Oil Test Results" = "Default"), + "temp_reading" = list("Condition Criteria: Temperature Readings" = "Default"), + "trip_test" = list("Condition Criteria: Trip Timing Test Result" = "Default"), + "ir_test" = list("Condition Criteria: IR Test Results" = "Default" )), + reliability_factor = "Default", + k_value = "Default", + c_value = 1.087, + normal_expected_life = 55) %>% round(5) + + expected_val <- 0.00114 expect_equal(res, expected_val) }) diff --git a/tests/testthat/test-pof_switchgear_secondary_10kv.R b/tests/testthat/test-pof_switchgear_secondary_10kv.R index 65242211..413e0127 100644 --- a/tests/testthat/test-pof_switchgear_secondary_10kv.R +++ b/tests/testthat/test-pof_switchgear_secondary_10kv.R @@ -27,7 +27,7 @@ test_that("Default case", { reliability_factor = "Default", k_value = 0.0067, c_value = 1.087, - normal_expected_life = 55) * 100 + normal_expected_life = 55) expected_val <- 0.0001496819 diff --git a/tests/testthat/test-pof_transformer_30_60kv.R b/tests/testthat/test-pof_transformer_30_60kv.R index 5a1b9de7..0b261945 100644 --- a/tests/testthat/test-pof_transformer_30_60kv.R +++ b/tests/testthat/test-pof_transformer_30_60kv.R @@ -4,7 +4,7 @@ library(CNAIM) context("Current Probability of Failure for a 60kV Transformer (GM)") test_that("pof_transformer_30_60kv", { - expect_equel(pof_transformer_30_60kv(transformer_type = "60kV Transformer (GM)", + expect_equal(pof_transformer_30_60kv(transformer_type = "60kV Transformer (GM)", year_of_manufacture = 1980, utilisation_pct = "Default", no_taps = "Default", @@ -45,7 +45,7 @@ test_that("pof_transformer_30_60kv", { k_value = 0.454, c_value = 1.087, normal_expected_life_tf = "Default", - normal_expected_life_tc = "Default") ,0.1244618) + normal_expected_life_tc = "Default") %>% round(7) ,0.1244618) }) From 4f8a039994077a1e1e812dff918060429af787d4 Mon Sep 17 00:00:00 2001 From: NicolaiHandreck Date: Wed, 3 Aug 2022 15:31:03 +0200 Subject: [PATCH 07/10] Update test-pof_future_transformer_30_60kv.R --- tests/testthat/test-pof_future_transformer_30_60kv.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-pof_future_transformer_30_60kv.R b/tests/testthat/test-pof_future_transformer_30_60kv.R index 9ab0b4e2..8747c3dd 100644 --- a/tests/testthat/test-pof_future_transformer_30_60kv.R +++ b/tests/testthat/test-pof_future_transformer_30_60kv.R @@ -48,7 +48,7 @@ test_that("pof_future_transformer_30_60kv", { c_value = 1.087, normal_expected_life_tf = "Default", normal_expected_life_tc = "Default", - simulation_end_year = 100) + simulation_end_year = 100) %>% round(7) expect_equal(res$PoF[which(res$year == 12)], 0.3657150) From d5b260038306bc304d22d601a9ba16f3ff92716d Mon Sep 17 00:00:00 2001 From: NicolaiHandreck Date: Wed, 3 Aug 2022 15:44:03 +0200 Subject: [PATCH 08/10] Update pof_cables_60_30kv.R --- R/pof_cables_60_30kv.R | 100 ++++++++++++++++++++++++----------------- 1 file changed, 58 insertions(+), 42 deletions(-) diff --git a/R/pof_cables_60_30kv.R b/R/pof_cables_60_30kv.R index d5b55593..de224bf1 100644 --- a/R/pof_cables_60_30kv.R +++ b/R/pof_cables_60_30kv.R @@ -1,15 +1,12 @@ #' @importFrom magrittr %>% -#' @title Current Probability of Failure for 30-60kV cables +#' @title Current Probability of Failure for 30-60kV Cables #' @description This function calculates the current #' annual probability of failure per kilometer for a 30-60kV cables. #' The function is a cubic curve that is based on #' the first three terms of the Taylor series for an -#' exponential function. For more information about the -#' probability of failure function see section 6 -#' on page 34 in CNAIM (2021). +#' exponential function. #' @param cable_type String. #' A sting that refers to the specific asset category. -#' See See page 17, table 1 in CNAIM (2021). #' Options: #' \code{cable_type = c("30kV UG Cable (Gas)", "60kV UG Cable (Gas)", #' "30kV UG Cable (Non Pressurised)", "60kV UG Cable (Non Pressurised)", @@ -20,47 +17,55 @@ #' made of. Options: #' \code{sub_division = c("Aluminium sheath - Aluminium conductor", #' "Aluminium sheath - Copper conductor", -#' "Lead sheath - Aluminium conductor", "Lead sheath - Copper conductor") -#'} +#' "Lead sheath - Aluminium conductor", "Lead sheath - Copper conductor")} #' @inheritParams duty_factor_cables #' @param sheath_test String. Only applied for non pressurised cables. #' Indicating the state of the sheath. Options: #' \code{sheath_test = c("Pass", "Failed Minor", "Failed Major", -#' "Default")}. See page 153, table 168 in CNAIM (2021). +#' "Default")}. #' @param partial_discharge String. Only applied for non pressurised cables. #' Indicating the level of partial discharge. Options: #' \code{partial_discharge = c("Low", "Medium", "High", -#' "Default")}. See page 153, table 169 in CNAIM (2021). +#' "Default")}. #' @param fault_hist Numeric. Only applied for non pressurised cables. #' The calculated fault rate for the cable in the period per kilometer. #' A setting of \code{"No historic faults recorded"} -#' indicates no fault. See page 153, table 170 in CNAIM (2021). +#' indicates no fault. #' @param leakage String. Only applied for oil and gas pressurised cables. #' Options: #' \code{leakage = c("No (or very low) historic leakage recorded", #' "Low/ moderate", "High", "Very High", "Default")}. -#' See page 157, table 182 (oil) and 183 (gas) in CNAIM (2021). #' @inheritParams current_health #' @param age Numeric. The current age in years of the cable. +#' @param k_value Numeric. \code{k_value = "Default"} by default. This number is +#' given in a percentage. The default value is accordingly to the CNAIM standard +#' on p. 110. +#' @param c_value Numeric. \code{c_value = 1.087} by default. +#' The default value is accordingly to the CNAIM standard see page 110 +#' @param normal_expected_life Numeric. \code{normal_expected_life = "Default"} by default. +#' The default value is accordingly to the CNAIM standard on page 107. #' @return Numeric. Current probability of failure #' per annum per kilometre for 60/30kV cables. -#' @source DNO Common Network Asset Indices Methodology (CNAIM), -#' Health & Criticality - Version 2.1, 2021: -#' \url{https://www.ofgem.gov.uk/sites/default/files/docs/2021/04/dno_common_network_asset_indices_methodology_v2.1_final_01-04-2021.pdf} #' @export #' @examples #' # Current annual probability of failure for #' # "60kV UG Cable (Non Pressurised)", 50 years old -#'pof_cables_60_30kv(cable_type = "66kV UG Cable (Non Pressurised)", -#'sub_division = "Lead sheath - Copper conductor", -#'utilisation_pct = 80, -#'operating_voltage_pct = 60, -#'sheath_test = "Default", -#'partial_discharge = "Default", -#'fault_hist = "Default", -#'leakage = "Default", -#'reliability_factor = "Default", -#'age = 50) * 100 +# pof_cables_60_30kv_res <- +# pof_cables_60_30kv(cable_type = "60kV UG Cable (Non Pressurised)", +# sub_division = "Lead sheath - Copper conductor", +# utilisation_pct = 80, +# operating_voltage_pct = 60, +# sheath_test = "Default", +# partial_discharge = "Default", +# fault_hist = "Default", +# leakage = "Default", +# reliability_factor = "Default", +# age = 50, +# k_value = "Default", +# c_value = 1.087, +# normal_expected_life = "Default") * 100 +# paste0(sprintf("Probability of failure %.4f", pof_cables_60_30kv_res), +# " percent per annum") pof_cables_60_30kv <- function(cable_type = "60kV UG Cable (Gas)", sub_division = "Aluminium sheath - Aluminium conductor", @@ -71,7 +76,10 @@ pof_cables_60_30kv <- fault_hist = "Default", leakage = "Default", reliability_factor = "Default", - age) { + age, + k_value = "Default", + c_value = 1.087, + normal_expected_life = "Default") { if (cable_type == "30kV UG Cable (Non Pressurised)" ) { cable_type <- "33kV UG Cable (Non Pressurised)" @@ -112,12 +120,21 @@ pof_cables_60_30kv <- dplyr::select(`Generic Term...2`) %>% dplyr::pull() # Normal expected life ------------------------- - normal_expected_life_cable <- gb_ref$normal_expected_life %>% - dplyr::filter(`Asset Register Category` == cable_type & - `Sub-division` == sub_division) %>% - dplyr::pull() + + + if (normal_expected_life == "Default") { + normal_expected_life_cable <- gb_ref$normal_expected_life %>% + dplyr::filter(`Asset Register Category` == cable_type & + `Sub-division` == sub_division) %>% + dplyr::pull() + } else { + normal_expected_life_cable <- normal_expected_life + } + + # Constants C and K for PoF function -------------------------------------- + if (asset_category == "EHV UG Cable (Non Pressurised)") { type_k_c <- gb_ref$pof_curve_parameters$`Functional Failure Category`[which( @@ -135,16 +152,16 @@ pof_cables_60_30kv <- )] } - k <- gb_ref$pof_curve_parameters %>% - dplyr::filter(`Functional Failure Category` == - type_k_c) %>% dplyr::select(`K-Value (%)`) %>% - dplyr::pull()/100 - - c <- gb_ref$pof_curve_parameters %>% - dplyr::filter(`Functional Failure Category` == - type_k_c) %>% dplyr::select(`C-Value`) %>% - dplyr::pull() + if (k_value == "Default") { + k <- gb_ref$pof_curve_parameters %>% + dplyr::filter(`Functional Failure Category` == + type_k_c) %>% dplyr::select(`K-Value (%)`) %>% + dplyr::pull()/100 + } else { + k <- k_value/100 + } + c <- c_value # Duty factor ------------------------------------------------------------- duty_factor_cable <- @@ -169,12 +186,11 @@ pof_cables_60_30kv <- # of the Health Score. However, in some instances # these parameters are set to other values in the # Health Score Modifier calibration tables. - # These overriding values are shown in Table 35 to Table 202 - # and Table 207 in Appendix B. + # Measured condition inputs --------------------------------------------- - asset_category_mmi <- gsub(pattern = "UG", "", asset_category) - asset_category_mmi <- gsub("(?<=[\\s])\\s*|^\\s+|\\s+$", "", asset_category_mmi, perl=TRUE) + asset_category_mmi <- stringr::str_remove(asset_category, pattern = "UG") + asset_category_mmi <- stringr::str_squish(asset_category_mmi) mcm_mmi_cal_df <- From 25b0bc0d4812e6a46b70410bf1d009bdc6c5f5be Mon Sep 17 00:00:00 2001 From: NicolaiHandreck Date: Thu, 15 Sep 2022 13:47:52 +0200 Subject: [PATCH 09/10] Made Meters, RTU and relays simpler --- R/pof_future_meter.R | 102 ++++++------------------------------- R/pof_future_relay.R | 98 +++++------------------------------- R/pof_future_rtu.R | 96 +++++------------------------------ R/pof_meter.R | 117 ++++++------------------------------------- R/pof_relay.R | 115 ++++++------------------------------------ R/pof_rtu.R | 116 ++++++------------------------------------ 6 files changed, 84 insertions(+), 560 deletions(-) diff --git a/R/pof_future_meter.R b/R/pof_future_meter.R index 72469f70..028da980 100644 --- a/R/pof_future_meter.R +++ b/R/pof_future_meter.R @@ -13,44 +13,18 @@ #' @export #' @examples #' # future annual probability of failure for meter -# pof_future_meter( -# placement = "Default", -# altitude_m = "Default", -# distance_from_coast_km = "Default", -# corrosion_category_index = "Default", -# age = 1, -# observed_condition_inputs = -# list("external_condition" = -# list("Condition Criteria: Observed Condition" = "Default"), -# "oil_gas" = list("Condition Criteria: Observed Condition" = "Default"), -# "thermo_assment" = list("Condition Criteria: Observed Condition" = "Default"), -# "internal_condition" = list("Condition Criteria: Observed Condition" = "Default"), -# "indoor_env" = list("Condition Criteria: Observed Condition" = "Default")), -# measured_condition_inputs = -# list("partial_discharge" = -# list("Condition Criteria: Partial Discharge Test Results" = "Default"), -# "ductor_test" = list("Condition Criteria: Ductor Test Results" = "Default"), -# "oil_test" = list("Condition Criteria: Oil Test Results" = "Default"), -# "temp_reading" = list("Condition Criteria: Temperature Readings" = "Default"), -# "trip_test" = list("Condition Criteria: Trip Timing Test Result" = "Default")), -# reliability_factor = "Default", -# k_value = 0.128, -# c_value = 1.087, -# normal_expected_life = 25, -# simulation_end_year = 100) +#' pof_future_meter( +#' age = 1, +#' k_value = 0.128, +#' c_value = 1.087, +#' normal_expected_life = 15, +#' simulation_end_year = 100) pof_future_meter <- - function(placement = "Default", - altitude_m = "Default", - distance_from_coast_km = "Default", - corrosion_category_index = "Default", - age, - measured_condition_inputs, - observed_condition_inputs, - reliability_factor = "Default", + function(age, k_value = 0.128, c_value = 1.087, - normal_expected_life = 25, + normal_expected_life = 15, simulation_end_year = 100) { hv_asset_category <- "6.6/11kV CB (GM) Secondary" @@ -83,11 +57,8 @@ pof_future_meter <- duty_factor_cond <- 1 # Location factor ---------------------------------------------------- - location_factor_cond <- location_factor(placement, - altitude_m, - distance_from_coast_km, - corrosion_category_index, - asset_type = hv_asset_category) + location_factor_cond <- 1 + # Expected life ------------------------------ expected_life_years <- expected_life(normal_expected_life, duty_factor_cond, @@ -99,56 +70,13 @@ pof_future_meter <- # Initial health score ---------------------------------------------------- initial_health_score <- initial_health(b1, age) - # Measured conditions - mci_table_names <- list("partial_discharge" = "mci_hv_swg_distr_prtl_dischrg", - "ductor_test" = "mci_hv_swg_distr_ductor_test", - "oil_test" = "mci_hv_swg_distr_oil_test", - "temp_reading" = "mci_hv_swg_distr_temp_reading", - "trip_test" = "mci_hv_swg_distr_trip_test") - - measured_condition_modifier <- - get_measured_conditions_modifier_hv_switchgear(asset_category, - mci_table_names, - measured_condition_inputs) - - # Observed conditions ----------------------------------------------------- - - oci_table_names <- list("external_condition" = "oci_hv_swg_dist_swg_ext_cond", - "oil_gas" = "oci_hv_swg_dist_oil_lek_gas_pr", - "thermo_assment" = "oci_hv_swg_dist_thermo_assment", - "internal_condition" = "oci_hv_swg_dist_swg_int_cond", - "indoor_env" = "oci_hv_swg_dist_indoor_environ") - - observed_condition_modifier <- - get_observed_conditions_modifier_hv_switchgear(asset_category, - oci_table_names, - observed_condition_inputs) - - # Health score factor --------------------------------------------------- - health_score_factor <- - health_score_excl_ehv_132kv_tf(observed_condition_modifier$condition_factor, - measured_condition_modifier$condition_factor) - - # Health score cap -------------------------------------------------------- - health_score_cap <- min(observed_condition_modifier$condition_cap, - measured_condition_modifier$condition_cap) - - # Health score collar ----------------------------------------------------- - health_score_collar <- max(observed_condition_modifier$condition_collar, - measured_condition_modifier$condition_collar) - - # Health score modifier --------------------------------------------------- - health_score_modifier <- data.frame(health_score_factor, - health_score_cap, - health_score_collar) - # Current health score ---------------------------------------------------- current_health_score <- current_health(initial_health_score, - health_score_modifier$health_score_factor, - health_score_modifier$health_score_cap, - health_score_modifier$health_score_collar, - reliability_factor = reliability_factor) + 1, # Condition Input Factor + 10, # Condition Input Cap + 0.5, # Condition Input Collar + 1) # Realiability factor # Probability of failure --------------------------------------------------- probability_of_failure <- k * @@ -157,6 +85,8 @@ pof_future_meter <- (((c * current_health_score)^3) / factorial(3))) + + # Future probability of failure ------------------------------------------- # the Health Score of a new asset diff --git a/R/pof_future_relay.R b/R/pof_future_relay.R index f7621ddd..574a6866 100644 --- a/R/pof_future_relay.R +++ b/R/pof_future_relay.R @@ -14,41 +14,15 @@ #' @export #' @examples #' # future annual probability of failure for relay -# pof_future_relay( -# placement = "Default", -# altitude_m = "Default", -# distance_from_coast_km = "Default", -# corrosion_category_index = "Default", -# age = 10, -# observed_condition_inputs = -# list("external_condition" = -# list("Condition Criteria: Observed Condition" = "Default"), -# "oil_gas" = list("Condition Criteria: Observed Condition" = "Default"), -# "thermo_assment" = list("Condition Criteria: Observed Condition" = "Default"), -# "internal_condition" = list("Condition Criteria: Observed Condition" = "Default"), -# "indoor_env" = list("Condition Criteria: Observed Condition" = "Default")), -# measured_condition_inputs = -# list("partial_discharge" = -# list("Condition Criteria: Partial Discharge Test Results" = "Default"), -# "ductor_test" = list("Condition Criteria: Ductor Test Results" = "Default"), -# "oil_test" = list("Condition Criteria: Oil Test Results" = "Default"), -# "temp_reading" = list("Condition Criteria: Temperature Readings" = "Default"), -# "trip_test" = list("Condition Criteria: Trip Timing Test Result" = "Default")), -# reliability_factor = "Default", -# k_value = 0.128, -# c_value = 1.087, -# normal_expected_life = 30, -# simulation_end_year = 100) +#' pof_future_relay( +#' age = 10, +#' k_value = 0.128, +#' c_value = 1.087, +#' normal_expected_life = 30, +#' simulation_end_year = 100) pof_future_relay <- - function(placement = "Default", - altitude_m = "Default", - distance_from_coast_km = "Default", - corrosion_category_index = "Default", - age, - measured_condition_inputs, - observed_condition_inputs, - reliability_factor = "Default", + function(age, k_value = 0.128, c_value = 1.087, normal_expected_life = 30, @@ -84,11 +58,8 @@ pof_future_relay <- duty_factor_cond <- 1 # Location factor ---------------------------------------------------- - location_factor_cond <- location_factor(placement, - altitude_m, - distance_from_coast_km, - corrosion_category_index, - asset_type = hv_asset_category) + location_factor_cond <- 1 + # Expected life ------------------------------ expected_life_years <- expected_life(normal_expected_life, duty_factor_cond, @@ -100,56 +71,13 @@ pof_future_relay <- # Initial health score ---------------------------------------------------- initial_health_score <- initial_health(b1, age) - # Measured conditions - mci_table_names <- list("partial_discharge" = "mci_hv_swg_distr_prtl_dischrg", - "ductor_test" = "mci_hv_swg_distr_ductor_test", - "oil_test" = "mci_hv_swg_distr_oil_test", - "temp_reading" = "mci_hv_swg_distr_temp_reading", - "trip_test" = "mci_hv_swg_distr_trip_test") - - measured_condition_modifier <- - get_measured_conditions_modifier_hv_switchgear(asset_category, - mci_table_names, - measured_condition_inputs) - - # Observed conditions ----------------------------------------------------- - - oci_table_names <- list("external_condition" = "oci_hv_swg_dist_swg_ext_cond", - "oil_gas" = "oci_hv_swg_dist_oil_lek_gas_pr", - "thermo_assment" = "oci_hv_swg_dist_thermo_assment", - "internal_condition" = "oci_hv_swg_dist_swg_int_cond", - "indoor_env" = "oci_hv_swg_dist_indoor_environ") - - observed_condition_modifier <- - get_observed_conditions_modifier_hv_switchgear(asset_category, - oci_table_names, - observed_condition_inputs) - - # Health score factor --------------------------------------------------- - health_score_factor <- - health_score_excl_ehv_132kv_tf(observed_condition_modifier$condition_factor, - measured_condition_modifier$condition_factor) - - # Health score cap -------------------------------------------------------- - health_score_cap <- min(observed_condition_modifier$condition_cap, - measured_condition_modifier$condition_cap) - - # Health score collar ----------------------------------------------------- - health_score_collar <- max(observed_condition_modifier$condition_collar, - measured_condition_modifier$condition_collar) - - # Health score modifier --------------------------------------------------- - health_score_modifier <- data.frame(health_score_factor, - health_score_cap, - health_score_collar) - # Current health score ---------------------------------------------------- current_health_score <- current_health(initial_health_score, - health_score_modifier$health_score_factor, - health_score_modifier$health_score_cap, - health_score_modifier$health_score_collar, - reliability_factor = reliability_factor) + 1, # Condition Input Factor + 10, # Condition Input Cap + 0.5, # Condition Input Collar + 1) # Realiability factor # Probability of failure --------------------------------------------------- probability_of_failure <- k * diff --git a/R/pof_future_rtu.R b/R/pof_future_rtu.R index 1606dcb7..0d846085 100644 --- a/R/pof_future_rtu.R +++ b/R/pof_future_rtu.R @@ -20,41 +20,15 @@ #' @export #' @examples #' # future annual probability of failure for RTU -# pof_future_rtu( -# placement = "Default", -# altitude_m = "Default", -# distance_from_coast_km = "Default", -# corrosion_category_index = "Default", -# age = 1, -# observed_condition_inputs = -# list("external_condition" = -# list("Condition Criteria: Observed Condition" = "Default"), -# "oil_gas" = list("Condition Criteria: Observed Condition" = "Default"), -# "thermo_assment" = list("Condition Criteria: Observed Condition" = "Default"), -# "internal_condition" = list("Condition Criteria: Observed Condition" = "Default"), -# "indoor_env" = list("Condition Criteria: Observed Condition" = "Default")), -# measured_condition_inputs = -# list("partial_discharge" = -# list("Condition Criteria: Partial Discharge Test Results" = "Default"), -# "ductor_test" = list("Condition Criteria: Ductor Test Results" = "Default"), -# "oil_test" = list("Condition Criteria: Oil Test Results" = "Default"), -# "temp_reading" = list("Condition Criteria: Temperature Readings" = "Default"), -# "trip_test" = list("Condition Criteria: Trip Timing Test Result" = "Default")), -# reliability_factor = "Default", -# k_value = 0.128, -# c_value = 1.087, -# normal_expected_life = 20, -# simulation_end_year = 100) +#' pof_future_rtu( +#' age = 1, +#' k_value = 0.128, +#' c_value = 1.087, +#' normal_expected_life = 20, +#' simulation_end_year = 100) pof_future_rtu <- - function(placement = "Default", - altitude_m = "Default", - distance_from_coast_km = "Default", - corrosion_category_index = "Default", - age, - measured_condition_inputs, - observed_condition_inputs, - reliability_factor = "Default", + function(age, k_value = 0.128, c_value = 1.087, normal_expected_life = 20, @@ -90,11 +64,7 @@ pof_future_rtu <- duty_factor_cond <- 1 # Location factor ---------------------------------------------------- - location_factor_cond <- location_factor(placement, - altitude_m, - distance_from_coast_km, - corrosion_category_index, - asset_type = hv_asset_category) + location_factor_cond <- 1 # Expected life ------------------------------ expected_life_years <- expected_life(normal_expected_life, duty_factor_cond, @@ -106,56 +76,14 @@ pof_future_rtu <- # Initial health score ---------------------------------------------------- initial_health_score <- initial_health(b1, age) - # Measured conditions - mci_table_names <- list("partial_discharge" = "mci_hv_swg_distr_prtl_dischrg", - "ductor_test" = "mci_hv_swg_distr_ductor_test", - "oil_test" = "mci_hv_swg_distr_oil_test", - "temp_reading" = "mci_hv_swg_distr_temp_reading", - "trip_test" = "mci_hv_swg_distr_trip_test") - - measured_condition_modifier <- - get_measured_conditions_modifier_hv_switchgear(asset_category, - mci_table_names, - measured_condition_inputs) - - # Observed conditions ----------------------------------------------------- - - oci_table_names <- list("external_condition" = "oci_hv_swg_dist_swg_ext_cond", - "oil_gas" = "oci_hv_swg_dist_oil_lek_gas_pr", - "thermo_assment" = "oci_hv_swg_dist_thermo_assment", - "internal_condition" = "oci_hv_swg_dist_swg_int_cond", - "indoor_env" = "oci_hv_swg_dist_indoor_environ") - - observed_condition_modifier <- - get_observed_conditions_modifier_hv_switchgear(asset_category, - oci_table_names, - observed_condition_inputs) - - # Health score factor --------------------------------------------------- - health_score_factor <- - health_score_excl_ehv_132kv_tf(observed_condition_modifier$condition_factor, - measured_condition_modifier$condition_factor) - - # Health score cap -------------------------------------------------------- - health_score_cap <- min(observed_condition_modifier$condition_cap, - measured_condition_modifier$condition_cap) - - # Health score collar ----------------------------------------------------- - health_score_collar <- max(observed_condition_modifier$condition_collar, - measured_condition_modifier$condition_collar) - - # Health score modifier --------------------------------------------------- - health_score_modifier <- data.frame(health_score_factor, - health_score_cap, - health_score_collar) # Current health score ---------------------------------------------------- current_health_score <- current_health(initial_health_score, - health_score_modifier$health_score_factor, - health_score_modifier$health_score_cap, - health_score_modifier$health_score_collar, - reliability_factor = reliability_factor) + 1, # Condition Input Factor + 10, # Condition Input Cap + 0.5, # Condition Input Collar + 1) # Realiability factor # Probability of failure --------------------------------------------------- probability_of_failure <- k * diff --git a/R/pof_meter.R b/R/pof_meter.R index 075d4c05..16c9782e 100644 --- a/R/pof_meter.R +++ b/R/pof_meter.R @@ -5,21 +5,7 @@ #' The function is a cubic curve that is based on #' the first three terms of the Taylor series for an #' exponential function. -#' @param placement String. Specify if the asset is located outdoor or indoor. -#' @param altitude_m Numeric. Specify the altitude location for -#' the asset measured in meters from sea level.\code{altitude_m} -#' is used to derive the altitude factor. A setting of \code{"Default"} -#' will set the altitude factor to 1 independent of \code{asset_type}. -#' @param distance_from_coast_km Numeric. Specify the distance from the -#' coast measured in kilometers. \code{distance_from_coast_km} is used -#' to derive the distance from coast factor. A setting of \code{"Default"} will set the -#' distance from coast factor to 1 independent of \code{asset_type}. -#' @param corrosion_category_index Integer. -#' Specify the corrosion index category, 1-5. #' @param age Numeric. The current age in years of the conductor. -#' @param measured_condition_inputs Named list observed_conditions_input -#' @param observed_condition_inputs Named list observed_conditions_input -#' \code{conductor_samp = c("Low","Medium/Normal","High","Default")}. #' @inheritParams current_health #' @param k_value Numeric. \code{k_value = 0.128} by default. This number is #' given in a percentage. The default value is accordingly to the CNAIM standard @@ -32,46 +18,20 @@ #' @export #' @examples #' # Current annual probability of failure for meter -# pof_meter_res <- -# pof_meter( -# placement = "Default", -# altitude_m = "Default", -# distance_from_coast_km = "Default", -# corrosion_category_index = "Default", -# age = 10, -# observed_condition_inputs = -# list("external_condition" = -# list("Condition Criteria: Observed Condition" = "Default"), -# "oil_gas" = list("Condition Criteria: Observed Condition" = "Default"), -# "thermo_assment" = list("Condition Criteria: Observed Condition" = "Default"), -# "internal_condition" = list("Condition Criteria: Observed Condition" = "Default"), -# "indoor_env" = list("Condition Criteria: Observed Condition" = "Default")), -# measured_condition_inputs = -# list("partial_discharge" = -# list("Condition Criteria: Partial Discharge Test Results" = "Default"), -# "ductor_test" = list("Condition Criteria: Ductor Test Results" = "Default"), -# "oil_test" = list("Condition Criteria: Oil Test Results" = "Default"), -# "temp_reading" = list("Condition Criteria: Temperature Readings" = "Default"), -# "trip_test" = list("Condition Criteria: Trip Timing Test Result" = "Default")), -# reliability_factor = "Default", -# k_value = 0.128, -# c_value = 1.087, -# normal_expected_life = 25) * 100 -# paste0(sprintf("Probability of failure %.4f", pof_meter_res), -# " percent per annum") +#' pof_meter_res <- +#' pof_meter( +#' age = 10, +#' k_value = 0.128, +#' c_value = 1.087, +#' normal_expected_life = 15) * 100 +#' paste0(sprintf("Probability of failure %.4f", pof_meter_res), +#' " percent per annum") pof_meter <- - function(placement = "Default", - altitude_m = "Default", - distance_from_coast_km = "Default", - corrosion_category_index = "Default", - age, - measured_condition_inputs, - observed_condition_inputs, - reliability_factor = "Default", + function(age, k_value = 0.128, c_value = 1.087, - normal_expected_life = 25) { + normal_expected_life = 15) { hv_asset_category <- "6.6/11kV CB (GM) Secondary" `Asset Register Category` = `Health Index Asset Category` = @@ -103,11 +63,7 @@ pof_meter <- duty_factor_cond <- 1 # Location factor ---------------------------------------------------- - location_factor_cond <- location_factor(placement, - altitude_m, - distance_from_coast_km, - corrosion_category_index, - asset_type = hv_asset_category) + location_factor_cond <- 1 # Expected life ------------------------------ expected_life_years <- expected_life(normal_expected_life, @@ -120,56 +76,13 @@ pof_meter <- # Initial health score ---------------------------------------------------- initial_health_score <- initial_health(b1, age) - # Measured conditions - mci_table_names <- list("partial_discharge" = "mci_hv_swg_distr_prtl_dischrg", - "ductor_test" = "mci_hv_swg_distr_ductor_test", - "oil_test" = "mci_hv_swg_distr_oil_test", - "temp_reading" = "mci_hv_swg_distr_temp_reading", - "trip_test" = "mci_hv_swg_distr_trip_test") - - measured_condition_modifier <- - get_measured_conditions_modifier_hv_switchgear(asset_category, - mci_table_names, - measured_condition_inputs) - - # Observed conditions ----------------------------------------------------- - - oci_table_names <- list("external_condition" = "oci_hv_swg_dist_swg_ext_cond", - "oil_gas" = "oci_hv_swg_dist_oil_lek_gas_pr", - "thermo_assment" = "oci_hv_swg_dist_thermo_assment", - "internal_condition" = "oci_hv_swg_dist_swg_int_cond", - "indoor_env" = "oci_hv_swg_dist_indoor_environ") - - observed_condition_modifier <- - get_observed_conditions_modifier_hv_switchgear(asset_category, - oci_table_names, - observed_condition_inputs) - - # Health score factor --------------------------------------------------- - health_score_factor <- - health_score_excl_ehv_132kv_tf(observed_condition_modifier$condition_factor, - measured_condition_modifier$condition_factor) - - # Health score cap -------------------------------------------------------- - health_score_cap <- min(observed_condition_modifier$condition_cap, - measured_condition_modifier$condition_cap) - - # Health score collar ----------------------------------------------------- - health_score_collar <- max(observed_condition_modifier$condition_collar, - measured_condition_modifier$condition_collar) - - # Health score modifier --------------------------------------------------- - health_score_modifier <- data.frame(health_score_factor, - health_score_cap, - health_score_collar) - # Current health score ---------------------------------------------------- current_health_score <- current_health(initial_health_score, - health_score_modifier$health_score_factor, - health_score_modifier$health_score_cap, - health_score_modifier$health_score_collar, - reliability_factor = reliability_factor) + 1, # Condition Input Factor + 10, # Condition Input Cap + 0.5, # Condition Input Collar + 1) # Realiability factor # Probability of failure --------------------------------------------------- probability_of_failure <- k * diff --git a/R/pof_relay.R b/R/pof_relay.R index 4698a561..ec4868aa 100644 --- a/R/pof_relay.R +++ b/R/pof_relay.R @@ -5,21 +5,7 @@ #' The function is a cubic curve that is based on #' the first three terms of the Taylor series for an #' exponential function. -#' @param placement String. Specify if the asset is located outdoor or indoor. -#' @param altitude_m Numeric. Specify the altitude location for -#' the asset measured in meters from sea level.\code{altitude_m} -#' is used to derive the altitude factor. A setting of \code{"Default"} -#' will set the altitude factor to 1 independent of \code{asset_type}. -#' @param distance_from_coast_km Numeric. Specify the distance from the -#' coast measured in kilometers. \code{distance_from_coast_km} is used -#' to derive the distance from coast factor. A setting of \code{"Default"} will set the -#' distance from coast factor to 1 independent of \code{asset_type}. -#' @param corrosion_category_index Integer. -#' Specify the corrosion index category, 1-5. #' @param age Numeric. The current age in years of the conductor. -#' @param measured_condition_inputs Named list observed_conditions_input -#' @param observed_condition_inputs Named list observed_conditions_input -#' \code{conductor_samp = c("Low","Medium/Normal","High","Default")}. #' @inheritParams current_health #' @param k_value Numeric. \code{k_value = 0.128} by default. This number is #' given in a percentage. The default value is accordingly to the CNAIM standard @@ -32,43 +18,17 @@ #' @export #' @examples #' # Current annual probability of failure for relay -# pof_relay_res <- -# pof_relay( -# placement = "Default", -# altitude_m = "Default", -# distance_from_coast_km = "Default", -# corrosion_category_index = "Default", -# age = 25, -# observed_condition_inputs = -# list("external_condition" = -# list("Condition Criteria: Observed Condition" = "Default"), -# "oil_gas" = list("Condition Criteria: Observed Condition" = "Default"), -# "thermo_assment" = list("Condition Criteria: Observed Condition" = "Default"), -# "internal_condition" = list("Condition Criteria: Observed Condition" = "Default"), -# "indoor_env" = list("Condition Criteria: Observed Condition" = "Default")), -# measured_condition_inputs = -# list("partial_discharge" = -# list("Condition Criteria: Partial Discharge Test Results" = "Default"), -# "ductor_test" = list("Condition Criteria: Ductor Test Results" = "Default"), -# "oil_test" = list("Condition Criteria: Oil Test Results" = "Default"), -# "temp_reading" = list("Condition Criteria: Temperature Readings" = "Default"), -# "trip_test" = list("Condition Criteria: Trip Timing Test Result" = "Default")), -# reliability_factor = "Default", -# k_value = 0.128, -# c_value = 1.087, -# normal_expected_life = 30) * 100 -# paste0(sprintf("Probability of failure %.4f", pof_relay_res), -# " percent per annum") +#' pof_relay_res <- +#' pof_relay( +#' age = 25, +#' k_value = 0.128, +#' c_value = 1.087, +#' normal_expected_life = 30) * 100 +#' paste0(sprintf("Probability of failure %.4f", pof_relay_res), +#' " percent per annum") pof_relay <- - function(placement = "Default", - altitude_m = "Default", - distance_from_coast_km = "Default", - corrosion_category_index = "Default", - age, - measured_condition_inputs, - observed_condition_inputs, - reliability_factor = "Default", + function(age, k_value = 0.128, c_value = 1.087, normal_expected_life = 30) { @@ -102,11 +62,7 @@ pof_relay <- duty_factor_cond <- 1 # Location factor ---------------------------------------------------- - location_factor_cond <- location_factor(placement, - altitude_m, - distance_from_coast_km, - corrosion_category_index, - asset_type = hv_asset_category) + location_factor_cond <- 1 # Expected life ------------------------------ expected_life_years <- expected_life(normal_expected_life, @@ -119,56 +75,13 @@ pof_relay <- # Initial health score ---------------------------------------------------- initial_health_score <- initial_health(b1, age) - # Measured conditions - mci_table_names <- list("partial_discharge" = "mci_hv_swg_distr_prtl_dischrg", - "ductor_test" = "mci_hv_swg_distr_ductor_test", - "oil_test" = "mci_hv_swg_distr_oil_test", - "temp_reading" = "mci_hv_swg_distr_temp_reading", - "trip_test" = "mci_hv_swg_distr_trip_test") - - measured_condition_modifier <- - get_measured_conditions_modifier_hv_switchgear(asset_category, - mci_table_names, - measured_condition_inputs) - - # Observed conditions ----------------------------------------------------- - - oci_table_names <- list("external_condition" = "oci_hv_swg_dist_swg_ext_cond", - "oil_gas" = "oci_hv_swg_dist_oil_lek_gas_pr", - "thermo_assment" = "oci_hv_swg_dist_thermo_assment", - "internal_condition" = "oci_hv_swg_dist_swg_int_cond", - "indoor_env" = "oci_hv_swg_dist_indoor_environ") - - observed_condition_modifier <- - get_observed_conditions_modifier_hv_switchgear(asset_category, - oci_table_names, - observed_condition_inputs) - - # Health score factor --------------------------------------------------- - health_score_factor <- - health_score_excl_ehv_132kv_tf(observed_condition_modifier$condition_factor, - measured_condition_modifier$condition_factor) - - # Health score cap -------------------------------------------------------- - health_score_cap <- min(observed_condition_modifier$condition_cap, - measured_condition_modifier$condition_cap) - - # Health score collar ----------------------------------------------------- - health_score_collar <- max(observed_condition_modifier$condition_collar, - measured_condition_modifier$condition_collar) - - # Health score modifier --------------------------------------------------- - health_score_modifier <- data.frame(health_score_factor, - health_score_cap, - health_score_collar) - # Current health score ---------------------------------------------------- current_health_score <- current_health(initial_health_score, - health_score_modifier$health_score_factor, - health_score_modifier$health_score_cap, - health_score_modifier$health_score_collar, - reliability_factor = reliability_factor) + 1, # Condition Input Factor + 10, # Condition Input Cap + 0.5, # Condition Input Collar + 1) # Realiability factor # Probability of failure --------------------------------------------------- probability_of_failure <- k * diff --git a/R/pof_rtu.R b/R/pof_rtu.R index 2e2f77d3..e1334662 100644 --- a/R/pof_rtu.R +++ b/R/pof_rtu.R @@ -5,21 +5,7 @@ #' The function is a cubic curve that is based on #' the first three terms of the Taylor series for an #' exponential function. -#' @param placement String. Specify if the asset is located outdoor or indoor. -#' @param altitude_m Numeric. Specify the altitude location for -#' the asset measured in meters from sea level.\code{altitude_m} -#' is used to derive the altitude factor. A setting of \code{"Default"} -#' will set the altitude factor to 1 independent of \code{asset_type}. -#' @param distance_from_coast_km Numeric. Specify the distance from the -#' coast measured in kilometers. \code{distance_from_coast_km} is used -#' to derive the distance from coast factor. A setting of \code{"Default"} will set the -#' distance from coast factor to 1 independent of \code{asset_type}. -#' @param corrosion_category_index Integer. -#' Specify the corrosion index category, 1-5. #' @param age Numeric. The current age in years of the conductor. -#' @param measured_condition_inputs Named list observed_conditions_input -#' @param observed_condition_inputs Named list observed_conditions_input -#' \code{conductor_samp = c("Low","Medium/Normal","High","Default")}. #' @inheritParams current_health #' @param k_value Numeric. \code{k_value = 0.0128} by default. This number is #' given in a percentage. The default value is accordingly to the CNAIM standard @@ -32,43 +18,17 @@ #' @export #' @examples #' # Current annual probability of failure for RTU -# pof_rtu_res <- -# pof_rtu( -# placement = "Default", -# altitude_m = "Default", -# distance_from_coast_km = "Default", -# corrosion_category_index = "Default", -# age = 10, -# observed_condition_inputs = -# list("external_condition" = -# list("Condition Criteria: Observed Condition" = "Default"), -# "oil_gas" = list("Condition Criteria: Observed Condition" = "Default"), -# "thermo_assment" = list("Condition Criteria: Observed Condition" = "Default"), -# "internal_condition" = list("Condition Criteria: Observed Condition" = "Default"), -# "indoor_env" = list("Condition Criteria: Observed Condition" = "Default")), -# measured_condition_inputs = -# list("partial_discharge" = -# list("Condition Criteria: Partial Discharge Test Results" = "Default"), -# "ductor_test" = list("Condition Criteria: Ductor Test Results" = "Default"), -# "oil_test" = list("Condition Criteria: Oil Test Results" = "Default"), -# "temp_reading" = list("Condition Criteria: Temperature Readings" = "Default"), -# "trip_test" = list("Condition Criteria: Trip Timing Test Result" = "Default")), -# reliability_factor = "Default", -# k_value = 0.128, -# c_value = 1.087, -# normal_expected_life = 20) * 100 -# paste0(sprintf("Probability of failure %.4f", pof_rtu_res), -# " percent per annum") +#' pof_rtu_res <- +#' pof_rtu( +#' age = 10, +#' k_value = 0.128, +#' c_value = 1.087, +#' normal_expected_life = 20) * 100 +#' paste0(sprintf("Probability of failure %.4f", pof_rtu_res), +#' " percent per annum") pof_rtu <- - function(placement = "Default", - altitude_m = "Default", - distance_from_coast_km = "Default", - corrosion_category_index = "Default", - age, - measured_condition_inputs, - observed_condition_inputs, - reliability_factor = "Default", + function(age, k_value = 0.128, c_value = 1.087, normal_expected_life = 20) { @@ -102,11 +62,7 @@ pof_rtu <- duty_factor_cond <- 1 # Location factor ---------------------------------------------------- - location_factor_cond <- location_factor(placement, - altitude_m, - distance_from_coast_km, - corrosion_category_index, - asset_type = hv_asset_category) + location_factor_cond <- 1 # Expected life ------------------------------ expected_life_years <- expected_life(normal_expected_life, @@ -119,57 +75,13 @@ pof_rtu <- # Initial health score ---------------------------------------------------- initial_health_score <- initial_health(b1, age) - # Measured conditions - mci_table_names <- list("partial_discharge" = "mci_hv_swg_distr_prtl_dischrg", - "ductor_test" = "mci_hv_swg_distr_ductor_test", - "oil_test" = "mci_hv_swg_distr_oil_test", - "temp_reading" = "mci_hv_swg_distr_temp_reading", - "trip_test" = "mci_hv_swg_distr_trip_test") - - measured_condition_modifier <- - get_measured_conditions_modifier_hv_switchgear(asset_category, - mci_table_names, - measured_condition_inputs) - - # Observed conditions ----------------------------------------------------- - - oci_table_names <- list("external_condition" = "oci_hv_swg_dist_swg_ext_cond", - "oil_gas" = "oci_hv_swg_dist_oil_lek_gas_pr", - "thermo_assment" = "oci_hv_swg_dist_thermo_assment", - "internal_condition" = "oci_hv_swg_dist_swg_int_cond", - "indoor_env" = "oci_hv_swg_dist_indoor_environ") - - observed_condition_modifier <- - get_observed_conditions_modifier_hv_switchgear(asset_category, - oci_table_names, - observed_condition_inputs) - - # Health score factor --------------------------------------------------- - health_score_factor <- - health_score_excl_ehv_132kv_tf(observed_condition_modifier$condition_factor, - measured_condition_modifier$condition_factor) - - # Health score cap -------------------------------------------------------- - health_score_cap <- min(observed_condition_modifier$condition_cap, - measured_condition_modifier$condition_cap) - - # Health score collar ----------------------------------------------------- - health_score_collar <- max(observed_condition_modifier$condition_collar, - measured_condition_modifier$condition_collar) - - # Health score modifier --------------------------------------------------- - health_score_modifier <- data.frame(health_score_factor, - health_score_cap, - health_score_collar) - # Current health score ---------------------------------------------------- current_health_score <- current_health(initial_health_score, - health_score_modifier$health_score_factor, - health_score_modifier$health_score_cap, - health_score_modifier$health_score_collar, - reliability_factor = reliability_factor) - + 1, # Condition Input Factor + 10, # Condition Input Cap + 0.5, # Condition Input Collar + 1) # Realiability factor # Probability of failure --------------------------------------------------- probability_of_failure <- k * (1 + (c * current_health_score) + From e27e2efe14ee86c9bdd34ed14db8bb65699b95c7 Mon Sep 17 00:00:00 2001 From: NicolaiHandreck Date: Tue, 21 Feb 2023 12:14:12 +0100 Subject: [PATCH 10/10] Found mistake in location factor --- R/location_factor.R | 319 ++++++++++++++++++++++---------------------- 1 file changed, 159 insertions(+), 160 deletions(-) diff --git a/R/location_factor.R b/R/location_factor.R index a1e58b36..e315717e 100644 --- a/R/location_factor.R +++ b/R/location_factor.R @@ -86,188 +86,187 @@ location_factor <- function(placement = "Default", sub_division = NULL) { -if (asset_type == "LV UGB" || - asset_type == "33kV UG Cable (Non Pressurised)" || - asset_type == "33kV UG Cable (Oil)" || - asset_type == "33kV UG Cable (Gas)" || - asset_type == "66kV UG Cable (Non Pressurised)" || - asset_type == "66kV UG Cable (Oil)" || - asset_type == "66kV UG Cable (Gas)" || - asset_type == "132kV UG Cable (Non Pressurised)" || - asset_type == "132kV UG Cable (Oil)" || - asset_type == "132kV UG Cable (Gas)" ){ + if (asset_type == "LV UGB" || + asset_type == "33kV UG Cable (Non Pressurised)" || + asset_type == "33kV UG Cable (Oil)" || + asset_type == "33kV UG Cable (Gas)" || + asset_type == "66kV UG Cable (Non Pressurised)" || + asset_type == "66kV UG Cable (Oil)" || + asset_type == "66kV UG Cable (Gas)" || + asset_type == "132kV UG Cable (Non Pressurised)" || + asset_type == "132kV UG Cable (Oil)" || + asset_type == "132kV UG Cable (Gas)" ){ - location_factor_asset <- 1 + location_factor_asset <- 1 -} else { - # Find generic term ------------------------------------------------------- - asset_category <- gb_ref$categorisation_of_assets$ - `Health Index Asset Category`[which(gb_ref$ - categorisation_of_assets$ - `Asset Register Category` == - asset_type)] + } else { + # Find generic term ------------------------------------------------------- + asset_category <- gb_ref$categorisation_of_assets$ + `Health Index Asset Category`[which(gb_ref$ + categorisation_of_assets$ + `Asset Register Category` == + asset_type)] - generic_term_1 <- gb_ref$generic_terms_for_assets$ - `Generic Term...1`[which(gb_ref$ - generic_terms_for_assets$ - `Health Index Asset Category` == - asset_category)] + generic_term_1 <- gb_ref$generic_terms_for_assets$ + `Generic Term...1`[which(gb_ref$ + generic_terms_for_assets$ + `Health Index Asset Category` == + asset_category)] - if (asset_category == "EHV OHL Conductor (Tower Lines)" || - asset_category == "132kV OHL Conductor (Tower Lines)") { - generic_term_1 <- "Towers (Conductor)" - } else if (asset_category == "EHV OHL Fittings" || - asset_category == "132kV OHL Fittings") { - generic_term_1 <- "Towers (Fittings)" - }else if (asset_category == "HV OHL Support - Poles" || - asset_category == "EHV OHL Support - Poles" || - asset_category == "LV OHL Support" ) { - # All the poles - if(sub_division %>% is.null()) - stop("No sub division specified for the pole") - if(sub_division == "Steel") - generic_term_1 <- "Poles (Steel)" - if(sub_division == "Concrete") - generic_term_1 <- "Poles (Concrete)" - if(sub_division == "Wood") - generic_term_1 <- "Poles (Wood)" - }else if(asset_category == "EHV OHL Support - Towers" || - asset_category == "132kV OHL Support - Tower"){ - generic_term_1 <- "Towers (Structure)" - } - if (asset_category == "Overhead Line") { - stop(paste0("Asset type not implemented: ", asset_type)) - } + if (asset_category == "EHV OHL Conductor (Tower Lines)" || + asset_category == "132kV OHL Conductor (Tower Lines)") { + generic_term_1 <- "Towers (Conductor)" + } else if (asset_category == "EHV OHL Fittings" || + asset_category == "132kV OHL Fittings") { + generic_term_1 <- "Towers (Fittings)" + }else if (asset_category == "HV OHL Support - Poles" || + asset_category == "EHV OHL Support - Poles" || + asset_category == "LV OHL Support" ) { + # All the poles + if(sub_division %>% is.null()) + stop("No sub division specified for the pole") + if(sub_division == "Steel") + generic_term_1 <- "Poles (Steel)" + if(sub_division == "Concrete") + generic_term_1 <- "Poles (Concrete)" + if(sub_division == "Wood") + generic_term_1 <- "Poles (Wood)" + }else if(asset_category == "EHV OHL Support - Towers" || + asset_category == "132kV OHL Support - Tower"){ + generic_term_1 <- "Towers (Structure)" + } + if (asset_category == "Overhead Line") { + stop(paste0("Asset type not implemented: ", asset_type)) + } - # Altitude ---------------------------------------------------------------- - altitude_factor_asset_df <- dplyr::select(gb_ref$altitude_factor_lut, - c("Lower", "Upper", - generic_term_1)) - if (altitude_m == "Default") { - row_no <- which(altitude_factor_asset_df$Lower == "Default") - } else if (altitude_m <= 100) { - row_no <- which(altitude_factor_asset_df$Lower == "0") - } else if (100 < altitude_m && altitude_m <= 200) { - row_no <- which(altitude_factor_asset_df$Lower == "100") - } else if (200 < altitude_m && altitude_m <= 300) { - row_no <- which(altitude_factor_asset_df$Lower == "200") - } else { - row_no <- which(altitude_factor_asset_df$Lower == "300") - } + # Altitude ---------------------------------------------------------------- + altitude_factor_asset_df <- dplyr::select(gb_ref$altitude_factor_lut, + c("Lower", "Upper", + generic_term_1)) + if (altitude_m == "Default") { + row_no <- which(altitude_factor_asset_df$Lower == "Default") + } else if (altitude_m <= 100) { + row_no <- which(altitude_factor_asset_df$Lower == "-Inf") + } else if (100 < altitude_m && altitude_m <= 200) { + row_no <- which(altitude_factor_asset_df$Lower == "100") + } else if (200 < altitude_m && altitude_m <= 300) { + row_no <- which(altitude_factor_asset_df$Lower == "200") + } else { + row_no <- which(altitude_factor_asset_df$Lower == "300") + } - altitude_factor <- - as.numeric(altitude_factor_asset_df[row_no, generic_term_1]) + altitude_factor <- + as.numeric(altitude_factor_asset_df[row_no, ..generic_term_1]) - # Corrosion ---------------------------------------------------------------- - corrosion_category_factor_a <- - dplyr::select(gb_ref$corrosion_category_factor_lut, - c("Corrosion Category Index", generic_term_1)) + # Corrosion ---------------------------------------------------------------- + corrosion_category_factor_a <- + dplyr::select(gb_ref$corrosion_category_factor_lut, + c("Corrosion Category Index", generic_term_1)) - if (corrosion_category_index == "Default") { - row_no <- - which(corrosion_category_factor_a$`Corrosion Category Index` == - "Default") - } else if (corrosion_category_index == 1) { - row_no <- which(corrosion_category_factor_a$ - `Corrosion Category Index` == "1") - } else if (corrosion_category_index == 2) { - row_no <- which(corrosion_category_factor_a$ - `Corrosion Category Index` == "2") - } else if (corrosion_category_index == 3) { - row_no <- which(corrosion_category_factor_a$ - `Corrosion Category Index` == "3") - } else if (corrosion_category_index == 4) { - row_no <- which(corrosion_category_factor_a$ - `Corrosion Category Index` == "4") - }else if (corrosion_category_index == 5) { - row_no <- which(corrosion_category_factor_a$ - `Corrosion Category Index` == "5") - } - corrosion_factor <- - as.numeric(corrosion_category_factor_a[row_no, generic_term_1]) + if (corrosion_category_index == "Default") { + row_no <- + which(corrosion_category_factor_a$`Corrosion Category Index` == + "Default") + } else if (corrosion_category_index == 1) { + row_no <- which(corrosion_category_factor_a$ + `Corrosion Category Index` == "1") + } else if (corrosion_category_index == 2) { + row_no <- which(corrosion_category_factor_a$ + `Corrosion Category Index` == "2") + } else if (corrosion_category_index == 3) { + row_no <- which(corrosion_category_factor_a$ + `Corrosion Category Index` == "3") + } else if (corrosion_category_index == 4) { + row_no <- which(corrosion_category_factor_a$ + `Corrosion Category Index` == "4") + }else if (corrosion_category_index == 5) { + row_no <- which(corrosion_category_factor_a$ + `Corrosion Category Index` == "5") + } + corrosion_factor <- + as.numeric(corrosion_category_factor_a[row_no, ..generic_term_1]) - # Distance from coast ----------------------------------------------------- - distance_from_coast_factor_lut <- gb_ref$distance_from_coast_factor_lut + # Distance from coast ----------------------------------------------------- - distance_from_coast_factor_a <- - dplyr::select(distance_from_coast_factor_lut, - c("Lower", "Upper", generic_term_1)) + distance_from_coast_factor_a <- + dplyr::select(gb_ref$distance_from_coast_factor_lut, + c("Lower", "Upper", generic_term_1)) - if (distance_from_coast_km == "Default") { - row_no <- which(distance_from_coast_factor_a$Lower == "Default") - } else if (distance_from_coast_km <= 1) { - row_no <- which(distance_from_coast_factor_a$Lower == "0") - } else if (1 < distance_from_coast_km && distance_from_coast_km <= 5) { - row_no <- which(distance_from_coast_factor_a$Lower == "1") - } else if (5 < distance_from_coast_km && distance_from_coast_km <= 10) { - row_no <- which(distance_from_coast_factor_a$Lower == "5") - } else if (10 < distance_from_coast_km && distance_from_coast_km <= 20) { - row_no <- which(distance_from_coast_factor_a$Lower == "10") - }else { - row_no <- which(distance_from_coast_factor_a$Lower == "20") - } - coast_factor <- - as.numeric(distance_from_coast_factor_a[row_no, generic_term_1]) - - # Increment constant ------------------------------------------------------ - increment_constants <- gb_ref$increment_constants - inc_constant <- increment_constants[, generic_term_1] + if (distance_from_coast_km == "Default") { + row_no <- which(distance_from_coast_factor_a$Lower == "Default") + } else if (distance_from_coast_km <= 1) { + row_no <- which(distance_from_coast_factor_a$Lower == "-Inf") + } else if (1 < distance_from_coast_km && distance_from_coast_km <= 5) { + row_no <- which(distance_from_coast_factor_a$Lower == "1") + } else if (5 < distance_from_coast_km && distance_from_coast_km <= 10) { + row_no <- which(distance_from_coast_factor_a$Lower == "5") + } else if (10 < distance_from_coast_km && distance_from_coast_km <= 20) { + row_no <- which(distance_from_coast_factor_a$Lower == "10") + }else { + row_no <- which(distance_from_coast_factor_a$Lower == "20") + } + coast_factor <- + as.numeric(distance_from_coast_factor_a[row_no, ..generic_term_1]) - # All factors ------------------------------------------------------------- - factors <- c(coast_factor, corrosion_factor, altitude_factor) + # Increment constant ------------------------------------------------------ + increment_constants <- gb_ref$increment_constants + inc_constant <- increment_constants[, ..generic_term_1] - # Location factor outdoor ------------------------------------------------- - environment_indoor_outdoor <- gb_ref$environment_indoor_outdoor + # All factors ------------------------------------------------------------- + factors <- c(coast_factor, corrosion_factor, altitude_factor) - if (placement == "Default") { - placement <- - environment_indoor_outdoor$ - `Default 'environment' to be assumed when deriving Location Factor`[ - which( - environment_indoor_outdoor$`Asset Register Category` == asset_type)] - } + # Location factor outdoor ------------------------------------------------- + environment_indoor_outdoor <- gb_ref$environment_indoor_outdoor - if (placement == "Outdoor") { - if (max(factors) > 1) { - count_factor <- length(which(factors > 1)) - location_factor_asset <- max(factors) + - ((count_factor - 1) * inc_constant) - } else { - location_factor_asset <- min(factors) - } - } else if (placement == "Indoor") { - if (max(factors) > 1) { - count_factor <- length(which(factors > 1)) - initial_location_factor <- max(factors) + - ((count_factor - 1) * inc_constant) - } else { - initial_location_factor <- min(factors) + if (placement == "Default") { + placement <- + environment_indoor_outdoor$ + `Default 'environment' to be assumed when deriving Location Factor`[ + which( + environment_indoor_outdoor$`Asset Register Category` == asset_type)] } - min_coast_factor <- - min(as.numeric(distance_from_coast_factor_a[, generic_term_1])) - min_corrosion_factor <- - min(as.numeric(corrosion_category_factor_a[, generic_term_1])) - min_altitude_factor <- - min(as.numeric(altitude_factor_asset_df[, generic_term_1])) - min_initial_location_factors <- - c(min_coast_factor, min_corrosion_factor, min_altitude_factor) + if (placement == "Outdoor") { + if (max(factors) > 1) { + count_factor <- length(which(factors > 1)) + location_factor_asset <- max(factors) + + ((count_factor - 1) * inc_constant) + } else { + location_factor_asset <- min(factors) + } + } else if (placement == "Indoor") { + if (max(factors) > 1) { + count_factor <- length(which(factors > 1)) + initial_location_factor <- max(factors) + + ((count_factor - 1) * inc_constant) + } else { + initial_location_factor <- min(factors) + } - if (max(min_initial_location_factors) > 1) { - count_min_factor <- length(which(min_initial_location_factors > 1)) - min_initial_location_factor <- max(min_initial_location_factors) + - ((count_min_factor - 1) * inc_constant) - } else { - min_initial_location_factor <- min(min_initial_location_factors) + min_coast_factor <- + min(distance_from_coast_factor_a[, ..generic_term_1]) + min_corrosion_factor <- + min(corrosion_category_factor_a[, ..generic_term_1]) + min_altitude_factor <- + min(altitude_factor_asset_df[, ..generic_term_1]) + min_initial_location_factors <- + c(min_coast_factor, min_corrosion_factor, min_altitude_factor) + + if (max(min_initial_location_factors) > 1) { + count_min_factor <- length(which(min_initial_location_factors > 1)) + min_initial_location_factor <- max(min_initial_location_factors) + + ((count_min_factor - 1) * inc_constant) + } else { + min_initial_location_factor <- min(min_initial_location_factors) + } + location_factor_asset <- 0.25 * + (initial_location_factor - min_initial_location_factor) + + min_initial_location_factor } - location_factor_asset <- 0.25 * - (initial_location_factor - min_initial_location_factor) + - min_initial_location_factor - } -} + }