From 36b380641de59b6d0b185fbbf6ad4966bfd49f35 Mon Sep 17 00:00:00 2001 From: colin Date: Thu, 22 Aug 2024 09:45:58 +0200 Subject: [PATCH 1/3] chore: rm devhistory --- devstuff_history.R | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 devstuff_history.R diff --git a/devstuff_history.R b/devstuff_history.R deleted file mode 100644 index 682e2d0..0000000 --- a/devstuff_history.R +++ /dev/null @@ -1,32 +0,0 @@ -# Hide this file from build -usethis::use_build_ignore("devstuff_history.R") -usethis::use_build_ignore("img") -usethis::use_git_ignore("docs") -usethis::use_pipe() - -# Doc -use_readme_rmd() -usethis::use_news_md() -usethis::use_mit_license(name = "ThinkR") -usethis::use_package_doc() -usethis::use_vignette("fake-client-database") - -# dev -attachment::att_to_description(extra.suggests = c("pkgdown", "covr", "ggplot2")) -devtools::check() - -# Readme and stuffs -use_readme_rmd() -use_mit_license(name = "Colin FAY") -use_lifecycle_badge("Experimental") -use_tidy_description() -use_code_of_conduct() - -# CI -use_testthat() -use_test("support") -usethis::use_github_action_check_release() -usethis::use_github_action("pkgdown") -usethis::use_github_action("test-coverage") -usethis::use_coverage() -usethis::use_pkgdown() From 65fa8e9fe5bd9f585dced8c2a2d3b69f3f39a74a Mon Sep 17 00:00:00 2001 From: colin Date: Thu, 22 Aug 2024 09:46:33 +0200 Subject: [PATCH 2/3] fix: local were forgotten in some columns --- R/fake_client.R | 75 ++++++++++++++++++++++++---------------- R/utils.R | 77 ++++++++++++++++++++++++++++++++++++++++++ R/utils_fake_clients.R | 11 ++++++ 3 files changed, 133 insertions(+), 30 deletions(-) create mode 100644 R/utils_fake_clients.R diff --git a/R/fake_client.R b/R/fake_client.R index 79fe587..f8f5e7d 100644 --- a/R/fake_client.R +++ b/R/fake_client.R @@ -23,7 +23,7 @@ fake_base_clients <- function( n, local = c("en_US", "fr_FR"), seed = 2811 - ) { +) { stop_if_not(n, is.numeric, "Please provide a numeric value for `n`") priority_levels <- c("Bronze", "Silver", "Gold", "Platinium") local <- match.arg(local) @@ -88,8 +88,6 @@ fake_base_clients <- function( (1 - fidelity_points / max(.$fidelity_points)), 5 )) %>% with_random_na(), - # priorite = sample(c("Gold","Silver","Bronze", "Platinium"), vol, replace = TRUE), - # priorite_encoded = recode(priorite, Bronze = 1L, Silver = 2L, Gold = 3L, Platinium = 4L), # priorite depending on fidelite priority_encoded = pmax( pmin( @@ -104,7 +102,18 @@ fake_base_clients <- function( levels = priority_levels ) ) %>% - select(num_client, first, last, job, age, region, id_dpt, departement, cb_provider, everything()) + select( + num_client, + first, + last, + job, + age, + region, + id_dpt, + departement, + cb_provider, + everything() + ) ) } ) @@ -168,11 +177,9 @@ fake_ticket_client <- function( split = FALSE, seed = 2811, local = c("en_US", "fr_FR") - ) { +) { local <- match.arg(local) - state_level <- c("En cours", "Attente confirmation client", "Attente validation", "Intervention technicien", "Termine") - source_level <- c("Local", "France", "Europe", "International") if (missing(x)) { x <- fake_base_clients(n = n, seed = seed, local = local) @@ -186,31 +193,17 @@ fake_ticket_client <- function( sample_n(vol, weight = runif(nrow(.), 0.5, 1), replace = TRUE) %>% # Ticket info mutate( - ref = paste0("DOSS-", as_vector(rerun(vol, sample(LETTERS, 4)) %>% map(paste0, collapse = "")), "-", formatC(1:vol, width = nchar(vol) + 1, flag = "0")), + ref = random_doss(vol), timestamp = as.Date(entry_date) + round(runif(nrow(.), 0, Sys.Date() - as.Date(entry_date))), year = year(timestamp), month = month(timestamp), day = day(timestamp), - # an = sample((as.numeric(format(min(entry_date), "%Y")) + 1): - # (as.numeric(format(Sys.Date(), "%Y")) - 1), - # vol, replace = TRUE), - # mois = sample(1:12, vol, replace = TRUE), - # jour = sample(1:28, vol, replace = TRUE), - # point_fidelite = sample(1:10000, vol, replace = TRUE), - # fidelity depending on date - # timestamp = paste(an, mois, jour, sep = "-"), - supported = sample(c("Oui", "Non"), vol, TRUE), - supported_encoded = recode(supported, Oui = 1L, Non = 0L), - type = with_random_na(sample(c("Installation", "Box", "Ligne"), vol, prob = runif(3, 0.25, 1), replace = TRUE)), - type_encoded = recode(type, Installation = 1L, Box = 2L, Ligne = 3L), - state = factor( - sample(state_level, vol, prob = runif(5, 0.25, 1), replace = TRUE), - levels = state_level - ), - source_call = factor( - sample(source_level, vol, replace = TRUE), - source_level - ) + supported = sample_yes(vol, local = local), + supported_encoded = recode_sample_yes(supported, local = local), + type = with_random_na(sample_type(vol, local = local)), + type_encoded = recode_sample_types(type, local = local), + state = sample_state_level(vol, local = local), + source_call = sample_source_call(vol, local = local) ) %>% arrange(year, month, day) %>% select(ref, everything()) @@ -235,12 +228,34 @@ fake_ticket_client <- function( } else if (local == "fr_FR") { list( clients = x, - tickets = res %>% select(ref, num_client, annee, mois, jour, timestamp, pris_en_charge, type, etat, source_appel) + tickets = res %>% select( + ref, + num_client, + annee, + mois, + jour, + timestamp, + pris_en_charge, + type, + etat, + source_appel + ) ) } else { list( clients = x, - tickets = res %>% select(ref, num_client, year, month, day, timestamp, supported, type, state, source_call) + tickets = res %>% select( + ref, + num_client, + year, + month, + day, + timestamp, + supported, + type, + state, + source_call + ) ) } } diff --git a/R/utils.R b/R/utils.R index 731a43f..9ebf2d0 100644 --- a/R/utils.R +++ b/R/utils.R @@ -15,6 +15,83 @@ sample_yes <- function(vol, local = "en_US") { sample(vec, vol, TRUE) } +recode_sample_yes <- function(vec, local = "en_US") { + if (local == "en_US") { + return(recode(vec, Yes = 1L, No = 0L)) + } + if (local == "fr_FR") { + return(recode(vec, Oui = 1L, Non = 0L)) + } +} + +sample_type <- function(vol, local = "en_US") { + if (local == "en_US") { + vec <- c("Settings", "Box", "Phone") + } + if (local == "fr_FR") { + vec <- c("Installation", "Box", "Ligne") + } + sample( + vec, + vol, + prob = runif(3, 0.25, 1), + replace = TRUE + ) +} + +recode_sample_types <- function(vec, local = "en_US") { + if (local == "en_US") { + return(recode(vec, Settings = 1L, Box = 2L, Phone = 3L)) + } + if (local == "fr_FR") { + return(recode(vec, Installation = 1L, Box = 2L, Ligne = 3L)) + } +} + +sample_state_level <- function(vol, local = "en_US") { + if (local == "en_US") { + state_level <- c( + "Running", + "Over", + "technician", + "Waiting for internal validation", + "Waiting for client feedback", + "Done" + ) + } + if (local == "fr_FR") { + state_level <- c( + "En cours", + "Attente confirmation client", + "Attente validation", + "Intervention technicien", + "Termine" + ) + } + factor( + sample( + state_level, + vol, + prob = runif(length(state_level), 0.25, 1), + replace = TRUE + ), + levels = state_level + ) +} + +sample_source_call <- function(vol, local = "en_US") { + source_level <- c( + "Local", + "France", + "Europe", + "International" + ) + factor( + sample(source_level, vol, replace = TRUE), + source_level + ) +} + sample_type <- function(vol, local = "en_US") { if (local == "en_US") vec <- c("Settings", "Box", "Phone") if (local == "fr_FR") vec <- c("Installation", "Box", "Ligne") diff --git a/R/utils_fake_clients.R b/R/utils_fake_clients.R new file mode 100644 index 0000000..0a28e54 --- /dev/null +++ b/R/utils_fake_clients.R @@ -0,0 +1,11 @@ +random_doss <- function(vol) { + paste0( + "DOSS-", + as_vector( + rerun(vol, sample(LETTERS, 4)) %>% + map(paste0, collapse = "") + ), + "-", + formatC(1:vol, width = nchar(vol) + 1, flag = "0") + ) +} From 183630697333500dacaeecaef58ea506a13d3b70 Mon Sep 17 00:00:00 2001 From: colin Date: Thu, 22 Aug 2024 09:47:46 +0200 Subject: [PATCH 3/3] doc: news and desc --- DESCRIPTION | 2 +- NEWS.md | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 71cc2a0..aa1c502 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: fakir Title: Generate Fake Datasets for Prototyping and Teaching -Version: 1.0.0 +Version: 1.1.0 Authors@R: c(person(given = "Colin", family = "Fay", diff --git a/NEWS.md b/NEWS.md index 1320fc8..c64ee4d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# fakir 1.0.0 + +* fix: fixing issue with locals in fake_ticket_client (#9) + # fakir 0.2.0 * New fake dataset with `fake_sondage_answers`: answers to location-transport habits.