Skip to content

Commit

Permalink
Various retrospective improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ibacher committed Aug 9, 2024
1 parent d24eb32 commit a8378a5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM rstudio/plumber:latest

ENV TZ "Africa/Nairobi"
ENV TZ="Africa/Nairobi"

# install base libraries we need
RUN apt-get -y update -qq && apt-get -y --no-install-recommends install \
Expand Down
2 changes: 1 addition & 1 deletion SQL/iit_prod_data_extract.sql
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,4 @@ where
-- filter dead patients
and fs.death_date is null
-- if not run retrospectively, don't generate new predictions for existing cases
and (?retrospective or mlp.encounter_id is null);
and (?retrospectiveTest or mlp.encounter_id is null);
25 changes: 18 additions & 7 deletions docker-resources/plumber.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,22 @@ cors <- function(req, res) {
#* @serializer json
#* @post /predict
function(
startDate = NA, # the startDate is the first day to start from
# note that it will be adjusted to the Monday of the week its in as we always run in weekly batches
weeks = "1", # the number of weeks to run; this is only used for testing
retrospective = "F" # whether or not the query is retrospective (run against past data for testing) or prospective
# (run normally); this mostly adjusts the query
startDate = NA, # the startDate is the first day to start from
# note that it will be adjusted to the Monday of the week its in as we always run in weekly batches
weeks = "1", # the number of weeks to run; this is only used for testing
retrospective = "F", # whether or not the query is retrospective (run against past data for testing) or prospective
# (run normally); this mostly adjusts the query
retrospectiveTest = NA # whether, when run retrospectively, to treat the run as a "test", so to generate all results
# and not write to the predictions table
) {
retrospective <- as.logical(retrospective)

if (is.na(retrospectiveTest)) {
retrospectiveTest = retrospective
} else {
retrospectiveTest = as.logical(retrospectiveTest)
}

# If the startDate is not specified, it defaults to NA and we set it to a week from today
if (is.na(startDate)) {
startDate = clock::add_weeks(Sys.Date(), 1)
Expand All @@ -119,7 +127,8 @@ function(
ml_sql,
startDate = start_of_week,
endDate = end_of_week,
retrospective = retrospective
retrospective = retrospective,
retrospectiveTest = retrospectiveTest
)

# run the query, giving us a dataframe
Expand Down Expand Up @@ -217,7 +226,9 @@ function(
prediction_result <- bind_rows(prediction_results_adults, prediction_results_minors)

# add the rows from the prediction_result to the ml_weekly_predictions table
DBI::dbAppendTable(my_pool, SQL('predictions.ml_weekly_predictions'), prediction_result)
if (!retrospectiveTest) {
DBI::dbAppendTable(my_pool, SQL('predictions.ml_weekly_predictions'), prediction_result)
}

# return the result so the API returns *something*
prediction_result
Expand Down

0 comments on commit a8378a5

Please sign in to comment.