Enhancement: use duration for audiobookshelf tottal, refactor uptime (#4229)

pull/4232/head
shamoon 3 weeks ago committed by GitHub
parent 3736c1fcab
commit e6cf86ed4a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -71,7 +71,7 @@ Homepage provides a set of common translations that you can use in your widgets.
| `common.ms` | `1,000 ms` | Format a number in milliseconds. |
| `common.date` | `2024-01-01` | Format a date. |
| `common.relativeDate` | `1 day ago` | Format a relative date. |
| `common.uptime` | `1 day, 1 hour` | Format an uptime. |
| `common.duration` | `1 day, 1 hour` | Format an duration. |
### Text

@ -84,12 +84,12 @@ function prettyBytes(number, options) {
return `${prefix + numberString} ${unit}`;
}
function uptime(uptimeInSeconds, i18next) {
const mo = Math.floor(uptimeInSeconds / (3600 * 24 * 31));
const d = Math.floor((uptimeInSeconds % (3600 * 24 * 31)) / (3600 * 24));
const h = Math.floor((uptimeInSeconds % (3600 * 24)) / 3600);
const m = Math.floor((uptimeInSeconds % 3600) / 60);
const s = Math.floor(uptimeInSeconds % 60);
function duration(durationInSeconds, i18next) {
const mo = Math.floor(durationInSeconds / (3600 * 24 * 31));
const d = Math.floor((durationInSeconds % (3600 * 24 * 31)) / (3600 * 24));
const h = Math.floor((durationInSeconds % (3600 * 24)) / 3600);
const m = Math.floor((durationInSeconds % 3600) / 60);
const s = Math.floor(durationInSeconds % 60);
const moDisplay = mo > 0 ? mo + i18next.t("common.months") : "";
const dDisplay = d > 0 ? d + i18next.t("common.days") : "";
@ -156,7 +156,7 @@ module.exports = {
i18next.services.formatter.add("relativeDate", (value, lng, options) =>
relativeDate(new Date(value), new Intl.RelativeTimeFormat(lng, { ...options })),
);
i18next.services.formatter.add("uptime", (value, lng) => uptime(value, i18next));
i18next.services.formatter.add("duration", (value, lng) => duration(value, i18next));
},
type: "3rdParty",
},

@ -13,7 +13,7 @@
"ms": "{{value, number}}",
"date": "{{value, date}}",
"relativeDate": "{{value, relativeDate}}",
"uptime": "{{value, uptime}}",
"duration": "{{value, duration}}",
"months": "mo",
"days": "d",
"hours": "h",

@ -25,7 +25,7 @@ export default function Uptime({ refresh = 1500 }) {
return (
<Resource
icon={FaRegClock}
value={t("common.uptime", { value: data.uptime })}
value={t("common.duration", { value: data.uptime })}
label={t("resources.uptime")}
percentage={percent}
/>

@ -39,11 +39,8 @@ export default function Component({ service }) {
<Block label="audiobookshelf.podcasts" value={t("common.number", { value: totalPodcasts })} />
<Block
label="audiobookshelf.podcastsDuration"
value={t("common.number", {
value: totalPodcastsDuration / 60,
maximumFractionDigits: 0,
style: "unit",
unit: "minute",
value={t("common.duration", {
value: totalPodcastsDuration,
})}
/>
<Block label="audiobookshelf.books" value={t("common.number", { value: totalBooks })} />

@ -40,7 +40,7 @@ export default function Component({ service }) {
/>
<Block
label="frigate.uptime"
value={t("common.uptime", {
value={t("common.duration", {
value: data.uptime,
})}
/>

@ -44,7 +44,7 @@ export default function Component({ service }) {
return (
<Container service={service}>
<Block label="fritzbox.connectionStatus" value={t(`fritzbox.connectionStatus${fritzboxData.connectionStatus}`)} />
<Block label="fritzbox.uptime" value={t("common.uptime", { value: fritzboxData.uptime })} />
<Block label="fritzbox.uptime" value={t("common.duration", { value: fritzboxData.uptime })} />
<Block label="fritzbox.maxDown" value={t("common.byterate", { value: fritzboxData.maxDown / 8, decimals: 1 })} />
<Block label="fritzbox.maxUp" value={t("common.byterate", { value: fritzboxData.maxUp / 8, decimals: 1 })} />
<Block label="fritzbox.down" value={t("common.byterate", { value: fritzboxData.down, decimals: 1 })} />

@ -20,7 +20,7 @@ export default function Component({ service }) {
return (
<Container service={service}>
<Block label="openwrt.uptime" value={t("common.uptime", { value: uptime })} />
<Block label="openwrt.uptime" value={t("common.duration", { value: uptime })} />
<Block label="openwrt.cpuLoad" value={cpuLoad} />
</Container>
);

@ -46,12 +46,12 @@ export default function Component({ service }) {
<Block label="stash.scenes" value={t("common.number", { value: stats.scene_count })} />
<Block label="stash.scenesPlayed" value={t("common.number", { value: stats.scenes_played })} />
<Block label="stash.playCount" value={t("common.number", { value: stats.total_play_count })} />
<Block label="stash.playDuration" value={t("common.uptime", { value: stats.total_play_duration })} />
<Block label="stash.playDuration" value={t("common.duration", { value: stats.total_play_duration })} />
<Block
label="stash.sceneSize"
value={t("common.bbytes", { value: stats.scenes_size, maximumFractionDigits: 1 })}
/>
<Block label="stash.sceneDuration" value={t("common.uptime", { value: stats.scenes_duration })} />
<Block label="stash.sceneDuration" value={t("common.duration", { value: stats.scenes_duration })} />
<Block label="stash.images" value={t("common.number", { value: stats.image_count })} />
<Block

@ -35,7 +35,7 @@ export default function Component({ service }) {
<>
<Container service={service}>
<Block label="truenas.load" value={t("common.number", { value: statusData.loadavg[0] })} />
<Block label="truenas.uptime" value={t("common.uptime", { value: statusData.uptime_seconds })} />
<Block label="truenas.uptime" value={t("common.duration", { value: statusData.uptime_seconds })} />
<Block label="truenas.alerts" value={t("common.number", { value: alertData.pending })} />
</Container>
{enablePools &&

@ -58,7 +58,7 @@ export default function Component({ service }) {
break;
case 2:
status = t("uptimerobot.up");
uptime = t("common.uptime", { value: monitor.logs[0].duration });
uptime = t("common.duration", { value: monitor.logs[0].duration });
logIndex = 1;
break;
case 8:
@ -73,7 +73,7 @@ export default function Component({ service }) {
}
const lastDown = new Date(monitor.logs[logIndex].datetime * 1000).toLocaleString();
const downDuration = t("common.uptime", { value: monitor.logs[logIndex].duration });
const downDuration = t("common.duration", { value: monitor.logs[logIndex].duration });
const hideDown = logIndex === 1 && monitor.logs[logIndex].type !== 1;
return (

Loading…
Cancel
Save