warning system
This commit is contained in:
parent
5e029ff99c
commit
0c5c7bcb5f
10 changed files with 1074 additions and 54 deletions
197
app/api/test-scenarios/route.ts
Normal file
197
app/api/test-scenarios/route.ts
Normal file
|
@ -0,0 +1,197 @@
|
|||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
interface TestSensorData {
|
||||
sensorId: string;
|
||||
value: number;
|
||||
status: string;
|
||||
warningStartTime?: number;
|
||||
}
|
||||
|
||||
// Test scenarios for the bed pressure monitoring system
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json();
|
||||
const { scenario } = body;
|
||||
|
||||
let testData: TestSensorData[] = [];
|
||||
|
||||
switch (scenario) {
|
||||
case 'normal':
|
||||
testData = generateNormalScenario();
|
||||
break;
|
||||
case 'warning':
|
||||
testData = generateWarningScenario();
|
||||
break;
|
||||
case 'alarm':
|
||||
testData = generateAlarmScenario();
|
||||
break;
|
||||
case 'escalation':
|
||||
testData = generateEscalationScenario();
|
||||
break;
|
||||
case 'mixed':
|
||||
testData = generateMixedScenario();
|
||||
break;
|
||||
default:
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
error: 'Invalid scenario. Use: normal, warning, alarm, escalation, or mixed'
|
||||
}, { status: 400 });
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
scenario,
|
||||
message: `Generated ${scenario} test scenario`,
|
||||
testData,
|
||||
timestamp: new Date().toISOString()
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('Test scenario API error:', error);
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
error: 'Failed to generate test scenario'
|
||||
}, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
function generateNormalScenario() {
|
||||
return [
|
||||
{ sensorId: 'head-1', value: 1200, status: 'normal' },
|
||||
{ sensorId: 'head-2', value: 1150, status: 'normal' },
|
||||
{ sensorId: 'shoulder-1', value: 1800, status: 'normal' },
|
||||
{ sensorId: 'shoulder-2', value: 1750, status: 'normal' },
|
||||
{ sensorId: 'back-1', value: 2000, status: 'normal' },
|
||||
{ sensorId: 'back-2', value: 2100, status: 'normal' },
|
||||
{ sensorId: 'back-3', value: 1950, status: 'normal' },
|
||||
{ sensorId: 'hip-1', value: 1900, status: 'normal' },
|
||||
{ sensorId: 'hip-2', value: 2000, status: 'normal' },
|
||||
{ sensorId: 'hip-3', value: 1850, status: 'normal' },
|
||||
{ sensorId: 'thigh-1', value: 1600, status: 'normal' },
|
||||
{ sensorId: 'thigh-2', value: 1550, status: 'normal' },
|
||||
{ sensorId: 'calf-1', value: 1400, status: 'normal' },
|
||||
{ sensorId: 'calf-2', value: 1350, status: 'normal' },
|
||||
{ sensorId: 'feet-1', value: 1200, status: 'normal' },
|
||||
{ sensorId: 'feet-2', value: 1150, status: 'normal' }
|
||||
];
|
||||
}
|
||||
|
||||
function generateWarningScenario() {
|
||||
return [
|
||||
{ sensorId: 'head-1', value: 3100, status: 'warning' }, // Above warning threshold
|
||||
{ sensorId: 'head-2', value: 1150, status: 'normal' },
|
||||
{ sensorId: 'shoulder-1', value: 2900, status: 'warning' }, // Above warning threshold
|
||||
{ sensorId: 'shoulder-2', value: 1750, status: 'normal' },
|
||||
{ sensorId: 'back-1', value: 2600, status: 'warning' }, // Above warning threshold
|
||||
{ sensorId: 'back-2', value: 2100, status: 'normal' },
|
||||
{ sensorId: 'back-3', value: 1950, status: 'normal' },
|
||||
{ sensorId: 'hip-1', value: 1900, status: 'normal' },
|
||||
{ sensorId: 'hip-2', value: 2300, status: 'warning' }, // Above warning threshold
|
||||
{ sensorId: 'hip-3', value: 1850, status: 'normal' },
|
||||
{ sensorId: 'thigh-1', value: 1600, status: 'normal' },
|
||||
{ sensorId: 'thigh-2', value: 1550, status: 'normal' },
|
||||
{ sensorId: 'calf-1', value: 1400, status: 'normal' },
|
||||
{ sensorId: 'calf-2', value: 1350, status: 'normal' },
|
||||
{ sensorId: 'feet-1', value: 1200, status: 'normal' },
|
||||
{ sensorId: 'feet-2', value: 1150, status: 'normal' }
|
||||
];
|
||||
}
|
||||
|
||||
function generateAlarmScenario() {
|
||||
return [
|
||||
{ sensorId: 'head-1', value: 3600, status: 'alarm' }, // Above alarm threshold
|
||||
{ sensorId: 'head-2', value: 3550, status: 'alarm' }, // Above alarm threshold
|
||||
{ sensorId: 'shoulder-1', value: 3300, status: 'alarm' }, // Above alarm threshold
|
||||
{ sensorId: 'shoulder-2', value: 1750, status: 'normal' },
|
||||
{ sensorId: 'back-1', value: 3100, status: 'alarm' }, // Above alarm threshold
|
||||
{ sensorId: 'back-2', value: 2100, status: 'normal' },
|
||||
{ sensorId: 'back-3', value: 1950, status: 'normal' },
|
||||
{ sensorId: 'hip-1', value: 2900, status: 'alarm' }, // Above alarm threshold
|
||||
{ sensorId: 'hip-2', value: 2000, status: 'normal' },
|
||||
{ sensorId: 'hip-3', value: 1850, status: 'normal' },
|
||||
{ sensorId: 'thigh-1', value: 1600, status: 'normal' },
|
||||
{ sensorId: 'thigh-2', value: 1550, status: 'normal' },
|
||||
{ sensorId: 'calf-1', value: 1400, status: 'normal' },
|
||||
{ sensorId: 'calf-2', value: 1350, status: 'normal' },
|
||||
{ sensorId: 'feet-1', value: 1200, status: 'normal' },
|
||||
{ sensorId: 'feet-2', value: 1150, status: 'normal' }
|
||||
];
|
||||
}
|
||||
|
||||
function generateEscalationScenario() {
|
||||
// This scenario would simulate sensors that have been in warning state for a while
|
||||
// and are about to escalate to alarm
|
||||
const now = Date.now();
|
||||
const warningStartTime = now - 25000; // Started warning 25 seconds ago (close to 30s threshold)
|
||||
|
||||
return [
|
||||
{ sensorId: 'head-1', value: 3100, status: 'warning', warningStartTime },
|
||||
{ sensorId: 'head-2', value: 1150, status: 'normal' },
|
||||
{ sensorId: 'shoulder-1', value: 2900, status: 'warning', warningStartTime: now - 40000 }, // Close to 45s threshold
|
||||
{ sensorId: 'shoulder-2', value: 1750, status: 'normal' },
|
||||
{ sensorId: 'back-1', value: 2600, status: 'warning', warningStartTime: now - 55000 }, // Close to 60s threshold
|
||||
{ sensorId: 'back-2', value: 2100, status: 'normal' },
|
||||
{ sensorId: 'back-3', value: 1950, status: 'normal' },
|
||||
{ sensorId: 'hip-1', value: 1900, status: 'normal' },
|
||||
{ sensorId: 'hip-2', value: 2300, status: 'warning', warningStartTime: now - 85000 }, // Close to 90s threshold
|
||||
{ sensorId: 'hip-3', value: 1850, status: 'normal' },
|
||||
{ sensorId: 'thigh-1', value: 2100, status: 'warning', warningStartTime: now - 115000 }, // Close to 120s threshold
|
||||
{ sensorId: 'thigh-2', value: 1550, status: 'normal' },
|
||||
{ sensorId: 'calf-1', value: 1400, status: 'normal' },
|
||||
{ sensorId: 'calf-2', value: 1350, status: 'normal' },
|
||||
{ sensorId: 'feet-1', value: 1200, status: 'normal' },
|
||||
{ sensorId: 'feet-2', value: 1150, status: 'normal' }
|
||||
];
|
||||
}
|
||||
|
||||
function generateMixedScenario() {
|
||||
const now = Date.now();
|
||||
|
||||
return [
|
||||
{ sensorId: 'head-1', value: 3600, status: 'alarm' }, // Immediate alarm
|
||||
{ sensorId: 'head-2', value: 3100, status: 'warning', warningStartTime: now - 10000 }, // Recent warning
|
||||
{ sensorId: 'shoulder-1', value: 2900, status: 'warning', warningStartTime: now - 40000 }, // Long warning
|
||||
{ sensorId: 'shoulder-2', value: 1750, status: 'normal' },
|
||||
{ sensorId: 'back-1', value: 3100, status: 'alarm' }, // Immediate alarm
|
||||
{ sensorId: 'back-2', value: 2600, status: 'warning', warningStartTime: now - 30000 }, // Warning close to escalation
|
||||
{ sensorId: 'back-3', value: 1950, status: 'normal' },
|
||||
{ sensorId: 'hip-1', value: 1900, status: 'normal' },
|
||||
{ sensorId: 'hip-2', value: 2900, status: 'alarm' }, // Immediate alarm
|
||||
{ sensorId: 'hip-3', value: 2300, status: 'warning', warningStartTime: now - 60000 }, // Warning
|
||||
{ sensorId: 'thigh-1', value: 1600, status: 'normal' },
|
||||
{ sensorId: 'thigh-2', value: 2100, status: 'warning', warningStartTime: now - 90000 }, // Warning
|
||||
{ sensorId: 'calf-1', value: 2300, status: 'alarm' }, // Immediate alarm
|
||||
{ sensorId: 'calf-2', value: 1900, status: 'warning', warningStartTime: now - 120000 }, // Warning
|
||||
{ sensorId: 'feet-1', value: 1200, status: 'normal' },
|
||||
{ sensorId: 'feet-2', value: 1900, status: 'alarm' } // Immediate alarm
|
||||
];
|
||||
}
|
||||
|
||||
export async function GET() {
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
availableScenarios: [
|
||||
{
|
||||
name: 'normal',
|
||||
description: 'All sensors operating within normal ranges'
|
||||
},
|
||||
{
|
||||
name: 'warning',
|
||||
description: 'Several sensors in warning state (above warning threshold)'
|
||||
},
|
||||
{
|
||||
name: 'alarm',
|
||||
description: 'Multiple sensors in immediate alarm state (above alarm threshold)'
|
||||
},
|
||||
{
|
||||
name: 'escalation',
|
||||
description: 'Sensors in warning state close to escalating to alarm after delay'
|
||||
},
|
||||
{
|
||||
name: 'mixed',
|
||||
description: 'Mixed scenario with normal, warning, and alarm states'
|
||||
}
|
||||
],
|
||||
usage: 'POST to /api/test-scenarios with body: { "scenario": "scenario_name" }'
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue