-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcfUtil_Time.py
More file actions
183 lines (147 loc) · 6.41 KB
/
cfUtil_Time.py
File metadata and controls
183 lines (147 loc) · 6.41 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
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
import time
import cv2
class TimeModule:
def __init__(self):
self.pTime = 0
self.ftWatchMode = 0
self.amWatchMode = 0
self.emWatchMode = 0
self.emRound = 1
def GetFps(self, img, draw=True):
cTime = time.time()
fps = 1 / (cTime - self.pTime)
self.pTime = cTime
if draw:
cv2.putText(img, str(int(fps)), (50, 100), cv2.FONT_HERSHEY_PLAIN,
2, (255, 0, 0), 2)
def FT(self, img, tCap=10, text=True):
# Static Variables
cTime = time.time()
# If clock is off then initiate start sequence
if self.ftWatchMode == 0:
self.hi, self.w, self.c = img.shape
self.ftStartTime = time.time()
self.ftWatchMode = 1
# If start countdown mode
if self.ftWatchMode == 1:
self.ftSec = int(11 - (cTime - self.ftStartTime))
cv2.putText(img, f"FT {tCap}:", (int(self.w*0.35), int(self.hi*0.1) ),
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
cv2.putText(img, f"{self.ftSec}", (int(self.w * 0.55), int(self.hi * 0.1)),
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
if self.ftSec <= 0:
self.ftWatchMode = 2
self.ftStartTime = time.time()
# If clock running mode
if self.ftWatchMode == 2:
tDiff = cTime - self.ftStartTime
if tDiff >= 60*tCap:
self.ftWatchMode = 0
return False
self.ftSec = int(tDiff % 60)
self.ftMin = int(tDiff // 60)
# Text Format
if self.ftMin < 10:
if self.ftSec < 10:
txt = f'0{self.ftMin}:0{self.ftSec}'
else:
txt = f'0{self.ftMin}:{self.ftSec}'
else:
if self.ftSec < 10:
txt = f'{self.ftMin}:0{self.ftSec}'
else:
txt = f'{self.ftMin}:{self.ftSec}'
cv2.putText(img, txt, (50, 50), cv2.FONT_HERSHEY_PLAIN, 2, (0, 0, 255), 2)
return True
def AMRAP(self, img, tCap, text=True):
# Static Variables
cTime = time.time()
# If clock is off then initiate start sequence
if self.amWatchMode == 0:
self.hi, self.w, self.c = img.shape
self.amStartTime = time.time()
self.amWatchMode = 1
# If start countdown mode
if self.amWatchMode == 1:
self.amSec = int(11 - (cTime - self.amStartTime))
cv2.putText(img, f"AMRAP {tCap}:", (int(self.w*0.35), int(self.hi*0.15) ), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 0, 0), 2)
cv2.putText(img, f"{self.amSec}", (int(self.w * 0.55), int(self.hi * 0.15)),
cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 0, 0), 2)
if self.amSec <= 0:
self.amWatchMode = 2
self.amStartTime = time.time()
# If clock running mode
if self.amWatchMode == 2:
tRemain = 60*tCap - (cTime - self.amStartTime)
if tRemain <= 0:
self.amWatchMode = 0
return False
self.amSec = int(tRemain % 60)
self.amMin = int(tRemain // 60)
# Text Format
if self.amMin < 10:
if self.amSec< 10:
txt = f'0{self.amMin}:0{self.amSec}'
else:
txt = f'0{self.amMin}:{self.amSec}'
else:
if self.amSec < 10:
txt = f'{self.amMin}:0{self.amSec}'
else:
txt = f'{self.amMin}:{self.amSec}'
cv2.putText(img, txt, (self.w - 150, 50), cv2.FONT_HERSHEY_PLAIN, 2, (255, 0, 0), 2)
return True
def EMOM(self, img, interval=1, rounds=10, text=True):
# Static Variables
cTime = time.time()
# If clock is off then initiate start sequence
if self.emWatchMode == 0:
self.hi, self.w, self.c = img.shape
self.emStartTime = time.time()
self.emWatchMode = 1
# If start countdown mode
if self.emWatchMode == 1:
self.emSec = int(11 - (cTime - self.emStartTime))
if interval != 1:
cv2.putText(img, f"E{interval}MOM:", (int(self.w * 0.35), int(self.hi * 0.20)),
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
cv2.putText(img, f"{self.emSec}", (int(self.w * 0.55), int(self.hi * 0.20)),
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
else:
cv2.putText(img, f"EMOM:", (int(self.w * 0.35), int(self.hi * 0.20)),
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
cv2.putText(img, f"{self.emSec}", (int(self.w * 0.55), int(self.hi * 0.20)),
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
if self.emSec <= 0:
self.emWatchMode = 2
self.emStartTime = time.time()
# If clock running mode
if self.emWatchMode == 2:
tRemain = 60 * interval * self.emRound - (cTime - self.emStartTime)
if tRemain <= 0:
self.emRound += 1
if self.emRound > rounds:
self.emRound = 1
self.emWatchMode = 0
return False
return True
self.emSec = int(tRemain % 60)
self.emMin = int(tRemain // 60)
# Text Format
if self.emMin < 10:
if self.emSec < 10:
txt = f'0{self.emMin}:0{self.emSec}'
else:
txt = f'0{self.emMin}:{self.emSec}'
else:
if self.emSec < 10:
txt = f'{self.emMin}:0{self.emSec}'
else:
txt = f'{self.emMin}:{self.emSec}'
if interval != 1:
cv2.putText(img, f"E{interval}MOM: {self.emRound}", (self.w - 400, 75), cv2.FONT_HERSHEY_PLAIN, 2, (0, 0, 255), 2)
cv2.putText(img, txt, (self.w - 150, 75), cv2.FONT_HERSHEY_PLAIN, 2, (255, 0, 0), 2)
else:
cv2.putText(img, str(self.emRound), (self.w - 180, 75), cv2.FONT_HERSHEY_PLAIN, 2, (0, 0, 255), 2)
cv2.putText(img, txt, (self.w - 150, 75), cv2.FONT_HERSHEY_PLAIN, 2, (255, 0, 0), 2)
return True