From 22510c38e5bfed91cab5c013a00eae2153de59a9 Mon Sep 17 00:00:00 2001
From: Christoph Alt <christoph.alt@fau.de>
Date: Wed, 5 Oct 2022 16:02:22 +0200
Subject: [PATCH] fixed typo in legend

---
 dashboards/dashboard_list.py     | 312 +++++++++++++------------------
 dashboards/units.py              |   7 +
 tests/test_dashboard_creation.py |   2 +-
 tests/test_units.py              |   5 +
 4 files changed, 139 insertions(+), 187 deletions(-)
 create mode 100644 dashboards/units.py
 create mode 100644 tests/test_units.py

diff --git a/dashboards/dashboard_list.py b/dashboards/dashboard_list.py
index 8907af3..93b71c2 100644
--- a/dashboards/dashboard_list.py
+++ b/dashboards/dashboard_list.py
@@ -1,4 +1,5 @@
 from typing import List
+from dashboards.units import Units
 
 from dashboards.dashboard_base import (DashboardOptions, build_dashboard,
                                        build_row_repeat_dashboard,
@@ -15,82 +16,71 @@ def _uniform_grid(arch: str, group_by: List[str]):
     measurment_name = f'UniformGrid{arch}'
     row_repeat = "collisionSetup"
     panel_repeat = "host"
-    unit = 'MLUPs per Process'
+    unit = Units.mlups
 
-    row_repeat_var = get_dashboard_variable_query(row_repeat,
-                                                  show_tag_values(measurment_name, row_repeat),
-                                                  dataSource)
-    panel_repeat_var = get_dashboard_variable_query(panel_repeat,
-                                                    show_tag_values(measurment_name, panel_repeat),
-                                                    dataSource)
+    row_repeat_var = get_dashboard_variable_query(
+        row_repeat, show_tag_values(measurment_name, row_repeat), dataSource)
+    panel_repeat_var = get_dashboard_variable_query(
+        panel_repeat, show_tag_values(measurment_name, panel_repeat),
+        dataSource)
     other_filter = 'cellsPerBlock_0'
-    cellsPerBlock_var = get_dashboard_variable_query(other_filter,
-                                                     show_tag_values(measurment_name, other_filter),
-                                                     dataSource
-                                                     )
+    cellsPerBlock_var = get_dashboard_variable_query(
+        other_filter, show_tag_values(measurment_name, other_filter),
+        dataSource)
     where = join_variable_and([row_repeat, panel_repeat, other_filter])
-    query = Query(
-        select_='mlupsPerProcess',
-        from_=measurment_name,
-        where_=where,
-        group_by=group_by
-    )
+    query = Query(select_='mlupsPerProcess',
+                  from_=measurment_name,
+                  where_=where,
+                  group_by=group_by)
     options = DashboardOptions(
         title=f'Uniform Grid {arch}',
-        description=f"Benchmark dashboard for the Uniform Grid {arch} Benchmark from walberla",
-        tags=[
-            arch,
-            'benchmark',
-            'walberla',
-            'Uniform Grid'
-        ],
+        description=
+        f"Benchmark dashboard for the Uniform Grid {arch} Benchmark from walberla",
+        tags=[arch, 'benchmark', 'walberla', 'Uniform Grid'],
         timezone="browser",
     )
-    return build_row_repeat_dashboard(options,
-                                      row_repeat_var,
-                                      panel_repeat_var,
-                                      dataSource,
-                                      measurment_name,
-                                      query,
-                                      unit,
-                                      [cellsPerBlock_var]
-                                      )
+    return build_row_repeat_dashboard(options, row_repeat_var,
+                                      panel_repeat_var, dataSource,
+                                      measurment_name, query, unit,
+                                      [cellsPerBlock_var])
 
 
 def dashboard_uniformGridGPU():
-    group_by = ["blocks_0",
-                "blocks_1",
-                "blocks_2",
-                "cellsPerBlock_0",
-                "cellsPerBlock_1",
-                "cellsPerBlock_2",
-                "gpuBlockSize_0",
-                "gpuBlockSize_1",
-                "gpuBlockSize_2",
-                "collisionSetup",
-                "stencil",
-                "streamingPattern",
-                ]
+    group_by = [
+        "blocks_0",
+        "blocks_1",
+        "blocks_2",
+        "cellsPerBlock_0",
+        "cellsPerBlock_1",
+        "cellsPerBlock_2",
+        "gpuBlockSize_0",
+        "gpuBlockSize_1",
+        "gpuBlockSize_2",
+        "collisionSetup",
+        "stencil",
+        "streamingPattern",
+    ]
 
     return _uniform_grid("GPU", group_by)
 
 
 def dashboard_uniformGridCPU():
-    group_by = ["blocks_0",
-                "blocks_1",
-                "blocks_2",
-                "cellsPerBlock_0",
-                "cellsPerBlock_1",
-                "cellsPerBlock_2",
-                "periodic_0",
-                "periodic_1",
-                "periodic_2",
-                "collisionSetup",
-                "mpi_num_processes",
-                "streamingPattern",
-                "timeStepStrategy",
-                "stencil",
-                ]
+    group_by = [
+        "blocks_0",
+        "blocks_1",
+        "blocks_2",
+        "cellsPerBlock_0",
+        "cellsPerBlock_1",
+        "cellsPerBlock_2",
+        "periodic_0",
+        "periodic_1",
+        "periodic_2",
+        "collisionSetup",
+        "mpi_num_processes",
+        "streamingPattern",
+        "timeStepStrategy",
+        "stencil",
+    ]
 
     return _uniform_grid("CPU", group_by)
 
@@ -100,37 +90,27 @@ def dashboard_granular_gas():
     measurment_name = 'MESA_PD_KernelBenchmark'
     row_repeat = "kernel"
     panel_repeat = "host"
-    unit = 'ms'
-
-    row_repeat_var = get_dashboard_variable_query(row_repeat,
-                                                  f"SHOW FIELD KEYS FROM {measurment_name}",
-                                                  dataSource)
-    panel_repeat_var = get_dashboard_variable_query(panel_repeat,
-                                                    show_tag_values(measurment_name, panel_repeat),
-                                                    dataSource)
-    query = Query(
-        select_='$kernel',
-        from_=measurment_name,
-        where_=f'"{panel_repeat}" =~ /^${panel_repeat}$/',
-        group_by=['mpi_num_processes', 'omp_max_threads'])
+    unit = Units.milliseconds
+
+    row_repeat_var = get_dashboard_variable_query(
+        row_repeat, f"SHOW FIELD KEYS FROM {measurment_name}", dataSource)
+    panel_repeat_var = get_dashboard_variable_query(
+        panel_repeat, show_tag_values(measurment_name, panel_repeat),
+        dataSource)
+    query = Query(select_='$kernel',
+                  from_=measurment_name,
+                  where_=f'"{panel_repeat}" =~ /^${panel_repeat}$/',
+                  group_by=['mpi_num_processes', 'omp_max_threads'])
     options = DashboardOptions(
         title='Granular Gas Kernel Benchmark',
-        description="Benchmark dashboard for the Granular Gas Benchmark from walberla",
-        tags=[
-            'CPU',
-            'benchmark',
-            'walberla',
-            'Granular Gas'
-        ],
+        description=
+        "Benchmark dashboard for the Granular Gas Benchmark from walberla",
+        tags=['CPU', 'benchmark', 'walberla', 'Granular Gas'],
         timezone="browser",
     )
-    return build_row_repeat_dashboard(options,
-                                      row_repeat_var,
-                                      panel_repeat_var,
-                                      dataSource,
-                                      measurment_name,
-                                      query,
-                                      unit)
+    return build_row_repeat_dashboard(options, row_repeat_var,
+                                      panel_repeat_var, dataSource,
+                                      measurment_name, query, unit)
 
 
 def dashboard_phasefieldallenchan():
@@ -138,48 +118,32 @@ def dashboard_phasefieldallenchan():
     measurment_name = 'PhaseFieldAllenCahn'
     row_repeat = "cellsPerBlock_0"
     panel_repeat = "host"
-    unit = 'MLUPs per Process'
+    unit = Units.mlups
 
     options = DashboardOptions(
         title='Phase Field Allen Chan',
-        description="Benchmark dashboard for the Phasefield Allen Cahn Benchmark from walberla",
-        tags=[
-            'CPU',
-            'benchmark',
-            'walberla',
-            'PhaseField Allen Cahn'
-        ],
+        description=
+        "Benchmark dashboard for the Phasefield Allen Cahn Benchmark from walberla",
+        tags=['CPU', 'benchmark', 'walberla', 'PhaseField Allen Cahn'],
         timezone="browser",
     )
-    row_repeat_var = get_dashboard_variable_query(row_repeat,
-                                                  show_tag_values(measurment_name, row_repeat),
-                                                  dataSource)
-    panel_repeat_var = get_dashboard_variable_query(panel_repeat,
-                                                    show_tag_values(measurment_name, panel_repeat),
-                                                    dataSource)
-    query = Query(
-        select_='mlupsPerProcess',
-        from_=measurment_name,
-        where_=join_variable_and([row_repeat, panel_repeat]),
-        group_by=[
-            "blocks_0",
-            "blocks_1",
-            "blocks_2",
-            "cellsPerBlock_0",
-            "mpi_num_processes",
-            "host",
-            "executable",
-            "timeStepStrategy",
-            "stencil_phase",
-            "stencil_hydro"
-        ]
-    )
-
-    power_query = Query(
-        select_="Power Core [W]",
-        from_="PhaseFieldAllenCahn_ENERGY",
-        where_=get_variable_condition(panel_repeat)
-    )
+    row_repeat_var = get_dashboard_variable_query(
+        row_repeat, show_tag_values(measurment_name, row_repeat), dataSource)
+    panel_repeat_var = get_dashboard_variable_query(
+        panel_repeat, show_tag_values(measurment_name, panel_repeat),
+        dataSource)
+    query = Query(select_='mlupsPerProcess',
+                  from_=measurment_name,
+                  where_=join_variable_and([row_repeat, panel_repeat]),
+                  group_by=[
+                      "blocks_0", "blocks_1", "blocks_2", "cellsPerBlock_0",
+                      "mpi_num_processes", "host", "executable",
+                      "timeStepStrategy", "stencil_phase", "stencil_hydro"
+                  ])
+
+    power_query = Query(select_="Power Core [W]",
+                        from_="PhaseFieldAllenCahn_ENERGY",
+                        where_=get_variable_condition(panel_repeat))
 
     panel_power = get_stat_panel("Total Power Consumption on $host in Watt[W]",
                                  dataSource,
@@ -187,14 +151,12 @@ def dashboard_phasefieldallenchan():
                                  repeat=panel_repeat_var,
                                  format='W')
 
-    dashboard = build_row_repeat_dashboard(options,
-                                           row_repeat_var,
-                                           panel_repeat_var,
-                                           dataSource,
-                                           measurment_name,
-                                           query,
-                                           unit)
-    dashboard.rows = [pack_in_row("Power Consumption", panel_power), *dashboard.rows]
+    dashboard = build_row_repeat_dashboard(options, row_repeat_var,
+                                           panel_repeat_var, dataSource,
+                                           measurment_name, query, unit)
+    dashboard.rows = [
+        pack_in_row("Power Consumption", panel_power), *dashboard.rows
+    ]
     return dashboard.auto_panel_ids()
 
 
@@ -203,53 +165,33 @@ def dashboard_phasefieldallenchangpu():
     measurment_name = 'PhaseFieldAllenCahnGPU'
     row_repeat = "cellsPerBlock_0"
     panel_repeat = "host"
-    unit = 'MLUPs per Process'
+    unit = Units.mlups
 
     options = DashboardOptions(
         title='Phase Field Allen Chan GPU',
-        description="Benchmark dashboard for the Phasefield Allen Cahn Benchmark from walberla",
-        tags=[
-            'GPU',
-            'benchmark',
-            'walberla',
-            'PhaseField Allen Cahn'
-        ],
+        description=
+        "Benchmark dashboard for the Phasefield Allen Cahn Benchmark from walberla",
+        tags=['GPU', 'benchmark', 'walberla', 'PhaseField Allen Cahn'],
         timezone="browser",
     )
-    row_repeat_var = get_dashboard_variable_query(row_repeat,
-                                                  show_tag_values(measurment_name, row_repeat),
-                                                  dataSource)
-    panel_repeat_var = get_dashboard_variable_query(panel_repeat,
-                                                    show_tag_values(measurment_name, panel_repeat),
-                                                    dataSource)
-    query = Query(
-        select_='mlupsPerProcess',
-        from_=measurment_name,
-        where_=join_variable_and([row_repeat, panel_repeat]),
-        group_by=[
-            "blocks_0",
-            "blocks_1",
-            "blocks_2",
-            "gpuBlockSize_0",
-            "gpuBlockSize_1",
-            "gpuBlockSize_2",
-            "cellsPerBlock_0",
-            "mpi_num_processes",
-            "host",
-            "executable",
-            "timeStepStrategy",
-            "stencil_phase",
-            "stencil_hydro"
-        ]
-    )
-
-    return build_row_repeat_dashboard(options,
-                                      row_repeat_var,
-                                      panel_repeat_var,
-                                      dataSource,
-                                      measurment_name,
-                                      query,
-                                      unit)
+    row_repeat_var = get_dashboard_variable_query(
+        row_repeat, show_tag_values(measurment_name, row_repeat), dataSource)
+    panel_repeat_var = get_dashboard_variable_query(
+        panel_repeat, show_tag_values(measurment_name, panel_repeat),
+        dataSource)
+    query = Query(select_='mlupsPerProcess',
+                  from_=measurment_name,
+                  where_=join_variable_and([row_repeat, panel_repeat]),
+                  group_by=[
+                      "blocks_0", "blocks_1", "blocks_2", "gpuBlockSize_0",
+                      "gpuBlockSize_1", "gpuBlockSize_2", "cellsPerBlock_0",
+                      "mpi_num_processes", "host", "executable",
+                      "timeStepStrategy", "stencil_phase", "stencil_hydro"
+                  ])
+
+    return build_row_repeat_dashboard(options, row_repeat_var,
+                                      panel_repeat_var, dataSource,
+                                      measurment_name, query, unit)
 
 
 def dashboard_general_infos():
@@ -264,12 +206,10 @@ def dashboard_general_infos():
         return Query(
             select_="duration",
             from_=measurment_name,
-            where_=join_conditions([f'"name" =~ /{name_base}/', f'"name" =~ /${host_var.name}/'],
-                                   "AND"),
-            group_by=[
-                'name'
-            ]
-        )
+            where_=join_conditions(
+                [f'"name" =~ /{name_base}/', f'"name" =~ /${host_var.name}/'],
+                "AND"),
+            group_by=['name'])
 
     options = DashboardOptions(
         title='Overview',
@@ -285,13 +225,13 @@ def dashboard_general_infos():
                                  get_query("build"),
                                  gridPos=get_grid_pos(12, 24, 0, 0),
                                  format='s',
-                                 alias="$tag_name"
-                                 )
+                                 alias="$tag_name")
     panel_benchmark = get_stat_panel("Benchmark Runtime",
                                      dataSource,
                                      get_query("benchmark"),
                                      gridPos=get_grid_pos(30, 24, 0, 13),
                                      format='s',
-                                     alias="$tag_name"
-                                     )
-    return build_dashboard(options, panels=[panel_build, panel_benchmark], templating=[host_var])
+                                     alias="$tag_name")
+    return build_dashboard(options,
+                           panels=[panel_build, panel_benchmark],
+                           templating=[host_var])
diff --git a/dashboards/units.py b/dashboards/units.py
new file mode 100644
index 0000000..ac2aae5
--- /dev/null
+++ b/dashboards/units.py
@@ -0,0 +1,7 @@
+from enum import Enum
+
+
+class Units(str, Enum):
+    mlups = 'MLUPS per process'
+    seconds = 's'
+    milliseconds = 'ms'
diff --git a/tests/test_dashboard_creation.py b/tests/test_dashboard_creation.py
index 7ac0b2f..6ca1d8c 100644
--- a/tests/test_dashboard_creation.py
+++ b/tests/test_dashboard_creation.py
@@ -62,7 +62,7 @@ dashboard = Dashboard(
                         get_influx_target(str(q1))
                     ],
                     repeat=Repeat('h', host_var.name),
-                    unit='MLUPs per Process',
+                    unit='MLUPS per process',
                 ),
             ],
             repeat=Repeat('v', collisionsetup_var.name),
diff --git a/tests/test_units.py b/tests/test_units.py
new file mode 100644
index 0000000..c3ff1e0
--- /dev/null
+++ b/tests/test_units.py
@@ -0,0 +1,5 @@
+from dashboards.units import Units
+
+
+def test_units():
+    assert Units.mlups == 'MLUPS per process'
-- 
GitLab