diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0958938 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM rocker/tidyverse:4.0.5 + +RUN R -e 'install.packages("argparse")' + +WORKDIR / + +COPY R/score.R . +COPY modules . +COPY data . +COPY minidream-challenge-2018.Rproj . +COPY modules/module0/.eval/eval_fxn.R modules/module0/.eval/eval_fxn.R +COPY modules/module1/.eval/eval_fxn.R modules/module1/.eval/eval_fxn.R +COPY modules/module2/.eval/eval_fxn.R modules/module2/.eval/eval_fxn.R +COPY modules/module3/.eval/eval_fxn.R modules/module3/.eval/eval_fxn.R +COPY modules/module4/.eval/eval_fxn.R modules/module4/.eval/eval_fxn.R +COPY modules/module5/.eval/eval_fxn.R modules/module5/.eval/eval_fxn.R +COPY modules/module6/.eval/eval_fxn.R modules/module6/.eval/eval_fxn.R +COPY modules/module7/.eval/eval_fxn.R modules/module7/.eval/eval_fxn.R diff --git a/R/score.R b/R/score.R new file mode 100755 index 0000000..f49e578 --- /dev/null +++ b/R/score.R @@ -0,0 +1,51 @@ +#!/usr/bin/env Rscript +suppressPackageStartupMessages(library(argparse)) +suppressPackageStartupMessages(library(jsonlite)) +suppressPackageStartupMessages(library(rprojroot)) + +parser <- ArgumentParser(description = 'Score submission') +parser$add_argument('-f', '--submission_file', type = "character", required = T, + help = 'Submission path') +parser$add_argument('-r', '--results', type = "character", required = T, + help = 'Results file') +args <- parser$parse_args() + + +root_dir <- find_root(is_rstudio_project, thisfile()) + +module_map = c( + "activity-0.yml"=0, "activity-1.yml"=1, + "activity-2.yml"=2, "activity-3.yml"=3, + "activity-4.yml"=1, "activity-4.yml"=4, + "activity-5.yml"=1, "activity-6.yml"=1, + "activity-7.yml" +) + + +compute_scores <- function(submission_path) { + filename = basename(submission_path) + filename_split = unlist(strsplit(filename, "_")) + module_name = filename_split[2] + module_no = module_map[module_name] + username = filename_split[1] + # Path on docker container + eval_path = glue::glue('/modules/module{module_no}/.eval/eval_fxn.R') + source(eval_path) + # TODO: add in module 6 later + # if moduleNo == 6: + # entity_annots = submission.entity['annotations'] + # with open(submission.filePath, 'w') as f: + # f.write(entity_annots['yaml'][0]) + + annotations = score_submission(submission_path) + annotations$module = glue::glue("Module {module_no}") + annotations$userName = username + return(annotations) +} + +# Mapping of scores +scores = compute_scores(args$submission_file) +scores$submission_status = "SCORED" + +export_json <- toJSON(scores, auto_unbox = TRUE, pretty=T) +write(export_json, args$results)