-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession.py
46 lines (37 loc) · 1.43 KB
/
session.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
42
43
44
45
46
from __future__ import annotations
import uuid
from datetime import datetime
from typing import TYPE_CHECKING
import utils
from constants import *
from logger import Logger
if TYPE_CHECKING:
from window import MainWindow
class Session:
def __init__(self, window: MainWindow) -> None:
self.window = window
self.logger = Logger()
self.timer_start = datetime.now()
# create the session folder
self.id = str(uuid.uuid4())
self.folder = os.path.join(SESSION_DIR, self.id)
os.mkdir(self.folder)
self.window.sessionButton.setText('End session')
self.logger.log('New session:', self.id)
self.window.custom_ui.reset() # reset the ui elements (graphs, etc)
def end(self) -> None:
self.window.sessionButton.setText('Open a session')
self.window.data.save(self)
self.window.session = None
folder_size = utils.get_dir_size(self.folder)
# log & save some metadata
self.logger.log(f'Session ended: {self.id}')
self.logger.log(f' Started on {self.timer_start}')
self.logger.log(f' Total size: {folder_size}o')
with open(os.path.join(self.folder, 'info.txt'), 'w') as f:
f.writelines([
f'id: {self.id}\n',
f'start: {self.timer_start.timestamp()}\n',
f'end: {datetime.now().timestamp()}\n',
f'size: {folder_size}'
])