Skip to content

Commit a22d75f

Browse files
committed
templates: Refine and simplify emoji count overview
1 parent e2640da commit a22d75f

File tree

5 files changed

+66
-85
lines changed

5 files changed

+66
-85
lines changed

kcidb/templates/build.j2

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
{# Build template macros #}
2+
{% import "test.j2" as test_macros %}
23

34
{% macro summary(build) %}
45
{{- [build.architecture, build.config_name,
56
none if build.comment is none else ('"' + build.comment + '"')] |
67
reject("none") | join(" ") | default(build.id, true) -}}
78
{% endmacro %}
89

9-
{% macro container_emoji_counts(output_dictionary, container) %}
10-
{% set invalid = container.builds | selectattr("valid", "false") | list | length %}
11-
{% set valid = container.builds | selectattr("valid", "true") | list | length %}
12-
{% set unknown = container.builds | selectattr("valid", "none") | list | length %}
13-
{% if invalid %}
14-
{% set _ = output_dictionary.__setitem__("❌", invalid | string) %}
15-
{% endif %}
16-
{% if valid %}
17-
{% set _ = output_dictionary.__setitem__("✅", valid | string) %}
18-
{% endif %}
19-
{% if unknown %}
20-
{% set _ = output_dictionary.__setitem__("❓", unknown | string) %}
21-
{% endif %}
10+
{% macro container_emoji_counts(emoji_counts, container) %}
11+
{% for emoji in test_macros.WAIVED_STATUS_EMOJIS.values() %}
12+
{% set _ = emoji_counts.__setitem__(
13+
emoji,
14+
container.builds |
15+
selectattr(
16+
"valid",
17+
"==",
18+
{"❌": false, "✅": true, "❓": none}.get(emoji, {})
19+
) | list | length
20+
) %}
21+
{% endfor %}
2222
{% endmacro %}
2323

2424
{% macro container_summary(container, max_list_len) %}

kcidb/templates/checkout_description.txt.j2

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ OVERVIEW
2222

2323
Checkout: {{ misc_macros.valid_badge(checkout.valid) }}
2424
{% if checkout.builds %}
25-
Builds: {{ overview_macros.emoji_overview(build_emoji_counts,
26-
test_emoji_counts) }}
25+
Builds: {{ overview_macros.emoji_counts(build_emoji_counts,
26+
test_emoji_counts) }}
2727
{% endif %}
2828
{% if checkout.tests %}
29-
Tests: {{ overview_macros.emoji_overview(test_emoji_counts,
30-
build_emoji_counts) }}
29+
Tests: {{ overview_macros.emoji_counts(test_emoji_counts,
30+
build_emoji_counts) }}
3131
{% endif %}
3232

3333
CHECKOUT

kcidb/templates/overview.j2

Lines changed: 39 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,45 @@
11
{# Overview template macros #}
2-
3-
{% macro partial_emoji_overview(ns) %}
4-
5-
# get the overview string for "❌", "✅", "❓".
6-
{%- for emoji in ["❌", "✅", "❓"] -%}
7-
{%- if emoji in varargs[0] %}
8-
{%- if emoji in varargs[1] %}
9-
# if "emoji" exists in each of the emoji count dictionaries,
10-
# generate a formatting string from the length of the longest
11-
# count between them.
12-
13-
{% set _ = ns.elements.extend([emoji, varargs[0][emoji]]) -%}
14-
{% if varargs[0][emoji] | length > varargs[1][emoji] | length %}
15-
{% set index = 0 %}
16-
{% else %}
17-
{% set index = 1 %}
18-
{% endif %}
19-
{% set ns.format_string = ns.format_string + "%s " + "%" +
20-
varargs[index][emoji] | length | string + "s " %}
21-
{% else %}
22-
# if "emoji" exists in the first but not latter of the
23-
# emoji count dictionaries, generate formatting string
24-
# from the length of first count.
25-
26-
{% set _ = ns.elements.extend([emoji, varargs[0][emoji]]) -%}
27-
{% set ns.format_string = ns.format_string + "%s " + "%" +
28-
varargs[0][emoji] | length | string + "s " %}
29-
{% endif %}
30-
31-
{% else %}
32-
{%- if emoji in varargs[1] %}
33-
# if "emoji" exist in the latter but not first of the
34-
# emoji count dictionaries, insert "➖" instead.
35-
36-
{% set _ = ns.elements.extend(["➖", ""]) %}
37-
{% set ns.format_string = ns.format_string + "%s " + "%" +
38-
varargs[1][emoji] | length | string + "s " %}
39-
{% endif %}
40-
41-
{% endif -%}
2+
{% import "test.j2" as test_macros %}
3+
4+
{%- macro emoji_counts() -%}
5+
{%- set ns = namespace(
6+
max_emojis={},
7+
pieces=[],
8+
first=test_macros.WAIVED_STATUS_EMOJIS | length,
9+
last=-1
10+
) -%}
11+
12+
{# Find maximum emoji counts accross all arguments #}
13+
{%- for emoji in test_macros.WAIVED_STATUS_EMOJIS.values() -%}
14+
{%- set _ = ns.max_emojis.__setitem__(
15+
emoji, varargs | map(attribute=emoji) | max
16+
) -%}
4217
{%- endfor -%}
43-
{% endmacro %}
44-
45-
{% macro emoji_overview() -%}
46-
{% set ns = namespace(elements=[], format_string='') %}
47-
{%- set _ = partial_emoji_overview(ns, varargs[0], varargs[1]) -%}
4818

49-
{# generate formatting string for other emoji(s) in TESTS. #}
50-
{% for emoji in varargs[0] -%}
51-
{% if emoji not in ["❌", "✅", '❓'] %}
52-
{% set _ = ns.elements.extend([emoji, varargs[0][emoji]]) %}
53-
{% set ns.format_string = ns.format_string + "%" +
54-
emoji | length | string + "s %" +
55-
varargs[0][emoji] | length | string + "s " %}
56-
{% endif %}
19+
{# Build a list of "<emoji> <count>" pieces for all emojis #}
20+
{%- for emoji, count in varargs[0].items() -%}
21+
{%- if ns.max_emojis[emoji] > 0 -%}
22+
{# Remember the first non-zero emoji across all arguments #}
23+
{%- set ns.first = [ ns.first, loop.index0 ] | min -%}
24+
{# Add an "<emoji> <count>" piece #}
25+
{%- set _ = ns.pieces.extend([
26+
(
27+
"%s %" +
28+
(ns.max_emojis[emoji] | string | length | string) +
29+
"s"
30+
) |
31+
format(
32+
"➖" if count == 0 else emoji,
33+
"" if count == 0 else (count | string)
34+
)
35+
]) -%}
36+
{# Remember the last non-zero emoji in this argument #}
37+
{%- if count > 0 -%}
38+
{%- set ns.last = loop.index0 -%}
39+
{%- endif -%}
40+
{%- endif -%}
5741
{%- endfor -%}
5842

59-
{{- ns.format_string | format(*ns.elements) -}}
43+
{# Output the pieces of interest #}
44+
{{- ns.pieces[ns.first:ns.last + 1] | join(" ") -}}
6045
{%- endmacro -%}

kcidb/templates/revision_description.txt.j2

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ OVERVIEW
2424
Patches: {{ misc_macros.valid_badge(revision.checkouts_valid) }}
2525
{% endif %}
2626
{% if revision.builds %}
27-
Builds: {{ overview_macros.emoji_overview(build_emoji_counts,
28-
test_emoji_counts) }}
27+
Builds: {{ overview_macros.emoji_counts(build_emoji_counts,
28+
test_emoji_counts) }}
2929
{% endif %}
3030
{% if revision.tests %}
31-
Tests: {{ overview_macros.emoji_overview(test_emoji_counts,
32-
build_emoji_counts) }}
31+
Tests: {{ overview_macros.emoji_counts(test_emoji_counts,
32+
build_emoji_counts) }}
3333
{% endif %}
3434

3535
REVISION

kcidb/templates/test.j2

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,12 @@
5757
reject("none") | join(" ") | default(test.id, true) -}}
5858
{% endmacro %}
5959

60-
{% macro container_emoji_counts(output_dictionary, container) %}
61-
{% for waived, status_nodes in container.tests_root.waived_status_nodes.items() %}
62-
{% for status, nodes in status_nodes.items() %}
63-
{% if nodes %}
64-
{% set _ = output_dictionary.__setitem__(
65-
waived_status_emoji(waived, status),
66-
nodes | length | string
67-
) %}
68-
{% endif %}
69-
{% endfor %}
60+
{% macro container_emoji_counts(emoji_counts, container) %}
61+
{% for (waived, status), emoji in WAIVED_STATUS_EMOJIS.items() %}
62+
{% set _ = emoji_counts.__setitem__(
63+
emoji,
64+
container.tests_root.waived_status_nodes[waived][status] | length
65+
) %}
7066
{% endfor -%}
7167
{% endmacro %}
7268

0 commit comments

Comments
 (0)