-
Notifications
You must be signed in to change notification settings - Fork 0
/
restrictions.py
47 lines (40 loc) · 1.53 KB
/
restrictions.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 datetime import datetime
import utilities
def restrictionDays(date, licensePlate):
"""
Each day is represented by a number, Monday=0...Sunday-6
during weekdays, according to each day, if a license plate has
one of those digits as its last one, is subject to the Pico y Placa restrictions
I.E: on Mondays, a car with its license plate ending on 1 or 2
is subject to restrictions
"""
plateNumbersPerDay={
0:[1,2],
1:[3,4],
2:[5,6],
3:[7,8],
4:[9,0],
5:[],
6:[]}
day=datetime.strptime(date, '%d/%m/%Y').weekday()
if day == 6 or day == 7:
return False
else:
dayRestrictions=plateNumbersPerDay[day] #Gets the plate's last digits that cannot be on the road acording to day
lastDigit=licensePlate[-1] #Get the input plate's last digit to check if is allowed or not to be on the road
if lastDigit in dayRestrictions:
return True
else:
return False
def restrictionHours(time):
restrictedHours={
"AM":["7:00","9:30"],
"PM":["16:00","19:30"]}
hour=datetime.strptime(time, "%H:%M").time()
AMRestrictionStartTime, AMRestrictionEndTime = utilities.getRestrictionHours(restrictedHours["AM"])
PMRestrictionStartTime, PMRestrictionEndTime = utilities.getRestrictionHours(restrictedHours["PM"])
if AMRestrictionStartTime <= hour <= AMRestrictionEndTime:
return True
if PMRestrictionStartTime <= hour <= PMRestrictionEndTime:
return True
return False