Advertisement
Guest User

Untitled

a guest
Dec 14th, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.11 KB | None | 0 0
  1. def get_start_time(schedules, duration):
  2.     print(schedules, duration)
  3.     time_management = [["{:02d}".format(i), [int(l) for l in range(0, 60) if i != 19]] for i in range(9, 20)]
  4.  
  5.     for row in schedules:
  6.         for time in row:
  7.             if time[0][3:].startswith("0") and time[0][3:] != "0":
  8.                 time[0] = time[0][:3] + time[0][4:]
  9.             elif time[1][3:].startswith("0") and time[1][3:] != "0":
  10.                 time[1] = time[1][:3] + time[1][4:]
  11.  
  12.     for row in schedules:
  13.         for time in row:
  14.             scope = []
  15.             for elem in time_management: ##Находим индексы schedules в timemanagement
  16.                 if elem[0] == time[0][:2]:
  17.                     scope.append(time_management.index(elem))
  18.                 if elem[0] == time[1][:2]:
  19.                     scope.append(time_management.index(elem))
  20.  
  21.             if scope[0] == scope[1]:
  22.                 for j in range(int(time[0][3:]), int(time[1][3:])):
  23.                     time_management[scope[0]][1][j] = 'x'
  24.             elif scope[0] != scope[1]:
  25.                 for i in range(scope[0], scope[1] + 1):
  26.                     if i == scope[0]:
  27.                         for j in range(int(time[0][3:]), 60):
  28.                             time_management[i][1][j] = 'x'
  29.                     elif i == scope[1]:
  30.                         for j in range(int(time[1][3:])):
  31.                             time_management[i][1][j] = 'x'
  32.                     else:
  33.                         for j in range(60):
  34.                             time_management[i][1][j] = 'x'
  35.     scope = []
  36.     counter = 0
  37.     for block in time_management:
  38.         for i in range(len(block[1])):
  39.             if block[1][i] != 'x':
  40.                 counter += 1
  41.                 if counter == 1:
  42.                     scope.append(block[0])
  43.                     scope.append(block[1][i])
  44.                     print(scope)
  45.                 if counter == duration:
  46.                     return str(scope[0]) + ":" + "{:02d}".format(scope[1])
  47.             else:
  48.                 scope = []
  49.                 counter = 0
  50.     return None
  51.     return None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement