Created
January 1, 2016 17:37
-
-
Save SamLR/d9c0e66d61107745c9cd to your computer and use it in GitHub Desktop.
Quick analysis of EMF 2014 talks
This file contains 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
Total Entries = 184 | |
Errors = 20 | |
Used Entries = 164 | |
Min = 15 min | |
Max = 180 min | |
Average = 52 min | |
---------------------------------------- | |
Duration (min) | Count | |
30 | 48 | |
60 | 38 | |
45 | 34 | |
90 | 19 | |
15 | 14 | |
120 | 10 | |
180 | 1 |
This file contains 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
import json | |
from datetime import datetime | |
from collections import OrderedDict | |
DATETIME_FORMAT = '%Y-%m-%dT%H:%M:%SZ' | |
def get_events(file_name): | |
f = open(file_name, 'r') | |
return json.load(f)['conference_events']['events'] | |
def get_length_in_minutes(event): | |
end = event.get('end_time', None) | |
start = event.get('start_time', None) | |
if end is None or start is None: | |
return None | |
end = datetime.strptime(end, DATETIME_FORMAT) | |
start = datetime.strptime(start, DATETIME_FORMAT) | |
duration = end - start | |
return duration.seconds / 60 | |
def get_hist(entries): | |
hist = {} | |
for e in entries: | |
hist[e] = 1 if e not in hist else hist[e] + 1 | |
return OrderedDict(sorted(hist.items(), key=lambda x: x[1], reverse=True)) | |
def main(file_name): | |
events = get_events(file_name) | |
all_durations = [get_length_in_minutes(e) for e in events] | |
errors = len([d for d in all_durations if d is None]) | |
durations = [d for d in all_durations if d is not None] | |
print('Total Entries = {0: >4d}'.format(len(all_durations))) | |
print('Errors = {0: >4d}'.format(errors)) | |
print('Used Entries = {0: >4d}'.format(len(durations))) | |
print('Min = {0: >4d} min'.format(int(min(durations)))) | |
print('Max = {0: >4d} min'.format(int(max(durations)))) | |
print('Average = {0: >4d} min'.format(int((sum(durations) / len(durations))))) | |
print('-' * 40) | |
hist = get_hist(durations) | |
print('Duration (min) | Count') | |
for time, count in hist.items(): | |
print('{0: >14d} | {1: >3d}'.format(int(time), count)) | |
if __name__ == '__main__': | |
talks_2014 = '2014/events.json' | |
main(talks_2014) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment