knitr::opts_chunk$set(echo = TRUE)

1 Makecondition

library(dplyr)
library(stringr)
library(rmdgrader)
library(econDS)
library(tidyverse)
library(googledrive)
library(gitterhub)
library(purrr)
rprojroot::is_rstudio_project$make_fix_file() -> .root
gradingflowFolder <- file.path(
  .root(), params$gradingFolder, params$title
)
gradeSavingFilename <- 
  file.path(.root(),params$gradingFolder,params$title,"data4step4.Rdata")
studentSubmissionFilename <- 
  file.path(.root(), params$gradingFolder, params$title, "df_studentSubmissions.Rdata")
load(gradeSavingFilename, envir=.GlobalEnv)
disputeFolder <- file.path(
  .root(), params$gradingFolder, params$title, "dispute"
)
if(!dir.exists(disputeFolder)) dir.create(disputeFolder)
# obtain result_copy2returnGDfolder
load(file.path(gradingflowFolder,"data4step5.Rdata"), envir = .GlobalEnv)

sourceReturnFolder=params$localGDReturnFolder
title=params$title

2 Obtain issue

issueComments = {
  params$githubRepo %>%
    str_split("/") %>%
    {
      list(
        owner=.[[1]][[1]],
        repo=.[[1]][[2]]
      )
    } -> ownerRepo

  obtainIssueComments(
    owner=ownerRepo$owner, 
    repo=ownerRepo$repo,
    titleKeyword=params$title,
  ) -> issueComments
  issueComments
}

3 Generate dispute files

disputeFileInfo = {

  sourceReturnFolder=params$localGDReturnFolder

  title=params$title 

  generate_disputeFilesFromIssueComments(
    issueComments,
    title,
    sourceReturnFolder,
    disputeFolder,
    overwrite=c("dupReturnRmd"=F, "disputeContentRmd"=F)
  )



}

4 (manual) Resolve dispute

Manual run this chunk, select one file. It will bring up two files for you to edit.

one: hw1_{id}.Rmd is the returned Rmd whose right sidebar menu has (*) marked where the dispute is. Once you finished review, please change grade for that question inside (grade) directly and change (*) to (R) which means already reviews.

second: hw1_{id}_reply.Rmd is the content the student left in github issue comment. If you have any word to converse with the student your regarding your final decision, please put it there.

source(
  file.path(.root(),params$gradingFolder,params$title,
            "plan_step5_inspection.R")
)
load_plan_step5_inspection(disputeFileInfo)
inspect_selectedDisputeFile(disputeFolder, disputeFileInfo)

4 Regrade 1 Rmd after processing

#' grade one student
#'
#' @param xpattern A character of pattern regarding target name in names(studentValues)
#' @param targetLabel A character of ans label
#' @param gradingMethod A name of grading method
#' @param whichCorrectAnsvalue An integer of index regarding the correct ans to use when there are multiple correct answers
#'
#' @return
#' @export
#'
#' @examples none.
gradeX <-
function(xpattern, targetLabel, gradingMethod, whichCorrectAnsvalue = 1){
  assertthat::assert_that(exists("studentValues", envir = .GlobalEnv),
                          exists("correctValues", envir = .GlobalEnv))
  y <<- correctValues[[targetLabel]][[whichCorrectAnsvalue]]
  require(stringr)
  str_which(names(studentValues),xpattern)-> .x
  studentValues[[.x]][[targetLabel]][[1]] -> x

  grade1 <- gradingMethod(x, y)
  grade1
}
source_step2 <- function(planDestfolder){
  list.files(planDestfolder, pattern = "^plan_step2_process", full.names = T) -> planDestfile
  source(file = planDestfile)
}
source_step4 <- function(planDestfolder){
  list.files(planDestfolder, pattern = "^plan_step4_return", full.names = T) -> planDestfile
  source(file = planDestfile)
}
get_listOfMethodsFromStep3 <- function(planDestfolder) {
  list.files(planDestfolder, pattern = "^plan_step3_grade", full.names = T) -> planDestfile
  source(file = planDestfile)
  basename(planDestfile) %>%
    stringr::str_remove("\\.R") %>%
    as.name() -> planObject
  loadfunname <- as.name(paste0("load_", as.character(planObject)))
  methodExpr <- rlang::expr({
    (!!planObject)$target -> targetNames
    stringr::str_subset(targetNames, "^m[0-9]+") -> allMethods
    allMethods
  })
  allMethods <- rlang::eval_bare(methodExpr)
  allMethods
  toExecLoad <- rlang::expr(exec(!!loadfunname))
  eval(toExecLoad)
  list_methods <- mget(allMethods, envir = .GlobalEnv)
  list_methods
}
gradeXpatternRmd <- function(xpattern, planDestfolder){
  list_methods <- get_listOfMethodsFromStep3(planDestfolder)
  methodNames <- names(list_methods)
  ansLabels <- stringr::str_replace(methodNames, "^m","ans")
  list_grades <- vector("list", length(ansLabels))
  for(.x in seq_along(methodNames)){
    list_grades[[.x]] <- 
      gradeX(
        xpattern=xpattern,
        ansLabels[[.x]],
        list_methods[[methodNames[[.x]]]])  
  }
  names(list_grades) <- ansLabels
  # list_grades
  convert_listGrades_to_tbGrade1(list_grades)
}
convert_listGrades_to_tbGrade1 <- function(list_grades) {
  list_grades %>%
    as.data.frame() -> tb_grades1
  tb_grades1 %>%
    mutate(
      name = basename(targetRmd)
    ) %>%
    rowwise() %>%
    mutate(
      total = sum(
        c_across(contains("ans"))
      )
    ) %>%
    mutate(
      final = {
        sum(str_detect(names(tb_grades1), "ans")) -> totalAns
        total / totalAns * 7 + 3
      }
    )
}
planDestfolder <- file.path(
  .root(), params$gradingFolder, params$title
)
xpattern="410874230"
gradeXpatternRmd(xpattern,planDestfolder) -> tb_grades1

source_step2(planDestfolder)
targetRmd <- str_subset(allRmds, xpattern)
source_step4(planDestfolder)
load_plan_step4_return(synthesizeWithCorrectAns)
synthesize_returnRmd(
        targetRmd, tb_grades1,
        synthesizeWithCorrectAns,
        disputeFolder)
tb_gradesNew %>%
  add_row(tb_grades1) -> tb_gradesNew2

5 Recalculate grades

source(
  file.path(.root(),params$gradingFolder,params$title,
            "plan_step5_inspection.R")
)
load_plan_step5_inspection(disputeFileInfo)
debug(update_tbGrades)
tb_gradesNew= update_tbGrades(tb_Grades, disputeFolder, disputeFileInfo, params$title)
if(!dir.exists(params$localGDGradeFolder)) dir.create(params$localGDGradeFolder)
jsonlite::write_json(tb_gradesNew, 
           path =file.path(
             params$localGDGradeFolder,
             paste0("grade_",params$title,".json"))
           )

6 Return Rmds In Batch

整批返還回覆結果:直接執行此chunk

returnAllDisputeFiles(
  disputeFolder, 
  localGDReturnFolder = params$localGDReturnFolder, 
  title = params$title
)

6 Return Rmd Individually

手動選擇返還回覆結果:

system(paste0('open ',glue::glue('"{disputeFolder}"')))
returnCopiedDisputeFilesFromMacFinder()
# system(paste0('open ',glue::glue('"{returnFolderx}"')))
開啟學生coursework webpage
courseWorkService$build_courseworkBrowse()

執行以下可在clipboard創造範本,直接paste在每個頁面回訊:

'同學好,

您對此次作業的提問已回答完畢,相關回覆及修正後的Rmd檔(前者即你的作業檔加上"_reply"字樣, 後者直接改在你的作業檔)都已放置在您的個人google drive return資料匣裡,請自行前往下載回覆檔案。

祝學習愉快' %>%
  clipr::write_clip()

7 gitter chat

  # select file to review
  disputeRmd <- rstudioapi::selectFile(path = disputeFolder)
  school_id <- str_extract(disputeRmd, "[:digit:]{9}")
  whichIsTheChosenOne <-
    which(completeRoster$學號==school_id)
  completeRoster$gitter[[whichIsTheChosenOne]] %>%
    paste0("https://gitter.im/",.) -> gitterUrl
browseURL(gitterUrl)
  completeRoster$classroom[[whichIsTheChosenOne]] %>% clipr::write_clip()


tpemartin/rmdgrader documentation built on Nov. 22, 2022, 6:39 p.m.