Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Muons
# Author: Alexey "FoxyLab" Voronin
# WWW: https://acdc.foxylab.com
from os import walk
import os, time
from array import array
from decimal import Decimal
hours = {
0: 0,
1: 0,
2: 0,
3: 0,
4: 1,
5: 1,
6: 1,
7: 1,
8: 2,
9: 2,
10: 2,
11: 2,
12: 3,
13: 3,
14: 3,
15: 3,
16: 4,
17: 4,
18: 4,
19: 4,
20: 5,
21: 5,
22: 5,
23: 5
}
hour_ints = {
0: "00...04",
1: "04...08",
2: "08...12",
3: "12...16",
4: "16...20",
5: "20...24"
}
files_list = []
divs = [0,0,0,0,0,0]
for (dirpath, dirnames, filenames) in walk("."):
files_list.extend(filenames)
break
cnt = 0
for file in files_list:
file_name, file_extension = os.path.splitext(file)
if file_extension == ".png":
hour = time.localtime(os.stat(file).st_mtime).tm_hour
div = hours.get(hour, 0)
divs[div] = divs[div] + 1
cnt += 1
print(str(cnt) + " PNG-file(s)")
print("Histogram:")
if cnt > 0:
div = 0
while div < 6:
stars = ""
stars_cnt = divs[div]*20/cnt
while stars_cnt > 0:
stars = stars + "*"
stars_cnt -= 1
print(hour_ints.get(div, "")+": "+ str(divs[div])+" "+str(round(Decimal(divs[div]*100/cnt),2))+" % "+stars)
div += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.