Initial commit: 宁夏智慧养殖监管平台
This commit is contained in:
48
backend/check-sensor-data.js
Normal file
48
backend/check-sensor-data.js
Normal file
@@ -0,0 +1,48 @@
|
||||
const db = require('./config/database');
|
||||
const SensorData = require('./models/SensorData');
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
// 检查传感器数据总数
|
||||
const count = await SensorData.count();
|
||||
console.log('传感器数据总数:', count);
|
||||
|
||||
// 检查最近的温度数据
|
||||
const temperatureData = await SensorData.findAll({
|
||||
where: { sensor_type: 'temperature' },
|
||||
limit: 10,
|
||||
order: [['recorded_at', 'DESC']]
|
||||
});
|
||||
console.log('\n最近10条温度数据:');
|
||||
temperatureData.forEach(r => {
|
||||
console.log(`${r.sensor_type}: ${r.value}${r.unit} at ${r.recorded_at}`);
|
||||
});
|
||||
|
||||
// 检查最近的湿度数据
|
||||
const humidityData = await SensorData.findAll({
|
||||
where: { sensor_type: 'humidity' },
|
||||
limit: 10,
|
||||
order: [['recorded_at', 'DESC']]
|
||||
});
|
||||
console.log('\n最近10条湿度数据:');
|
||||
humidityData.forEach(r => {
|
||||
console.log(`${r.sensor_type}: ${r.value}${r.unit} at ${r.recorded_at}`);
|
||||
});
|
||||
|
||||
// 检查24小时内的数据
|
||||
const twentyFourHoursAgo = new Date(Date.now() - 24 * 60 * 60 * 1000);
|
||||
const recentCount = await SensorData.count({
|
||||
where: {
|
||||
recorded_at: {
|
||||
[require('sequelize').Op.gte]: twentyFourHoursAgo
|
||||
}
|
||||
}
|
||||
});
|
||||
console.log('\n24小时内的传感器数据总数:', recentCount);
|
||||
|
||||
} catch (error) {
|
||||
console.error('检查数据时出错:', error);
|
||||
} finally {
|
||||
process.exit();
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user