Beispiel #1
0
def test_bucket_scheduler(buckets, tasks):
    "TODO: improve checking for time availability"
    assume(all(task[1] <= len(buckets) for task in tasks))
    assume(all(task[1] > 0 for task in tasks))
    assume(all(bucket >= 0 for bucket in buckets)) #for faster testing
    assume(sum(task[0] for task in tasks) <= sum(bucket for bucket in buckets))
    fixed_buckets = [(x, {}) for x in buckets]
    fixed_tasks = []
    for i, (x, y) in enumerate(tasks):
        fixed_tasks.append((str(i), x, y))
    try:
        buckets = bucket_scheduler(fixed_buckets, fixed_tasks)
    except NotEnoughTime:
        return
    buckets = grow_buckets(buckets, fixed_tasks)
    grown_buckets = {}
    for _hours, d in buckets:
        for task_name, hours in d.iteritems():
            if task_name in grown_buckets:
                grown_buckets[task_name] += hours
            else:
                grown_buckets[task_name] = hours
    task_buckets = {}
    for name, hours_remaining, _last_bucket_num in fixed_tasks:
        if hours_remaining > 0:
            task_buckets[name] = hours_remaining
    assert grown_buckets == task_buckets
def test(buckets, tasks):
    fixed_buckets = [(x, {}) for x in buckets]
    fixed_tasks = []
    for i, (x, y) in enumerate(tasks):
        fixed_tasks.append((str(i), x, y))
    try:
        buckets = bucket_scheduler(fixed_buckets, fixed_tasks)
    except NotEnoughTime:
        return
    grow_buckets(buckets, fixed_tasks)
Beispiel #3
0
    def _calc_agenda_assignments(self, assignments, work_today, max_days, plan_tasks):
        assert plan_tasks is not None
        if not work_today:
            plan_tasks[0][0] = 0

        #format tasks in bucket_scheduler way
        tasks = []
        for task in assignments:
            if task.due > datetime.date.today():
                tasks.append((task.description, task.hours, (task.due - datetime.date.today()).days))
        
        #get the schedule
        plan_tasks = bucket_scheduler(plan_tasks, tasks)

        if max_days:
            plan_tasks = grow_buckets(plan_tasks, tasks)

        return plan_tasks
Beispiel #4
0
def test_bucket_scheduler_constrained():
    buckets = [(8, {}), (0, {}), (8, {})]
    tasks = [("test1", 8, 2)]
    bucket_scheduler(buckets, tasks)
Beispiel #5
0
def test_bucket_scheduler_dev():
    buckets = [(8, {}), (0, {}), (8, {})]
    tasks = [("test1", 4, 2), ("test2", 4, 3)]
    buckets = bucket_scheduler(buckets, tasks)
    print grow_buckets(buckets, tasks)