Skip to content

Commit

Permalink
Add support for contents configuration with course name and game name
Browse files Browse the repository at this point in the history
Fix #90

Signed-off-by: Liang Zhang <[email protected]>
  • Loading branch information
psychelzh committed Jul 20, 2024
1 parent d8c9a58 commit ef3bed5
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 26 deletions.
9 changes: 5 additions & 4 deletions R/targets.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
#' @param params,contents Used as the configuration of data fetching. These two
#' arguments are mutually exclusive. If `params` is specified, it will be used
#' as parameters to be bound to the query, see [DBI::dbBind()] for more
#' details. The default template requires specifying `organization_name` and
#' `project_name`, in that order. If `contents` is specified, it should be a
#' [data.frame] and will be used directly as the configuration of data
#' fetching. Note `contents` should at least contain `project_id` and
#' details. The default template requires specifying `organization_name`,
#' `project_name`, `course_name` and `game_name`, in that order. Set the
#' column as `NA` to skip that parameter. If `contents` is specified, it
#' should be a [data.frame] and will be used directly as the configuration of
#' data fetching. Note `contents` should at least contain `project_id` and
#' `game_id` names.
#' @param ... For future usage. Should be empty.
#' @param what What to fetch. There are basically two types of data, i.e., raw
Expand Down
6 changes: 3 additions & 3 deletions inst/pipelines/use_targets.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ tar_source()
# source("other_functions.R") # Source other scripts as needed.

params <- tibble::tribble(
~organization_name, ~project_name,
~organization_name, ~project_name, ~course_name, ~game_name,
# TODO: replace these with your own
"Organization1", "Project1",
"Organization2", NA # set as NA if you want to fetch all projects
"Organization1", "Project1", NA, NA,
"Organization2", NA, NA, NA # set as NA to skip that column
)

# Replace the target list below with your own:
Expand Down
3 changes: 2 additions & 1 deletion inst/sql/contents.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ SELECT
c.Name course_name,
c.Period course_period,
c2.Id game_id,
c2.Name game_name,
c2.ContentType game_type
FROM
iquizoo_business_db.project_course_config pcc
Expand All @@ -15,4 +16,4 @@ FROM
INNER JOIN iquizoo_content_db.course_child_config ccc ON ccc.ChildCourseId = cc.Id AND ccc.Deleted <> 1
INNER JOIN iquizoo_content_db.content c2 ON c2.Id = ccc.ContentId AND c2.ContentType <> 4 AND c2.Deleted <> 1
INNER JOIN iquizoo_user_db.base_organization bo ON bo.Id = pcc.OrganizationId AND bo.Deleted <> 1
WHERE bo.Name = ? AND pcc.Name = IFNULL(?, pcc.Name);
WHERE bo.Name = IFNULL(?, bo.Name) AND pcc.Name = IFNULL(?, pcc.Name) AND c.Name = IFNULL(?, c.Name) AND c2.Name = IFNULL(?, c2.Name);
9 changes: 5 additions & 4 deletions man/tar_prep_iquizoo.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions tests/testthat/test-targets.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
skip_if_not(check_source())
test_that("Default templates work", {
params <- tibble::tribble(
~organization_name, ~project_name,
"北京师范大学", "认知测评预实验"
~organization_name, ~project_name, ~course_name, ~game_name,
"北京师范大学", "认知测评预实验", NA, NA
)
tar_prep_iquizoo(params) |>
expect_targets_list()
Expand Down Expand Up @@ -36,8 +36,8 @@ test_that("Support `data.frame` contents", {

test_that("Signal error if `contents` contains no data", {
params_bad <- tibble::tribble(
~organization_name, ~project_name,
"Unexisted", "Malvalue"
~organization_name, ~project_name, ~course_name, ~game_name,
"Unexisted", "Malvalue", NA, NA
)
tar_prep_iquizoo(params_bad) |>
expect_error(class = "tarflow_bad_contents")
Expand Down
16 changes: 8 additions & 8 deletions tests/testthat/test_basic-cases.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ targets::tar_test("Works when single game on different projects", {
targets::tar_test("`combine` work properly", {
targets::tar_script({
params <- tibble::tribble(
~organization_name, ~project_name,
"北京师范大学(测试)", "元认知测试"
~organization_name, ~project_name, ~course_name, ~game_name,
"北京师范大学(测试)", "元认知测试", NA, NA
)
tar_prep_iquizoo(
params,
Expand All @@ -33,8 +33,8 @@ targets::tar_test("`combine` work properly", {
objects()
)
params <- tibble::tribble(
~organization_name, ~project_name,
"北京师范大学(测试)", "元认知测试"
~organization_name, ~project_name, ~course_name, ~game_name,
"北京师范大学(测试)", "元认知测试", NA, NA
)
tar_prep_iquizoo(params, combine = "bad") |>
expect_error(class = "tarflow_bad_combine")
Expand All @@ -44,8 +44,8 @@ targets::tar_test("Serialize check (no roundtrip error)", {
withr::local_envvar(c(TARFLOW_CACHE = "memory"))
targets::tar_script({
params <- tibble::tribble(
~organization_name, ~project_name,
"四川省双流棠湖中学高中部", "棠湖中学英才计划测训体验账号"
~organization_name, ~project_name, ~course_name, ~game_name,
"四川省双流棠湖中学高中部", "棠湖中学英才计划测训体验账号", NA, NA
)
tar_prep_iquizoo(params)[1]
})
Expand All @@ -56,8 +56,8 @@ targets::tar_test("Serialize check (no roundtrip error)", {
read_file(setup_templates()$contents),
params = unname(as.list(
tibble::tribble(
~organization_name, ~project_name,
"四川省双流棠湖中学高中部", "棠湖中学英才计划测训体验账号"
~organization_name, ~project_name, ~course_name, ~game_name,
"四川省双流棠湖中学高中部", "棠湖中学英才计划测训体验账号", NA, NA
)
))
)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test_basic-workflow.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ targets::tar_test("Workflow works", {
skip_if_not_installed("preproc.iquizoo")
targets::tar_script({
params <- tibble::tribble(
~organization_name, ~project_name,
"北京师范大学", "4.19-4.20夜晚睡眠test"
~organization_name, ~project_name, ~course_name, ~game_name,
"北京师范大学", "4.19-4.20夜晚睡眠test", NA, NA
)
tarflow.iquizoo::tar_prep_iquizoo(
params,
Expand Down

0 comments on commit ef3bed5

Please sign in to comment.