Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix single value and unix timestamp. fixes #211 #212

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions plugins/datalog/__init__.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,29 @@ class DataLog():
_buffer_lock = None

def __init__(self, smarthome, path="var/log/data", filepatterns={ "default" : "{log}-{year}-{month}-{day}.csv" }, logpatterns={ "csv" : "{time};{item};{value}\n" }, cycle=10):

self._sh = smarthome
self.path = path

if type(filepatterns) is str:
filepatterns = [filepatterns]
if type(filepatterns) is list:
for pattern in filepatterns:
key, value = pattern.split(':')
self.filepatterns[key] = value
else:
self.filepatterns = filepatterns

if type(logpatterns) is str:
logpatterns = [logpatterns]
if type(logpatterns) is list:
newlogpatterns = {}
for pattern in logpatterns:
key, value = pattern.split(':')
newlogpatterns[key] = value
logpatterns = newlogpatterns


for log in self.filepatterns:
ext = self.filepatterns[log].split('.')[-1]
if ext in logpatterns:
Expand All @@ -61,7 +67,7 @@ def __init__(self, smarthome, path="var/log/data", filepatterns={ "default" : "{
self._items = {}
self._buffer = {}
self._buffer_lock = threading.Lock()

logger.info('DataLog: Initialized, logging to "{}"'.format(self.path))
for log in self.filepatterns:
logger.info('DataLog: Registered log "{}", file="{}", format="{}"'.format(log, self.filepatterns[log], self.logpatterns[log]))
Expand Down Expand Up @@ -136,7 +142,7 @@ def _dump(self):
handles[filename] = open(self.path + '/' + filename, 'a')

data = entry
data['stamp'] = data['time'].time();
data['stamp'] = data['time'].timestamp()
handles[filename].write(logpattern.format(**data))

except Exception as e:
Expand Down