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: local were forgotten in some columns #12

Merged
merged 5 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
7 changes: 5 additions & 2 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ on:
pull_request:
branches: [main, master]

name: R-CMD-check
name: R-CMD-check.yaml

permissions: read-all

jobs:
R-CMD-check:
Expand All @@ -29,7 +31,7 @@ jobs:
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

Expand All @@ -47,3 +49,4 @@ jobs:
- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
85 changes: 85 additions & 0 deletions .github/workflows/pr-commands.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
issue_comment:
types: [created]

name: pr-commands.yaml

permissions: read-all

jobs:
document:
if: ${{ github.event.issue.pull_request && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') && startsWith(github.event.comment.body, '/document') }}
name: document
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/pr-fetch@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::roxygen2
needs: pr-document

- name: Document
run: roxygen2::roxygenise()
shell: Rscript {0}

- name: commit
run: |
git config --local user.name "$GITHUB_ACTOR"
git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com"
git add man/\* NAMESPACE
git commit -m 'Document'
- uses: r-lib/actions/pr-push@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

style:
if: ${{ github.event.issue.pull_request && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') && startsWith(github.event.comment.body, '/style') }}
name: style
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/pr-fetch@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- uses: r-lib/actions/setup-r@v2

- name: Install dependencies
run: install.packages("styler")
shell: Rscript {0}

- name: Style
run: styler::style_pkg()
shell: Rscript {0}

- name: commit
run: |
git config --local user.name "$GITHUB_ACTOR"
git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com"
git add \*.R
git commit -m 'Style'
- uses: r-lib/actions/pr-push@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
45 changes: 38 additions & 7 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Workflow derived from https://github.com/r-lib/actions/tree/master/examples
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: test-coverage
name: test-coverage.yaml

permissions: read-all

jobs:
test-coverage:
Expand All @@ -15,16 +17,45 @@ jobs:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v1
- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v1
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: covr
extra-packages: any::covr, any::xml2
needs: coverage

- name: Test coverage
run: covr::codecov()
run: |
cov <- covr::package_coverage(
quiet = FALSE,
clean = FALSE,
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
covr::to_cobertura(cov)
shell: Rscript {0}

- uses: codecov/codecov-action@v4
with:
fail_ci_if_error: ${{ github.event_name != 'pull_request' && true || false }}
file: ./cobertura.xml
plugin: noop
disable_search: true
token: ${{ secrets.CODECOV_TOKEN }}

- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v4
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
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
)
)
}
}
Loading
Loading