feat: format la différence
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
bc4e7fbe91
commit
dde8201264
25
index.js
25
index.js
|
@ -58,6 +58,23 @@ async function sendAlert(msg) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatTime(seconds) {
|
||||||
|
if (seconds < 60) {
|
||||||
|
return `${seconds} seconde${seconds > 1 ? 's' : ''}`;
|
||||||
|
} else if (seconds < 3600) {
|
||||||
|
const minutes = Math.floor(seconds / 60);
|
||||||
|
const remainingSeconds = seconds % 60;
|
||||||
|
return remainingSeconds === 0
|
||||||
|
? `environ ${minutes} minute${minutes > 1 ? 's' : ''}`
|
||||||
|
: `${minutes} minute${minutes > 1 ? 's' : ''} et ${remainingSeconds} seconde${remainingSeconds > 1 ? 's' : ''}`;
|
||||||
|
} else {
|
||||||
|
const hours = Math.floor(seconds / 3600);
|
||||||
|
const remainingMinutes = Math.floor((seconds % 3600) / 60);
|
||||||
|
return remainingMinutes === 0
|
||||||
|
? `environ ${hours} heure${hours > 1 ? 's' : ''}`
|
||||||
|
: `environ ${hours} heure${hours > 1 ? 's' : ''} et ${remainingMinutes} minute${remainingMinutes > 1 ? 's' : ''}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const data = await getData();
|
const data = await getData();
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
|
@ -65,10 +82,12 @@ const currentPower = await getCurrentPower(data);
|
||||||
const lastUpdateTime = await getLastUpdateTime(data);
|
const lastUpdateTime = await getLastUpdateTime(data);
|
||||||
console.log(`[${lastUpdateTime}] La salle Greyzollon Duluth produissait ${currentPower} watt${currentPower>0?'s':''} !`)
|
console.log(`[${lastUpdateTime}] La salle Greyzollon Duluth produissait ${currentPower} watt${currentPower>0?'s':''} !`)
|
||||||
const secondDifference = Math.ceil(Math.abs(now.getTime() - new Date(lastUpdateTime).getTime()) / 1000);
|
const secondDifference = Math.ceil(Math.abs(now.getTime() - new Date(lastUpdateTime).getTime()) / 1000);
|
||||||
|
const formatedDifference = formatTime(secondDifference)
|
||||||
|
|
||||||
if (secondDifference > (6 * 60)) {
|
if (secondDifference > (6 * 60)) {
|
||||||
console.log(`❌ L'installation n'a pas répondu depuis '${lastUpdateTime}' ça fait ${secondDifference} secondes !`);
|
const msg = `❌ L'installation n'a pas répondu depuis '${lastUpdateTime}' ça fait ${formatedDifference} (${secondDifference}) !`
|
||||||
await sendAlert(`❌ L'installation n'a pas répondu depuis '${lastUpdateTime}' ça fait ${secondDifference} secondes !`);
|
console.log(msg);
|
||||||
|
await sendAlert(msg);
|
||||||
} else {
|
} else {
|
||||||
console.log(`✅ L'installation répond correctement dernière mise à jour il y a ${secondDifference} secondes.`);
|
console.log(`✅ L'installation répond correctement dernière mise à jour il y a ${formatedDifference} (${secondDifference}).`);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue