mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-25 16:38:36 +01:00
Merge pull request #55 from avollkopf/revert-54-master
Revert "Allow changing logfile size and logfile backup count"
This commit is contained in:
commit
3d72071303
2 changed files with 8 additions and 40 deletions
|
@ -31,8 +31,8 @@ class LogController:
|
||||||
self.influxdb = self.cbpi.config.get("INFLUXDB", "No")
|
self.influxdb = self.cbpi.config.get("INFLUXDB", "No")
|
||||||
if self.logfiles == "Yes":
|
if self.logfiles == "Yes":
|
||||||
if name not in self.datalogger:
|
if name not in self.datalogger:
|
||||||
max_bytes = int(self.cbpi.config.get("SENSOR_LOG_MAX_BYTES", 131072))
|
max_bytes = self.cbpi.config.get("SENSOR_LOG_MAX_BYTES", 1048576)
|
||||||
backup_count = int(self.cbpi.config.get("SENSOR_LOG_BACKUP_COUNT", 3))
|
backup_count = self.cbpi.config.get("SENSOR_LOG_BACKUP_COUNT", 3)
|
||||||
|
|
||||||
data_logger = logging.getLogger('cbpi.sensor.%s' % name)
|
data_logger = logging.getLogger('cbpi.sensor.%s' % name)
|
||||||
data_logger.propagate = False
|
data_logger.propagate = False
|
||||||
|
@ -42,7 +42,7 @@ class LogController:
|
||||||
self.datalogger[name] = data_logger
|
self.datalogger[name] = data_logger
|
||||||
|
|
||||||
formatted_time = strftime("%Y-%m-%d %H:%M:%S", localtime())
|
formatted_time = strftime("%Y-%m-%d %H:%M:%S", localtime())
|
||||||
self.datalogger[name].info("%s,%s" % (formatted_time, str(value)))
|
self.datalogger[name].info("%s,%s" % (formatted_time, value))
|
||||||
if self.influxdb == "Yes":
|
if self.influxdb == "Yes":
|
||||||
self.influxdbcloud = self.cbpi.config.get("INFLUXDBCLOUD", "No")
|
self.influxdbcloud = self.cbpi.config.get("INFLUXDBCLOUD", "No")
|
||||||
self.influxdbaddr = self.cbpi.config.get("INFLUXDBADDR", None)
|
self.influxdbaddr = self.cbpi.config.get("INFLUXDBADDR", None)
|
||||||
|
@ -116,6 +116,7 @@ class LogController:
|
||||||
for name in names:
|
for name in names:
|
||||||
# get all log names
|
# get all log names
|
||||||
all_filenames = glob.glob('./logs/sensor_%s.log*' % name)
|
all_filenames = glob.glob('./logs/sensor_%s.log*' % name)
|
||||||
|
|
||||||
# concat all logs
|
# concat all logs
|
||||||
df = pd.concat([pd.read_csv(f, parse_dates=True, date_parser=dateparse, index_col='DateTime', names=['DateTime', name], header=None) for f in all_filenames])
|
df = pd.concat([pd.read_csv(f, parse_dates=True, date_parser=dateparse, index_col='DateTime', names=['DateTime', name], header=None) for f in all_filenames])
|
||||||
logging.info("Read all files for {}".format(names))
|
logging.info("Read all files for {}".format(names))
|
||||||
|
@ -124,14 +125,6 @@ class LogController:
|
||||||
df = df[name].resample(sample_rate).max()
|
df = df[name].resample(sample_rate).max()
|
||||||
logging.info("Sampled now for {}".format(names))
|
logging.info("Sampled now for {}".format(names))
|
||||||
df = df.dropna()
|
df = df.dropna()
|
||||||
# take every nth row so that total number of rows does not exceed max_rows * 2
|
|
||||||
max_rows = 500
|
|
||||||
total_rows = df.shape[0]
|
|
||||||
if (total_rows > 0) and (total_rows > max_rows):
|
|
||||||
nth = int(total_rows/max_rows)
|
|
||||||
if nth > 1:
|
|
||||||
df = df.iloc[::nth]
|
|
||||||
|
|
||||||
if result is None:
|
if result is None:
|
||||||
result = df
|
result = df
|
||||||
else:
|
else:
|
||||||
|
@ -144,9 +137,7 @@ class LogController:
|
||||||
data[name] = result[name].interpolate(limit_direction='both', limit=10).tolist()
|
data[name] = result[name].interpolate(limit_direction='both', limit=10).tolist()
|
||||||
else:
|
else:
|
||||||
data[name] = result.interpolate().tolist()
|
data[name] = result.interpolate().tolist()
|
||||||
|
|
||||||
logging.info("Send Log for {}".format(names))
|
logging.info("Send Log for {}".format(names))
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
async def get_data2(self, ids) -> dict:
|
async def get_data2(self, ids) -> dict:
|
||||||
|
@ -155,12 +146,7 @@ class LogController:
|
||||||
|
|
||||||
result = dict()
|
result = dict()
|
||||||
for id in ids:
|
for id in ids:
|
||||||
# df = pd.read_csv("./logs/sensor_%s.log" % id, parse_dates=True, date_parser=dateparse, index_col='DateTime', names=['DateTime',"Values"], header=None)
|
df = pd.read_csv("./logs/sensor_%s.log" % id, parse_dates=True, date_parser=dateparse, index_col='DateTime', names=['DateTime',"Values"], header=None)
|
||||||
# concat all logs
|
|
||||||
all_filenames = glob.glob('./logs/sensor_%s.log*' % id)
|
|
||||||
df = pd.concat([pd.read_csv(f, parse_dates=True, date_parser=dateparse, index_col='DateTime', names=['DateTime', 'Values'], header=None) for f in all_filenames])
|
|
||||||
df = df.resample('60s').max()
|
|
||||||
df = df.dropna()
|
|
||||||
result[id] = {"time": df.index.astype(str).tolist(), "value":df.Values.tolist()}
|
result[id] = {"time": df.index.astype(str).tolist(), "value":df.Values.tolist()}
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
|
@ -47,8 +47,7 @@ class ConfigUpdate(CBPiExtension):
|
||||||
influxdbcloud = self.cbpi.config.get("INFLUXDBCLOUD", None)
|
influxdbcloud = self.cbpi.config.get("INFLUXDBCLOUD", None)
|
||||||
mqttupdate = self.cbpi.config.get("MQTTUpdate", None)
|
mqttupdate = self.cbpi.config.get("MQTTUpdate", None)
|
||||||
PRESSURE_UNIT = self.cbpi.config.get("PRESSURE_UNIT", None)
|
PRESSURE_UNIT = self.cbpi.config.get("PRESSURE_UNIT", None)
|
||||||
SENSOR_LOG_BACKUP_COUNT = self.cbpi.config.get("SENSOR_LOG_BACKUP_COUNT", None)
|
|
||||||
SENSOR_LOG_MAX_BYTES = self.cbpi.config.get("SENSOR_LOG_MAX_BYTES", None)
|
|
||||||
|
|
||||||
if boil_temp is None:
|
if boil_temp is None:
|
||||||
logger.info("INIT Boil Temp Setting")
|
logger.info("INIT Boil Temp Setting")
|
||||||
|
@ -287,23 +286,6 @@ class ConfigUpdate(CBPiExtension):
|
||||||
except:
|
except:
|
||||||
logger.warning('Unable to update config')
|
logger.warning('Unable to update config')
|
||||||
|
|
||||||
# check if SENSOR_LOG_BACKUP_COUNT exists in config
|
|
||||||
if SENSOR_LOG_BACKUP_COUNT is None:
|
|
||||||
logger.info("INIT SENSOR_LOG_BACKUP_COUNT")
|
|
||||||
try:
|
|
||||||
await self.cbpi.config.add("SENSOR_LOG_BACKUP_COUNT", 3, ConfigType.NUMBER, "Max. number of backup logs")
|
|
||||||
except:
|
|
||||||
logger.warning('Unable to update database')
|
|
||||||
|
|
||||||
# check if SENSOR_LOG_MAX_BYTES exists in config
|
|
||||||
if SENSOR_LOG_MAX_BYTES is None:
|
|
||||||
logger.info("INIT SENSOR_LOG_MAX_BYTES")
|
|
||||||
try:
|
|
||||||
await self.cbpi.config.add("SENSOR_LOG_MAX_BYTES", 100000, ConfigType.NUMBER, "Max. number of bytes in sensor logs")
|
|
||||||
except:
|
|
||||||
logger.warning('Unable to update database')
|
|
||||||
|
|
||||||
|
|
||||||
def setup(cbpi):
|
def setup(cbpi):
|
||||||
cbpi.plugin.register("ConfigUpdate", ConfigUpdate)
|
cbpi.plugin.register("ConfigUpdate", ConfigUpdate)
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in a new issue