refactor: remove rules endpoint and related logic
- Deleted the rules routes and associated logic from the API. - Removed rules-related functionality from params.sensor.js. - Updated dashboard and rulesets HTML to remove references to rulesets. - Removed force update button and related functionality from rulesets page. - Cleaned up styles related to the force update button. - Removed unused WebSocket client example. - Updated realtime server to eliminate rules pushing logic. - Refactored WebSocket handler to streamline data processing.
This commit is contained in:
@@ -13,42 +13,11 @@ const writeApi = client.getWriteApi(org, bucket, 'ms', {
|
||||
batchSize: 50,
|
||||
});
|
||||
|
||||
// Mapping legacy per sensor_data (logs telemetry)
|
||||
const fieldMap = {
|
||||
t: 'temperature',
|
||||
h: 'humidity',
|
||||
spd: 'speed',
|
||||
cog: 'cog',
|
||||
sog: 'sog',
|
||||
hdg: 'headingTrue',
|
||||
lat: 'latitude',
|
||||
lon: 'longitude',
|
||||
};
|
||||
|
||||
/**
|
||||
* Scrive dati telemetria sensore (logs) con mapping campi abbreviati.
|
||||
* Measurement: sensor_data
|
||||
*/
|
||||
function writeSensorData(fields, sensor, session, timestamp) {
|
||||
const point = new Point('sensor_data')
|
||||
.tag('sensor', sensor)
|
||||
.tag('session', session)
|
||||
.timestamp(timestamp);
|
||||
|
||||
for (const [short, long] of Object.entries(fieldMap)) {
|
||||
if (fields[short] !== undefined) {
|
||||
point.floatField(long, fields[short]);
|
||||
}
|
||||
}
|
||||
|
||||
writeApi.writePoint(point);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scrive dati generici (weather, forecast, ecc.) senza mapping.
|
||||
* I campi vengono scritti con il nome originale (ref da Open-Meteo).
|
||||
* @param {string} measurement - nome della measurement InfluxDB (es. 'weather_current', 'weather_forecast')
|
||||
* @param {Object} fields - campi { ref: value }
|
||||
* Scrive dati generici su InfluxDB senza mapping.
|
||||
* I campi vengono scritti con il nome originale.
|
||||
* @param {string} measurement - nome della measurement (es. 'logs', 'weather')
|
||||
* @param {Object} fields - campi { key: value }
|
||||
* @param {string} sensor - nome del sensore
|
||||
* @param {string} session - id sessione
|
||||
* @param {number} timestamp - timestamp unix ms
|
||||
@@ -73,8 +42,7 @@ function writeGenericData(measurement, fields, sensor, session, timestamp) {
|
||||
|
||||
/**
|
||||
* Scrive un batch di punti forecast (previsioni orarie).
|
||||
* Ogni punto ha il proprio timestamp.
|
||||
* @param {Array} points - array di [timestamp_ms, { ref: value, ... }]
|
||||
* @param {Array} points - array di [timestamp_ms, { key: value, ... }]
|
||||
* @param {string} sensor - nome del sensore
|
||||
* @param {string} session - id sessione
|
||||
*/
|
||||
@@ -86,10 +54,10 @@ function writeForecastBatch(points, sensor, session) {
|
||||
|
||||
async function queryHistory(sensor, session, since) {
|
||||
const queryApi = client.getQueryApi(org);
|
||||
const query = `
|
||||
const fluxQuery = `
|
||||
from(bucket: "${bucket}")
|
||||
|> range(start: ${since})
|
||||
|> filter(fn: (r) => r._measurement == "sensor_data")
|
||||
|> filter(fn: (r) => r._measurement == "logs")
|
||||
|> filter(fn: (r) => r.sensor == "${sensor}")
|
||||
|> filter(fn: (r) => r.session == "${session}")
|
||||
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
|
||||
@@ -97,7 +65,7 @@ async function queryHistory(sensor, session, since) {
|
||||
|
||||
const rows = [];
|
||||
return new Promise((resolve, reject) => {
|
||||
queryApi.queryRows(query, {
|
||||
queryApi.queryRows(fluxQuery, {
|
||||
next(row, tableMeta) {
|
||||
rows.push(tableMeta.toObject(row));
|
||||
},
|
||||
@@ -107,4 +75,4 @@ async function queryHistory(sensor, session, since) {
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = { writeSensorData, writeGenericData, writeForecastBatch, queryHistory };
|
||||
module.exports = { writeGenericData, writeForecastBatch, queryHistory };
|
||||
|
||||
Reference in New Issue
Block a user