Skip to content

Commit

Permalink
Merge branches 'connect-to-real-data' and 'master' of github.com:seat…
Browse files Browse the repository at this point in the history
…tleflu/incidence-mapper into connect-to-real-data

# Conflicts:
#	modelServR/R/returnModel.R
#	modelServR/R/saveModel.R
  • Loading branch information
devclinton committed May 9, 2019
2 parents d5883b5 + e124219 commit 8063cfe
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 55 deletions.
2 changes: 1 addition & 1 deletion api_service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ ADD docker_scripts/entrypoint.sh docker_scripts/wsgi.ini ./
# Add the rest of our library here
ADD seattle_flu_incidence_mapper ./seattle_flu_incidence_mapper


EXPOSE 80
VOLUME [/model_store]

CMD /app/entrypoint.sh
37 changes: 10 additions & 27 deletions api_service/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,25 @@
version: '3'


services:
redis:
# We use management so we can have a nice gui
# Default login is guest/guest
image: redis
ports:
- "6379:6379"
# Our queue container
rabbit:
# We use management so we can have a nice gui
# Default login is guest/guest
image: rabbitmq:3.7-management
ports:
- "5672:5672"
- "8081:15672"
workers:
build:
context: .
dockerfile: Dockerfile
image: idm-docker-production.packages.idmod.org/sfim
command: python3 seattle_flu/app.py workers start
db:
image: postgres
restart: always
environment:
- "DRAMATIQ_USE_PROD=True"
POSTGRES_USER: seattle_flu
POSTGRES_PASSWORD: seattle_flu

service:
build:
context: .
dockerfile: Dockerfile
image: idm-docker-production.packages.idmod.org/sfim
ports:
- 5000:5000
- 5000:80
volumes:
- "/model_store:/model_store"
- "./test_model_store:/model_store"
environment:
- "DEBUG=1"
- "FLASK_ENV=development"
- "DRAMATIQ_USE_PROD=True"
- "CREATE_DB=1"
- "SQLALCHEMY_URI=postgres+psycopg2://seattle_flu:@db"



4 changes: 2 additions & 2 deletions api_service/docker_scripts/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ http {
#include /etc/nginx/conf.d/*.conf;

server {
listen 5000 default_server;
listen [::]:5000 default_server;
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
#root /usr/share/nginx/html;

Expand Down
8 changes: 4 additions & 4 deletions api_service/docs/_static/jquery-3.2.1.js
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ setDocument = Sizzle.setDocument = function( node ) {
// Support: IE<10
// Check if getElementById returns elements by name
// The broken getElementById methods don't pick up programmatically-set names,
// so use a roundabout getElementsByName test
// so use a roundabout getElementsByName tests
support.getById = assert(function( el ) {
docElem.appendChild( el ).id = expando;
return !document.getElementsByName || !document.getElementsByName( expando ).length;
Expand Down Expand Up @@ -1280,7 +1280,7 @@ setDocument = Sizzle.setDocument = function( node ) {
// Regex strategy adopted from Diego Perini
assert(function( el ) {
// Select is set to empty string on purpose
// This is to test IE's treatment of not explicitly
// This is to tests IE's treatment of not explicitly
// setting a boolean content attribute,
// since its presence should be enough
// https://bugs.jquery.com/ticket/12359
Expand All @@ -1290,7 +1290,7 @@ setDocument = Sizzle.setDocument = function( node ) {

// Support: IE8, Opera 11-12.16
// Nothing should be selected when empty strings follow ^= or $= or *=
// The test attribute must be unknown in Opera but "safe" for WinRT
// The tests attribute must be unknown in Opera but "safe" for WinRT
// https://msdn.microsoft.com/en-us/library/ie/hh465388.aspx#attribute_section
if ( el.querySelectorAll("[msallowcapture^='']").length ) {
rbuggyQSA.push( "[*^$]=" + whitespace + "*(?:''|\"\")" );
Expand Down Expand Up @@ -6229,7 +6229,7 @@ function addGetHookIf( conditionFn, hookFn ) {
return;
}

// Hook needed; redefine it so that the support test is not executed again.
// Hook needed; redefine it so that the support tests is not executed again.
return ( this.get = hookFn ).apply( this, arguments );
}
};
Expand Down
10 changes: 5 additions & 5 deletions api_service/docs/_static/underscore-1.3.1.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
return initial ? _.reduce(reversed, iterator, memo, context) : _.reduce(reversed, iterator);
};

// Return the first value which passes a truth test. Aliased as `detect`.
// Return the first value which passes a truth tests. Aliased as `detect`.
_.find = _.detect = function(obj, iterator, context) {
var result;
any(obj, function(value, index, list) {
Expand All @@ -147,7 +147,7 @@
return result;
};

// Return all the elements that pass a truth test.
// Return all the elements that pass a truth tests.
// Delegates to **ECMAScript 5**'s native `filter` if available.
// Aliased as `select`.
_.filter = _.select = function(obj, iterator, context) {
Expand All @@ -160,7 +160,7 @@
return results;
};

// Return all the elements for which a truth test fails.
// Return all the elements for which a truth tests fails.
_.reject = function(obj, iterator, context) {
var results = [];
if (obj == null) return results;
Expand All @@ -170,7 +170,7 @@
return results;
};

// Determine whether all of the elements match a truth test.
// Determine whether all of the elements match a truth tests.
// Delegates to **ECMAScript 5**'s native `every` if available.
// Aliased as `all`.
_.every = _.all = function(obj, iterator, context) {
Expand All @@ -183,7 +183,7 @@
return result;
};

// Determine if at least one element in the object matches a truth test.
// Determine if at least one element in the object matches a truth tests.
// Delegates to **ECMAScript 5**'s native `some` if available.
// Aliased as `any`.
var any = _.some = _.any = function(obj, iterator, context) {
Expand Down
16 changes: 15 additions & 1 deletion api_service/seattle_flu_incidence_mapper/swagger/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ info:
license:
name: "Apache 2.0"
url: "http://www.apache.org/licenses/LICENSE-2.0.html"
host: "localhost"
basePath: "/v1"
tags:
- name: "pathogen_model"
Expand Down Expand Up @@ -39,11 +38,26 @@ paths:
schema:
type: object
additionalProperties: true
example:
model_type: inla
observed:
- catchment
- encountered_week
- flu_shot
- n
- pathogen
- positive
- PUMA5CE
- sampling_location
- time_row
responses:
200:
description: "successful operation"
schema:
type: "array"
items:
type: "object"

/pathogen_models:
get:
tags:
Expand Down
4 changes: 3 additions & 1 deletion api_service/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
'flask_sqlalchemy',
'flask_marshmallow',
'marshmallow-sqlalchemy',
"docker"
"docker",
'psycopg2',
''
],

extras_require={
Expand Down
20 changes: 17 additions & 3 deletions docker-compose.production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,30 @@ services:
restart: always
environment:
POSTGRES_USER: seattle_flu
# placeholder for building worker
workers:
build:
context: .
dockerfile: Dockerfile.worker
image: idm-docker-production.packages.idmod.org/sfim-worker:${version:-latest}
command: touch t
service:
build:
context: api_service
dockerfile: Dockerfile
image: idm-docker-production.packages.idmod.org/sfim-api:${version:-latest}
volumes:
- "/model_store:/model_store"
- db-data:/var/lib/mysql/data
volumes:
- /model_store:/model_store
# pass docker so we can execute other containers
- /var/run/docker.sock:/var/run/docker.sock
environment:
- SQLALCHEMY_URI=postgres://seattle_flu:@db
- SQLALCHEMY_URI=postgres+psycopg2://seattle_flu:@db
- "CREATE_DB=1"
#- "MODEL_HOST_PATH=`pwd`/test_model_store"
#- "DEBUG_TOKENS=1"
depends_on:
- db
ports:
- "80:5000"
- "80:80"
6 changes: 1 addition & 5 deletions modelServR/R/queryModel.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,4 @@ queryLoadedModel <-
jsonlite::write_json(model, file.path(outputDir, outputFile))
}
return(TRUE)
}

#initializeModel <- function (modelId) {
# return(loadModelFileById(modelId))
#}
}
4 changes: 3 additions & 1 deletion modelServR/R/returnModel.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
library(logging)

#' loadModelFileById function for getting modeled data
#'
#' This function will load a model from the model_store_dir by Id
Expand Down Expand Up @@ -52,7 +54,7 @@ returnModel <- function(queryIn = jsonlite::toJSON(
cloudDir = Sys.getenv('MODEL_STORE', '/home/rstudio/seattle_flu/test_model_store')){

basicConfig()

if(class(queryIn)== 'list'){
queryList <- queryIn
queryIn <- jsonlite::toJSON(queryIn)
Expand Down
15 changes: 10 additions & 5 deletions modelServR/R/saveModel.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#' getHumanReadableModelIdFromModel: return human readable verion of model from query
library(logging)


#'
#' @param model INLA model object that will generatie id from
#'
Expand Down Expand Up @@ -55,14 +58,14 @@ getModelQueryObjectFromModel<- function(model, model_type = 'inla', latent = FAL
#' @param query query object container the observed and the model_type attributes
#'
#' @import logging
#'
#'
#' @return An object containing the observed and the model_type fields
#' @export
#'
getModelQueryObjectFromQuery <- function(query) {
basicConfig()
setLevel("FINEST")

logdebug("getModelQueryObjectFromQuery Src:", str(query))
logdebug("$observed", attr(query, "observed"))
result <- newEmptyObject()
Expand Down Expand Up @@ -95,7 +98,7 @@ getModelIdFromModel <- function(model) {
getModelIdFromQuery <- function(query) {
basicConfig()
setLevel("FINEST")

#props <- getModelQueryObjectFromQuery(query)
modelId <- as.character(jsonlite::toJSON(query, simplifyDataFrame=))
logdebug("Model ID JSON:", jsonlite::toJSON(query, simplifyDataFrame=))
Expand All @@ -111,6 +114,8 @@ getModelIdFromQuery <- function(query) {
#' @export
#'
saveModel <- function(model, modelStoreDir = Sys.getenv('MODEL_STORE', '/home/rstudio/seattle_flu/test_model_store')) {
basicConfig()
setLevel("FINEST")
ts <- Sys.time()
attr(ts, "tzone") <- 'UTC'
ts <- paste0(as.character(ts), 'Z')
Expand Down Expand Up @@ -139,13 +144,13 @@ saveModel <- function(model, modelStoreDir = Sys.getenv('MODEL_STORE', '/home/r
created = ts
)

print("Saving RDS")
loginfo("Saving RDS")
outfile <- xzfile(paste(modelStoreDir, '/', filename, '.RDS', sep = ''), 'wb', compress=9, encoding = 'utf8')
saveRDS(model,file = outfile)
close(outfile)


print("Saving smooth model")
loginfo("Saving smooth model")
# all models output smooth
newRow$latent <- FALSE
write.csv(
Expand Down

0 comments on commit 8063cfe

Please sign in to comment.