89 lines
2.4 KiB
Python
Executable File
89 lines
2.4 KiB
Python
Executable File
#!/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
|
|
|
|
|
|
def getStrings(door):
|
|
"""Parses out the message strings from source."""
|
|
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})
|
|
|
|
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])
|
|
|
|
def main():
|
|
for door in doors.values():
|
|
getMessages(door)
|
|
|
|
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')
|