-
Notifications
You must be signed in to change notification settings - Fork 1
/
logger.py
41 lines (29 loc) · 984 Bytes
/
logger.py
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
import os
import shutil
import numpy as np
from serialization import serialize_cellmap
class Logger:
__slots__ = ('session', 'id', 'count')
def __init__(self, session: str='default'):
self.session = session
self.id = 0
self.count = 1
def get_file_name(self) -> str:
return '{0}/{1}_step.log'.format(self.session, self.count)
def log(self, cellmap: np.ndarray):
serialize_cellmap(cellmap, self.get_file_name())
self.count += 1
def start_session(self, cellmap: np.ndarray, session_name: str=''):
if os.path.exists(self.session):
shutil.rmtree(self.session)
os.makedirs(self.session)
if session_name == '':
self.id += 1
self.session = 'default_' + str(self.id)
else:
self.session = session_name
self.count = 0
self.log(cellmap)
def end_session(self):
self.session = 'default'
self.count = 1