| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- #!/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):
- for minute in range(0, 60):
- hist[str(hour).zfill(2) + str(minute).zfill(2)]=0
- for message in messages:
- if "date_unixtime" in message :
- message_hour = str(datetime.fromtimestamp(int(message["date_unixtime"])).hour).zfill(2)
- message_minute = str(datetime.fromtimestamp(int(message["date_unixtime"])).minute).zfill(2)
- hist[message_hour + message_minute] += 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)
- #plt.show()
- plt.savefig("msg-heureminutes.png")
- if __name__ == '__main__':
- main()
|