Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixing issue with locals in fake_ticket_client #10

Merged
merged 3 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
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")
)
}
32 changes: 0 additions & 32 deletions devstuff_history.R

This file was deleted.

Loading