This repository has been archived on 2024-02-23. You can view files and clone it, but cannot push or open issues or pull requests.
memberPlumbing/events.py

89 lines
2.4 KiB
Python
Raw Permalink Normal View History

#!/usr/bin/env python3
import datetime
import itertools
import re
import numpy as np
import pandas as pd
import requests
from lxml import etree
from common import doors
from hid.DoorController import ROOT, E
2018-05-09 10:12:02 -04:00
2018-08-16 14:01:42 -04:00
def getStrings(door):
"""Parses out the message strings from source."""
2018-08-16 14:01:42 -04:00
r = requests.get('https://' + door.ip + '/html/en_EN/en_EN.js',
auth=requests.auth.HTTPDigestAuth(door.username,
door.password),
verify=False)
regex = re.compile(r'([0-9]+)="([^"]*)')
strings = [regex.search(s) for s in r.text.split(';')
if s.startswith('localeStrings.eventDetails')]
print({int(g.group(1)): g.group(2) for g in strings})
2018-08-16 14:01:42 -04:00
def getMessages(door):
events = None
recordCount = 0
moreRecords = True
while moreRecords:
res = door.doXMLRequest(ROOT(
E.EventMessages({
"action": "LR",
"recordCount": str(1000 - recordCount),
"recordOffset": str(recordCount),
})))
if events is None:
events = res[0]
else:
for event in res[0]:
events.append(event)
recordCount += int(res[0].get('recordCount'))
moreRecords = res[0].get('moreRecords') == 'true'
print(recordCount, moreRecords)
etree.dump(events, pretty_print=True)
return events
# def stats(events):
# eventsByDay = {k: list(v) for k, v in
# itertools.groupby(sorted(events, key=get_day), key=get_day)}
# print({k: len(v) for k, v in eventsByDay.items()})
# #print([get_day(e) for e in events])
2018-06-01 13:56:46 -04:00
def main():
2018-08-16 14:01:42 -04:00
for door in doors.values():
getMessages(door)
2018-06-01 13:51:50 -04:00
if __name__ == '__main__':
main()
events = getMessages(doors["Studio Space"])
# stats(events)
df = pd.DataFrame([dict(e.attrib) for e in events])
idx = pd.to_datetime(df['timestamp'], format='%Y-%m-%dT%H:%M:%S')
df = df.set_index(pd.DatetimeIndex(idx.values)).drop('timestamp', axis=1)
print()
print(df[df.eventType == '2020'].dropna(axis=1, how='all').head())
entriesPerDay = df[df.eventType == '2020'] \
.dropna(axis=1, how='all') \
.resample('1D') \
.count()['eventType']
entriesPerDay.index = entriesPerDay.index.map(lambda t: t.strftime('%Y-%m-%d'))
print(df.groupby(by=['forename', 'surname']).size().sort_values())
entriesPerDay.plot(kind='bar')