wnstnb commited on
Commit
8f12e15
Β·
1 Parent(s): 45ba8c9

guardrails for time

Browse files
Files changed (2) hide show
  1. app.py +66 -2
  2. requirements.txt +3 -1
app.py CHANGED
@@ -3,6 +3,65 @@ import pandas as pd
3
  import numpy as np
4
  from sklearn.metrics import roc_auc_score, precision_score, recall_score
5
  from pandas.tseries.offsets import BDay
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  st.set_page_config(
8
  page_title="Gameday $SPX",
@@ -21,9 +80,11 @@ with st.form("choose_model"):
21
 
22
  with col1:
23
  option = st.select_slider(
24
- 'Slide the scale based on PST, then run.',
25
- ['06:30', '07:00', '07:30', '08:00']
 
26
  )
 
27
  with col2:
28
  submitted = st.form_submit_button('πŸƒπŸ½β€β™‚οΈ Run',use_container_width=True)
29
  cleared = st.form_submit_button('🧹 Clear All',use_container_width=True)
@@ -501,6 +562,9 @@ with st.form("choose_model"):
501
  f"{len(data.query('High > VIX_EM_15_High | Low < VIX_EM_15_Low')) / len(data):.1%}"
502
  ]
503
 
 
 
 
504
  st.dataframe(top_of_fold, use_container_width=True)
505
 
506
  tab1, tab2, tab3, tab4 = st.tabs(["πŸ€– Stats", "✨ New Data", "πŸ“š Historical", "πŸ“Š Performance"])
 
3
  import numpy as np
4
  from sklearn.metrics import roc_auc_score, precision_score, recall_score
5
  from pandas.tseries.offsets import BDay
6
+ import streamlit as st
7
+ from datetime import datetime, time, timedelta
8
+ import pytz
9
+ import holidays
10
+
11
+ # Function to convert UTC to PST
12
+ def convert_to_pst(utc_time):
13
+ utc_timezone = pytz.timezone('UTC')
14
+ pst_timezone = pytz.timezone('America/Los_Angeles')
15
+ utc_time = utc_timezone.localize(utc_time)
16
+ pst_time = utc_time.astimezone(pst_timezone)
17
+ return pst_time
18
+
19
+ # Get the current UTC time
20
+ utc_now = datetime.utcnow()
21
+
22
+ # Convert UTC to PST
23
+ pst_now = convert_to_pst(utc_now)
24
+
25
+ # Function to check if a date is a business day (Monday to Friday)
26
+ def is_business_day(date):
27
+ return date.weekday() < 5 # Monday = 0, Friday = 4
28
+
29
+ # Function to get the list of holidays in the US for the current year
30
+ def get_us_holidays():
31
+ return holidays.US(years=datetime.now().year)
32
+
33
+ # Function to convert the time string to a datetime object
34
+ def convert_to_datetime(time_str, pst_now):
35
+ time_obj = datetime.strptime(time_str, "%H:%M")
36
+ # Combine the time with the current date to get the full datetime in PST
37
+ return datetime.combine(pst_now.date(), time_obj.time())
38
+
39
+ # Function to determine the emoji for each time
40
+ def get_time_emojis(times, pst_now):
41
+ pst_now_time = pst_now.time()
42
+ us_holidays = get_us_holidays()
43
+ emojis = []
44
+
45
+ for t in times:
46
+ time_obj = convert_to_datetime(t, pst_now)
47
+
48
+ # Check if the time is less than or equal to the current time in PST
49
+ if time_obj.time() <= pst_now_time:
50
+ emoji = "βœ…"
51
+ else:
52
+ # Check if it's a business day or a holiday
53
+ if is_business_day(time_obj) or time_obj.date() in us_holidays:
54
+ emoji = "β›”"
55
+ else:
56
+ emoji = "βœ…"
57
+
58
+ emojis.append(emoji)
59
+
60
+ return emojis
61
+
62
+ # Example usage:
63
+ times_list = ['06:30', '07:00', '07:30', '08:00']
64
+ emojis_list = get_time_emojis(times_list, pst_now)
65
 
66
  st.set_page_config(
67
  page_title="Gameday $SPX",
 
80
 
81
  with col1:
82
  option = st.select_slider(
83
+ f"""Slide the scale based on PST, then run [{pst_now.strftime('%H:%M')}]""",
84
+ times_list,
85
+ format_func=lambda x: f"{emojis_list[times_list.index(x)]} {x}"
86
  )
87
+
88
  with col2:
89
  submitted = st.form_submit_button('πŸƒπŸ½β€β™‚οΈ Run',use_container_width=True)
90
  cleared = st.form_submit_button('🧹 Clear All',use_container_width=True)
 
562
  f"{len(data.query('High > VIX_EM_15_High | Low < VIX_EM_15_Low')) / len(data):.1%}"
563
  ]
564
 
565
+ # Cache all DFs
566
+ all_dfs = []
567
+
568
  st.dataframe(top_of_fold, use_container_width=True)
569
 
570
  tab1, tab2, tab3, tab4 = st.tabs(["πŸ€– Stats", "✨ New Data", "πŸ“š Historical", "πŸ“Š Performance"])
requirements.txt CHANGED
@@ -14,4 +14,6 @@ streamlit==1.24.1
14
  scikit-learn==1.3.0
15
  scipy==1.9.3
16
  datasets
17
- huggingface_hub
 
 
 
14
  scikit-learn==1.3.0
15
  scipy==1.9.3
16
  datasets
17
+ huggingface_hub
18
+ holidays
19
+ pytz