Update power.inc.sh

This commit is contained in:
2025-07-19 10:09:36 -05:00
parent eee0f282f0
commit 5c9df194ef

View File

@@ -17,6 +17,7 @@ AVERAGEPOWER(){
logsfound_watt=0;
total_amp=0
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
total_amp=$(bc <<< "scale=2; ${total_amp}+${amp}")
@@ -26,6 +27,8 @@ AVERAGEPOWER(){
total_watt=$(bc <<< "scale=2; ${total_watt}+${watt}")
((logsfound_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}")
@@ -34,7 +37,6 @@ AVERAGEPOWER(){
average_amp=0
average_watt=0
fi
# echo "HERE: ${sensorid}-"
echo "${average_amp}~${average_watt}"
else
logsfound=0;
@@ -530,7 +532,7 @@ CHECKPOWER(){
[ ${REPORT} -eq 0 ] && echo -e "${spc3}${VOLT}'V${idsCL[Default]}"
else
echo -en "${idsCL[Yellow]} Calculating ${avgdays_disp} Average ... "
# AVERAGEPOWER ${PW_POWERSENSOR_ID[${mSENSOR}]} ${avgdays} both
AVERAGEPOWER ${PW_POWERSENSOR_ID[${mSENSOR}]} ${avgdays} both
avg=$(AVERAGEPOWER ${PW_POWERSENSOR_ID[${mSENSOR}]} ${avgdays} both)
AMP_avg=$(echo ${avg} | cut -d'~' -f 1)
WATT_avg=$(echo ${avg} | cut -d'~' -f 2)