|
|
@@ -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()
|