-
Notifications
You must be signed in to change notification settings - Fork 1
/
print_data.py
80 lines (65 loc) · 2.71 KB
/
print_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from tabulate import tabulate
def print_metadata(metadata):
'''
prints basic info about the chat
'''
print('First message: ' + metadata['first_day_date'])
print('Last message: ' + metadata['last_day_date'])
print('Number of days: ' + str(metadata['days']))
print('Number of messages: ' + str(metadata['nmessages']))
def print_user_info(users):
'''
prints basic info about users and their messages
'''
print('\n')
print('Number of messages:')
for user in users:
print('\t' + user + '(' + users[user]['gender'] + '): ')
print('\t\t' + 'Messages: ' + str(users[user]['n_messages']))
print('\t\t' + 'Most common word: ' +
str(users[user]['most_common_word'][0]))
print('\t\t' + 'MPD: ' + str(users[user]['mpd']))
print('\t\t' + 'Files sent: ' + str(users[user]['n_files']))
print('\t\t' + 'Files sent every 100 messages: ' +
str(round(users[user]['ratio_files_and_messages'], 2)) + " %")
print('\t\t' + 'Links sent: ' + str(users[user]['n_links']))
print('\t\t' + 'Links sent every 100 messages: ' +
str(round(users[user]['ratio_links_and_messages'], 2)) + " %")
print('\n')
def print_longest_messages(users):
'''
prints the length and the message of the longest message for every user
'''
print('********* LONGEST MESSAGES *********\n')
for user in users:
print(user + " (" + str(users[user]['len_longest_message']) + '): ')
print("\t" + users[user]['longest_message'] + "\n\n")
print('\n\n')
def print_info_table(users):
'''
prints a table with short and basic info about users
'''
rows = []
for user in users:
rows.append([
user,
users[user]['gender'],
str(users[user]['n_messages']),
str(users[user]['most_common_word'][0]),
str(users[user]['len_longest_message']),
str(users[user]['n_emojis']),
str(round(users[user]['mpd'], 4)),
str(users[user]['n_files']),
str(round(users[user]['ratio_files_and_messages'], 2)),
str(users[user]['n_links']),
str(round(users[user]['ratio_links_and_messages'], 2))
])
headers = [
'User', 'Gender', 'Messages', 'MCM', 'LM', 'Emojis', 'MPD', 'Files', '% Files', 'Links', '% Links'
]
print(tabulate(rows, headers=headers, tablefmt="grid"))
print('\n\tMCM: Most common word.')
print('\tLM: Longest message (length). Just below you can see the message for every user.')
print('\tMPD: Messages per day.')
print('\t% Files and % Links: Files and/or links sent every 100 messages.\n\n')
print_longest_messages(users)