From c6b3eff76bb419f4c9e2f1881d0cd19f5fc24a85 Mon Sep 17 00:00:00 2001 From: "alex.hill@gmail.com" Date: Wed, 11 Dec 2024 13:04:24 +0000 Subject: [PATCH] include data series type --- R/api.R | 13 +++++++++---- inst/schema/DatasetMetadata.schema.json | 6 +++++- inst/spec.yaml | 1 + 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/R/api.R b/R/api.R index 842c584..144969a 100644 --- a/R/api.R +++ b/R/api.R @@ -13,6 +13,7 @@ target_post_dataset <- function(req, res) { logger::log_info("Parsing multipart form request") parsed <- mime::parse_multipart(req) xcol <- get_xcol(parsed) + series_type <- parsed$type name <- get_dataset_name(parsed) if (is.null(parsed$file$type) || parsed$file$type != "text/csv") { return(invalid_file_type(res)) @@ -35,17 +36,18 @@ target_post_dataset <- function(req, res) { } logger::log_info(paste("Saving dataset", name, "to disk")) - save_dataset(path, file_body, xcol) + save_dataset(path, file_body, xcol, series_type) response_success(jsonlite::unbox(name)) } -save_dataset <- function(path, file_body, xcol) { +save_dataset <- function(path, file_body, xcol, series_type) { xtype <- get_xtype(file_body[, xcol]) dir.create(path, recursive = TRUE) utils::write.csv(file_body, file.path(path, "data"), row.names = FALSE) write(xcol, file.path(path, "xcol")) write(xtype, file.path(path, "xtype")) + write(series_type, file.path(path, "series_type")) } get_parsed_values <- function(raw_values) { @@ -111,6 +113,7 @@ target_get_dataset <- function(name, req) { logger::log_info(paste("Found dataset:", name)) dat <- dataset$data xcol <- dataset$xcol + series_type <- dataset$series_type cols <- setdiff(colnames(dat), c("value", "biomarker", xcol)) if (length(cols) == 0) { logger::log_info("No covariates detected") @@ -128,7 +131,8 @@ target_get_dataset <- function(name, req) { } list(variables = unname(variables), biomarkers = biomarkers, - xcol = jsonlite::unbox(xcol)) + xcol = jsonlite::unbox(xcol), + type = jsonlite::unbox(series_type)) } target_get_datasets <- function(req) { @@ -293,11 +297,12 @@ read_dataset <- function(req, name, scale) { } xcol <- readLines(file.path(path, "xcol")) xtype <- readLines(file.path(path, "xtype")) + series_type <- readLines(file.path(path, "series_type")) logger::log_info("Parsing x column values") if (xtype == "date") { dat[, xcol] <- as.Date(dat[, xcol], origin = "1970-01-01") } - list(data = dat, xcol = xcol, xtype = xtype) + list(data = dat, xcol = xcol, xtype = xtype, series_type = series_type) } model_out <- function(dat, xcol, diff --git a/inst/schema/DatasetMetadata.schema.json b/inst/schema/DatasetMetadata.schema.json index e78b19d..a712e2e 100644 --- a/inst/schema/DatasetMetadata.schema.json +++ b/inst/schema/DatasetMetadata.schema.json @@ -16,12 +16,16 @@ }, "xcol": { "type": "string" + }, + "type": { + "type": "string" } }, "additionalProperties": false, "required": [ "variables", "biomarkers", - "xcol" + "xcol", + "type" ] } diff --git a/inst/spec.yaml b/inst/spec.yaml index db881bb..940d754 100644 --- a/inst/spec.yaml +++ b/inst/spec.yaml @@ -142,6 +142,7 @@ paths: - ab_unit - ab_spike xcol: day_of_study + type: surveillance '404': description: Dataset with the given name not found content: