-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rutine_4
263 lines (227 loc) · 6.81 KB
/
Rutine_4
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
rutine = [
[],
[],
[]
]
## Get the input of the before results
before = input("Press enter to start the program. ")
## Some variables to prevent the absense of a variable
char_n = 0
last_type = None
temp_n_storage = ""
last_st_h = 0
DAYS = 1
## The loop sorting each character
while True:
try:
## Splitting minutes from hours
if before[char_n] == ":":
character = ":"
## Finding out the type of the character
else:
try:
int(before[char_n])
character = "integer"
except ValueError:
character = "string"
## The actual sorting part
if last_type == "string" and character == "string":
rutine[0][-1] += before[char_n]
if last_type == "string" and character == "integer":
temp_n_storage += before[char_n]
if last_type == "integer" and character == "string":
rutine[0].append(before[char_n])
rutine[2].append(int(temp_n_storage))
temp_n_storage = ""
if last_type == "integer" and character == "integer":
temp_n_storage += before[char_n]
if last_type == "integer" and character == ":":
DAYS = int(temp_n_storage) + 1
temp_n_storage = ""
if last_type == ":" and character == "integer":
temp_n_storage += before[char_n]
if last_type == None and character == "integer":
temp_n_storage += before[char_n]
## Quit the loop when there are no more characters to check
except IndexError:
break
last_type = character
char_n += 1
## Get the input of the daily rutine
rutine_input = input("Daily rutine ")
## Some variables to prevent the absense of a variable
char_n = 0
last_type = None
temp_n_storage = ""
last_st_h = 0
## The loop sorting each character
while True:
try:
## Splitting minutes from hours
if rutine_input[char_n] == ":":
character = ":"
## Finding out the type of the character
else:
try:
int(rutine_input[char_n])
character = "integer"
except ValueError:
character = "string"
## The actual sorting part
if last_type == "string" and character == "string":
rutine[0][-1] += rutine_input[char_n]
if last_type == "string" and character == "integer":
temp_n_storage += rutine_input[char_n]
if last_type == "string" and character == ":":
rutine[1].append(last_st_h * 60)
if last_type == "integer" and character == "string":
rutine[0].append(rutine_input[char_n])
rutine[1][-1] += int(temp_n_storage)
temp_n_storage = ""
if last_type == "integer" and character == "integer":
temp_n_storage += rutine_input[char_n]
if last_type == "integer" and character == ":":
rutine[1].append(int(temp_n_storage) * 60)
last_st_h = int(temp_n_storage)
temp_n_storage = ""
if last_type == ":" and character == "string":
rutine[0].append(rutine_input[char_n])
temp_n_storage = ""
if last_type == ":" and character == "integer":
temp_n_storage += rutine_input[char_n]
if last_type == None and character == "integer":
temp_n_storage += rutine_input[char_n]
## Quit the loop when there are no more characters to check
except IndexError:
break
last_type = character
char_n += 1
## Counting the minutes
nitem = 0
while nitem < len(rutine[1]):
if nitem == len(rutine[1]) - 1:
neste = 1440
if nitem < len(rutine[1]) - 1:
neste = rutine[1][nitem + 1]
rutine[2].append(neste - rutine[1][nitem])
nitem += 1
rutine.remove(rutine[1])
## Merging equivilant activities
crut = [[], []]
nitem = 0
while nitem < len(rutine[0]):
if rutine[0][nitem] in crut[0]:
first = crut[0].index(rutine[0][nitem])
crut[1][first] += rutine[1][nitem]
else:
crut[0].append(rutine[0][nitem])
crut[1].append(rutine[1][nitem])
nitem += 1
rutine = crut
## Sorting
def list_is_from_biggest_to_smallest(li):
thisv = 0
nextv = 1
while nextv < len(li):
if li[thisv] >= li[nextv]:
returnv = True
if li[thisv] < li[nextv]:
returnv = False
break
nextv += 1
thisv += 1
return returnv
crut = rutine
items_sorted = 0
while not list_is_from_biggest_to_smallest(crut[1]):
biggest_yet = 0
item = 0
while item < len(crut[1]):
if crut[1][item] > crut[1][biggest_yet]:
biggest_yet = item
item += 1
move_item = crut[0].pop(biggest_yet)
crut[0].insert(items_sorted, move_item)
move_item = crut[1].pop(biggest_yet)
crut[1].insert(items_sorted, move_item)
items_sorted += 1
print(crut)
## Conversion to percents bit
rutine.append([])
for n in rutine[1]:
percent = n / 1440 * 100 / DAYS
if percent.is_integer():
rutine[2].append(int(percent))
else:
rutine[2].append(percent)
## Output
def hm(mins):
quotient, remainder = divmod(mins, 60)
if len(str(quotient)) == 1:
aq = "0"
else:
aq = ""
if len(str(remainder)) == 1:
ar = "0"
else:
ar = ""
return f"{aq}{quotient}:{ar}{remainder}"
i = 0
for percentage in rutine[2]:
print(f"{rutine[0][i]}: {percentage}% ({hm(rutine[1][i])})")
i += 1
## More visual output
colours = ["\u001b[32m", "\u001b[33m", "\u001b[36m", "\u001b[37m", "\u001b[92m", "\u001b[93m", "\u001b[96m"]
res = "\u001b[0m"
def split_word(s):
word = []
imagin = 0
while imagin < len(s):
if imagin == len(s) - 1:
add = "_"
else:
add = ""
word.append(s[imagin] + add)
imagin += 1
return word
## All in one line
#act = 0
#co = 0
#for activity in rutine[0]:
# if co == 7:
# co = 0
# chars = 0
# ch = 0
# while True:
# if chars >= (round(rutine[2][act]) - 1) * 4.8:
# print(" ", end="")
# break
# if ch == len(split_word(rutine[0][act])):
# ch = 0
# print(colours[co] + split_word(rutine[0][act])[ch] + res, end="")
# chars += 1
# ch += 1
# co += 1
# act += 1
## Vertically
porhq = input("(% / h) ") # p[ercents ]or[ ]h[ours ]q[uestion]
if porhq in ("%", "%/4"):
porhq = 0.25
else:
porhq = 0.24
def round_as_normal_and_round_up_if_less_than_one(number):
if number <= 1:
return 1
else:
return round(number)
act = 0
co = 0
for activity in rutine[0]:
if co == 7:
co = 0
lines = 1
while lines <= round_as_normal_and_round_up_if_less_than_one(rutine[2][act] * porhq):
print(colours[co] + rutine[0][act] + res)
lines += 1
co += 1
act += 1