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

Review by records instead of subject_id & form_id "rv_row" #137

Merged
merged 39 commits into from
Dec 2, 2024
Merged
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
7c58504
Migrate to `review_records` from `review_row`
jthompson-arcus Nov 13, 2024
b271add
Update test-fct_SQLite.R
jthompson-arcus Nov 13, 2024
39d8da1
Update test-mod_review_forms.R
jthompson-arcus Nov 13, 2024
43931ed
Update test-mod_main_sidebar.R
jthompson-arcus Nov 13, 2024
d311ab1
Fix R CMD checks
jthompson-arcus Nov 13, 2024
ccd9bb1
Fix `db_get_review()` example
jthompson-arcus Nov 13, 2024
0743880
Helps if you update documentation
jthompson-arcus Nov 13, 2024
e5e8acb
Only UPDATE reviews when review status is changed
jthompson-arcus Nov 14, 2024
2551970
Resolve merge conflicts with `jt-113-simplify_review_process`
jthompson-arcus Nov 19, 2024
d863300
Keep current structure for enabling reviews
jthompson-arcus Nov 19, 2024
6ad27a6
Resolve merge conflict with `dev`
jthompson-arcus Nov 20, 2024
a23b462
Generalize `db_get_review()`
jthompson-arcus Nov 20, 2024
6990cf1
Update version and NEWS
jthompson-arcus Nov 20, 2024
3db4274
Update scenario description for two rows
jthompson-arcus Nov 21, 2024
1c675a9
Update language from row to records
jthompson-arcus Nov 21, 2024
c177a30
Grab un-duplicated `rv_records`
jthompson-arcus Nov 21, 2024
d2fa0d6
Remove unnecessary `dplyr::select()`
jthompson-arcus Nov 21, 2024
de24777
Remove unneeded `dplyr::distinct()`
jthompson-arcus Nov 21, 2024
d372afa
Return `db_get_review()` when `...` is empty
jthompson-arcus Nov 21, 2024
f28f174
Update test-mod_review_forms.R
jthompson-arcus Nov 21, 2024
7e26f83
Update only one table in `db_save_review()`
jthompson-arcus Nov 21, 2024
ad3f05e
Fix oopsies
jthompson-arcus Nov 21, 2024
939566f
Fix merge conflict with `dev`
jthompson-arcus Nov 21, 2024
439d14b
Add test for `db_get_review()` when no filters are specified
jthompson-arcus Nov 22, 2024
0079348
Fix `updated_items_memory`
jthompson-arcus Nov 22, 2024
ca83997
Don't export db_get_review anymore
LDSamson Nov 28, 2024
0f680cd
Update documentation
LDSamson Nov 28, 2024
a08c510
Ensure db_get_review errors before sending a db query if `...` cannot…
LDSamson Nov 28, 2024
f7ba04a
Add additional tests
LDSamson Nov 28, 2024
205896f
Use more consistent naming in the save review process
LDSamson Nov 28, 2024
b8f3f52
Change a dplyr::filter call to base R filter for performance reasons
LDSamson Nov 28, 2024
0154355
Ensure that updated_records_memory has the same columns as in the db
LDSamson Nov 28, 2024
f0144a2
Ensure tests will fail if there is a review discrepancy
LDSamson Nov 28, 2024
5360760
Export review_save_error to ensure errors are captured when saving re…
LDSamson Nov 28, 2024
88f5b04
Update snaps
LDSamson Nov 28, 2024
23b6e91
Also update mod_main_sidebar snaps
LDSamson Nov 28, 2024
6ce5827
Change to base R filter
LDSamson Dec 2, 2024
0e8ecc7
Fix review saving by selecting correct rows to update within the appl…
LDSamson Dec 2, 2024
d8e24d4
Remove the (now) redundant filtering by timestamp for updated_records…
LDSamson Dec 2, 2024
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
Prev Previous commit
Next Next commit
Update only one table in db_save_review()
jthompson-arcus committed Nov 21, 2024
commit 7e26f83330703d3b14625a05afaf4f360ce4d523
13 changes: 7 additions & 6 deletions R/fct_SQLite.R
Original file line number Diff line number Diff line change
@@ -322,7 +322,7 @@ db_upsert <- function(con, data, idx_cols) {
#' @param rv_records A data frame containing the rows of data that needs to be
#' checked.
#' @param db_path Character vector. Path to the database.
#' @param tables Character vector. Names of the tables within the database to
#' @param table Character vector. Names of the table within the database to
#' save the review in.
#'
#' @return Review information will be written in the database. No local objects
@@ -332,9 +332,10 @@ db_upsert <- function(con, data, idx_cols) {
db_save_review <- function(
rv_records,
db_path,
tables = c("all_review_data")
table = "all_review_data"
){
stopifnot(is.data.frame(rv_records))
stopifnot(is.character(table) && length(table) != 1)
if (any(duplicated(rv_records[["id"]]))) {
warning("duplicate records detected to save in database. Only the first will be selected.")
rv_records <- rv_records[!duplicated(rv_records[["id"]]),]
@@ -350,18 +351,18 @@ db_save_review <- function(
dplyr::copy_to(db_con, rv_records, "row_updates")
rs <- DBI::dbSendStatement(db_con, paste(
"UPDATE",
tables,
table,
"SET",
sprintf("%1$s = row_updates.%1$s", cols_to_change) |> paste(collapse = ", "),
"FROM",
"row_updates",
"WHERE",
sprintf("%s.id = row_updates.id", tables),
sprintf("%s.id = row_updates.id", table),
"AND",
sprintf("%s.reviewed <> row_updates.reviewed", tables)
sprintf("%s.reviewed <> row_updates.reviewed", table)
))
DBI::dbClearResult(rs)
cat("finished writing to the tables:", tables, "\n")
cat("finished writing to the table:", table, "\n")
}

#' Append database table
4 changes: 1 addition & 3 deletions R/mod_review_forms.R
Original file line number Diff line number Diff line change
@@ -242,9 +242,7 @@ mod_review_forms_server <- function(
db_save_review(
review_records,
db_path = db_path,
# More tables can be added here if needed, to track process of
# individual reviewers in individual tables:
tables = "all_review_data"
table = "all_review_data"
)

updated_rows_db <- db_get_review(
4 changes: 2 additions & 2 deletions man/db_save_review.Rd

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

6 changes: 3 additions & 3 deletions tests/testthat/test-fct_SQLite.R
Original file line number Diff line number Diff line change
@@ -267,7 +267,7 @@ describe(
db_save_review(
cbind(id = 1, df, new_review),
temp_path,
tables = c("all_review_data")
table = c("all_review_data")
)
expect_equal(
dplyr::collect(dplyr::tbl(con, "all_review_data")),
@@ -317,7 +317,7 @@ describe(
db_save_review(
review_row,
temp_path,
tables = c("all_review_data")
table = c("all_review_data")
)
expect_true(is.data.frame(dplyr::collect(dplyr::tbl(con, "all_review_data"))))
results <- dplyr::collect(dplyr::tbl(con, "all_review_data"))
@@ -347,7 +347,7 @@ describe(
db_save_review(
rbind(cbind(id = 1:2, df, new_review), cbind(id = 1:2, df, new_review)),
temp_path,
tables = "all_review_data"
table = "all_review_data"
) |> expect_warning()
})
}