Skip to content
Snippets Groups Projects
Commit 0d904890 authored by Christoph Alt's avatar Christoph Alt
Browse files

added a alias building feature

parent 8452b12c
No related branches found
No related tags found
No related merge requests found
Pipeline #47114 passed
...@@ -13,7 +13,7 @@ from dashboards.influx_queries import Query ...@@ -13,7 +13,7 @@ from dashboards.influx_queries import Query
def get_influx_target(target_query: str, **kwargs) -> InfluxDBTarget: def get_influx_target(target_query: str, **kwargs) -> InfluxDBTarget:
return InfluxDBTarget( return InfluxDBTarget(
query=target_query, query=target_query,
**kwargs, **{k: v for k, v in kwargs.items() if v is not None},
) )
...@@ -69,8 +69,19 @@ def build_row_repeat_dashboard( ...@@ -69,8 +69,19 @@ def build_row_repeat_dashboard(
axisLabel: str, axisLabel: str,
other_vars: List[Template] = [], other_vars: List[Template] = [],
annotations: Annotations = Annotations(), annotations: Annotations = Annotations(),
alias: str = None,
) -> Dashboard: ) -> Dashboard:
"""Build a Dashboard that takes one query and repeats that with 2 variables.""" """Build a Dashboard that takes one query and repeats that with 2 variables."""
time_series_kwargs = {
'title': f'{panel_repeat_var.name}: ${panel_repeat_var.name}',
'dataSource': dataSource,
'targets': [get_influx_target(str(panel_query), alias=alias)],
'repeat': Repeat('h', panel_repeat_var.name),
'unit': unit,
'axisLabel': axisLabel,
'pointSize': 9,
}
dashboard = Dashboard( dashboard = Dashboard(
**asdict(options), **asdict(options),
rows=[ rows=[
...@@ -78,13 +89,7 @@ def build_row_repeat_dashboard( ...@@ -78,13 +89,7 @@ def build_row_repeat_dashboard(
title=f'{row_repeat_var.name}: ${row_repeat_var.name}', title=f'{row_repeat_var.name}: ${row_repeat_var.name}',
panels=[ panels=[
TimeSeries( TimeSeries(
title=f'{panel_repeat_var.name}: ${panel_repeat_var.name}', **time_series_kwargs,
dataSource=dataSource,
targets=[get_influx_target(str(panel_query))],
repeat=Repeat('h', panel_repeat_var.name),
unit=unit,
axisLabel=axisLabel,
pointSize=9,
), ),
], ],
repeat=Repeat('v', row_repeat_var.name), repeat=Repeat('v', row_repeat_var.name),
......
...@@ -135,6 +135,18 @@ def dashboard_phasefieldallenchan(): ...@@ -135,6 +135,18 @@ def dashboard_phasefieldallenchan():
panel_repeat = "host" panel_repeat = "host"
unit = Units.number unit = Units.number
axisLabel = AxisLabel.mlups axisLabel = AxisLabel.mlups
alias_tags = ["blocks_0",
"blocks_1",
"blocks_2",
"mpi_num_processes",
"timeStepStrategy"]
# alias_descr = [
# *[f"Blocks in {chr(ord('x') + i)} dimension" for i in range(3)],
# "Number of Processes",
# "Timestep Strategy"
# ]
#
# alias = build_alias(zip(alias_descr, alias_tags))
options = DashboardOptions( options = DashboardOptions(
title='Phase Field Allen Chan', title='Phase Field Allen Chan',
...@@ -151,9 +163,12 @@ def dashboard_phasefieldallenchan(): ...@@ -151,9 +163,12 @@ def dashboard_phasefieldallenchan():
from_=measurment_name, from_=measurment_name,
where_=join_variable_and([row_repeat, panel_repeat]), where_=join_variable_and([row_repeat, panel_repeat]),
group_by=[ group_by=[
"blocks_0", "blocks_1", "blocks_2", "cellsPerBlock_0", *alias_tags,
"mpi_num_processes", "host", "executable", "cellsPerBlock_0",
"timeStepStrategy", "stencil_phase", "stencil_hydro" "host",
"executable",
"stencil_phase",
"stencil_hydro"
]) ])
power_query = Query(select_="Power Core [W]", power_query = Query(select_="Power Core [W]",
...@@ -171,7 +186,8 @@ def dashboard_phasefieldallenchan(): ...@@ -171,7 +186,8 @@ def dashboard_phasefieldallenchan():
dashboard = build_row_repeat_dashboard(options, row_repeat_var, dashboard = build_row_repeat_dashboard(options, row_repeat_var,
panel_repeat_var, dataSource, panel_repeat_var, dataSource,
measurment_name, query, unit, axisLabel, measurment_name, query, unit, axisLabel,
annotations=annotations) annotations=annotations,
)
dashboard.rows = [ dashboard.rows = [
pack_in_row("Power Consumption", panel_power), *dashboard.rows pack_in_row("Power Consumption", panel_power), *dashboard.rows
] ]
......
from enum import Enum from enum import Enum
from typing import Iterable, Tuple
class Units(str, Enum): class Units(str, Enum):
...@@ -10,3 +11,14 @@ class Units(str, Enum): ...@@ -10,3 +11,14 @@ class Units(str, Enum):
class AxisLabel(str, Enum): class AxisLabel(str, Enum):
mlups = 'MLUPS per process' mlups = 'MLUPS per process'
runtime = 'Runtime' runtime = 'Runtime'
def build_alias_entry(descr, var_name) -> str:
return f"{descr}: $tag_{var_name}"
def build_alias(alias_entries: Iterable[Tuple[str, str]]) -> str:
return ", ".join(
build_alias_entry(descr, var_name)
for descr, var_name in alias_entries
)
import pytest
from dashboards.legends import AxisLabel, Units, build_alias, build_alias_entry
def test_units():
assert Units.seconds == 's'
assert Units.milliseconds == 'ms'
def test_labels():
assert AxisLabel.mlups == 'MLUPS per process'
assert AxisLabel.runtime == 'Runtime'
@pytest.fixture
def alias_content_single():
return ("Timestep Strategy", "timeStepStrategy")
def alias_content_multiple(alias_content_single):
yield alias_content_single
yield ("Number of Processes", "num_mpi_processes")
for i in range(3):
dim = chr(ord('x') + i)
yield (f"Blocks in {dim} dimension", f"block_{i}")
def test_entry(*alias_content):
expected = "Timestep Strategy: $tag_timeStepStrategy"
assert build_alias_entry("Timestep Strategy", "timeStepStrategy") == expected
def test_alias_single(alias_content_single):
assert build_alias([alias_content_single]) == build_alias_entry(*alias_content_single)
def test_alias_multiple(alias_content_single):
actual = build_alias(alias_content_multiple(alias_content_single))
for desc, var_name in alias_content_multiple(alias_content_single):
assert build_alias_entry(desc, var_name) in actual
from dashboards.legends import AxisLabel, Units
def test_units():
assert Units.seconds == 's'
assert Units.milliseconds == 'ms'
def test_labels():
assert AxisLabel.mlups == 'MLUPS per process'
assert AxisLabel.runtime == 'Runtime'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment