fix issue with 24h gauge and missing measurements

This commit is contained in:
arne 2024-11-28 01:32:35 +01:00
commit d0a6ee9052
2 changed files with 4 additions and 9 deletions

View file

@ -13,16 +13,11 @@ export default {
// calculate high / low marks for the past 24h
marks: (data) => {
const battery = data["power-history"]
const today = new RegExp(`^${new Date().toISOString().split('T')[0]}`)
const now = new Date().getTime()
const min = now - oneDay
return battery
.filter(val => val.timestamp.match(today) != null)
.filter(val => val.timestamp && new Date(val.timestamp).getTime() >= min)
.reduce((acc, cur) => {
// it's a bit weird to not ".filter()" this, but there is something
// odd about the 11ty data cascade that runs this multiple times
// with different results
const t = new Date(cur).getTime()
const high = acc.high['qcom-battery'].capacity.value
const low = acc.low['qcom-battery'].capacity.value
const v = cur['qcom-battery'].capacity.value

View file

@ -330,7 +330,7 @@
<ul class="battery-history">
{% for day in powerInfo.previousDays %}
<li>
{% for m in day.measurements %}<samp class="battery-percentage" title="{% if m %}{{m}}%{% else %}???{% endif %}">{% batteryGauge m %}</samp>{%- endfor %}
{% for m in day.measurements %}<samp class="battery-percentage" {% if m %}title="{{m}}%"{% else %}title="???" style="opacity: 0"{% endif %}">{% batteryGauge m %}</samp>{%- endfor %}
<time datetime="{{ day.date }}">{{ day.date }}</time>
</li>
{% endfor %}