Commit 1bc88ca3 authored by Adrien Simon's avatar Adrien Simon
Browse files

Ajout de la fonction de statistiques des mots les plus utilisés

parent f3c1c7ce
......@@ -13,11 +13,11 @@ if __name__ == "__main__":
name = '.'
# choose action to do
choice = 0
while choice != 7:
while choice != 8:
if name == '.':
choice = 5
else :
choice = input("\n1 - Afficher les messages\n2 - Afficher les participants\n3 - Afficher les statistiques\n4 - Afficher les reactions\n5 - Changer de conversation\n6 - Nombre de messages supprimés\n7 - Quitter l\'application\n")
choice = input("\n1 - Afficher les messages\n2 - Afficher les participants\n3 - Afficher les statistiques\n4 - Afficher les reactions\n5 - Changer de conversation\n6 - Nombre de messages supprimés\n7 - Classement des mots\n8 - Quitter l\'application\n")
try:
choice = int(choice)
except ValueError:
......@@ -42,4 +42,6 @@ if __name__ == "__main__":
print( "Désolé, Conversation non trouvée." )
name = '.'
if choice == 6:
stats.countunset(data)
\ No newline at end of file
stats.countunset(data)
if choice == 7:
stats.countwords(data)
\ No newline at end of file
......@@ -42,6 +42,7 @@ def countreacts(data):
print(participants[participant][react], end=' ')
print("")
def countunset(data):
messages = data["messages"]
participants = users.userdico(data)
......@@ -53,3 +54,30 @@ def countunset(data):
for nb_unsent in participants:
print(nb_unsent + " : " + str(participants[nb_unsent]))
def countwords(data):
messages = data["messages"]
count_words = {}
for msg in messages:
try:
message = decode.string_decode(msg["content"])
message = message.replace("\'", " ")
message = message.replace("’", " ")
if "a rejoint l" not in message:
for word in message.split():
if len(word) > 4:
if word in count_words:
count_words[word] += 1
else:
count_words[word] = 1
except KeyError:
pass
sorted_keys = sorted(count_words, key=count_words.get, reverse=True)
i = 0;
for i in range(10):
print(sorted_keys[i] + " : " + str(count_words[sorted_keys[i]]))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment