I am writing a script to find meeting time for three people. I manage to get their Free/Busy status encoding in a binary format with 0 being free and 1 being busy in increment of 30 minutes for the next three days. I grouped their status by day into a dictionary format as below.
print(date_schedule)
{'Monday, 2020-02-03': ['000000000000000000101101001110110000000000000000',
'000000000000000000001111011100001100000000000000',
'000000000000000011110100011000110000000000000000'],
'Tuesday, 2020-02-04': ['000000000000000000100010000000000000000000000000',
'000000000000000000001111001000110000000000000000',
'000000000000000011111000111100101000000000000000'],
'Wednesday, 2020-02-05': ['000000000000000000111000000000000000000000000000',
'000000000000000001001100110000000000000000000000',
'000000000000000000111100000001001000000000000000']}
Goal: Translate those 0 into a block of thirty minutes intervals.
For Example: 00:00----00:30
00:30----01:00
...
23:30----24:00
Attempted:
#Separate the code into a two dimensional list
schedule = date_free.values()
#Append the block to a new list.
free = []
for value in schedule:
for v in value:
for idx, time in enumerate(v):
if time == '0':
idx = idx/2
end = idx + 0.5
#5 slots, and two decimals
idx = '{:05.2f}'.format(idx).replace('.50','.30').replace('.',':')
end = '{:05.2f}'.format(end).replace('.50','.30').replace('.',':')
free.append((idx + '----' + end))
Problem: free has 372 elements and I don't know how to make it become a two-dimensional-list structure as it was before in schedule (because the number of 0 is different for each v). Is there a way to not creating a new list but directly apply the above logic element-wise to schedule?
Bonus question: I have not gotten there yet, but my next goal is to find the intersection of those 30 time block for each day as demonstrated in the random example below. If you have any suggestions, please let me know
print(date_time_final)
{'Monday, 2020-02-03': ['08:00----08:30','09:30----10:00','12:00----12:30'],
'Tuesday, 2020-02-04' : ['09:00----09:30','10:30----11:00','13:00----13:30','14:00----14:30']
'Wednesday, 2020-02-05' : ['07:00----07:30','14:30----15:00','15:00----15:30','19:00----19:30']}
Thank you in advance for your help!