render missing entries

This commit is contained in:
4cuck committed 2023-07-28 03:14:59 +02:00
1 parent 29489b5618
commit 660da56c3f
5 files changed
+73 -44

No files matched your search

-1
View File
@@ -19,7 +19,6 @@ pub async fn instances(
context.insert("instances", &guard.hosts);
let time = guard.last_update.format("%Y.%m.%d %H:%M").to_string();
context.insert("last_updated", &time);
let res = Html(template.render("instances.html.j2", &context)?).into_response();
drop(guard);
res
+39 -17
View File
@@ -26,34 +26,56 @@
</tr>
</thead>
<tbody>
{% for host in instances %}
{% for host in instances -%}
<tr>
<td><a href="{{host.url}}">{{host.domain}}</a></td>
<td>{% if host.healthy%} ✅ {% else %} ❌ {% endif %}</td>
<td>{% if host.healthy -%} ✅ {% else -%} ❌ {% endif -%}</td>
<td>
{% if host.recent_pings|length > 0 %}
{% set height = 57 %}
{% set width = 182 %}
{% set amount = host.recent_pings|length %}
{% set width_bar = width / amount %}
{% set offset = 5 %}
{% set step_size = (host.ping_max - host.ping_min)/(height-offset) %}
{% if host.recent_pings|length > 0 -%}
{% set height = 57 -%}
{% set width = 182 -%}
{% set amount = host.recent_pings|length -%}
{% set width_bar = width / amount -%}
{% set offset = 5 -%}
{% set error_size = height / 3 %}
{% if host.ping_max and host.ping_min -%}
{# only one entry, so max = min => step_size would be 0 #}
{% if host.ping_max == host.ping_min -%}
{% set step_size = 5/(height-offset) -%}
{% else -%}
{% set step_size = (host.ping_max - host.ping_min)/(height-offset) -%}
{% endif -%}
{% else %}
{# no valid entries, only nulls #}
{% set step_size = 5/(height-offset) -%}
{% endif %}
{# <!-- step size {{step_size}} -->
<!-- ping_max {{host.ping_max}} -->
<!-- ping_min {{host.ping_min}} --> #}
<svg viewBox="0 0 182 56" width="{{width - 1}}" height="{{height - 1}}">
{% set avg_pos = (height-(host.ping_avg - host.ping_min )/step_size) - offset %}
<line x1="1" x2="181" y1="{{avg_pos}}" y2="{{avg_pos}}" stroke="black" stroke-width="0.72727275" stroke-linecap="butt" stroke-opacity="0.3"><title>Average</title></line>
{% for ping in host.recent_pings %}
{% set height_bar = (ping - host.ping_min )/step_size + offset%}
<rect x="{{(loop.index-1) * width_bar}}" y="{{height - height_bar - offset}}" width="{{width_bar}}" height="{{height_bar}}" fill="#a09df2" fill-opacity="0.95"><title>{{ping}}</title></rect>
{% endfor %}
{% if host.ping_avg and host.ping_min -%}
{% set avg_pos = (height-(host.ping_avg - host.ping_min )/step_size) - offset -%}
<line x1="1" x2="181" y1="{{avg_pos}}" y2="{{avg_pos}}" stroke="black" stroke-width="0.72727275" stroke-linecap="butt" stroke-opacity="0.3"><title>Average</title></line>
{% endif -%}
{% for ping in host.recent_pings -%}
{% if ping -%}
{% set height_bar = (ping - host.ping_min )/step_size + offset -%}
{% set color_bar = "#a09df2" -%}
{% else %}
{% set height_bar = error_size -%}
{% set color_bar = "#cc0000" -%}
{% endif %}
<rect x="{{(loop.index-1) * width_bar}}" y="{{height - height_bar - offset}}" width="{{width_bar}}" height="{{height_bar}}" fill="{{color_bar}}" fill-opacity="0.95"><title>{{ping | default(value="unhealthy") }}</title></rect>
{% endfor -%}
</svg>
{% endif %}
</td>
<td>{{host.ping_avg}}</td>
<td>{% if host.rss%} ✅ {% else %} ❌ {% endif %}</td>
<td>{% if host.rss -%} ✅ {% else %} ❌ {% endif %}</td>
<td>{{host.version}}</td>
<td>{{host.points}}</td>
</tr>
{% endfor %}
{% endfor -%}
</tbody>
</table>
</div>