Update power.inc.sh

This commit is contained in:
2025-07-19 10:11:58 -05:00
parent 5c9df194ef
commit 7813cf47ab

View File

@@ -19,16 +19,16 @@ AVERAGEPOWER(){
total_watt=0
echo "HERE: ${sensorid}-"
while IFS=$'\t' read date amp watt ;do
if [ "${amp}" != "" ] && [ "${amp}" != "0" ] && [ "${amp}" != "NULL" ] && [[ "${amp}" =~ ^[0-9]+(\.[0-9]+)?$ ]]; then
if [ "${amp}" != "" ] && [ "${amp}" != "0" ] && [ "${amp}" != "0.00" ] && [ "${amp}" != "NULL" ] && [[ "${amp}" =~ ^[0-9]+(\.[0-9]+)?$ ]]; then
total_amp=$(bc <<< "scale=2; ${total_amp}+${amp}")
((logsfound_amp++))
echo "A:${amp}-${total_amp}=${average_amp}"
fi
if [ "${watt}" != "" ] && [ "${watt}" != "0" ] && [ "${watt}" != "NULL" ] && [[ "${watt}" =~ ^[0-9]+(\.[0-9]+)?$ ]]; then
if [ "${watt}" != "" ] && [ "${watt}" != "0" ] && [ "${watt}" != "0.00" ] && [ "${watt}" != "NULL" ] && [[ "${watt}" =~ ^[0-9]+(\.[0-9]+)?$ ]]; then
total_watt=$(bc <<< "scale=2; ${total_watt}+${watt}")
((logsfound_watt++))
echo "W:${watt}-${total_watt}=${average_watt}"
fi
echo "A:${amp}-${total_amp}=${average_amp}"
echo "W:${watt}-${total_watt}=${average_watt}"
done < <(${mysql_conn} -se "USE servermonitor; SELECT date,amp,watt from power_data WHERE sensorid=${sensorid} AND date >= DATE_SUB(NOW(), INTERVAL ${interval}) ORDER BY id DESC;")
if [ "${logsfound_watt}" != "0" ]; then
average_amp=$(bc <<< "scale=2; ${total_amp}/${logsfound_amp}")