dynamic graph
This commit is contained in:
parent
a606796d9e
commit
5e029ff99c
17 changed files with 1707 additions and 569 deletions
38
app/api/sensors/history/route.ts
Normal file
38
app/api/sensors/history/route.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { SensorDataStorage } from '@/services/SensorDataStorage';
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const sensorId = searchParams.get('sensorId');
|
||||
const timespan = parseInt(searchParams.get('timespan') || '86400000'); // Default 24 hours in ms
|
||||
|
||||
if (!sensorId) {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
error: 'sensorId parameter is required'
|
||||
}, { status: 400 });
|
||||
}
|
||||
|
||||
const sensorDataStorage = SensorDataStorage.getInstance();
|
||||
const sensorData = await sensorDataStorage.getDataForSensor(sensorId, timespan);
|
||||
|
||||
const timeSeriesData = sensorDataStorage.generateTimeSeriesData(sensorData, timespan);
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
sensorId,
|
||||
timespan,
|
||||
dataPoints: sensorData.length,
|
||||
data: timeSeriesData,
|
||||
timestamp: new Date().toISOString()
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('Sensor history API error:', error);
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
error: 'Failed to get sensor history data'
|
||||
}, { status: 500 });
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue