Skip to content

Commit

Permalink
new server test
Browse files Browse the repository at this point in the history
  • Loading branch information
scc-usc committed May 24, 2021
1 parent 60a6075 commit 5b3040b
Show file tree
Hide file tree
Showing 39 changed files with 2,389 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<<<<<<< HEAD

.DS_Store
.DS_Store
backend/data/.DS_Store
.MATLABDriveTag
=======
.idea
__pycache__
venv
>>>>>>> 67fa49eea5d682e9d3eb569e07d9d13adaeccb83
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn covid19_site.wsgi --log-file -
52 changes: 51 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<<<<<<< HEAD
# ReCOVER: Accurate Predictions and Resource Allocation for COVID-19 Epidemic Response

### Created by
Expand Down Expand Up @@ -34,4 +35,53 @@ Our web-interface provides the following
This work is supported by National Science Foundation Award No. 2027007 (RAPID).

PIs: Viktor K. Prasanna (prasanna@usc.edu), Ajitesh Srivastava (ajiteshs@usc.edu)
University of Southern California
University of Southern California
=======
# Development

## Running Local Server
```
python manage.py runserver --settings=covid19_site.settings_dev
```

## Ingesting New Data
Optional One: Run the shell script ```migrate_data_scripts``` to fetch data from JHU's repository and update the predictions with the files within the ```forecasts``` folder. (MUST make sure the database structure and migration codes are not modified before running the command, otherwise unexpected results may show up.)
```
.\migrate_data_scripts`
```
&nbsp;

Optional Two: Manually reset the database and re-migrate the code.
Delete all previously-existing data (ideally we would not have to do this step
but it's just more robust given that JHU recently changed the areas they had
in their data).
```
python manage.py dbshell
> .tables // lists all tables
> DROP TABLE model_api_area;
> DROP TABLE model_api_covid19cumulativedatapoint;
> DROP TABLE model_api_covid19datapoint;
> DROP TABLE model_api_covid19deathdatapoint;
> DROP TABLE model_api_covid19deathmodel;
> DROP TABLE model_api_covid19infectionmodel;
> DROP TABLE model_api_covid19model;
> DROP TABLE model_api_covid19predictiondatapoint;
> DROP TABLE model_api_quarantinescoredatapoint;
> .quit
```
Now we need to fake back to migration state 0 so that Django can rerun all the
migrations.
```
python manage.py migrate model_api zero --fake
```
Now Django thinks we're at the state before we ran all migrations, so we can
simply rerun them to load the newest data to our database.
```
python manage.py migrate
```

## Deploying
```
git subtree push --prefix backend heroku master
```
>>>>>>> 67fa49eea5d682e9d3eb569e07d9d13adaeccb83
1 change: 1 addition & 0 deletions covid19_site/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__
Empty file added covid19_site/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions covid19_site/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for covid19_site project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'covid19_site.settings')

application = get_asgi_application()
132 changes: 132 additions & 0 deletions covid19_site/settings_dev.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
"""
Django settings for covid19_site project.
Generated by 'django-admin startproject' using Django 3.0.4.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '!+n%hfe8@5@0t_e=to@p7$l9feiebw6hce%@ub&#ah(f%ojlb8'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'corsheaders',
'rest_framework',
'model_api.apps.ModelApiConfig',
]

MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

CORS_ORIGIN_ALLOW_ALL = True

CORS_ORIGIN_WHITELIST = [
# React dev server.
'http://localhost:3000',
'http://127.0.0.1:3000',
]

ROOT_URLCONF = 'covid19_site.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'covid19_site.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}


# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/

STATIC_URL = '/static/'
134 changes: 134 additions & 0 deletions covid19_site/settings_prod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
"""
Django settings for covid19_site project.
Generated by 'django-admin startproject' using Django 3.0.4.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ['SECRET_KEY']

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

ALLOWED_HOSTS = [
'dslab-covid19-backend.herokuapp.com',
]


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'corsheaders',
'rest_framework',
'model_api.apps.ModelApiConfig',
]

MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

CORS_ORIGIN_ALLOW_ALL = True

CORS_ORIGIN_WHITELIST = [
# React dev server.
'http://localhost:3000',
'http://127.0.0.1:3000',
]

ROOT_URLCONF = 'covid19_site.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'covid19_site.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}


# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/

STATIC_URL = '/static/'
23 changes: 23 additions & 0 deletions covid19_site/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from django.urls import include
"""covid19_site URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path

urlpatterns = [
path('admin/', admin.site.urls),
path('api/', include('model_api.urls')),
]

0 comments on commit 5b3040b

Please sign in to comment.