我的夜间审计脚本(Rscript,base R)会标出峰值温度超过上限的冰柜。昨晚 U-03 的记录仪被拔掉了,所以导出文件里它的 temp_c 全是字符串 ERR。报告里 U-03 仍然显示 ok。没有人收到告警。打印出来的表里,这台设备的 n_valid 是 0,peak_c 是 -Inf,mean_c 是 NaN。其他设备看起来都对。
我以为是读取这一步出了问题。我把 "ERR" 加进了 na.strings,确认了 temp_c 读进来是数值型,还用 --verbose 跑了一遍。行数是对的。没有任何变化。
相关部分如下。
readings <- read.csv(infile, stringsAsFactors = FALSE,
na.strings = c("", "NA", "ERR"))
peak_c = max(df$temp_c, na.rm = TRUE),
mean_c = round(mean(df$temp_c, na.rm = TRUE), 1)
...
res$status <- ifelse(res$peak_c > LIMIT_C, "ALARM", "ok")
LIMIT_C 是 -65。R 在运行快结束时还会打印一条警告。我的终端本来每次启动就会报 LC_CTYPE 的问题,所以我已经不看警告了。有一次,我的一个任务就带着这样的警告跑了一个月。
是读取这一步的问题,还是它后面的某一步?
从英语翻译·查看原文My nightly audit script (Rscript, base R) flags freezers whose peak temp is above a limit. Last night U-03's logger was unplugged, so every temp_c for it in the export is the string ERR. The report still says U-03 is ok. Nobody got paged. The printed table shows n_valid 0, peak_c -Inf and mean_c NaN for that unit. The other units look right.
I assumed the reading step was broken. I added "ERR" to na.strings, checked that temp_c comes in numeric, and ran with --verbose. The row count is correct. Nothing changed.
The relevant part:
readings <- read.csv(infile, stringsAsFactors = FALSE,
na.strings = c("", "NA", "ERR"))
peak_c = max(df$temp_c, na.rm = TRUE),
mean_c = round(mean(df$temp_c, na.rm = TRUE), 1)
...
res$status <- ifelse(res$peak_c > LIMIT_C, "ALARM", "ok")
LIMIT_C is -65. R also prints a warning near the end of the run. My terminal already complains about LC_CTYPE on every start, so I stopped reading warnings. Once, a job of mine ran for a month on a warning like that.
Is this the reading step or something after it?