-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
117 lines (101 loc) · 3.35 KB
/
test.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import datetime
from prometheus_client import Enum
class DayPeriods(Enum):
MORNING = 0
AFTERNOON = 1
EVENING = 2
class ScheduledTime:
year : int
month : int
day : int
startTime : int
endTime : int
hours : int
court : int
def __init__(self, year, month, day, startTime, endTime, hours, court):
self._year = int(year)
self._month = int(month)
self._day = int(day)
self._startTime = int(startTime)
self._endTime = int(endTime)
self._hours = int(hours)
self._court = int(court)
self._bookingGap = 3
self._prepareTime = 10
self._bufferTime = 10
if self._endTime <= self._startTime or self._startTime < 6 or self._endTime > 22:
raise BaseException("Time Invalid Error")
if not self.isVaildDate():
raise BaseException("Date Invalid Error")
def getScheduledDate(self):
if self._month < 10:
orderDay = str(self._year) + '/0'+ str(self._month)
else:
orderDay = str(self._year) + '/'+ str(self._month)
if self._day < 10:
orderDay = orderDay + '/0' + str(self._day)
else:
orderDay = orderDay + '/' + str(self._day)
return orderDay
def getScheduledDateWithBuffer(self):
orderDay = self.getScheduledDate()
orderDay = orderDay + '/' + str(self._bufferTime)
return orderDay
def getCalendarDayPeriods(self):
if self._startTime >= 18:
return 2
elif self._startTime >= 12:
return 1
else:
return 0
def getStartTime(self):
return self._startTime
def getEndTime(self):
return self._endTime
def getOrderCourts(self):
return self._court
def getOrderTime(self):
return self._hours
def isVaildDate(self):
now = datetime.datetime.now()
target = datetime.datetime.strptime(self.getScheduledDate(), "%Y/%m/%d")
delta = target - now
if(delta.days < 0):
return 0
else :
return 1
def isAfterPrepareTime(self):
now = datetime.datetime.now()
target = datetime.datetime.strptime(self.getScheduledDate(), "%Y/%m/%d")
shift = datetime.timedelta(days=self._bookingGap)
prepareTime = datetime.timedelta(seconds=self._prepareTime)
now = now + shift
target = target - prepareTime
delta = target - now
print("delta.day = {}", delta.days)
print("delta.second = {}", delta.seconds)
if delta.days > 0:
return 1
else :
return 0
def isAfterBufferTime(self):
now = datetime.datetime.now()
target = datetime.datetime.strptime(self.getScheduledDate(), "%Y/%m/%d")
shift = datetime.timedelta(days=self._bookingGap)
bufferTime = datetime.timedelta(seconds=self._bufferTime)
now = now + shift
target = target + bufferTime
delta = target - now
print("delta.day = {}", delta.days)
print("delta.second = {}", delta.seconds)
if __name__ == '__main__':
year = 2022
month = 12
day = 30
startTime = 19
endTime = 22
hours = 2
court = 1
time2week = ScheduledTime(year, month, day, startTime, endTime, hours, court)
print (time2week.isAfterPrepareTime())
pass