Add duration for stage (#15857)
* Add duration for stage * formatNumber
This commit is contained in:
parent
c29568d164
commit
a5ea7b33b0
|
@ -13,6 +13,7 @@ import "../../../../../../layouts/hass-subpage";
|
||||||
import { SubscribeMixin } from "../../../../../../mixins/subscribe-mixin";
|
import { SubscribeMixin } from "../../../../../../mixins/subscribe-mixin";
|
||||||
import { haStyle } from "../../../../../../resources/styles";
|
import { haStyle } from "../../../../../../resources/styles";
|
||||||
import { HomeAssistant } from "../../../../../../types";
|
import { HomeAssistant } from "../../../../../../types";
|
||||||
|
import { formatNumber } from "../../../../../../common/number/format_number";
|
||||||
|
|
||||||
const RUN_DATA = {
|
const RUN_DATA = {
|
||||||
pipeline: "Pipeline",
|
pipeline: "Pipeline",
|
||||||
|
@ -30,14 +31,36 @@ const INTENT_DATA = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderProgress = (
|
const renderProgress = (
|
||||||
|
hass: HomeAssistant,
|
||||||
pipelineRun: PipelineRun,
|
pipelineRun: PipelineRun,
|
||||||
stage: PipelineRun["stage"]
|
stage: PipelineRun["stage"]
|
||||||
) =>
|
) => {
|
||||||
pipelineRun.stage !== stage && stage in pipelineRun
|
const startEvent = pipelineRun.events.find(
|
||||||
? html`✅`
|
(ev) => ev.type === `${stage}-start`
|
||||||
: pipelineRun.stage === stage
|
);
|
||||||
? html`<ha-circular-progress size="tiny" active></ha-circular-progress>`
|
const finishEvent = pipelineRun.events.find(
|
||||||
: "";
|
(ev) => ev.type === `${stage}-finish`
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!startEvent) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!finishEvent) {
|
||||||
|
return html`<ha-circular-progress
|
||||||
|
size="tiny"
|
||||||
|
active
|
||||||
|
></ha-circular-progress>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const duration =
|
||||||
|
new Date(finishEvent.timestamp).getTime() -
|
||||||
|
new Date(startEvent.timestamp).getTime();
|
||||||
|
const durationString = formatNumber(duration / 1000, hass.locale, {
|
||||||
|
maximumFractionDigits: 2,
|
||||||
|
});
|
||||||
|
return html`${durationString}s ✅`;
|
||||||
|
};
|
||||||
|
|
||||||
const renderData = (data: Record<string, any>, keys: Record<string, string>) =>
|
const renderData = (data: Record<string, any>, keys: Record<string, string>) =>
|
||||||
Object.entries(keys).map(
|
Object.entries(keys).map(
|
||||||
|
@ -123,7 +146,7 @@ export class AssistPipelineDebug extends SubscribeMixin(LitElement) {
|
||||||
<div class="card-content">
|
<div class="card-content">
|
||||||
<div class="row heading">
|
<div class="row heading">
|
||||||
<span>Natural Language Processing</span>
|
<span>Natural Language Processing</span>
|
||||||
${renderProgress(this._pipelineRun, "intent")}
|
${renderProgress(this.hass, this._pipelineRun, "intent")}
|
||||||
</div>
|
</div>
|
||||||
${this._pipelineRun.intent
|
${this._pipelineRun.intent
|
||||||
? html`
|
? html`
|
||||||
|
@ -191,6 +214,7 @@ export class AssistPipelineDebug extends SubscribeMixin(LitElement) {
|
||||||
}
|
}
|
||||||
.heading {
|
.heading {
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
|
margin-bottom: 16px;
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
|
|
Loading…
Reference in New Issue