-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsole_logging.py
More file actions
43 lines (37 loc) · 1.33 KB
/
console_logging.py
File metadata and controls
43 lines (37 loc) · 1.33 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
import time
def print_blank(n):
print(" "*n, end="\r")
def message_step(n):
message = 'Training Step: {}'.format(n)
return message
def tabbed_string(s, sep='\t'):
message = ''
if hasattr(s, '__class__') and not isinstance(s, list):
obj = s
for t in s.all_variables:
h = getattr(obj, str(t))
action_key = ' |{}| '.format(h['action'])
message = message + '{}{}: {}'.format(action_key, t, h['value'])
elif isinstance(s,dict):
for k, v in s.items():
message = message + '{}{}: {}'.format(sep, k, v)
elif isinstance(s,list):
for v in s:
message = message + '{}{}'.format(sep, v)
return message + '\t'
def print_iter(n, HPx):
step_print = message_step(n)
setting_string = tabbed_string(HPx, sep=' | ')
message_str = tabbed_string([HPx.message])
print_line = tabbed_string([step_print, setting_string, message_str], sep='')
return print_line
def create_message(obj, n):
direction = '+' if n >= 0 else '-'
incrementer = ' {} {}(x{})'.format(direction, obj['increment'], abs(n))
message = '[{}: {}]'.format(obj['name'], obj['value']-obj['increment']) + incrementer
return message
# Countdown timer for training
def countdown(t):
for i in list(range(t))[::-1]:
print(i+1)
time.sleep(0.5)