#' Title
#'
#' @param folder - path to a folder
#' @param id - an MD5 file id
#'
#' @return - the full path to an .RData file
#' @export
#'
#' @examples
create_file_name <- function(folder, id) {
paste(folder, id, ".RData", sep = "")
}
# Generate hash id functions ----------------------------------------------
#' Generate an MD5 id for a vector of parameters
#'
#' @param datasource_type - the type of data source TP (for trade panel) default to TP
#' @param country - the Country name ex. UK, default to NA
#' @param category - the Category name ex. LAUNDRY, default to NA
#' @param frequency - the frequency of the data (Monthly, Bimonthly, Weekly), default to NA
#' @param product_line - product line ex. Procter & Gamble or Ariel, default to NA
#' @param kpi - Value share, Volume share or TDP share, default to NA
#' @param market_type - market type ex. Retailer, default to NA
#' @param market - a market like Walmart, default to NA
#' @param share_base - a share base like all Liquid detergents, default to NA
#' @param market_to_path - whether the processing involved market on the search path, default to NA
#' @param is_disruption_period - whether the object involved any structural changes, default to NA
#' @param current_period_dates - the current period dates, default to NA
#' @param ref_period_dates - the reference period dates, default to NA
#' @param type - the type of object being saved (like the search tree, or the )
#'
#' @return
#' @export
#'
#' @examples
genederate_hash_id <- function(datasource_type = "TP",
country = NA,
category = NA,
frequency = NA,
product_line = NA,
kpi = NA,
market_type = NA,
market = NA,
share_base = NA,
market_to_path = NA,
is_disruption_period = NA,
current_period_start_date = NA,
current_period_end_date = NA,
ref_period_start_date = NA,
ref_period_end_date = NA,
type
) {
x <- c(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market_type,
market,
share_base,
market_to_path,
is_disruption_period,
as.character(current_period_start_date),
as.character(current_period_end_date),
as.character(ref_period_start_date),
as.character(ref_period_end_date),
type)
id <- digest::digest(x)
return(id)
}
#' A wrapper function for generating hash id for a table containg the dropdowns
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#'
#' @return
#' @export
#'
#' @examples
generate_dropdown_total_market_hash_id <- function(datasource_type,
country,
category,
frequency) {
id <- genederate_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
type = "total_market_dropdown")
return(id)
}
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#'
#' @return
#' @export
#'
#' @examples
generate_versioning_hash_id <- function(datasource_type,
country,
category,
frequency) {
id <- genederate_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
type = "code_version")
return(id)
}
#' A wrapper function for generating hash id for a list of market levels
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#'
#' @return
#' @export
#'
#' @examples
generate_market_level_list_hash_id <- function(datasource_type,
country,
category,
frequency) {
id <- genederate_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
type = "market_level_list")
return(id)
}
#' A wrapper function for generating hash id for a table for the attribute color map
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#'
#' @return
#' @export
#'
#' @examples
generate_attribute_color_map_hash_id <- function(datasource_type,
country,
category,
frequency) {
id <- genederate_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
type = "attribute_color_map")
return(id)
}
#' A wrapper function for generating hash id for a table containg the dropdowns
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#'
#' @return
#' @export
#'
#' @examples
generate_full_dropdown_hash_id <- function(datasource_type,
country,
category,
frequency) {
id <- genederate_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
type = "full_dropdown")
return(id)
}
#' A wrapper function for generating hash id for a disruption period dataframe
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market
#' @param share_base
#'
#' @return
#' @export
#'
#' @examples
generate_disruption_df_hash_id <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base) {
id <- genederate_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
is_disruption_period = T,
type = "disruption_df")
return(id)
}
#' A wrapper function for generating hash id for a disruption period dataframe
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market
#' @param share_base
#'
#' @return
#' @export
#'
#' @examples
generate_dropdown_info_hash_id <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base) {
id <- genederate_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
type = "dropdown_info")
return(id)
}
#' A wrapper function for generating hash id for a disruption period dataframe
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market
#' @param share_base
#'
#' @return
#' @export
#'
#' @examples
generate_standard_periods_hash_id <- function(datasource_type,
country,
category,
frequency) {
id <- genederate_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
is_disruption_period = F,
type = "standard_periods_df")
return(id)
}
#' A wrapper function for generating hash id for a the high level top tables
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market_level
#' @param share_base
#' @param current_period_dates
#' @param ref_period_dates
#'
#' @return
#' @export
#'
#' @examples
generate_top_table_hash_id <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market_level,
share_base,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period) {
id <- genederate_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market_level,
share_base = share_base,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
type = "top_table",
is_disruption_period = is_disruption_period)
return(id)
}
#' A wrapper function for generating hash id for a the high level top tables
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market_level
#' @param share_base
#' @param current_period_dates
#' @param ref_period_dates
#'
#' @return
#' @export
#'
#' @examples
generate_best_marke_type_hash_id <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
share_base,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period) {
id <- genederate_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
share_base = share_base,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
type = "best_market_type",
is_disruption_period = is_disruption_period)
return(id)
}
#' A wrapper function for generating hash id for a core table dataframe
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market
#' @param share_base
#'
#' @return
#' @export
#'
#' @examples
generate_core_table_hash_id <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
market_to_path,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period) {
id <- genederate_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
is_disruption_period = is_disruption_period,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
type = "core_table")
return(id)
}
#' A wrapper function for generating hash id for a core table dataframe
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market
#' @param share_base
#'
#' @return
#' @export
#'
#' @examples
generate_core_comb_res_hash_id <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
market_to_path,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period) {
id <- genederate_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
is_disruption_period = is_disruption_period,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
type = "combination_results")
return(id)
}
generate_core_comb_res_hash_id_bytype <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
market_to_path,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period,
is_iya,
is_category_size,
is_share_of_total_market) {
if (is_iya && is_share_of_total_market) {
core_table_type <- "combination_results_6"
} else if (!is_iya && is_share_of_total_market) {
core_table_type <- "combination_results_5"
} else if (is_iya && is_category_size) {
core_table_type <- "combination_results_4"
} else if (!is_iya && is_category_size) {
core_table_type <- "combination_results_3"
} else if (is_iya && !is_category_size) {
core_table_type <- "combination_results_2"
} else {
core_table_type <- "combination_results_1"
}
id <- genederate_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
is_disruption_period = is_disruption_period,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
type = core_table_type)
return(id)
}
#' A wrapper function for generating hash id for a core table dataframe
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market
#' @param share_base
#'
#' @return
#' @export
#'
#' @examples
generate_core_table_markers_id <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
market_to_path,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period) {
id <- genederate_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
is_disruption_period = is_disruption_period,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
type = "markers")
return(id)
}
#' A wrapper function for generating hash id for a core table dataframe
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market
#' @param share_base
#'
#' @return
#' @export
#'
#' @examples
generate_disruption_drivers_hash_id <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
market_to_path,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period) {
id <- genederate_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
is_disruption_period = is_disruption_period,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
type = "disruption_drivers")
return(id)
}
#' A wrapper function for generating hash id for a core table dataframe
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market
#' @param share_base
#'
#' @return
#' @export
#'
#' @examples
generate_tree_table_hash_id <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
market_to_path,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period) {
id <- genederate_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
is_disruption_period = is_disruption_period,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
type = "tree_table")
return(id)
}
#' A wrapper function for generating hash id for a core table dataframe
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market
#' @param share_base
#'
#' @return
#' @export
#'
#' @examples
generate_full_tree_table_hash_id <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
market_to_path,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period) {
id <- genederate_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
is_disruption_period = is_disruption_period,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
type = "full_tree_table")
return(id)
}
#' A wrapper function for generating hash id for a competition rtb table dataframe
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market
#' @param share_base
#' @param market_to_path
#' @param current_period_start_date
#' @param current_period_end_date
#' @param ref_period_start_date
#' @param ref_period_end_date
#' @param is_disruption_period
#'
#' @return
#' @export
#'
#' @examples
generate_competition_rtb_hash_id <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
market_to_path,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period) {
id <- genederate_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
is_disruption_period = is_disruption_period,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
type = "competition_rtb_tbl")
return(id)
}
#' A wrapper function for generating hash id for a competition time series object
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market
#' @param share_base
#' @param market_to_path
#' @param current_period_start_date
#' @param current_period_end_date
#' @param ref_period_start_date
#' @param ref_period_end_date
#' @param is_disruption_period
#'
#' @return
#' @export
#'
#' @examples
generate_competition_time_series_hash_id <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
market_to_path,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period) {
id <- genederate_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
is_disruption_period = is_disruption_period,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
type = "competition_time_series")
return(id)
}
#' A wrapper function for generating hash id for a tree rtb table
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market
#' @param share_base
#' @param market_to_path
#' @param current_period_start_date
#' @param current_period_end_date
#' @param ref_period_start_date
#' @param ref_period_end_date
#' @param is_disruption_period
#'
#' @return
#' @export
#'
#' @examples
generate_tree_rtb_hash_id <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
market_to_path,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period) {
id <- genederate_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
is_disruption_period = is_disruption_period,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
type = "tree_rtb")
return(id)
}
#' A wrapper function for generating hash id for driver time series
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market
#' @param share_base
#' @param market_to_path
#' @param current_period_start_date
#' @param current_period_end_date
#' @param ref_period_start_date
#' @param ref_period_end_date
#' @param is_disruption_period
#'
#' @return
#' @export
#'
#' @examples
generate_driver_time_series_hash_id <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
market_to_path,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period) {
id <- genederate_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
is_disruption_period = is_disruption_period,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
type = "driver_time_series")
return(id)
}
# Get functions section ---------------------------------------------------
#' A function that returns a disruption period data frame from, stored on a file whose
#' file name is generated by an MD5 digest of a vector of parameters
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market
#' @param share_base
#' @param folder
#'
#' @return
#' @export
#'
#' @examples
get_disruption_df <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
folder) {
id <- generate_disruption_df_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base)
file_name <- create_file_name(folder, id)
if (!file.exists(file_name)) stop("Couldn't find the file with id ", id, " in folder ", folder)
load(file_name)
if (!exists("disruption_periods_df", environment())) stop("Disruption period not loaded from file")
return(disruption_periods_df)
}
#' A function that returns a disruption period data frame from, stored on a file whose
#' file name is generated by an MD5 digest of a vector of parameters
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market
#' @param share_base
#' @param folder
#'
#' @return
#' @export
#'
#' @examples
get_dropdown_info <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
folder) {
id <- generate_dropdown_info_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base)
file_name <- create_file_name(folder, id)
if (!file.exists(file_name)) stop("Couldn't find the file with id ", id, " in folder ", folder)
load(file_name)
if (!exists("dropdown_info", environment())) stop("Disruption period not loaded from file")
dropdown_info <- add_warning_message_to_standard_periods(dropdown_info)
dropdown_info[["opening_sentence"]] <- samanta_top_message(dropdown_info)
return(dropdown_info)
}
#' A function that returns a standard periods data frame from, stored on a file whose
#' file name is generated by an MD5 digest of a vector of parameters
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market
#' @param share_base
#' @param folder
#'
#' @return
#' @export
#'
#' @examples
get_standard_periods_df <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
folder) {
id <- generate_standard_periods_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency)
file_name <- create_file_name(folder, id)
if (!file.exists(file_name)) stop("Couldn't find the file with id ", id, " in folder ", folder)
load(file_name)
if (!exists("standard_periods_df", environment())) stop("Standard periods not loaded from file")
res <- standard_periods_df[standard_periods_df$product_line == product_line &
standard_periods_df$kpi == kpi &
standard_periods_df$market == market &
standard_periods_df$share_base == share_base
, -c(1,2,3,4), drop = F]
return(res)
}
#' A function that returns a top table data frame stored on a file whose
#' file name is generated by an MD5 digest of a vector of parameters
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market_level
#' @param share_base
#' @param current_period_dates
#' @param ref_period_dates
#' @param folder
#'
#' @return
#' @export
#'
#' @examples
get_top_table <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market_level,
share_base,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period,
folder) {
id <- generate_top_table_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market_level = market_level,
share_base = share_base,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
is_disruption_period = is_disruption_period)
file_name <- create_file_name(folder, id)
if (!file.exists(file_name)) stop("Couldn't find the file with id ", id, " in folder ", folder)
load(file_name)
if (!exists("top_table", environment())) stop("Top table not loaded from file")
return(top_table)
}
#' A function that returns a top table data frame stored on a file whose
#' file name is generated by an MD5 digest of a vector of parameters
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market_level
#' @param share_base
#' @param current_period_dates
#' @param ref_period_dates
#' @param folder
#'
#' @return
#' @export
#'
#' @examples
get_best_market_type <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
share_base,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period,
folder) {
id <- generate_best_marke_type_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
share_base = share_base,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
is_disruption_period = is_disruption_period)
file_name <- create_file_name(folder, id)
if (!file.exists(file_name)) stop("Couldn't find the file with id ", id, " in folder ", folder)
load(file_name)
if (!exists("best_market_type", environment())) stop("Best market type not loaded from file")
return(best_market_type)
}
#' A function that returns a top table data frame stored on a file whose
#' file name is generated by an MD5 digest of a vector of parameters
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market_level
#' @param share_base
#' @param current_period_dates
#' @param ref_period_dates
#' @param folder
#'
#' @return
#' @export
#'
#' @examples
get_core_table <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
market_to_path,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period,
folder) {
id <- generate_core_table_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
is_disruption_period = is_disruption_period)
# id <- generate_core_comb_res_hash_id(datasource_type = datasource_type,
# country = country,
# category = category,
# frequency = frequency,
# product_line = product_line,
# kpi = kpi,
# market = market,
# share_base = share_base,
# market_to_path = market_to_path,
# current_period_start_date = current_period_start_date,
# current_period_end_date = current_period_end_date,
# ref_period_start_date = ref_period_start_date,
# ref_period_end_date = ref_period_end_date,
# is_disruption_period = is_disruption_period)
file_name <- create_file_name(folder, id)
if (!file.exists(file_name)) stop("Couldn't find the file with id ", id, " in folder ", folder)
load(file_name)
# if (!exists("core_table", environment())) stop("Core table not loaded from file")
# if (!exists("res_list", environment())) stop("Core table not loaded from file")
# core_table <- res_list$core_table
# core_table <- remove_unwanted_cols(core_table)
return(core_table)
}
#' A function that returns a top table data frame stored on a file whose
#' file name is generated by an MD5 digest of a vector of parameters
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market_level
#' @param share_base
#' @param current_period_dates
#' @param ref_period_dates
#' @param folder
#'
#' @return
#' @export
#'
#' @examples
get_disruption_drivers <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
market_to_path,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period,
folder) {
id <- generate_disruption_drivers_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
is_disruption_period = is_disruption_period)
# id <- generate_core_comb_res_hash_id(datasource_type = datasource_type,
# country = country,
# category = category,
# frequency = frequency,
# product_line = product_line,
# kpi = kpi,
# market = market,
# share_base = share_base,
# market_to_path = market_to_path,
# current_period_start_date = current_period_start_date,
# current_period_end_date = current_period_end_date,
# ref_period_start_date = ref_period_start_date,
# ref_period_end_date = ref_period_end_date,
# is_disruption_period = is_disruption_period)
file_name <- create_file_name(folder, id)
if (!file.exists(file_name)) stop("Couldn't find the file with id ", id, " in folder ", folder)
load(file_name)
if (!exists("disruption_drivers", environment())) stop("Disruptuion drivers could not be loaded from file")
return(disruption_drivers)
# if (!exists("res_list", environment())) stop("Disruptuion drivers could not be loaded from file")
# return(res_list$disruption_drivers)
}
#' A function that returns a top table data frame stored on a file whose
#' file name is generated by an MD5 digest of a vector of parameters
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market_level
#' @param share_base
#' @param current_period_dates
#' @param ref_period_dates
#' @param folder
#'
#' @return
#' @export
#'
#' @examples
get_core_table_markers <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
market_to_path,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period,
folder) {
id <- generate_core_table_markers_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
is_disruption_period = is_disruption_period)
# id <- generate_core_comb_res_hash_id(datasource_type = datasource_type,
# country = country,
# category = category,
# frequency = frequency,
# product_line = product_line,
# kpi = kpi,
# market = market,
# share_base = share_base,
# market_to_path = market_to_path,
# current_period_start_date = current_period_start_date,
# current_period_end_date = current_period_end_date,
# ref_period_start_date = ref_period_start_date,
# ref_period_end_date = ref_period_end_date,
# is_disruption_period = is_disruption_period)
file_name <- create_file_name(folder, id)
if (!file.exists(file_name)) stop("Couldn't find the file with id ", id, " in folder ", folder)
load(file_name)
if (!exists("core_table_markers", environment())) stop("Core table markers not loaded from file")
return(core_table_markers)
# if (!exists("res_list", environment())) stop("Core table markers not loaded from file")
# return(res_list$core_table_markers)
}
#' A function that returns a top table data frame stored on a file whose
#' file name is generated by an MD5 digest of a vector of parameters
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market_level
#' @param share_base
#' @param current_period_dates
#' @param ref_period_dates
#' @param folder
#'
#' @return
#' @export
#'
#' @examples
get_tree_table <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
market_to_path,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period,
folder) {
id <- generate_tree_table_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
is_disruption_period = is_disruption_period)
# id <- generate_core_comb_res_hash_id(datasource_type = datasource_type,
# country = country,
# category = category,
# frequency = frequency,
# product_line = product_line,
# kpi = kpi,
# market = market,
# share_base = share_base,
# market_to_path = market_to_path,
# current_period_start_date = current_period_start_date,
# current_period_end_date = current_period_end_date,
# ref_period_start_date = ref_period_start_date,
# ref_period_end_date = ref_period_end_date,
# is_disruption_period = is_disruption_period)
file_name <- create_file_name(folder, id)
if (!file.exists(file_name)) stop("Couldn't find the file with id ", id, " in folder ", folder)
load(file_name)
if (!exists("tree_table", environment())) stop("Core table not loaded from file")
return(tree_table)
# if (!exists("res_list", environment())) stop("Core table not loaded from file")
# return(res_list$pruned_tree)
}
#' A function that returns a top table data frame stored on a file whose
#' file name is generated by an MD5 digest of a vector of parameters
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market_level
#' @param share_base
#' @param current_period_dates
#' @param ref_period_dates
#' @param folder
#'
#' @return
#' @export
#'
#' @examples
get_full_tree_table <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
market_to_path,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period,
folder) {
id <- generate_full_tree_table_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
is_disruption_period = is_disruption_period)
# id <- generate_core_comb_res_hash_id(datasource_type = datasource_type,
# country = country,
# category = category,
# frequency = frequency,
# product_line = product_line,
# kpi = kpi,
# market = market,
# share_base = share_base,
# market_to_path = market_to_path,
# current_period_start_date = current_period_start_date,
# current_period_end_date = current_period_end_date,
# ref_period_start_date = ref_period_start_date,
# ref_period_end_date = ref_period_end_date,
# is_disruption_period = is_disruption_period)
file_name <- create_file_name(folder, id)
if (!file.exists(file_name)) stop("Couldn't find the file with id ", id, " in folder ", folder)
load(file_name)
if (!exists("full_tree_table", environment())) stop("Core table not loaded from file")
return(full_tree_table)
# if (!exists("res_list", environment())) stop("Core table not loaded from file")
# return(res_list$full_tree)
}
#' A function that returns a competition R.T.B. data frame stored on a file whose
#' file name is generated by an MD5 digest of a vector of parameters
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market_level
#' @param share_base
#' @param current_period_dates
#' @param ref_period_dates
#' @param folder
#'
#' @return
#' @export
#'
#' @examples
get_competition_rtb_table <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
market_to_path,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period,
folder) {
id <- generate_competition_rtb_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
is_disruption_period = is_disruption_period)
# id <- generate_core_comb_res_hash_id(datasource_type = datasource_type,
# country = country,
# category = category,
# frequency = frequency,
# product_line = product_line,
# kpi = kpi,
# market = market,
# share_base = share_base,
# market_to_path = market_to_path,
# current_period_start_date = current_period_start_date,
# current_period_end_date = current_period_end_date,
# ref_period_start_date = ref_period_start_date,
# ref_period_end_date = ref_period_end_date,
# is_disruption_period = is_disruption_period)
file_name <- create_file_name(folder, id)
if (!file.exists(file_name)) stop("Couldn't find the file with id ", id, " in folder ", folder)
load(file_name)
if (!exists("competition_rtb", environment())) stop("Core table not loaded from file")
return(competition_rtb)
# if (!exists("res_list", environment())) stop("Core table not loaded from file")
# return(res_list$competition_rtb)
}
#' A function that returns a compeition time series data frame stored on a file whose
#' file name is generated by an MD5 digest of a vector of parameters
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market_level
#' @param share_base
#' @param current_period_dates
#' @param ref_period_dates
#' @param folder
#'
#' @return
#' @export
#'
#' @examples
get_competition_time_series_table <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
market_to_path,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period,
folder) {
id <- generate_competition_time_series_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
is_disruption_period = is_disruption_period)
# id <- generate_core_comb_res_hash_id(datasource_type = datasource_type,
# country = country,
# category = category,
# frequency = frequency,
# product_line = product_line,
# kpi = kpi,
# market = market,
# share_base = share_base,
# market_to_path = market_to_path,
# current_period_start_date = current_period_start_date,
# current_period_end_date = current_period_end_date,
# ref_period_start_date = ref_period_start_date,
# ref_period_end_date = ref_period_end_date,
# is_disruption_period = is_disruption_period)
file_name <- create_file_name(folder, id)
if (!file.exists(file_name)) stop("Couldn't find the file with id ", id, " in folder ", folder)
load(file_name)
if (!exists("competition_time_series", environment())) stop("Core table not loaded from file")
return(competition_time_series)
# if (!exists("res_list", environment())) stop("Core table not loaded from file")
# return(res_list$competition_time_series)
}
#' A function that returns a list of tree R.T.B. frame stored on a file whose
#' file name is generated by an MD5 digest of a vector of parameters
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market_level
#' @param share_base
#' @param current_period_dates
#' @param ref_period_dates
#' @param folder
#'
#' @return
#' @export
#'
#' @examples
get_tree_rtb <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
market_to_path,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period,
folder) {
id <- generate_tree_rtb_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
is_disruption_period = is_disruption_period)
# id <- generate_core_comb_res_hash_id(datasource_type = datasource_type,
# country = country,
# category = category,
# frequency = frequency,
# product_line = product_line,
# kpi = kpi,
# market = market,
# share_base = share_base,
# market_to_path = market_to_path,
# current_period_start_date = current_period_start_date,
# current_period_end_date = current_period_end_date,
# ref_period_start_date = ref_period_start_date,
# ref_period_end_date = ref_period_end_date,
# is_disruption_period = is_disruption_period)
file_name <- create_file_name(folder, id)
if (!file.exists(file_name)) stop("Couldn't find the file with id ", id, " in folder ", folder)
load(file_name)
if (!exists("tree_rtb", environment())) stop("Core table not loaded from file")
return(tree_rtb)
# if (!exists("res_list", environment())) stop("Core table not loaded from file")
# return(res_list$tree_rtb)
}
#' A function that returns a top table data frame stored on a file whose
#' file name is generated by an MD5 digest of a vector of parameters
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market_level
#' @param share_base
#' @param current_period_dates
#' @param ref_period_dates
#' @param folder
#'
#' @return
#' @export
#'
#' @examples
get_driver_time_series <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
market_to_path,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period,
folder) {
id <- generate_driver_time_series_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
is_disruption_period = is_disruption_period)
# id <- generate_core_comb_res_hash_id(datasource_type = datasource_type,
# country = country,
# category = category,
# frequency = frequency,
# product_line = product_line,
# kpi = kpi,
# market = market,
# share_base = share_base,
# market_to_path = market_to_path,
# current_period_start_date = current_period_start_date,
# current_period_end_date = current_period_end_date,
# ref_period_start_date = ref_period_start_date,
# ref_period_end_date = ref_period_end_date,
# is_disruption_period = is_disruption_period)
file_name <- create_file_name(folder, id)
if (!file.exists(file_name)) stop("Couldn't find the file with id ", id, " in folder ", folder)
load(file_name)
if (!exists("driver_time_series", environment())) stop("Core table not loaded from file")
return(driver_time_series)
# if (!exists("res_list", environment())) stop("Core table not loaded from file")
# return(res_list$driver_time_series)
}
#' A wrapper function for generating hash id for a table containg the dropdowns
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param folder
#' @param dropdown_tbl
#'
#' @return
#' @export
#'
#' @examples
get_dropdown_total_market <- function(datasource_type,
country,
category,
frequency,
folder) {
id <- generate_dropdown_total_market_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency)
file_name <- create_file_name(folder, id)
if (!file.exists(file_name)) stop("Couldn't find the file with id ", id, " in folder ", folder)
load(file_name)
if (!exists("dropdown_tbl", environment())) stop("Dropdown couldn't be loaded from file")
res <- create_pre_json_list(dropdown_tbl)
res
}
#' A wrapper function for generating hash id for a table containg the dropdowns
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param folder
#' @param dropdown_tbl
#'
#' @return
#' @export
#'
#' @examples
get_code_version <- function(datasource_type,
country,
category,
frequency,
folder) {
id <- generate_versioning_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency)
file_name <- create_file_name(folder, id)
backend_code_versions <- list(`Priority execution version` = "Unavailable",
`Points of interest version` = "Unavailable",
`Flower algo version` = "Unavailable",
`Opinion on drivers version` = "Unavailable")
if (!file.exists(file_name)) return(backend_code_versions)
load(file_name)
if (!exists("code_version", environment())) return(backend_code_versions)
if (!is.null(code_version$prioritization_code_version)) {
backend_code_versions$`Priority execution version` <- code_version$prioritization_code_version
}
if (!is.null(code_version$breakpoints_code_version)) {
backend_code_versions$`Points of interest version` <- code_version$breakpoints_code_version
}
if (!is.null(code_version$core_algorithms_version)) {
backend_code_versions$`Flower algo version` <- code_version$core_algorithms_version
}
if (!is.null(code_version$opinion_on_drivers_ver)) {
backend_code_versions$`Opinion on drivers version` <- code_version$opinion_on_drivers_ver
} else if (is.null(code_version$opinion_on_drivers_ver) & !is.null(code_version$opinion_on_drivers_ver)) { # this part makes sense only because we have a transition
backend_code_versions$`Opinion on drivers version` <- "1.0.0"
}
return(backend_code_versions)
}
generate_versioning_hash_id
#' A wrapper function for generating hash id for a table containg the dropdowns
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param folder
#' @param dropdown_tbl
#'
#' @return
#' @export
#'
#' @examples
get_full_dropdown <- function(datasource_type,
country,
category,
frequency,
folder) {
id <- generate_full_dropdown_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency)
file_name <- create_file_name(folder, id)
if (!file.exists(file_name)) stop("Couldn't find the file with id ", id, " in folder ", folder)
load(file_name)
if (!exists("dropdown_tbl", environment())) stop("Dropdown couldn't be loaded from file")
res <- list()
res$full_dropdown <- create_pre_json_list(dropdown_tbl)
res$`R code version` <- get_code_version(datasource_type,
country,
category,
frequency,
folder)
res
}
#' A wrapper function for generating getting the attribute color map
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param folder
#' @param dropdown_tbl
#'
#' @return
#' @export
#'
#' @examples
get_attribute_color_map <- function(datasource_type,
country,
category,
frequency,
folder) {
id <- generate_attribute_color_map_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency)
file_name <- create_file_name(folder, id)
if (!file.exists(file_name)) stop("Couldn't find the file with id ", id, " in folder ", folder)
load(file_name)
if (!exists("attribute_color_map", environment())) stop("attribute_color_map couldn't be loaded from file")
return(attribute_color_map)
}
#' A wrapper function for getting the list of market types
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param folder
#' @param dropdown_tbl
#'
#' @return
#' @export
#'
#' @examples
get_market_types <- function(datasource_type,
country,
category,
frequency,
folder) {
id <- generate_market_level_list_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency)
file_name <- create_file_name(folder, id)
if (!file.exists(file_name)) stop("Couldn't find the file with id ", id, " in folder ", folder)
load(file_name)
if (!exists("market_types", environment())) stop("attribute_color_map couldn't be loaded from file")
return(market_types)
}
# Saving functions section ------------------------------------------------
#' Saves the disruption period ot a file
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market
#' @param share_base
#' @param folder
#' @param disruption_periods_df
#'
#' @return
#' @export
#'
#' @examples
save_disruption_df <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
folder,
disruption_periods_df) {
id <- generate_disruption_df_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base)
file_name <- create_file_name(folder, id)
save(disruption_periods_df, file = file_name)
return(NULL)
}
#' A function that returns a disruption period data frame from, stored on a file whose
#' file name is generated by an MD5 digest of a vector of parameters
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market
#' @param share_base
#' @param folder
#'
#' @return
#' @export
#'
#' @examples
save_dropdown_info <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
folder,
dropdown_info) {
id <- generate_dropdown_info_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base)
file_name <- create_file_name(folder, id)
save(dropdown_info, file = file_name)
return(NULL)
}
#' Saves the disruption period ot a file
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market
#' @param share_base
#' @param folder
#' @param standard_periods_df
#'
#' @return
#' @export
#'
#' @examples
save_standard_periods_df <- function(datasource_type,
country,
category,
frequency,
folder,
standard_periods_df) {
id <- generate_standard_periods_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency)
file_name <- create_file_name(folder, id)
save(standard_periods_df, file = file_name)
return(NULL)
}
#' Saves the top table to a file
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market_level
#' @param share_base
#' @param folder
#' @param current_period_dates
#' @param ref_period_dates
#' @param top_table
#'
#' @return
#' @export
#'
#' @examples
save_top_table <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market_level,
share_base,
folder,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period,
top_table) {
id <- generate_top_table_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market_level = market_level,
share_base = share_base,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
is_disruption_period = is_disruption_period)
file_name <- create_file_name(folder, id)
save(top_table, file = file_name)
return(NULL)
}
#' Saves the top table to a file
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market_level
#' @param share_base
#' @param folder
#' @param current_period_dates
#' @param ref_period_dates
#' @param top_table
#'
#' @return
#' @export
#'
#' @examples
save_best_market_type <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
share_base,
folder,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period,
best_market_type) {
id <- generate_best_marke_type_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
share_base = share_base,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
is_disruption_period = is_disruption_period)
file_name <- create_file_name(folder, id)
save(best_market_type, file = file_name)
return(NULL)
}
#' Saves the top table to a file
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market_level
#' @param share_base
#' @param folder
#' @param current_period_dates
#' @param ref_period_dates
#' @param top_table
#'
#' @return
#' @export
#'
#' @examples
save_core_combination_results <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
folder,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period,
market_to_path,
core_table,
pruned_tree,
full_tree,
disruption_drivers,
core_table_markers,
competition_rtb,
tree_rtb,
competition_time_series,
drivers_time_series
) {
id <- generate_core_comb_res_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
is_disruption_period = is_disruption_period)
file_name <- create_file_name(folder, id)
res_list <- list(core_table = core_table,
pruned_tree = pruned_tree,
full_tree = full_tree,
disruption_drivers = disruption_drivers,
core_table_markers = core_table_markers,
competition_rtb = competition_rtb,
tree_rtb = tree_rtb,
competition_time_series = competition_time_series,
drivers_time_series = drivers_time_series)
save(res_list, file = file_name)
return(NULL)
}
#' Saves the top table to a file
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market_level
#' @param share_base
#' @param folder
#' @param current_period_dates
#' @param ref_period_dates
#' @param top_table
#'
#' @return
#' @export
#'
#' @examples
save_core_table <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
folder,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period,
market_to_path,
core_table) {
id <- generate_core_table_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
is_disruption_period = is_disruption_period)
file_name <- create_file_name(folder, id)
save(core_table, file = file_name)
return(NULL)
}
#' Saves the top table to a file
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market_level
#' @param share_base
#' @param folder
#' @param current_period_dates
#' @param ref_period_dates
#' @param top_table
#'
#' @return
#' @export
#'
#' @examples
save_disruption_drivers <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
folder,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period,
market_to_path,
disruption_drivers) {
id <- generate_disruption_drivers_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
is_disruption_period = is_disruption_period)
file_name <- create_file_name(folder, id)
save(disruption_drivers, file = file_name)
return(NULL)
}
#' Saves the top table to a file
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market_level
#' @param share_base
#' @param folder
#' @param current_period_dates
#' @param ref_period_dates
#' @param top_table
#'
#' @return
#' @export
#'
#' @examples
save_core_table_markers <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
folder,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period,
market_to_path,
core_table_markers) {
id <- generate_core_table_markers_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
is_disruption_period = is_disruption_period)
file_name <- create_file_name(folder, id)
save(core_table_markers, file = file_name)
return(NULL)
}
#' Saves the top table to a file
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market_level
#' @param share_base
#' @param folder
#' @param current_period_dates
#' @param ref_period_dates
#' @param top_table
#'
#' @return
#' @export
#'
#' @examples
save_tree_table <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
folder,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period,
market_to_path,
tree_table) {
id <- generate_tree_table_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
is_disruption_period = is_disruption_period)
file_name <- create_file_name(folder, id)
save(tree_table, file = file_name)
return(NULL)
}
#' Saves the tree table to a file
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market_level
#' @param share_base
#' @param folder
#' @param current_period_dates
#' @param ref_period_dates
#' @param top_table
#'
#' @return
#' @export
#'
#' @examples
save_full_tree_table <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
folder,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period,
market_to_path,
full_tree_table) {
id <- generate_full_tree_table_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
is_disruption_period = is_disruption_period)
file_name <- create_file_name(folder, id)
save(full_tree_table, file = file_name)
return(NULL)
}
#' Saves the top table to a file
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market_level
#' @param share_base
#' @param folder
#' @param current_period_dates
#' @param ref_period_dates
#' @param top_table
#'
#' @return
#' @export
#'
#' @examples
save_competition_rtb <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
folder,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period,
market_to_path,
competition_rtb) {
id <- generate_competition_rtb_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
is_disruption_period = is_disruption_period)
file_name <- create_file_name(folder, id)
save(competition_rtb, file = file_name)
return(NULL)
}
#' Saves the top table to a file
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market_level
#' @param share_base
#' @param folder
#' @param current_period_dates
#' @param ref_period_dates
#' @param top_table
#'
#' @return
#' @export
#'
#' @examples
save_competition_time_series <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
folder,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period,
market_to_path,
competition_time_series) {
id <- generate_competition_time_series_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
is_disruption_period = is_disruption_period)
file_name <- create_file_name(folder, id)
save(competition_time_series, file = file_name)
return(NULL)
}
#' Saves the top table to a file
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market_level
#' @param share_base
#' @param folder
#' @param current_period_dates
#' @param ref_period_dates
#' @param top_table
#'
#' @return
#' @export
#'
#' @examples
save_tree_rtb <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
folder,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period,
market_to_path,
tree_rtb) {
id <- generate_tree_rtb_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
is_disruption_period = is_disruption_period)
file_name <- create_file_name(folder, id)
save(tree_rtb, file = file_name)
return(NULL)
}
#' Saves the top table to a file
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param product_line
#' @param kpi
#' @param market_level
#' @param share_base
#' @param folder
#' @param current_period_dates
#' @param ref_period_dates
#' @param top_table
#'
#' @return
#' @export
#'
#' @examples
save_driver_time_series <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
folder,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period,
market_to_path,
driver_time_series) {
id <- generate_driver_time_series_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
is_disruption_period = is_disruption_period)
file_name <- create_file_name(folder, id)
save(driver_time_series, file = file_name)
return(NULL)
}
#' A wrapper function for generating hash id for a table containg the dropdowns
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param folder
#' @param dropdown_tbl
#'
#' @return
#' @export
#'
#' @examples
save_dropdown_total_market <- function(datasource_type,
country,
category,
frequency,
folder,
dropdown_tbl) {
id <- generate_dropdown_total_market_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency)
file_name <- create_file_name(folder, id)
save(dropdown_tbl, file = file_name)
return(NULL)
}
#' A wrapper function for generating hash id for a table containg the dropdowns
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param folder
#' @param dropdown_tbl
#'
#' @return
#' @export
#'
#' @examples
save_code_version <- function(datasource_type,
country,
category,
frequency,
folder,
code_version) {
id <- generate_versioning_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency)
file_name <- create_file_name(folder, id)
save(code_version, file = file_name)
return(NULL)
}
#' A wrapper function for generating hash id for a table containg the dropdowns
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param folder
#' @param dropdown_tbl
#'
#' @return
#' @export
#'
#' @examples
save_full_dropdown <- function(datasource_type,
country,
category,
frequency,
folder,
dropdown_tbl) {
id <- generate_full_dropdown_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency)
file_name <- create_file_name(folder, id)
save(dropdown_tbl, file = file_name)
return(NULL)
}
#' A wrapper function for saving the attribute color map
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param folder
#' @param dropdown_tbl
#'
#' @return
#' @export
#'
#' @examples
save_attribute_color_map <- function(datasource_type,
country,
category,
frequency,
folder,
attribute_color_map) {
id <- generate_attribute_color_map_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency)
file_name <- create_file_name(folder, id)
save(attribute_color_map, file = file_name)
return(NULL)
}
#' A wrapper function for saving the market types
#'
#' @param datasource_type
#' @param country
#' @param category
#' @param frequency
#' @param folder
#' @param dropdown_tbl
#'
#' @return
#' @export
#'
#' @examples
save_market_types <- function(datasource_type,
country,
category,
frequency,
folder,
market_types) {
id <- generate_market_level_list_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency)
file_name <- create_file_name(folder, id)
save(market_types, file = file_name)
return(NULL)
}
save_core_combination_res <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
market_to_path,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period,
folder,
core_res_list) {
id <- generate_core_comb_res_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
is_disruption_period = is_disruption_period,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date)
file_name <- create_file_name(folder, id)
save(core_res_list, file = file_name)
return(NULL)
}
load_core_combination_res <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
market_to_path,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period,
folder) {
id <- generate_core_comb_res_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
is_disruption_period = is_disruption_period,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date)
file_name <- create_file_name(folder, id)
load(file = file_name)
if (!exists("core_res_list", environment())) stop("Core combination result not loaded from file")
return(core_res_list)
}
append_core_combination_res <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
market_to_path,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period,
folder,
load_folder_source = NULL, # this is needed due to dropzone archietcture
list_to_append) {
id <- generate_core_comb_res_hash_id(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
is_disruption_period = is_disruption_period,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date)
if (!is.null(load_folder_source)) {
load_file_name <- create_file_name(load_folder_source, id)
file_name <- create_file_name(folder, id)
} else {
load_file_name <- create_file_name(folder, id)
file_name <- load_file_name
}
load(file = load_file_name)
if (!exists("core_res_list", environment())) stop("Core combination result not loaded from file")
core_res_list <- append(core_res_list, list_to_append)
save(core_res_list, file = file_name)
return(NULL)
}
save_core_combination_res_bytype <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
market_to_path,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period,
folder,
core_res_list,
is_iya,
is_category_size,
is_share_of_total_market) {
id <- generate_core_comb_res_hash_id_bytype(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
is_disruption_period = is_disruption_period,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
is_iya = is_iya,
is_category_size = is_category_size,
is_share_of_total_market = is_share_of_total_market)
file_name <- create_file_name(folder, id)
save(core_res_list, file = file_name)
return(NULL)
}
load_core_combination_res_bytype <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
market_to_path,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period,
folder,
is_iya,
is_category_size,
is_share_of_total_market) {
id <- generate_core_comb_res_hash_id_bytype(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
is_disruption_period = is_disruption_period,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
is_iya = is_iya,
is_category_size = is_category_size,
is_share_of_total_market = is_share_of_total_market)
file_name <- create_file_name(folder, id)
load(file = file_name)
if (!exists("core_res_list", environment())) stop("Core combination result not loaded from file")
return(core_res_list)
}
append_core_combination_res_bytype <- function(datasource_type,
country,
category,
frequency,
product_line,
kpi,
market,
share_base,
market_to_path,
current_period_start_date,
current_period_end_date,
ref_period_start_date,
ref_period_end_date,
is_disruption_period,
folder,
list_to_append,
is_iya,
is_category_size,
is_share_of_total_market) {
id <- generate_core_comb_res_hash_id_bytype(datasource_type = datasource_type,
country = country,
category = category,
frequency = frequency,
product_line = product_line,
kpi = kpi,
market = market,
share_base = share_base,
market_to_path = market_to_path,
is_disruption_period = is_disruption_period,
current_period_start_date = current_period_start_date,
current_period_end_date = current_period_end_date,
ref_period_start_date = ref_period_start_date,
ref_period_end_date = ref_period_end_date,
is_iya = is_iya,
is_category_size = is_category_size,
is_share_of_total_market = is_share_of_total_market)
file_name <- create_file_name(folder, id)
load(file = file_name)
if (!exists("core_res_list", environment())) stop("Core combination result not loaded from file")
core_res_list <- append(core_res_list, list_to_append)
save(core_res_list, file = file_name)
return(NULL)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.