Skip to content

Commit

Permalink
fix: local were forgotten in some columns
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinFay committed Aug 22, 2024
1 parent dfc1cfe commit c2302ff
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 30 deletions.
75 changes: 45 additions & 30 deletions R/fake_client.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand All @@ -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()
)
)
}
)
Expand Down Expand Up @@ -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)
Expand All @@ -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())
Expand All @@ -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
)
)
}
}
77 changes: 77 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
11 changes: 11 additions & 0 deletions R/utils_fake_clients.R
Original file line number Diff line number Diff line change
@@ -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")
)
}

0 comments on commit c2302ff

Please sign in to comment.