Created
May 13, 2013 16:57
-
-
Save radiosilence/5569771 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
total = 900 | |
blocks = [(datetime.datetime(*start), datetime.datetime(*end), q) for start, end, q in [ | |
((2012,01,02,8,00), (2012,01,10,10,32), 3), | |
((2012,01,02,8,00), (2012,01,10,10,32), 3), | |
((2012,01,01,8,00), (2012,01,12,10,32), 1), | |
((2012,01,02,8,00), (2012,01,10,10,32), 3), | |
((2012,01,02,8,00), (2012,01,10,10,32), 3), | |
((2012,01,01,8,00), (2013,01,12,10,32), 1), | |
((2012,01,02,8,00), (2012,01,10,10,32), 3), | |
((2012,01,01,8,00), (2012,01,12,10,32), 1), | |
((2012,01,02,8,00), (2012,01,10,10,32), 3), | |
((2012,01,02,8,00), (2012,01,10,10,32), 3), | |
((2012,01,01,8,00), (2013,01,12,10,32), 1), | |
((2012,01,02,8,00), (2012,01,10,10,32), 3), | |
((2012,01,01,8,00), (2012,01,12,10,32), 1), | |
((2012,01,02,8,00), (2012,01,10,10,32), 3), | |
((2012,01,02,8,00), (2012,01,10,10,32), 3), | |
((2012,01,01,8,00), (2013,01,12,10,32), 1), | |
((2012,01,02,8,00), (2012,01,10,10,32), 3), | |
((2012,01,01,8,00), (2012,01,12,10,32), 1), | |
((2012,01,02,8,00), (2012,01,10,10,32), 3), | |
((2012,01,02,8,00), (2012,01,10,10,32), 3), | |
((2012,01,01,8,00), (2013,01,12,10,32), 1), | |
((2012,01,02,8,00), (2012,01,10,10,32), 3), | |
((2012,01,01,8,00), (2012,01,12,10,32), 1), | |
((2012,01,02,8,00), (2012,01,10,10,32), 3), | |
((2012,01,02,8,00), (2012,01,10,10,32), 3), | |
((2012,01,01,8,00), (2013,01,12,10,32), 1), | |
((2012,01,02,8,00), (2012,01,10,10,32), 3), | |
((2012,01,01,8,00), (2012,01,12,10,32), 1), | |
((2012,01,02,8,00), (2012,01,10,10,32), 3), | |
((2012,01,02,8,00), (2012,01,10,10,32), 3), | |
((2012,01,01,8,00), (2013,01,12,10,32), 1), | |
((2012,01,02,8,00), (2012,01,10,10,32), 3), | |
((2012,01,01,8,00), (2012,01,12,10,32), 1), | |
((2012,01,02,8,00), (2012,01,10,10,32), 3), | |
((2012,01,02,8,00), (2012,01,10,10,32), 3), | |
((2012,01,01,8,00), (2013,01,12,10,32), 1), | |
((2012,01,02,8,00), (2012,01,10,10,32), 3), | |
((2012,01,01,8,00), (2012,01,12,10,32), 1), | |
((2012,01,02,8,00), (2012,01,10,10,32), 3), | |
((2012,01,02,8,00), (2012,01,10,10,32), 3), | |
((2012,01,01,8,00), (2013,01,12,10,32), 1), | |
]] | |
allocated = [] | |
def get_graph(total, allocated): | |
pass | |
def get_avail_at_point(total, allocated, point): | |
avail = total | |
for start, end, quantity in allocated: | |
if start < point and end > point: | |
avail -= quantity | |
return avail | |
def try_add(total, allocated, start, end, quantity): | |
granularity = datetime.timedelta(minutes=30) | |
x = start | |
while x <= end: | |
avail = get_avail_at_point(total, allocated, x) | |
if avail < quantity: | |
raise Exception("Cannot add because availability is {} at {}".format( | |
avail, x)) | |
x += granularity | |
allocated.append((start, end, quantity)) | |
for block in blocks: | |
try_add(total, allocated, *block) | |
print allocated |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment