Skip to content

Commit b661fd8

Browse files
authored
Merge branch 'develop' into dsgit1-patch-2
2 parents f49ac01 + 225879d commit b661fd8

File tree

5 files changed

+132
-14
lines changed

5 files changed

+132
-14
lines changed

setup.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
__version__ = "1.1.3" # update VERSION in constants.py
44
__author__ = "Predictive Healthcare @ Penn Medicine"
55

6-
from os import path
7-
from setuptools import setup, find_packages, find_namespace_packages
6+
from setuptools import setup, find_namespace_packages
87

98

109
setup(
@@ -24,6 +23,7 @@
2423
install_requires=[
2524
"altair",
2625
"black",
26+
"gspread",
2727
"gunicorn",
2828
"dash",
2929
"dash_bootstrap_components",
@@ -33,17 +33,18 @@
3333
"pyyaml",
3434
"selenium",
3535
"streamlit",
36+
"gspread",
37+
"oauth2client"
3638
],
3739
classifiers=[
3840
"Programming Language :: Python :: 3",
3941
"License :: OSI Approved :: MIT License",
4042
"Operating System :: OS Independent",
4143
],
4244
python_requires='>=3.7',
43-
entry_points = {
45+
entry_points={
4446
'console_scripts': ['penn_chime=penn_chime.cli:main'],
4547
},
4648
keywords=[],
4749
include_package_data=True,
4850
)
49-

src/penn_chime/parameters.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
)
2020
from .validators import (
2121
Date,
22+
GteOne,
2223
OptionalDate,
2324
OptionalValue,
2425
OptionalStrictlyPositive,
@@ -64,7 +65,7 @@ class Disposition(_Disposition):
6465
@classmethod
6566
def create(cls, *, days: int, rate: float):
6667
"""Mandate key word arguments."""
67-
Positive(key="days", value=days)
68+
GteOne(key="days", value=days)
6869
Rate(key="rate", value=rate)
6970
return cls(days, rate)
7071

@@ -201,7 +202,7 @@ def validate(string):
201202
(
202203
"hospitalized_days",
203204
int,
204-
0,
205+
1,
205206
None,
206207
True,
207208
),
@@ -215,7 +216,7 @@ def validate(string):
215216
(
216217
"icu_days",
217218
int,
218-
0,
219+
1,
219220
None,
220221
True,
221222
),
@@ -285,7 +286,7 @@ def validate(string):
285286
(
286287
"ventilated_days",
287288
int,
288-
0,
289+
1,
289290
None,
290291
True,
291292
),

src/penn_chime/presentation.py

Lines changed: 76 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
import altair as alt
77
import numpy as np
8+
import os
9+
import json
810
import pandas as pd
9-
11+
import penn_chime.spreadsheet as sp
1012
from .constants import (
1113
CHANGE_DATE,
1214
DOCS_URL,
@@ -172,6 +174,8 @@ def display_sidebar(st, d: Parameters) -> Parameters:
172174
# it's kindof like ember or angular if you are familiar with those
173175

174176
st_obj = st.sidebar
177+
# used_widget_key = st.get_last_used_widget_key ( )
178+
175179
current_hospitalized_input = NumberInput(
176180
st_obj,
177181
"Currently hospitalized COVID-19 patients",
@@ -216,7 +220,11 @@ def display_sidebar(st, d: Parameters) -> Parameters:
216220
step=1.0,
217221
)
218222
hospitalized_pct_input = PercentInput(
219-
st_obj, "Hospitalization %(total infections)", value=d.hospitalized.rate,
223+
st_obj,
224+
"Hospitalization %(total infections)",
225+
value=d.hospitalized.rate,
226+
min_value=FLOAT_INPUT_MIN,
227+
max_value=100.0
220228
)
221229
icu_pct_input = PercentInput(st_obj,
222230
"ICU %(total infections)",
@@ -230,23 +238,23 @@ def display_sidebar(st, d: Parameters) -> Parameters:
230238
hospitalized_days_input = NumberInput(
231239
st_obj,
232240
"Average hospital length of stay (in days)",
233-
min_value=0,
241+
min_value=1,
234242
value=d.hospitalized.days,
235243
step=1,
236244
format="%i",
237245
)
238246
icu_days_input = NumberInput(
239247
st_obj,
240248
"Average days in ICU",
241-
min_value=0,
249+
min_value=1,
242250
value=d.icu.days,
243251
step=1,
244252
format="%i",
245253
)
246254
ventilated_days_input = NumberInput(
247255
st_obj,
248256
"Average days on ventilator",
249-
min_value=0,
257+
min_value=1,
250258
value=d.ventilated.days,
251259
step=1,
252260
format="%i",
@@ -268,7 +276,7 @@ def display_sidebar(st, d: Parameters) -> Parameters:
268276
infectious_days_input = NumberInput(
269277
st_obj,
270278
"Infectious days",
271-
min_value=0,
279+
min_value=1,
272280
value=d.infectious_days,
273281
step=1,
274282
format="%i",
@@ -349,6 +357,8 @@ def display_sidebar(st, d: Parameters) -> Parameters:
349357
max_y_axis = max_y_axis_input()
350358

351359
current_date = current_date_input()
360+
#Subscribe implementation
361+
subscribe(st_obj)
352362

353363
return Parameters(
354364
current_hospitalized=current_hospitalized,
@@ -374,6 +384,66 @@ def display_sidebar(st, d: Parameters) -> Parameters:
374384
days=ventilated_days),
375385
)
376386

387+
#Read the environment variables and cteate json key object to use with ServiceAccountCredentials
388+
def readGoogleApiSecrets():
389+
client_secret = {}
390+
os.getenv
391+
type = os.getenv ('GAPI_CRED_TYPE').strip()
392+
print (type)
393+
client_secret['type'] = type,
394+
client_secret['project_id'] = os.getenv ('GAPI_CRED_PROJECT_ID'),
395+
client_secret['private_key_id'] = os.getenv ('GAPI_CRED_PRIVATE_KEY_ID'),
396+
client_secret['private_key'] = os.getenv ('GAPI_CRED_PRIVATE_KEY'),
397+
client_secret['client_email'] = os.getenv ('GAPI_CRED_CLIENT_EMAIL'),
398+
client_secret['client_id'] = os.getenv ('GAPI_CRED_CLIENT_ID'),
399+
client_secret['auth_uri'] = os.getenv ('GAPI_CRED_AUTH_URI'),
400+
client_secret['token_uri'] = os.getenv ('GAPI_CRED_TOKEN_URI'),
401+
client_secret['auth_provider_x509_cert_url'] = os.getenv ('GAPI_CRED_AUTH_PROVIDER_X509_CERT_URL'),
402+
client_secret['client_x509_cert_url'] = os.getenv ('GAPI_CRED_CLIENT_X509_CERT_URI'),
403+
json_data = json.dumps (client_secret)
404+
print(json_data)
405+
return json_data
406+
407+
def readGoogleApiSecretsDict():
408+
type = os.getenv ('GAPI_CRED_TYPE')
409+
project_id = os.getenv ('GAPI_CRED_PROJECT_ID')
410+
private_key_id = os.getenv ('GAPI_CRED_PRIVATE_KEY_ID')
411+
private_key = os.getenv ('GAPI_CRED_PRIVATE_KEY')
412+
client_email = os.getenv ('GAPI_CRED_CLIENT_EMAIL')
413+
client_id = os.getenv ('GAPI_CRED_CLIENT_ID')
414+
auth_uri = os.getenv ('GAPI_CRED_AUTH_URI')
415+
token_uri = os.getenv ('GAPI_CRED_TOKEN_URI')
416+
auth_provider_x509_cert_url = os.getenv ('GAPI_CRED_AUTH_PROVIDER_X509_CERT_URL')
417+
client_x509_cert_url = os.getenv ('GAPI_CRED_CLIENT_X509_CERT_URI')
418+
419+
secret = {
420+
'type' : type,
421+
'project_id' : project_id,
422+
'private_key_id' : private_key_id,
423+
'private_key':private_key,
424+
'client_email': client_email,
425+
'client_id': client_id,
426+
'auth_uri': auth_uri,
427+
'token_uri': token_uri,
428+
'auth_provider_x509_cert_url':auth_provider_x509_cert_url,
429+
'client_x509_cert_url':client_x509_cert_url
430+
}
431+
return secret
432+
433+
def subscribe(st_obj):
434+
st_obj.subheader ("Subscribe")
435+
email = st_obj.text_input (label="Enter Email", value="", key="na_lower_1")
436+
name = st_obj.text_input (label="Enter Name", value="", key="na_upper_1")
437+
affiliation = st_obj.text_input (label="Enter Affiliation", value="", key="na_upper_2")
438+
if st_obj.button (label="Submit", key="ta_submit_1"):
439+
row = [email, name, affiliation]
440+
send_subscription_to_google_sheet(st_obj, row)
441+
442+
def send_subscription_to_google_sheet(st_obj, row):
443+
json_secret = readGoogleApiSecretsDict()
444+
#print(json_secret)
445+
spr = sp.spreadsheet (st_obj, json_secret)
446+
spr.writeToSheet("CHIME Form Submissions", row)
377447

378448
def display_footer(st):
379449
st.subheader("References & Acknowledgements")

src/penn_chime/spreadsheet.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import gspread
2+
from oauth2client.service_account import ServiceAccountCredentials
3+
4+
class spreadsheet:
5+
def __init__(self, st_obj, secret):
6+
self.st_obj = st_obj
7+
# use creds to create a client to interact with the Google Drive API
8+
self.scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
9+
#secret = 'client_secret.json'
10+
self.creds = ServiceAccountCredentials.from_json(secret)
11+
#self.creds = ServiceAccountCredentials.from_json_keyfile_name(secret, self.scope)
12+
self.client = gspread.authorize(self.creds)
13+
14+
15+
def createsheet(self, sheetname, header):
16+
sheet = None
17+
try:
18+
self.client.create(sheetname)
19+
except Exception as e:
20+
print("Caught exception " + e.__str__())
21+
try:
22+
sheet = self.client.open (sheetname).sheet1
23+
index = 0
24+
sheet.insert_row (header, index)
25+
except Exception as e:
26+
print("Caught exception " + e.__str__())
27+
return sheet
28+
29+
def writeToSheet(self, sheetname, row):
30+
try:
31+
sheet = self.client.open (sheetname).sheet1
32+
list_of_hashes = sheet.get_all_records ( )
33+
currentrow = sheet.row_count
34+
sheet.insert_row (row, currentrow)
35+
except Exception as e:
36+
print("Caught exception " + e.__str__())
37+
38+
def getAllRows(self, sheetname):
39+
allrows = None
40+
try:
41+
sheet = self.client.open (sheetname).sheet1
42+
allrows = sheet.get_all_records ( )
43+
except Exception as e:
44+
print("Caught exception " + e.__str__())
45+
return allrows

src/penn_chime/validators/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
OptionalStrictlyPositive = ValOptionalBounded(lower_bound=EPSILON)
1616
StrictlyPositive = ValBounded(lower_bound=EPSILON)
1717
Positive = ValBounded(lower_bound=-EPSILON)
18+
GteOne = ValBounded(lower_bound=1)
1819
Rate = ValRate()
1920
Date = ValDate()
2021
OptionalDate = ValOptionalDate()

0 commit comments

Comments
 (0)