Skip to content

Commit

Permalink
Allow for no trend data to exist
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Jun 8, 2020
1 parent 83706d8 commit a4732d4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def save_to_disk(self):
# Ensure state is not changed whilst getting data
with self.r.lock("saving", timeout=5, blocking_timeout=2.5):
keys = self.r.keys()
vals = self.cache.get_many(keys)
vals = self.cache.get_many(*[key.decode("UTF8") for key in keys])
timestamps = []
for key in keys:
timestamps.append(self.get_key_timestamp(key).isoformat())
Expand Down
12 changes: 7 additions & 5 deletions src/components/render_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _set_components(self, trend_keys: dict, **kwargs):
target_value = kwargs.pop("TV")
components_properties = {k[:2]: [] for k in kwargs.keys()}
for full_key, v in kwargs.items():
prev_trend_val = trend_dict[full_key]
prev_trend_val = trend_dict.get(full_key)
key = full_key[:2]
label = None

Expand All @@ -75,14 +75,14 @@ def _set_components(self, trend_keys: dict, **kwargs):
aim = 0
actual = v
compliant = v <= target_value
trend_up = v <= prev_trend_val
trend_up = v <= prev_trend_val if prev_trend_val else None

if key == "AA":
aim = "100%" # Render with percent sign
target = "98.5%"
actual = f"{v:.1f}%"
compliant = v >= 98.5 # Custom target value for disclosures
trend_up = v >= prev_trend_val
trend_up = v >= prev_trend_val if prev_trend_val else None

components_properties[key].append(dict(
aim=aim,
Expand All @@ -104,7 +104,9 @@ def _create_component(self, head: str, desc: str, colour: str, component_propert
num_props = len(component_properties)
class_name = "component-stats component-stats-1" if num_props <= 2 else "component-stats component-stats-3"
for target_props in component_properties:
trend = "happy" if target_props["trend_up"] else "sad"
trend = target_props["trend_up"]
if trend is not None:
trend = "happy" if target_props["trend_up"] else "sad"
target_props["status"] = "compliant" if target_props["compliant"] else "non-compliant"

component_stats.append(html.Div([
Expand All @@ -114,7 +116,7 @@ def _create_component(self, head: str, desc: str, colour: str, component_propert
], className="component-aim"),
html.Div([
html.Span(f"Actual: {target_props['actual']}", className="component-actual-text"),
html.Img(src=self._asset_path(f"{trend}.svg"), className="trend-svg"),
html.Img(src=self._asset_path(f"{trend}.svg"), className="trend-svg") if trend is not None else None,
], className=f"component-actual {target_props['status']}")
], className=class_name))

Expand Down

0 comments on commit a4732d4

Please sign in to comment.