refactor: 移除 success 字段,简化为 matched 单层判定模型
This commit is contained in:
@@ -22,7 +22,6 @@ CREATE TABLE IF NOT EXISTS check_results (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
target_id INTEGER NOT NULL,
|
||||
timestamp TEXT NOT NULL,
|
||||
success INTEGER NOT NULL,
|
||||
matched INTEGER NOT NULL,
|
||||
duration_ms REAL,
|
||||
status_detail TEXT,
|
||||
@@ -93,7 +92,7 @@ export class ProbeStore {
|
||||
getTargets(): StoredTarget[] {
|
||||
if (this.closed) return [];
|
||||
return this.db
|
||||
.query("SELECT * FROM targets ORDER BY CASE WHEN grp='default' THEN 0 ELSE 1 END, grp, id")
|
||||
.query("SELECT * FROM targets ORDER BY CASE WHEN grp='default' THEN 0 ELSE 1 END, id")
|
||||
.all() as StoredTarget[];
|
||||
}
|
||||
|
||||
@@ -105,7 +104,6 @@ export class ProbeStore {
|
||||
insertCheckResult(result: {
|
||||
targetId: number;
|
||||
timestamp: string;
|
||||
success: boolean;
|
||||
matched: boolean;
|
||||
durationMs: number | null;
|
||||
statusDetail: string | null;
|
||||
@@ -114,12 +112,11 @@ export class ProbeStore {
|
||||
if (this.closed) return;
|
||||
this.db
|
||||
.prepare(
|
||||
"INSERT INTO check_results (target_id, timestamp, success, matched, duration_ms, status_detail, failure) VALUES (?, ?, ?, ?, ?, ?, ?)",
|
||||
"INSERT INTO check_results (target_id, timestamp, matched, duration_ms, status_detail, failure) VALUES (?, ?, ?, ?, ?, ?)",
|
||||
)
|
||||
.run(
|
||||
result.targetId,
|
||||
result.timestamp,
|
||||
result.success ? 1 : 0,
|
||||
result.matched ? 1 : 0,
|
||||
result.durationMs,
|
||||
result.statusDetail,
|
||||
@@ -191,7 +188,7 @@ export class ProbeStore {
|
||||
.prepare(
|
||||
`SELECT
|
||||
strftime('%Y-%m-%dT%H:00:00', timestamp) as hour,
|
||||
AVG(CASE WHEN success = 1 THEN duration_ms END) as avgDurationMs,
|
||||
AVG(CASE WHEN matched = 1 THEN duration_ms END) as avgDurationMs,
|
||||
CASE WHEN COUNT(*) > 0 THEN (SUM(CASE WHEN matched = 1 THEN 1 ELSE 0 END) * 100.0 / COUNT(*)) ELSE 0 END as availability,
|
||||
COUNT(*) as totalChecks
|
||||
FROM check_results
|
||||
@@ -222,7 +219,7 @@ export class ProbeStore {
|
||||
const latest = this.getLatestCheck(target.id);
|
||||
|
||||
if (latest) {
|
||||
if (latest.success && latest.matched) {
|
||||
if (latest.matched) {
|
||||
up++;
|
||||
} else {
|
||||
down++;
|
||||
@@ -247,15 +244,14 @@ export class ProbeStore {
|
||||
getRecentSamples(
|
||||
targetId: number,
|
||||
limit: number,
|
||||
): Array<{ timestamp: string; duration_ms: number | null; success: number; matched: number }> {
|
||||
): Array<{ timestamp: string; duration_ms: number | null; matched: number }> {
|
||||
return this.db
|
||||
.prepare(
|
||||
"SELECT timestamp, duration_ms, success, matched FROM check_results WHERE target_id = ? ORDER BY timestamp DESC LIMIT ?",
|
||||
"SELECT timestamp, duration_ms, matched FROM check_results WHERE target_id = ? ORDER BY timestamp DESC LIMIT ?",
|
||||
)
|
||||
.all(targetId, limit) as Array<{
|
||||
timestamp: string;
|
||||
duration_ms: number | null;
|
||||
success: number;
|
||||
matched: number;
|
||||
}>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user