Created
March 21, 2021 21:24
-
-
Save SeanFelipe/72f7a11178e47560fd184c903f07e9e0 to your computer and use it in GitHub Desktop.
for care.coach, 21 Mar 2021 Sean Wolfe
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
from pdb import set_trace | |
activity = [ | |
(1, '@login', None), | |
(5, '@startVideo', 'Bob'), | |
(20, '@startVideo', 'Thomas'), | |
(66, '@stopVideo', 'Thomas'), | |
(70, '@startVideo', 'Lily'), | |
(75, '@stopVideo', 'Bob'), | |
(78, '@stopVideo', 'Lily'), | |
(100, '@logout', None), | |
(150, '@login', None), | |
(160, '@startVideo', 'Thomas'), | |
(205, '@stopVideo', 'Thomas'), | |
(210, '@logout', None) | |
] | |
total_logged_in_time = 0 | |
total_with_two_clients = 0 | |
last_login_at = None | |
num_active_clients = 0 | |
last_two_clients_ts = None | |
logged_in = False | |
for act in activity: | |
ts = act[0] | |
action = act[1] | |
client = act[2] | |
if action == '@login': | |
logged_in = True | |
last_login_at = ts | |
elif action == '@startVideo': | |
num_active_clients += 1 | |
if num_active_clients == 2: | |
last_two_clients_ts = ts | |
elif action == '@stopVideo': | |
num_active_clients -= 1 | |
if num_active_clients == 1: | |
elapsed_with_two_clients = ts - last_two_clients_ts | |
total_with_two_clients += elapsed_with_two_clients | |
elif action == '@logout': | |
elapsed = ts - last_login_at | |
total_logged_in_time += elapsed | |
logged_in = False | |
print("total logged in time: %i" % total_logged_in_time) | |
print("total time with two clients: %i" % total_with_two_clients) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment