Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Add R scoring code and Dockerfile #16

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
51 changes: 51 additions & 0 deletions R/score.R
Original file line number Diff line number Diff line change
@@ -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)