Ashmi Banerjee commited on
Commit
29a4bc9
·
1 Parent(s): fa1e621

another hacky vversion

Browse files
Files changed (4) hide show
  1. app.py +9 -6
  2. views/intro_screen.py +1 -0
  3. views/nav_buttons.py +28 -23
  4. views/ui_helpers.py +13 -5
app.py CHANGED
@@ -6,7 +6,7 @@ from dotenv import load_dotenv
6
  from views.intro_screen import welcome_screen
7
  from views.questions_screen import questions_screen
8
  from views.continue_survey import continue_survey_screen
9
- from views.ui_helpers import exit_screen
10
  from css.layout import custom_css
11
 
12
  st.set_page_config(layout="wide")
@@ -29,12 +29,14 @@ def initialization():
29
  st.session_state.show_questions = False
30
  if "survey_continued" not in st.session_state:
31
  st.session_state.survey_continued = None
32
- if "start_new_survey" not in st.session_state:
33
- st.session_state.start_new_survey = False
34
  if 'ratings' not in st.session_state:
35
  st.session_state.ratings = {}
36
  if 'previous_ratings' not in st.session_state:
37
  st.session_state.previous_ratings = {}
 
 
38
 
39
 
40
  def ui():
@@ -43,11 +45,12 @@ def ui():
43
  data = load_data()
44
  initialization()
45
 
46
- if st.session_state.completed and not st.session_state.start_new_survey:
 
47
  exit_screen()
48
  return
49
 
50
- if st.session_state.username is None:
51
  welcome_screen()
52
  else:
53
  # Check if user progress exists in Firebase
@@ -60,7 +63,7 @@ def ui():
60
  if st.session_state.current_index >= len(data):
61
  # If all questions have been answered, show the exit screen
62
  print("survey completed")
63
- survey_completed()
64
  # Otherwise, show questions from where they left off
65
  questions_screen(data)
66
  else:
 
6
  from views.intro_screen import welcome_screen
7
  from views.questions_screen import questions_screen
8
  from views.continue_survey import continue_survey_screen
9
+ from views.ui_helpers import exit_screen, display_completion_message
10
  from css.layout import custom_css
11
 
12
  st.set_page_config(layout="wide")
 
29
  st.session_state.show_questions = False
30
  if "survey_continued" not in st.session_state:
31
  st.session_state.survey_continued = None
32
+ # if "start_new_survey" not in st.session_state:
33
+ # st.session_state.start_new_survey = False
34
  if 'ratings' not in st.session_state:
35
  st.session_state.ratings = {}
36
  if 'previous_ratings' not in st.session_state:
37
  st.session_state.previous_ratings = {}
38
+ if 'screen' not in st.session_state:
39
+ st.session_state.screen = 'welcome'
40
 
41
 
42
  def ui():
 
45
  data = load_data()
46
  initialization()
47
 
48
+ if st.session_state.completed: \
49
+ # and not st.session_state.start_new_survey:
50
  exit_screen()
51
  return
52
 
53
+ if st.session_state.username is None and st.session_state.screen == 'welcome':
54
  welcome_screen()
55
  else:
56
  # Check if user progress exists in Firebase
 
63
  if st.session_state.current_index >= len(data):
64
  # If all questions have been answered, show the exit screen
65
  print("survey completed")
66
+ display_completion_message()
67
  # Otherwise, show questions from where they left off
68
  questions_screen(data)
69
  else:
views/intro_screen.py CHANGED
@@ -33,6 +33,7 @@ def welcome_screen():
33
  if (username_input and validation_code_input) or next_button:
34
  if validate_username(username_input) and validate_code(validation_code_input):
35
  st.session_state.username = username_input
 
36
  else:
37
  if not validate_username(username_input):
38
  st.warning("Invalid username. Please check and try again.")
 
33
  if (username_input and validation_code_input) or next_button:
34
  if validate_username(username_input) and validate_code(validation_code_input):
35
  st.session_state.username = username_input
36
+ st.session_state.screen = "questions"
37
  else:
38
  if not validate_username(username_input):
39
  st.warning("Invalid username. Please check and try again.")
views/nav_buttons.py CHANGED
@@ -5,26 +5,30 @@ from datetime import datetime
5
  import os
6
  from dotenv import load_dotenv
7
 
8
- from views.ui_helpers import display_completion_message
9
 
10
  load_dotenv()
11
  VALIDATION_CODE = os.getenv("VALIDATION_CODE")
12
 
13
 
14
- def submit_feedback(current_index):
15
  """Handles feedback submission to the database."""
16
- feedback = Feedback(
17
- id=current_index + 1,
18
- user_id=st.session_state.username,
19
- time_stamp=datetime.now().isoformat(),
20
- responses=st.session_state.responses,
21
- )
22
- try:
23
- save_feedback(feedback)
24
- st.session_state.completed = True
25
- st.rerun()
26
- except Exception as e:
27
- st.error(f"An error occurred while submitting feedback: {e}")
 
 
 
 
28
 
29
 
30
  def flatten_ratings(response):
@@ -61,17 +65,18 @@ def navigation_buttons(data, response: Response):
61
  st.warning("Please provide all ratings before proceeding.")
62
  else:
63
  if current_index < len(data) - 1:
64
- st.session_state.previous_ratings[data.iloc[st.session_state.current_index]['config_id']] = response.model_ratings
 
65
  st.session_state.current_index += 1
66
  st.rerun()
67
- else:
68
- if st.button("Finish"):
69
- submit_feedback(current_index)
 
70
 
71
  with col3: # Save & Resume Later button
72
  if st.button("Exit & Resume Later"):
73
- submit_feedback(current_index)
74
- if st.session_state.current_index == len(data) - 1:
75
- st.session_state.completed = True
76
- display_completion_message()
77
- # st.rerun()
 
5
  import os
6
  from dotenv import load_dotenv
7
 
8
+ from views.ui_helpers import display_completion_message, exit_screen
9
 
10
  load_dotenv()
11
  VALIDATION_CODE = os.getenv("VALIDATION_CODE")
12
 
13
 
14
+ def submit_feedback(current_index, all_ratings):
15
  """Handles feedback submission to the database."""
16
+ if any(rating == 0 for rating in all_ratings):
17
+ st.warning("Please provide all ratings before exiting.")
18
+ st.session_state.show_exit_screen = True
19
+ else:
20
+ feedback = Feedback(
21
+ id=current_index + 1,
22
+ user_id=st.session_state.username,
23
+ time_stamp=datetime.now().isoformat(),
24
+ responses=st.session_state.responses,
25
+ )
26
+ try:
27
+ save_feedback(feedback)
28
+ st.session_state.completed = True
29
+ st.session_state.screen = "exit"
30
+ except Exception as e:
31
+ st.error(f"An error occurred while submitting feedback: {e}")
32
 
33
 
34
  def flatten_ratings(response):
 
65
  st.warning("Please provide all ratings before proceeding.")
66
  else:
67
  if current_index < len(data) - 1:
68
+ st.session_state.previous_ratings[
69
+ data.iloc[st.session_state.current_index]['config_id']] = response.model_ratings
70
  st.session_state.current_index += 1
71
  st.rerun()
72
+
73
+ if st.button("Finish", disabled=st.session_state.current_index != len(data) - 1):
74
+ st.session_state.screen = "exit"
75
+ submit_feedback(current_index, all_ratings)
76
 
77
  with col3: # Save & Resume Later button
78
  if st.button("Exit & Resume Later"):
79
+ all_ratings = flatten_ratings(response)
80
+ submit_feedback(current_index, all_ratings)
81
+ st.session_state.screen = "exit"
82
+ # st.rerun()
 
views/ui_helpers.py CHANGED
@@ -1,5 +1,7 @@
1
  import streamlit as st
2
 
 
 
3
 
4
  def exit_screen():
5
  """Display exit screen"""
@@ -10,17 +12,21 @@ def exit_screen():
10
  <p>You can safely close this window or start a new survey.</p>
11
  </div>
12
  """, unsafe_allow_html=True)
13
-
14
- if st.button("Resume Survey"):
15
- reset_survey()
16
- st.rerun()
 
 
 
17
 
18
 
19
  def reset_survey():
20
  """Reset the survey state to start over."""
21
  st.session_state.responses = []
22
  st.session_state.completed = True
23
- st.session_state.start_new_survey = True
 
24
 
25
 
26
  def display_completion_message():
@@ -35,6 +41,8 @@ def display_completion_message():
35
  """,
36
  unsafe_allow_html=True,
37
  )
 
38
  st.session_state.show_questions = False
39
  st.session_state.completed = True
40
  st.session_state.start_new_survey = True
 
 
1
  import streamlit as st
2
 
3
+ from views.intro_screen import welcome_screen
4
+
5
 
6
  def exit_screen():
7
  """Display exit screen"""
 
12
  <p>You can safely close this window or start a new survey.</p>
13
  </div>
14
  """, unsafe_allow_html=True)
15
+ st.session_state.completed = True
16
+ st.session_state.show_exit_screen = True
17
+ # btn = st.button("Resume Survey")
18
+ # if btn:
19
+ # reset_survey()
20
+ # st.session_state.screen ="welcome"
21
+ # st.rerun()
22
 
23
 
24
  def reset_survey():
25
  """Reset the survey state to start over."""
26
  st.session_state.responses = []
27
  st.session_state.completed = True
28
+ # st.session_state.start_new_survey = True
29
+ st.show_exit_screen = False
30
 
31
 
32
  def display_completion_message():
 
41
  """,
42
  unsafe_allow_html=True,
43
  )
44
+ print("trying to show completion message agian")
45
  st.session_state.show_questions = False
46
  st.session_state.completed = True
47
  st.session_state.start_new_survey = True
48
+ st.rerun()