feat(uti): Add constant TIME_PERIOD 54/36054/4
authorTibor Frank <tifrank@cisco.com>
Wed, 27 Apr 2022 11:39:07 +0000 (13:39 +0200)
committerTibor Frank <tifrank@cisco.com>
Wed, 27 Apr 2022 13:17:30 +0000 (15:17 +0200)
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 <tifrank@cisco.com>
resources/tools/dash/app/pal/__init__.py
resources/tools/dash/app/pal/stats/layout.py
resources/tools/dash/app/pal/stats/stats.py
resources/tools/dash/app/pal/trending/layout.py
resources/tools/dash/app/pal/trending/trending.py

index ba68c01..4e32598 100644 (file)
@@ -20,6 +20,17 @@ from flask import Flask
 from flask_assets import Environment
 
 
 from flask_assets import Environment
 
 
+# Maximal value of TIME_PERIOD in days.
+# Do not change without a good reason.
+MAX_TIME_PERIOD = 180
+
+# It defines the time period in days from now back to the past from which data
+# is read to dataframes.
+# TIME_PERIOD = None means all data (max MAX_TIME_PERIOD days) is read.
+# TIME_PERIOD = MAX_TIME_PERIOD is the default value
+TIME_PERIOD = MAX_TIME_PERIOD  # [days]
+
+
 def init_app():
     """Construct core Flask application with embedded Dash app.
     """
 def init_app():
     """Construct core Flask application with embedded Dash app.
     """
@@ -42,13 +53,19 @@ def init_app():
         assets = Environment()
         assets.init_app(app)
 
         assets = Environment()
         assets.init_app(app)
 
+        if TIME_PERIOD is None or TIME_PERIOD > MAX_TIME_PERIOD:
+            time_period = MAX_TIME_PERIOD
+        else:
+            time_period = TIME_PERIOD
+
         # Import Dash applications.
         from .stats.stats import init_stats
         # Import Dash applications.
         from .stats.stats import init_stats
-        app = init_stats(app)
+        app = init_stats(app, time_period=time_period)
 
         from .trending.trending import init_trending
 
         from .trending.trending import init_trending
-        app = init_trending(app)
+        app = init_trending(app, time_period=time_period)
 
     return app
 
 
     return app
 
+
 app = init_app()
 app = init_app()
index 0ae83cf..0c5c22e 100644 (file)
@@ -17,6 +17,7 @@
 import pandas as pd
 import dash_bootstrap_components as dbc
 
 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
 from dash import dcc
 from dash import html
 from dash import callback_context, no_update
@@ -33,8 +34,9 @@ class Layout:
     """
     """
 
     """
     """
 
-    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: int=None) -> None:
         """
         """
 
         """
         """
 
@@ -44,12 +46,13 @@ class Layout:
         self._spec_file = spec_file
         self._graph_layout_file = graph_layout_file
         self._data_spec_file = data_spec_file
         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_stats, data_mrr, data_ndrpdr = Data(
             data_spec_file=self._data_spec_file,
             debug=True
 
         # Read the data:
         data_stats, data_mrr, data_ndrpdr = Data(
             data_spec_file=self._data_spec_file,
             debug=True
-        ).read_stats()
+        ).read_stats(days=self._time_period)
 
         df_tst_info = pd.concat([data_mrr, data_ndrpdr], ignore_index=True)
 
 
         df_tst_info = pd.concat([data_mrr, data_ndrpdr], ignore_index=True)
 
@@ -59,6 +62,11 @@ class Layout:
         data_stats = data_stats[~data_stats.job.str.contains("-iterative-")]
         data_stats = data_stats[["job", "build", "start_time", "duration"]]
 
         data_stats = data_stats[~data_stats.job.str.contains("-iterative-")]
         data_stats = data_stats[["job", "build", "start_time", "duration"]]
 
+        data_time_period = \
+            (datetime.utcnow() - data_stats["start_time"].min()).days
+        if self._time_period > data_time_period:
+            self._time_period = data_time_period
+
         self._jobs = sorted(list(data_stats["job"].unique()))
 
         tst_info = {
         self._jobs = sorted(list(data_stats["job"].unique()))
 
         tst_info = {
@@ -144,6 +152,10 @@ class Layout:
     def jobs(self) -> list:
         return self._jobs
 
     def jobs(self) -> list:
         return self._jobs
 
+    @property
+    def time_period(self):
+        return self._time_period
+
     def add_content(self):
         """
         """
     def add_content(self):
         """
         """
@@ -160,7 +172,7 @@ class Layout:
                     ),
                     dcc.Loading(
                         dbc.Offcanvas(
                     ),
                     dcc.Loading(
                         dbc.Offcanvas(
-                            class_name="w-50",
+                            class_name="w-25",
                             id="offcanvas-metadata",
                             title="Detailed Information",
                             placement="end",
                             id="offcanvas-metadata",
                             title="Detailed Information",
                             placement="end",
@@ -302,10 +314,13 @@ class Layout:
                             id="dpr-period",
                             className="d-flex justify-content-center",
                             min_date_allowed=\
                             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(),
                             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"
                         )
                             end_date=datetime.utcnow(),
                             display_format="D MMMM YY"
                         )
index 78bb6e6..d733e0c 100644 (file)
@@ -19,7 +19,7 @@ import dash_bootstrap_components as dbc
 from .layout import Layout
 
 
 from .layout import Layout
 
 
-def init_stats(server):
+def init_stats(server, time_period=None):
     """Create a Plotly Dash dashboard.
 
     :param server: Flask server.
     """Create a Plotly Dash dashboard.
 
     :param server: Flask server.
@@ -40,7 +40,8 @@ def init_stats(server):
         html_layout_file="pal/templates/stats_layout.jinja2",
         spec_file="pal/stats/spec_job_selection.yaml",
         graph_layout_file="pal/stats/layout.yaml",
         html_layout_file="pal/templates/stats_layout.jinja2",
         spec_file="pal/stats/spec_job_selection.yaml",
         graph_layout_file="pal/stats/layout.yaml",
-        data_spec_file="pal/data/data.yaml"
+        data_spec_file="pal/data/data.yaml",
+        time_period=time_period
     )
     dash_app.index_string = layout.html_layout
     dash_app.layout = layout.add_content()
     )
     dash_app.index_string = layout.html_layout
     dash_app.layout = layout.add_content()
index fa5f821..470f72e 100644 (file)
@@ -17,6 +17,7 @@
 import pandas as pd
 import dash_bootstrap_components as dbc
 
 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
 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("")
 
 
     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._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 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
 
         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)
 
 
         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
         # Read from files:
         self._html_layout = ""
         self._spec_tbs = None
@@ -139,6 +147,10 @@ class Layout:
     def layout(self):
         return self._graph_layout
 
     def layout(self):
         return self._graph_layout
 
+    @property
+    def time_period(self):
+        return self._time_period
+
     def add_content(self):
         """
         """
     def add_content(self):
         """
         """
@@ -273,9 +285,13 @@ class Layout:
                                 dbc.InputGroupText("Infra"),
                                 dbc.Select(
                                     id="dd-ctrl-phy",
                                 dbc.InputGroupText("Infra"),
                                 dbc.Select(
                                     id="dd-ctrl-phy",
-                                    placeholder="Select a Physical Test Bed Topology...",
+                                    placeholder=(
+                                        "Select a Physical Test Bed "
+                                        "Topology..."
+                                    ),
                                     options=[
                                     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=\
                             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(),
                             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"
                         )
                             end_date=datetime.utcnow(),
                             display_format="D MMMM YY"
                         )
index 99a5713..8cd52b5 100644 (file)
@@ -19,7 +19,7 @@ import dash_bootstrap_components as dbc
 from .layout import Layout
 
 
 from .layout import Layout
 
 
-def init_trending(server):
+def init_trending(server, time_period=None):
     """Create a Plotly Dash dashboard.
 
     :param server: Flask server.
     """Create a Plotly Dash dashboard.
 
     :param server: Flask server.
@@ -40,7 +40,8 @@ def init_trending(server):
         html_layout_file="pal/templates/trending_layout.jinja2",
         spec_file="pal/trending/spec_test_selection.yaml",
         graph_layout_file="pal/trending/layout.yaml",
         html_layout_file="pal/templates/trending_layout.jinja2",
         spec_file="pal/trending/spec_test_selection.yaml",
         graph_layout_file="pal/trending/layout.yaml",
-        data_spec_file="pal/data/data.yaml"
+        data_spec_file="pal/data/data.yaml",
+        time_period=time_period
     )
     dash_app.index_string = layout.html_layout
     dash_app.layout = layout.add_content()
     )
     dash_app.index_string = layout.html_layout
     dash_app.layout = layout.add_content()