Browse Source

refactoring

Théo Ertzscheid 2 years ago
parent
commit
96c6649795
4 changed files with 5 additions and 53 deletions
  1. 0 1
      challenge-heure.py
  2. 0 50
      classement-reactions.py
  3. 1 1
      histogramme-heure.py
  4. 4 1
      outils.py

+ 0 - 1
challenge-heure.py

@@ -3,7 +3,6 @@ import json
 import sys
 from datetime import datetime
 
-
 def check_challenge_win(message, hour, minute):
   # Check that the message has text and that the text is "1337"
   if "text" in message and message["text"] == hour + minute:

+ 0 - 50
classement-reactions.py

@@ -1,50 +0,0 @@
-#!/usr/bin/python3
-import json
-import sys
-from datetime import datetime
-import matplotlib.pyplot as plt
-from outils import import_array
-
-def create_hist(messages):
-    # Initialize the dict in which we'll store the 
-    # number of messages for each hour of the day
-    hist = {}
-    for hour in range(0, 24):
-      hist[hour]=0
-
-    for message in messages:
-      if "date_unixtime" in message :
-        message_hour = datetime.fromtimestamp(int(message["date_unixtime"])).hour
-        hist[message_hour] += 1
-    
-    return hist
-
-def main():
-  # Get the file name from the first command line argument
-  filename = sys.argv[1]
-
-  # Import the array from the JSON file
-  messages = import_array(filename)
-  
-  # create a dict containing the number of messages for each hour
-  hist = create_hist(messages)
-  
-  # sort and print the resulting wins dict
-  print(sorted(hist.items(), key=lambda x:x[1], reverse=True))
-
-  hours = list(hist.keys())
-  counts = list(hist.values())
-
-  fig = plt.figure(figsize = (10, 5))
-
-  plt.xlabel("Messages par heure")
-  plt.ylabel("Nb de messages")
-  plt.title("Heure de la journée")
-
-  # creating the bar plot
-  plt.bar(hours, counts,width = 0.4)
-  #plt.show()
-  plt.savefig("msg-heures.png")
-
-if __name__ == '__main__':
-  main()

+ 1 - 1
histogramme-heure.py

@@ -3,7 +3,7 @@ import json
 import sys
 from datetime import datetime
 import matplotlib.pyplot as plt
-from outils import import_array
+from outils import import_array, btz_core
 
 def create_hist(messages):
     # Initialize the dict in which we'll store the 

+ 4 - 1
outils.py

@@ -5,4 +5,7 @@ def import_array(filename):
 
   # Access the "messages" array
   array = data['messages']
-  return array
+  return array
+
+btz_core = ['Nathan Spaeter', 'Luyzon', 'Clément Krebs', 't o', 'Leous', 'Arnaud']
+btz_ext = [*btz_core, *['Senkei', 'Éléonore', 'Tozpa', 'Léo', 'XxX_MatthieuXPlume_XxX', 'poline', 'Sarah Guillemant']]