Skip to content

tables

measurement.dash_apps.tables ¤

Functions defining columns and style conditions for tables in the measurement app

Functions¤

create_columns_daily() ¤

Creates columns for Daily Report table

Parameters:

Name Type Description Default
value_columns list

List of value columns

required

Returns:

Name Type Description
list list

List of columns

Source code in measurement\dash_apps\tables.py
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
def create_columns_daily() -> list:
    """Creates columns for Daily Report table

    Args:
        value_columns (list): List of value columns

    Returns:
        list: List of columns
    """
    styles = create_style_conditions()

    columns = [
        {
            "valueGetter": {
                "function": "d3.timeParse('%Y-%m-%d')(params.data.date.split('T')[0])"
            },
            "headerName": "Date",
            "filter": "agDateColumnFilter",
            "valueFormatter": {"function": "params.data.date.split('T')[0]"},
            "sort": "asc",
            **styles["date"],
        },
        *[
            {
                "field": c,
                "headerName": c.capitalize(),
                "filter": "agNumberColumnFilter",
                "valueFormatter": {"function": "d3.format(',.2f')(params.value)"},
                **styles[c],
            }
            for c in ["value", "minimum", "maximum"]
        ],
        {
            "field": "daily_count_fraction",
            "headerName": "Daily count fraction",
            "filter": "agNumberColumnFilter",
            "valueFormatter": {"function": "d3.format(',.2f')(params.value)"},
            **styles["daily_count_fraction"],
        },
        {
            "field": "total_suspicious_entries",
            "headerName": "Suspicious entries",
            "filter": "agNumberColumnFilter",
            **styles["total_suspicious_entries"],
        },
    ]
    return columns

create_columns_detail() ¤

Creates columns for Detail table

Parameters:

Name Type Description Default
value_columns list

List of value columns

required

Returns:

Name Type Description
list list

List of columns

Source code in measurement\dash_apps\tables.py
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
def create_columns_detail() -> list:
    """Creates columns for Detail table

    Args:
        value_columns (list): List of value columns

    Returns:
        list: List of columns
    """
    styles = create_style_conditions()

    columns = [
        {
            "field": "id",
            "headerName": "Measurement ID",
            "filter": "agNumberColumnFilter",
        },
        {
            "field": "time",
            "valueFormatter": {"function": "params.value.split('T')[1].split('+')[0]"},
            "headerName": "Time",
            "editable": True,
            "sort": "asc",
            **styles["time"],
        },
        *[
            {
                "field": c,
                "headerName": c.capitalize(),
                "filter": "agNumberColumnFilter",
                "editable": True,
                "valueFormatter": {"function": "d3.format(',.2f')(params.value)"},
                **styles[c],
            }
            for c in ["value", "minimum", "maximum"]
        ],
    ]
    return columns

create_style_condition(condition, style_true, style_false) ¤

Create a cell style condition

Parameters:

Name Type Description Default
condition str

Javascript code to evaluate

required
style_true dict

Style to apply when condition is true

required
style_false dict

Style to apply when condition is false

required

Returns:

Type Description
list[dict]

list[dict]: Style condition

Source code in measurement\dash_apps\tables.py
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
def create_style_condition(
    condition: str, style_true: dict, style_false: dict
) -> list[dict]:
    """Create a cell style condition

    Args:
        condition (str): Javascript code to evaluate
        style_true (dict): Style to apply when condition is true
        style_false (dict): Style to apply when condition is false

    Returns:
        list[dict]: Style condition
    """
    return [
        {
            "condition": condition,
            "style": style_true,
        },
        {
            "condition": f"!({condition})",
            "style": style_false,
        },
    ]

create_style_conditions() ¤

Creates style conditions for Daily Report table

Returns:

Name Type Description
dict dict

Style conditions

Source code in measurement\dash_apps\tables.py
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
def create_style_conditions() -> dict:
    """Creates style conditions for Daily Report table

    Returns:
        dict: Style conditions
    """
    style_error = {"backgroundColor": "#E45756"}
    style_normal = {"backgroundColor": "transparent"}

    styles = {}

    styles["date"] = {
        "cellStyle": {
            "styleConditions": create_style_condition(
                condition="params.data['date_error'] > 0",
                style_true=style_error,
                style_false=style_normal,
            )
        },
    }

    styles["time"] = {
        "cellStyle": {
            "styleConditions": create_style_condition(
                condition="params.data['suspicious_time_lapse']",
                style_true=style_error,
                style_false=style_normal,
            )
        },
    }

    styles["value"] = {
        "cellStyle": {
            "styleConditions": create_style_condition(
                condition="params.data['suspicious_value_limits'] > 0 || params.data['suspicious_value_difference'] > 0",  # noqa: E501
                style_true=style_error,
                style_false=style_normal,
            )
        },
    }

    for field in ["maximum", "minimum"]:
        styles[field] = {
            "cellStyle": {
                "styleConditions": create_style_condition(
                    condition=f"params.data['suspicious_{field}_limits'] > 0",
                    style_true=style_error,
                    style_false=style_normal,
                )
            },
        }

    styles["daily_count_fraction"] = {
        "cellStyle": {
            "styleConditions": create_style_condition(
                condition="params.data['daily_count_fraction'] != 1",
                style_true=style_error,
                style_false=style_normal,
            )
        },
    }

    styles["total_suspicious_entries"] = {
        "cellStyle": {
            "styleConditions": create_style_condition(
                condition="params.data['total_suspicious_entries'] > 0",
                style_true=style_error,
                style_false=style_normal,
            )
        },
    }

    return styles