From 3c421a0c9690b782f299946903a928632cb36f52 Mon Sep 17 00:00:00 2001 From: Tibor Frank Date: Wed, 27 Apr 2022 13:39:07 +0200 Subject: feat(uti): Add constant TIME_PERIOD It defines the time period from now back to the past from which data is raed to dataframes. Change-Id: Ic6feeb8e7958d69aa2e39922b48e9898e09b45dd Signed-off-by: Tibor Frank --- resources/tools/dash/app/pal/trending/layout.py | 35 +++++++++++++++++++------ 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'resources/tools/dash/app/pal/trending/layout.py') diff --git a/resources/tools/dash/app/pal/trending/layout.py b/resources/tools/dash/app/pal/trending/layout.py index fa5f8218ad..470f72ef22 100644 --- a/resources/tools/dash/app/pal/trending/layout.py +++ b/resources/tools/dash/app/pal/trending/layout.py @@ -17,6 +17,7 @@ import pandas as pd import dash_bootstrap_components as dbc +from flask import Flask from dash import dcc from dash import html from dash import callback_context, no_update, ALL @@ -52,8 +53,9 @@ class Layout: PLACEHOLDER = html.Nobr("") - def __init__(self, app, html_layout_file, spec_file, graph_layout_file, - data_spec_file): + def __init__(self, app: Flask, html_layout_file: str, spec_file: str, + graph_layout_file: str, data_spec_file: str, + time_period: str=None) -> None: """ """ @@ -63,20 +65,26 @@ class Layout: self._spec_file = spec_file self._graph_layout_file = graph_layout_file self._data_spec_file = data_spec_file + self._time_period = time_period # Read the data: data_mrr = Data( data_spec_file=self._data_spec_file, debug=True - ).read_trending_mrr() + ).read_trending_mrr(days=self._time_period) data_ndrpdr = Data( data_spec_file=self._data_spec_file, debug=True - ).read_trending_ndrpdr() + ).read_trending_ndrpdr(days=self._time_period) self._data = pd.concat([data_mrr, data_ndrpdr], ignore_index=True) + data_time_period = \ + (datetime.utcnow() - self._data["start_time"].min()).days + if self._time_period > data_time_period: + self._time_period = data_time_period + # Read from files: self._html_layout = "" self._spec_tbs = None @@ -139,6 +147,10 @@ class Layout: def layout(self): return self._graph_layout + @property + def time_period(self): + return self._time_period + def add_content(self): """ """ @@ -273,9 +285,13 @@ class Layout: dbc.InputGroupText("Infra"), dbc.Select( id="dd-ctrl-phy", - placeholder="Select a Physical Test Bed Topology...", + placeholder=( + "Select a Physical Test Bed " + "Topology..." + ), options=[ - {"label": k, "value": k} for k in self.spec_tbs.keys() + {"label": k, "value": k} \ + for k in self.spec_tbs.keys() ], ), ], @@ -431,10 +447,13 @@ class Layout: id="dpr-period", className="d-flex justify-content-center", min_date_allowed=\ - datetime.utcnow()-timedelta(days=180), + datetime.utcnow() - timedelta( + days=self.time_period), max_date_allowed=datetime.utcnow(), initial_visible_month=datetime.utcnow(), - start_date=datetime.utcnow() - timedelta(days=180), + start_date=\ + datetime.utcnow() - timedelta( + days=self.time_period), end_date=datetime.utcnow(), display_format="D MMMM YY" ) -- cgit 1.2.3-korg