Created
October 29, 2018 17:26
-
-
Save bernikr/9dd962eba9c1a61a18d2d4349c262c48 to your computer and use it in GitHub Desktop.
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 | |
import operator | |
from datetime import datetime, timedelta | |
import iso8601 as iso8601 | |
import pytz as pytz | |
from collections import defaultdict | |
if __name__ == '__main__': | |
with open('result.json', encoding="utf-8") as f: | |
data = json.load(f) | |
name = 'HIER EIGENEN NAMEN EINSETZEN' | |
results = [] | |
for chat in data['chats']['list']: | |
if 'name' not in chat: | |
continue | |
delta = timedelta(days=1) | |
count = defaultdict(lambda: 0) | |
last_msg_time = pytz.UTC.localize(datetime.min) | |
for msg in chat['messages']: | |
if not msg['type'] == 'message': | |
continue | |
t = iso8601.parse_date(msg['date']) | |
if t > last_msg_time + delta: | |
count[msg['from']] += 1 | |
last_msg_time = t | |
me = count[name] | |
others = list(count.keys()) | |
others.remove(name) | |
if len(others) == 0: | |
chat_name = chat['name'] | |
other = 0 | |
elif len(others) == 1: | |
chat_name = others[0] | |
other = count[chat_name] | |
else: | |
print('ERROR: Wrong Participant count') | |
print('Skipping %s' % chat['name']) | |
continue | |
results.append({ | |
'name': chat_name, | |
'me': me, | |
'other': other, | |
'ratio': me / (me + other), | |
'sum': me + other, | |
'messages': len(chat['messages']) | |
}) | |
results = [x for x in results if x['messages'] >= 100] | |
results.sort(key=operator.itemgetter('ratio'), reverse=True) | |
for i, r in enumerate(results): | |
print('%2d. %.2f (%3d:%3d, %3d, %5d) %s' % (i, r['ratio'], r['me'], r['other'], r['sum'], r['messages'], r['name'])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment