2baf29b3ae
Deliver encrypted health zone, observation API, baseline maturity pipeline, page-data bindings, and H5/WeChat channel integration for health P0. Co-authored-by: Cursor <cursoragent@cursor.com>
33 lines
1.4 KiB
JavaScript
33 lines
1.4 KiB
JavaScript
import { buildHealthTimeline, summarizeTimelineForAssess } from './health-timeline.mjs';
|
|
import { computeHealthBaselines } from './health-baseline-engine.mjs';
|
|
import { evaluateHealthEvents } from './health-event-engine.mjs';
|
|
|
|
export function buildHealthAssessSummary(observations = [], { now = Date.now() } = {}) {
|
|
const timeline = buildHealthTimeline(observations);
|
|
const baselines = computeHealthBaselines(observations, { now });
|
|
const events = evaluateHealthEvents(observations, baselines, { now, mode: 'active' });
|
|
const lines = [summarizeTimelineForAssess(timeline)];
|
|
|
|
const stableBaselines = baselines.filter(
|
|
(b) => b.windowDays === 30 && b.maturity === 'stable' && b.mean != null,
|
|
);
|
|
if (stableBaselines.length > 0) {
|
|
lines.push('', '30 天基线(已成熟):');
|
|
for (const base of stableBaselines.slice(0, 6)) {
|
|
lines.push(`- ${base.metricType} (${base.context}): 均值 ${base.mean}`);
|
|
}
|
|
}
|
|
|
|
const openEvents = events.filter((e) => e.severity === 'watch' || e.severity === 'alert');
|
|
if (openEvents.length > 0) {
|
|
lines.push('', '需要留意的信号:');
|
|
for (const event of openEvents.slice(0, 5)) {
|
|
lines.push(`- [${event.severity}] ${event.message}`);
|
|
}
|
|
} else if (stableBaselines.length > 0) {
|
|
lines.push('', '当前未检测到需要立即留意的规则事件。');
|
|
}
|
|
|
|
return lines.join('\n');
|
|
}
|