atodorov284 commited on
Commit
dfb33ee
·
1 Parent(s): 0573e79

color scheme for gauge plots

Browse files
streamlit_src/controllers/user_controller.py CHANGED
@@ -1,4 +1,4 @@
1
- from typing import Callable, Dict, List, Tuple
2
  import streamlit as st
3
  import numpy as np
4
  from models.air_quality_model import AirQualityModel
@@ -50,7 +50,7 @@ class UserController:
50
  """
51
  self._show_current_data()
52
 
53
- self._two_columns_layout(0.7, self._raise_awareness, self._quiz)
54
 
55
  self._display_plots()
56
 
@@ -192,29 +192,6 @@ class UserController:
192
  f"Wrong answer! The correct answer was {correct_answer[0].lower() + correct_answer[1:]}."
193
  )
194
 
195
- def _two_columns_layout(
196
- self, ratio: float, left_function: Callable, right_function: Callable
197
- ) -> None:
198
- """
199
- Divide the page into two columns and call the left and right functions within them.
200
-
201
- Parameters
202
- ----------
203
- ratio : float
204
- The ratio of the left to the right column.
205
- left_function : Callable
206
- The function to be called in the left column.
207
- right_function : Callable
208
- The function to be called in the right column.
209
- """
210
- left, right = st.columns([ratio, 1 - ratio], gap="large")
211
-
212
- with left:
213
- left_function()
214
-
215
- with right:
216
- right_function()
217
-
218
  def _prepare_line_plot(self) -> go.Figure:
219
  """
220
  Prepare a line plot for the next three days' NO2 and O3 levels.
@@ -370,7 +347,7 @@ class UserController:
370
  mode="gauge+number",
371
  value=value,
372
  title={"text": title},
373
- gauge={"axis": {"range": [0, 2 * guideline]}, "bar": {"color": color}},
374
  )
375
  )
376
  fig.update_layout(height=250, width=250, margin=dict(t=0, b=0, l=0, r=0))
@@ -387,15 +364,16 @@ class UserController:
387
  Returns:
388
  str: A hex color code representing the calculated color.
389
  """
 
390
  half_who_limit = who_limit / 2
391
 
392
  if value <= half_who_limit:
393
- # Green -> Yellow gradient
394
- return f"rgba({int(255 * value / half_who_limit)}, 255, 0, 1)" # Gradient from green to yellow
395
  elif value <= who_limit:
396
- # Yellow -> Red gradient
397
  excess_value = value - half_who_limit
398
- return f"rgba(255, {int(255 - (255 * excess_value / half_who_limit))}, 0, 1)" # Gradient from yellow to red
399
  else:
400
- # Beyond the WHO limit, fully red
401
- return "rgba(255, 0, 0, 1)" # Fully red
 
1
+ from typing import Dict, List, Tuple
2
  import streamlit as st
3
  import numpy as np
4
  from models.air_quality_model import AirQualityModel
 
50
  """
51
  self._show_current_data()
52
 
53
+ self._view.two_columns_layout(0.7, self._raise_awareness, self._quiz)
54
 
55
  self._display_plots()
56
 
 
192
  f"Wrong answer! The correct answer was {correct_answer[0].lower() + correct_answer[1:]}."
193
  )
194
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
  def _prepare_line_plot(self) -> go.Figure:
196
  """
197
  Prepare a line plot for the next three days' NO2 and O3 levels.
 
347
  mode="gauge+number",
348
  value=value,
349
  title={"text": title},
350
+ gauge={"axis": {"range": [0, guideline]}, "bar": {"color": color}},
351
  )
352
  )
353
  fig.update_layout(height=250, width=250, margin=dict(t=0, b=0, l=0, r=0))
 
364
  Returns:
365
  str: A hex color code representing the calculated color.
366
  """
367
+
368
  half_who_limit = who_limit / 2
369
 
370
  if value <= half_who_limit:
371
+ # Green to Bright Yellow (exaggerated contrast)
372
+ return f"rgba(0, {int(255 * value / half_who_limit)}, 0, 1)" # Gradient from dark green to bright green
373
  elif value <= who_limit:
374
+ # Yellow to Dark Orange (stronger contrast between safe and danger)
375
  excess_value = value - half_who_limit
376
+ return f"rgba(255, {int(200 - (200 * excess_value / half_who_limit))}, 0, 1)" # Gradient from bright yellow to dark orange
377
  else:
378
+ # Dark Red for exceeding WHO limit
379
+ return "rgba(180, 0, 0, 1)" # Dark red for dangerous levels
streamlit_src/views/user_view.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import streamlit as st
2
  import pandas as pd
3
  import plotly.graph_objects as go
@@ -90,6 +91,29 @@ class UserView:
90
  elif level == "success":
91
  st.sidebar.success(message)
92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  def raise_awareness(
94
  self, random_fact: str, awareness_expanders: list, health_message: dict
95
  ) -> None:
 
1
+ from typing import Callable
2
  import streamlit as st
3
  import pandas as pd
4
  import plotly.graph_objects as go
 
91
  elif level == "success":
92
  st.sidebar.success(message)
93
 
94
+ def two_columns_layout(
95
+ self, ratio: float, left_function: Callable, right_function: Callable
96
+ ) -> None:
97
+ """
98
+ Divide the page into two columns and call the left and right functions within them.
99
+
100
+ Parameters
101
+ ----------
102
+ ratio : float
103
+ The ratio of the left to the right column.
104
+ left_function : Callable
105
+ The function to be called in the left column.
106
+ right_function : Callable
107
+ The function to be called in the right column.
108
+ """
109
+ left, right = st.columns([ratio, 1 - ratio], gap="large")
110
+
111
+ with left:
112
+ left_function()
113
+
114
+ with right:
115
+ right_function()
116
+
117
  def raise_awareness(
118
  self, random_fact: str, awareness_expanders: list, health_message: dict
119
  ) -> None: