-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
96 lines (68 loc) · 1.96 KB
/
utils.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
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
import time
import logging
from threading import Thread
from dataclasses import dataclass
from queue import PriorityQueue
logging.basicConfig(
format = '%(asctime)s : %(levelname)s : %(message)s',
level = logging.INFO)
class Logger:
def info(self, message):
logging.info(message)
def warning(self, message):
logging.warning(message)
def error(self, message):
logging.error(message)
def critical(self, message):
logging.critical(message)
class Timer:
def __init__(self):
self._start_time = None
self._elapsed_time = 0
self._is_stop = False
def start(self):
if self._start_time: return
self._is_stop = False
self._elapsed_time = 0
self._start_time = time.perf_counter()
while not self._is_stop:
end_time = time.perf_counter()
self._elapsed_time += end_time - self._start_time
self._start_time = time.perf_counter()
time.sleep(0.01)
def stop(self):
self._is_stop = True
self._start_time = None
@property
def elapsed_time(self):
return round(self._elapsed_time, 2)
class AsyncTimer(Thread, Timer):
def __init__(self):
Thread.__init__(self)
Timer.__init__(self)
def start(self):
Thread.setDaemon(self, True)
Thread.start(self)
def run(self):
Timer.start(self)
def get_type_name(instance):
return type(instance).__name__
@dataclass
class LatLng:
latitude: float = 0.0
longitude: float = 0.0
def initialize_vars():
global GLOBAL_LOGGER
GLOBAL_LOGGER = Logger()
global GLOBAL_SPEECH_CONTENT
GLOBAL_SPEECH_CONTENT = ''
global GLOBAL_IMAGE
GLOBAL_IMAGE = None
global GLOBAL_DATASET
GLOBAL_DATASET = []
global GLOBAL_LATLNG
GLOBAL_LATLNG = LatLng()
global AUDIO_PLAYING
AUDIO_PLAYING = False
global AUDIO_QUEUE
AUDIO_QUEUE = PriorityQueue()