• Creato un nuovo file CSS per gli stili del chiosco (kiosk) con variabili, stili per le schede (card) e animazioni. • Aggiunto un file HTML per l'interfaccia della mappa utilizzando Mapbox, inclusi gli stili e il JavaScript per le funzionalità della mappa. • Introdotto un file JSON per i riferimenti ai sensori, definendo percorsi ed elementi per i dati di temperatura, vento, onde, posizione, batteria, motore e sistema. Co-authored-by: Copilot <copilot@github.com>
105 lines
3.8 KiB
JavaScript
105 lines
3.8 KiB
JavaScript
const skFlow = require('../../config/skFlow');
|
|
const { startSession } = require('../utility/live');
|
|
|
|
const logsPaths = [
|
|
"navigation.position",
|
|
"navigation.headingTrue",
|
|
"navigation.speedOverGround",
|
|
"propulsion.p1.temperature"
|
|
];
|
|
|
|
// Funzioni per generare il testo aggiornato per ogni tipo di dato
|
|
const textGenerators = {
|
|
logs: () => {
|
|
const data = skFlow.getFrom(logsPaths);
|
|
if (!data || Object.keys(data).length === 0) return 'Nessun log disponibile.';
|
|
let text = '*Telemetria di Bordo*\n\n';
|
|
for (const [path, value] of Object.entries(data)) {
|
|
const displayValue = typeof value === 'object' ? JSON.stringify(value) : value;
|
|
text += `*${path}*: ${displayValue}\n`;
|
|
}
|
|
return text;
|
|
},
|
|
weather: () => {
|
|
const data = skFlow.getWithFilter('meb.forecast');
|
|
if (!data || Object.keys(data).length === 0) return 'Nessun dato meteo disponibile.';
|
|
let text = '*Dati Meteo*\n\n';
|
|
for (const [path, value] of Object.entries(data)) {
|
|
const displayValue = typeof value === 'object' ? JSON.stringify(value) : value;
|
|
text += `*${path}*: ${displayValue}\n`;
|
|
}
|
|
return text;
|
|
},
|
|
marine: () => {
|
|
const data = skFlow.getWithFilter('meb.marine');
|
|
if (!data || Object.keys(data).length === 0) return 'Nessun dato sul mare disponibile.';
|
|
let text = '*Dati Meteo del mare*\n\n';
|
|
for (const [path, value] of Object.entries(data)) {
|
|
const displayValue = typeof value === 'object' ? JSON.stringify(value) : value;
|
|
text += `*${path}*: ${displayValue}\n`;
|
|
}
|
|
return text;
|
|
},
|
|
data: () => {
|
|
let text = '';
|
|
|
|
const logs = skFlow.getFrom(logsPaths);
|
|
text += '*Telemetria di Bordo*\n\n';
|
|
if (logs && Object.keys(logs).length > 0) {
|
|
for (const [path, value] of Object.entries(logs)) {
|
|
const displayValue = typeof value === 'object' ? JSON.stringify(value) : value;
|
|
text += `*${path}*: ${displayValue}\n`;
|
|
}
|
|
} else {
|
|
text += 'Nessun dato disponibile.\n';
|
|
}
|
|
|
|
const weather = skFlow.getWithFilter('meb.forecast');
|
|
text += '\n*Dati Meteo*\n\n';
|
|
if (weather && Object.keys(weather).length > 0) {
|
|
for (const [path, value] of Object.entries(weather)) {
|
|
const displayValue = typeof value === 'object' ? JSON.stringify(value) : value;
|
|
text += `*${path}*: ${displayValue}\n`;
|
|
}
|
|
} else {
|
|
text += 'Nessun dato disponibile.\n';
|
|
}
|
|
|
|
const marine = skFlow.getWithFilter('meb.marine');
|
|
text += '\n*Dati Meteo del mare*\n\n';
|
|
if (marine && Object.keys(marine).length > 0) {
|
|
for (const [path, value] of Object.entries(marine)) {
|
|
const displayValue = typeof value === 'object' ? JSON.stringify(value) : value;
|
|
text += `*${path}*: ${displayValue}\n`;
|
|
}
|
|
} else {
|
|
text += 'Nessun dato disponibile.\n';
|
|
}
|
|
|
|
return text;
|
|
}
|
|
};
|
|
|
|
module.exports = {
|
|
prefix: 'live:',
|
|
handler: async (bot, query) => {
|
|
const chatId = query.message.chat.id;
|
|
const botMessageId = query.message.message_id;
|
|
|
|
// callback_data = live:<dataType>:<userMessageId>
|
|
const parts = query.data.split(':');
|
|
const dataType = parts[1];
|
|
const userMessageId = parts[2];
|
|
|
|
const getTextFn = textGenerators[dataType];
|
|
if (!getTextFn) {
|
|
bot.answerCallbackQuery(query.id, { text: 'Tipo non supportato' });
|
|
return;
|
|
}
|
|
|
|
startSession(bot, chatId, botMessageId, userMessageId, getTextFn);
|
|
bot.answerCallbackQuery(query.id, { text: 'Live avviato' });
|
|
},
|
|
textGenerators
|
|
};
|