Last active
August 29, 2015 14:21
-
-
Save alexwoolford/87a7ccdae834adfcfd3e to your computer and use it in GitHub Desktop.
Get started http://stackoverflow.com/questions/30431100/staff-activity-monitor-adding-up-login-logout-timestamps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In[1]: | |
import re | |
import datetime | |
# In[2]: | |
log = """[23:40:45]ACCESS: Login: StaffMember/(StaffMember) | |
[23:41:09]ACCESS: Logout: *no key*/(StaffMember) | |
[23:41:09]ACCESS: Login: StaffMember/(John Smith) | |
[23:41:29]ACCESS: Logout: *no key*/(John Smith) | |
[23:41:29]ACCESS: Login: StaffMember/(John Smith) | |
[23:41:52]ACCESS: Logout: *no key*/(John Smith) | |
[23:41:52]ACCESS: Login: StaffMember/(John Smith)""" | |
# In[3]: | |
logLinePattern = re.compile("\[(\d\d):(\d\d):(\d\d)\]ACCESS: (Login|Logout):.*/\((.*)\)") | |
# In[4]: | |
for line in log.split("\n"): | |
eventTime = datetime.time(int(re.match(logLinePattern, line).group(1)), \ | |
int(re.match(logLinePattern, line).group(2)), \ | |
int(re.match(logLinePattern, line).group(3))) | |
eventType = re.match(logLinePattern, line).group(4) | |
user = re.match(logLinePattern, line).group(5) | |
print eventTime, eventType, user | |
# TODO: | |
# Make a dictionary of events for each user, iterate through the users, sort the events, then iterate through the events capturing the cumulative time between login/logout |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment