5
5
6
6
import altair as alt
7
7
import numpy as np
8
+ import os
9
+ import json
8
10
import pandas as pd
9
-
11
+ import penn_chime . spreadsheet as sp
10
12
from .constants import (
11
13
CHANGE_DATE ,
12
14
DOCS_URL ,
@@ -172,6 +174,8 @@ def display_sidebar(st, d: Parameters) -> Parameters:
172
174
# it's kindof like ember or angular if you are familiar with those
173
175
174
176
st_obj = st .sidebar
177
+ # used_widget_key = st.get_last_used_widget_key ( )
178
+
175
179
current_hospitalized_input = NumberInput (
176
180
st_obj ,
177
181
"Currently hospitalized COVID-19 patients" ,
@@ -216,7 +220,11 @@ def display_sidebar(st, d: Parameters) -> Parameters:
216
220
step = 1.0 ,
217
221
)
218
222
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
220
228
)
221
229
icu_pct_input = PercentInput (st_obj ,
222
230
"ICU %(total infections)" ,
@@ -230,23 +238,23 @@ def display_sidebar(st, d: Parameters) -> Parameters:
230
238
hospitalized_days_input = NumberInput (
231
239
st_obj ,
232
240
"Average hospital length of stay (in days)" ,
233
- min_value = 0 ,
241
+ min_value = 1 ,
234
242
value = d .hospitalized .days ,
235
243
step = 1 ,
236
244
format = "%i" ,
237
245
)
238
246
icu_days_input = NumberInput (
239
247
st_obj ,
240
248
"Average days in ICU" ,
241
- min_value = 0 ,
249
+ min_value = 1 ,
242
250
value = d .icu .days ,
243
251
step = 1 ,
244
252
format = "%i" ,
245
253
)
246
254
ventilated_days_input = NumberInput (
247
255
st_obj ,
248
256
"Average days on ventilator" ,
249
- min_value = 0 ,
257
+ min_value = 1 ,
250
258
value = d .ventilated .days ,
251
259
step = 1 ,
252
260
format = "%i" ,
@@ -268,7 +276,7 @@ def display_sidebar(st, d: Parameters) -> Parameters:
268
276
infectious_days_input = NumberInput (
269
277
st_obj ,
270
278
"Infectious days" ,
271
- min_value = 0 ,
279
+ min_value = 1 ,
272
280
value = d .infectious_days ,
273
281
step = 1 ,
274
282
format = "%i" ,
@@ -349,6 +357,8 @@ def display_sidebar(st, d: Parameters) -> Parameters:
349
357
max_y_axis = max_y_axis_input ()
350
358
351
359
current_date = current_date_input ()
360
+ #Subscribe implementation
361
+ subscribe (st_obj )
352
362
353
363
return Parameters (
354
364
current_hospitalized = current_hospitalized ,
@@ -374,6 +384,66 @@ def display_sidebar(st, d: Parameters) -> Parameters:
374
384
days = ventilated_days ),
375
385
)
376
386
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 )
377
447
378
448
def display_footer (st ):
379
449
st .subheader ("References & Acknowledgements" )
0 commit comments