Skip to content

Commit

Permalink
include unit_id as optional argument for formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ha0ye committed Feb 8, 2024
1 parent 50272ac commit ce43c93
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 40 deletions.
76 changes: 38 additions & 38 deletions R/processing.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
#' @param roadmap_url URL of a google doc (Unit Roadmap)
#' @param tracker_url URL of a google sheet (Unit Tracker)
#' @param tracker_sheet name of the google sheet for the specific unit's tasks
#' @param unit_id unit id
#'
#' @return NULL
#' @export
sync_statuses <- function(roadmap_url, tracker_url, tracker_sheet)
sync_statuses <- function(roadmap_url, tracker_url, tracker_sheet, unit_id = "")
{
# stop early if missing values
if (anyNA(c(roadmap_url, tracker_url, tracker_sheet)))
Expand All @@ -23,9 +24,11 @@ sync_statuses <- function(roadmap_url, tracker_url, tracker_sheet)
tryCatch({
# get statuses from unit roadmap
roadmap_dat <- read_roadmap_statuses(roadmap_url)
roadmap_dat$unit_id <- unit_id

# get statuses from task spreadsheet
tracker_dat <- read_tracker_statuses(tracker_url, tracker_sheet)
tracker_dat$unit_id <- unit_id

# check for same number of rows
stopifnot(NROW(roadmap_dat) == NROW(tracker_dat))
Expand Down Expand Up @@ -96,62 +99,53 @@ handle_diff_statuses <- function(roadmap_dat, roadmap_url,
roadmap_status <- roadmap_dat[i, "Status"]
tracker_status <- tracker_dat[i, "Status"]
phase <- match(roadmap_dat[i, "Phase"], getOption("gdrv_auto_env.phase_names"))
status_msg <- format_status_msg(roadmap_dat[i,])
roadmap_task <- roadmap_dat[i, "Task"]
unit_id <- roadmap_dat[i, "unit_id"]

if (roadmap_status == "Submitted" &&
tracker_status == "Not started" &&
phase == 4) {
# if roadmap is submitted and tracker is not started AND phase == 4
tracker_dat$Status[i] <- roadmap_status
roadmap_task <- roadmap_dat[i, "Task"]

if (roadmap_task == "Activity Description" ||
roadmap_task == "Activity Demonstration") {
## notify Hao for METER to review Activity Description OR Activity Demonstration
status_msg <- format_status_msg(roadmap_dat[i,])
log_action(paste0("Updating status: {\n", status_msg, "}"),
url = tracker_url,
"ACTION TAKEN")
notify(item_name = paste("New Submission:", roadmap_task),
log_status_update(status_msg, tracker_url)

notify(item_name = paste("New Submission:", unit_id, "-", roadmap_task),
item_body = status_msg,
notify_text = format_notification_msg("METER to review: ", tracker_dat[i, ]),
to = "Hao Ye")
} else if (roadmap_task == "Activity Tech Specs") {
## notify Thomas to review Activity Tech Spec
status_msg <- format_status_msg(roadmap_dat[i,])
log_action(paste0("Updating status: {\n", status_msg, "}"),
url = tracker_url,
"ACTION TAKEN")
notify(item_name = paste("New Submission:", roadmap_task),
log_status_update(status_msg, tracker_url)

notify(item_name = paste("New Submission:", unit_id, "-", roadmap_task),
item_body = status_msg,
notify_text = format_notification_msg("Production to review: ", tracker_dat[i, ]),
to = "Thomas McDonald")
} else if (roadmap_task == "Prototype") {
## notify Hao and Thomas to review Prototype
status_msg <- format_status_msg(roadmap_dat[i,])
log_action(paste0("Updating status: {\n", status_msg, "}"),
url = tracker_url,
"ACTION TAKEN")
notify(item_name = paste("New Submission:", roadmap_task),
log_status_update(status_msg, tracker_url)

notify(item_name = paste("New Submission:", unit_id, "-", roadmap_task),
item_body = status_msg,
notify_text = format_notification_msg("CENTER to review: ", tracker_dat[i, ]),
to = c("Thomas McDonald", "Hao Ye"))
} else {
stage_todo(paste0("Unknown Status Difference: {\n",
format_status_msg(roadmap_dat[i,]),
"}"),
stage_todo(paste0("Unknown Status Difference: {\n", status_msg, "}"),
url = roadmap_url)
}
} else if (roadmap_status == "Submitted" &&
tracker_status == "Not started" && phase < 4) {
# if roadmap is submitted and tracker is not started
# take action for submission

log_status_update(status_msg, tracker_url)
tracker_dat$Status[i] <- roadmap_status
status_msg <- format_status_msg(roadmap_dat[i,])
log_action(paste0("Updating status: {\n", status_msg, "}"),
url = tracker_url,
"ACTION TAKEN")
notify(item_name = paste("New Submission:", roadmap_dat[i, "Task"]),

notify(item_name = paste("New Submission:", unit_id, "-", roadmap_task),
item_body = status_msg,
notify_text = format_notification_msg("Submitted: ", roadmap_dat[i, ]),
to = "Hao Ye")
Expand All @@ -160,13 +154,10 @@ handle_diff_statuses <- function(roadmap_dat, roadmap_url,
roadmap_dat$`Signoff by`[i] != "CENTER") {
# if roadmap is approved and signoff is by METER or NIH
# take action for approval

log_status_update(status_msg, tracker_url)
tracker_dat$Status[i] <- roadmap_status
status_msg <- format_status_msg(roadmap_dat[i,])
log_action(paste0("Updating status: {\n", status_msg, "}"),
url = tracker_url,
"ACTION TAKEN")
notify(item_name = paste("New Approval:", roadmap_dat[i, "Task"]),

notify(item_name = paste("New Approval:", unit_id, "-", roadmap_task),
item_body = status_msg,
notify_text = format_notification_msg("Approved: ", roadmap_dat[i, ]),
to = "Hao Ye")
Expand All @@ -176,20 +167,29 @@ handle_diff_statuses <- function(roadmap_dat, roadmap_url,
# if tracker is approved and roadmap is not approved
# log action needed (update roadmap)

stage_todo(paste0("Approve: {\n",
format_status_msg(roadmap_dat[i,]),
"}"),
stage_todo(paste0("Approve: {\n", status_msg, "}"),
url = roadmap_url)
} else {
# if any other discrepancy
# log action needed

stage_todo(paste0("Unknown Status Difference: {\n",
format_status_msg(roadmap_dat[i,]),
"}"),
stage_todo(paste0("Unknown Status Difference: {\n", status_msg, "}"),
url = roadmap_url)
}
}

tracker_dat
}

#' generate status update content
#'
#' @param status_msg formatted status msg
#' @param tracker_url URL of a google sheet (Unit Tracker)
#'
#' @return
log_status_update <- function(status_msg, tracker_url)
{
log_action(paste0("Updating status: {\n", status_msg, "}"),
url = tracker_url,
"ACTION TAKEN")
}
3 changes: 2 additions & 1 deletion R/scratchspace.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ if (run_sync)
roadmap_url <- roadmap_urls[idx]
tracker_url <- tracker_urls[idx]
tracker_sheet <- tracker_sheets[idx]
sync_statuses(roadmap_url, tracker_url, tracker_sheet)
unit_id <- db_units[[idx, "unit-id"]]
sync_statuses(roadmap_url, tracker_url, tracker_sheet, unit_id)
merge_todo()
}

Expand Down
16 changes: 16 additions & 0 deletions man/log_status_update.Rd

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

4 changes: 3 additions & 1 deletion man/sync_statuses.Rd

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

1 change: 1 addition & 0 deletions vignettes/Setup-Google-OAuth.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Results:
* The decryption key can live as a github secret that enables github actions to use the token for access

```{r create token}
drive_auth_configure(path = ".secrets/gdrive-oauth.json")
drive_auth(email = TRUE, scopes = "https://www.googleapis.com/auth/drive", cache = FALSE)
my_token <- drive_token()
Expand Down

0 comments on commit ce43c93

Please sign in to comment.