From c1a1d418ee58ec2d47b8359502794d13bc2406b8 Mon Sep 17 00:00:00 2001 From: David Schroeder Date: Sun, 17 Dec 2023 10:40:30 -0600 Subject: [PATCH] update --- defaults.inc | 2 +- inc/temp.inc.sh | 84 +++++++++++++++++++++++++++++++++++++++++++++++++ powerwall.sh | 1 + 3 files changed, 86 insertions(+), 1 deletion(-) diff --git a/defaults.inc b/defaults.inc index c2b11a7b..b8620252 100755 --- a/defaults.inc +++ b/defaults.inc @@ -1,5 +1,5 @@ -VERS='2.5.31-12152023' +VERS='2.5.32-12152023' noheader=' update service dailytemp confsync ' diff --git a/inc/temp.inc.sh b/inc/temp.inc.sh index 0875b866..3acc7c4d 100644 --- a/inc/temp.inc.sh +++ b/inc/temp.inc.sh @@ -593,5 +593,89 @@ GET_LACROSSE_INFO(){ echo ${DEVICE_INFO['probe_temp']} } +SERVERROOM_TEMP_DIFFERENCE(){ + start=$(date +%s) + scandefault=288 + while [ $# -gt 0 ]; do + case "${1}" in + -l|-last) LAST=${2};; + -h|-help|--help) + echo -e "Usage: ${idsCL[Yellow]}[powerwall or pw] tempdiff {opt}${idsCL[Default]} {" + width=15 + printf "%-${width}s- %s\n" " -l|-last" "(number of last scan times to average from, defaults to ${scandefault})" + echo -e "}\n" + exit 0;; + esac + shift + done + [ "${LAST}" == "" ] && LAST=${scandefault} + + echo -en "${idsCL[Yellow]}Pulling data and calculating average scan times for the last '${LAST}' scans ... " + + lastscantime=$(tail -n 1 ${PW_TMPFOLDER}/.log.sr.difference) + lastscantime=${lastscantime#*~} + scantimes=$(tail -n ${LAST} ${PW_TMPFOLDER}/.log.sr.difference) + longest_scantime=0 + IFS=$'\n' + read -rd '' -a scantimes <<<"${scantimes}" + unset IFS + scantimes_total=0; scansfound=0 + for scantime in "${scantimes[@]}"; do + [[ "${scantime}" = *"~"* ]] && scantime=${scantime#*~} + [ ${scantime} -gt ${longest_scantime} ] && longest_scantime=${scantime} + scantimes_total=$(bc <<< "scale=2; ${scantimes_total}+${scantime}") + ((scansfound++)) + done + + [ ${scansfound} -eq 0 ] && average=0 || average=$(ROUND_NUMBER $(bc <<< "scale=2; ${scantimes_total}/${scansfound}") 0) + + average_disp=$(SHOW_TIME ${average} s) + c=0; spcT=''; spc1=`expr ${cw} - ${#average}`; until [ $c = ${spc1} ]; do spct="${spct} "; c=`expr $c + 1`; done + + lastscantime_disp=$(SHOW_TIME ${lastscantime} s) + longest_scantime_disp=$(SHOW_TIME ${longest_scantime} s) + + [ -f ${PW_TMPFOLDER}/.log.sr.difference ] && last_scancheck=$(date -d @$(stat -c %Y ${PW_TMPFOLDER}/.log.sr.difference) "+%Y-%m-%d %H:%M:%S") || last_scancheck="" + + echo -en "\r\033[K" + echo -e "${idsCL[LightCyan]}Scan Type Scans Average Scantime${idsCL[Default]}" + DIVIDER . lightCyan 60 + echo -e "${idsCL[Green]}Average for last `IDS_NUMBER_FORMAT ${scansfound}` ${idsCL[LightGreen]}(${average}s)${spct}${idsCL[Green]}${average_disp}${idsCL[Default]}" + DIVIDER . lightCyan 60 + echo + echo -e "${idsCL[LightCyan]}Longest scan from above : ${idsCL[LightGreen]}(${longest_scantime}s) ${idsCL[Green]}${longest_scantime_disp}${idsCL[Default]}" + echo + echo -e "${idsCL[LightCyan]}Last Scan Time : ${idsCL[LightGreen]}(${lastscantime}s) ${idsCL[Green]}${lastscantime_disp}${idsCL[Default]}" + echo -e "${idsCL[LightCyan]}Last Scan Check : ${idsCL[LightGreen]}${last_scancheck}${idsCL[Default]}" + + if [ ${scansfound} -le 500 ]; then + echo -en "\n${idsCL[LightCyan]}List out these '${scansfound}' scan times? (y/N): ${idsCL[Default]}" + read -n1 choice + if [ "${choice^^}" == "Y" ]; then + echo -en "\r\033[K" + lastscansnum=${scansfound} + last_scantimes=$(tail -n ${lastscansnum} ${NM_LOGFOLDER}/status-check.scantimes) + IFS=$'\n' + read -rd '' -a last_scantimes <<<"${last_scantimes}" + unset IFS + echo -e "${idsCL[LightCyan]}Last ${lastscansnum} Scan Times\n${idsCL[Green]}------------------------------------------${idsCL[Default]}" + for scantime in "${last_scantimes[@]}"; do + if [[ "${scantime}" = *"~"* ]]; then + dt="${scantime%~*}" + scantime=${scantime#*~} + else + dt=" " + fi + echo -e "${idsCL[White]} ${dt} (${scantime}s) ${idsCL[Yellow]}$(SHOW_TIME ${scantime} s)${idsCL[Default]}" + done + fi + fi + end=`date +%s`; runtime=$((end-start)) + echo -e "\nRuntime: ${runtime}\n" +} + + + + diff --git a/powerwall.sh b/powerwall.sh index d115cc09..c1d56319 100755 --- a/powerwall.sh +++ b/powerwall.sh @@ -817,6 +817,7 @@ fi CHECKTEMP -S ${2} ${3} CHECK_SERVICES ;; + tempdiff) SERVERROOM_TEMP_DIFFERENCE ${2} ${3} ${4};; average) AVERAGETEMP ${2} ${3} ${4};; oldhelp) echo -e "${idsCL[White]} Usage: ${idsCL[LightYellow]}[powerwall or pw]${idsCL[LightCyan]} {option}"