-
Notifications
You must be signed in to change notification settings - Fork 0
/
new.py
94 lines (73 loc) · 1.67 KB
/
new.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
from datetimerange import DateTimeRange
def same_time(rows):
ll = []
counter = 0
for i in range(0, len(rows)):
for j in range(i + 1, len(rows)):
if rows[i]['time'].is_intersection(rows[j]['time']):
counter += 1
ll.append([rows[i]['id'],rows[j]['id']])
return ll
def same_days(rows,day_name):
ll = []
counter = 0
for item in rows:
if item['day'] == day_name :
counter+=1
ll.append(item)
if counter > 1:
return ll
else:
return []
def make_rows(rows):
ll = []
for item in rows:
collection = {
'id': item['id'],
'day': item['day'],
'time': DateTimeRange("2019-03-22T%s+0900" % item['time']['start'], "2019-03-22T%s+0900" % item['time']['end']),
}
ll.append(collection)
return ll
before = [
{
'id': 1,
'day': 'shanbe',
'time': {
'start':'8:00:00',
'end':'10:00:00',
}
},
{
'id': 2,
'day': 'doshanbe',
'time': {
'start': '9:30:00',
'end': '11:00:00',
}
},
{
'id': 3,
'day': 'shanbe',
'time': {
'start': '9:00:00',
'end': '14:30:00',
}
},
{
'id': 4,
'day': 'shanbe',
'time': {
'start': '9:30:00',
'end': '12:00:00',
}
}
]
rows = make_rows(before)
ll = []
for item in ['saturday','sunday','monday','tuesday','wednesday']:
day = same_days(rows,item)
time = same_time(day)
if(time):
ll.append(time)
print(ll[0])