Skip to content

Commit

Permalink
add schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
hillalex committed Aug 16, 2024
1 parent c239696 commit 79b4427
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 10 deletions.
16 changes: 9 additions & 7 deletions R/api.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,22 @@ target_get_trace <- function(name, biomarker, facet = NULL, trace = NULL) {
# code = "BAD_REQUEST", status_code = 400L)
# }
# dat <- dat[dat[facet_var] == facet_level & dat["biomarker"] == biomarker,]
dat <- dat[dat["biomarker"] == biomarker, ]
dat <- dat[dat["biomarker"] == biomarker,]

Check warning on line 72 in R/api.R

View workflow job for this annotation

GitHub Actions / lint

file=R/api.R,line=72,col=44,[commas_linter] Commas should always have a space after.
dat$value <- log(dat$value)
if (length(trace) > 0) {
logger::log_info(paste("Disaggregating by trace variables", trace))
groups <- split(dat, eval(parse(text = paste("~", trace))))
model_result <- lapply(groups, model_out)
raw <- lapply(groups, data_out)
return(lapply(seq_along(groups), function(i) {
list(name = jsonlite::unbox(nms[[g]]),
model = model_out(groups[[i]]),
raw = data_out(groups[[i]]))
}))
} else {
logger::log_info("Returning single trace")
browser()
model_result <- list(all = model_out(dat))
raw <- list(all = data_out(dat))
return(list(list(name = jsonlite::unbox("all"),
model = model_out(dat),
raw = data_out(dat))))
}
list(model = model_result, raw = raw)
}

read_dataset <- function(name) {
Expand Down
6 changes: 3 additions & 3 deletions R/router.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ get_dataset <- function() {
porcelain::porcelain_endpoint$new(
"GET", "/dataset/<name>",
target_get_dataset,
returning = porcelain::porcelain_returning_json())
returning = porcelain::porcelain_returning_json("DatasetMetadata"))
}

get_datasets <- function() {
porcelain::porcelain_endpoint$new(
"GET",
"/datasets/",
target_get_datasets,
returning = porcelain::porcelain_returning_json("Datasets"))
returning = porcelain::porcelain_returning_json("DatasetNames"))
}

get_trace <- function() {
Expand All @@ -53,5 +53,5 @@ get_trace <- function() {
"/dataset/<name>/<biomarker>/",
target_get_trace,
porcelain::porcelain_input_query(facet = "string", trace = "string"),
returning = porcelain::porcelain_returning_json())
returning = porcelain::porcelain_returning_json("DataSeries"))
}
46 changes: 46 additions & 0 deletions inst/schema/DataSeries.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"model": {
"type": "object",
"properties": {
"x": {
"type": "array",
"items": {
"type": "number"
}
},
"y": {
"type": "array",
"items": {
"type": ["number", "null"]
}
}
}
},
"raw": {
"type": "object",
"properties": {
"x": {
"type": "array",
"items": {
"type": "number"
}
},
"y": {
"type": "array",
"items": {
"type": ["number", "null"]
}
}
}
}
}
}
}
File renamed without changes.
File renamed without changes.

0 comments on commit 79b4427

Please sign in to comment.