-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSTimer-Total.py
More file actions
147 lines (118 loc) · 5.21 KB
/
CSTimer-Total.py
File metadata and controls
147 lines (118 loc) · 5.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import glob
import json
import math
total_solves = 0
total_time_ms = 0
# This is where the stats of individual sessions will go
session_stats = []
# Finds all .txt files and if only 1 is present save that file name, else exit the program
file_names = glob.glob("*.txt")
if len(file_names) != 1:
print("Please have 1 .txt file in this directory")
exit()
else:
file_name = file_names[0]
# Loads the found file
with open(file_name, "r") as file:
text = file.read()
# Make read string into a JSON file, if it is an invalid file, ask the user for a good file and exit the program
try:
json_file = json.loads(text)
except json.JSONDecodeError:
print("Please supply a valid CSTimer file")
exit()
# Go through all the sessions in the file,
# Range should be + 1 to reach the last one, because it is not inclusive
# But since we have an extra object with session no modification is required
for session_nr in range(1, len(json_file)):
session = json_file["session%s" % session_nr]
# Don't know why this works or why it's needed
session = json.loads(session)
# First index is time and second is number of solves
# Third is the name of the session which will be filled in later
session_stats.append([0, 0, None])
for solve in session:
total_solves += 1
session_stats[session_nr - 1][1] += 1
# Get the time in milliseconds
time_ms = solve[0][1]
total_time_ms += time_ms
# Add the time to that sessions stats
session_stats[session_nr - 1][0] += time_ms
# Load into the part where the session names are
properties = json.loads(json_file["properties"])
session_data = json.loads(properties["sessionData"])
# For all the session add the sessions name to session_stats
for session_nr in range(1, len(session_data) + 1):
current_session = session_data[str(session_nr)]
session_name = current_session["name"]
session_stats[session_nr - 1][2] = session_name
# Calculate the time in hours, minutes and seconds
# Function because it is used multiple times
# Returns a tuple with the times
def get_time(ms):
# Everything gets floored because it gets covered by the lower unit
# Seconds are so small and just gets rounded anyways
# First and second is obvious
seconds = ms / 1000
hours = math.floor(seconds / 3600)
# Gives me total minutes mod 60 because the rest are taken by hours
minutes = math.floor((seconds / 60) % 60)
# Takes the number of seconds mod 60 because of the minutes
seconds = round(seconds % 60)
return hours, minutes, seconds
# Find the most used session in time
highest_time = 0
for session in session_stats:
if session[0] > highest_time:
most_used_time = session
highest_time = session[0]
# Find the most used session in number of solves
highest_solves = 0
for session in session_stats:
if session[1] > highest_solves:
most_used_solves = session
highest_solves = session[1]
# Print out all the special statistics at the end
print("You have spent a total of %s hours, %s minutes and %s seconds of solving in CSTimer" % get_time(total_time_ms))
print("With a total of %s solves" % total_solves)
# if the number of hours is 0, 0 evaluates to False in python, print the time without hours
if not get_time((total_time_ms/total_solves))[0]:
# [1:] Gets the tuple without the hour
print("Average time: %s minutes and %s seconds" % get_time((total_time_ms/total_solves))[1:])
else:
print("Average time: %s hours, %s minutes and %s seconds" % get_time((total_time_ms/total_solves)))
print("")
print("The session you have spent the most time solving with is %s" % most_used_time[2])
print("In that session you spent a total of %s hours, %s minutes and %s seconds" % get_time(most_used_time[0]))
print("With a total of %s solves" % most_used_time[1])
# if the number of hours is 0, 0 evaluates to False in python, print the time without hours
if not get_time(most_used_time[0]/most_used_time[1])[0]:
# [1:] Gets the tuple without the hour
print("Average time: %s minutes and %s seconds" % get_time((most_used_time[0]/most_used_time[1]))[1:])
else:
print("Average time: %s hours, %s minutes and %s seconds" % get_time((most_used_time[0]/most_used_time[1])))
print("")
print("The session you have the most solves with is %s" % most_used_solves[2])
print("In that session you spent a total of %s hours, %s minutes and %s seconds" % get_time(most_used_solves[0]))
print("With a total of %s solves" % most_used_solves[1])
# if the number of hours is 0, 0 evaluates to False in python, print the time without hours
if not get_time(most_used_solves[0]/most_used_solves[1])[0]:
# [1:] Gets the tuple without the hour
print("Average time: %s minutes and %s seconds" % get_time(most_used_solves[0]/most_used_solves[1])[1:])
else:
print("Average time: %s hours, %s minutes and %s seconds" % get_time((most_used_solves[0]/most_used_solves[1])))
# Prints out all of the stats at the end
for session in session_stats:
print("")
print(session[2])
print("%s hours, %s minutes and %s seconds" % get_time(session[0]))
print("%s solves" % session[1])
# If there are no solves, there is no average
if not session[1]:
continue
if not get_time(session[0]/session[1])[0]:
print("Average time: %s minutes and %s seconds" % get_time(session[0]/session[1])[1:])
else:
print("Average time: %s hours, %s minutes and %s seconds" % get_time(session[0]/session[1]))
input()