import random
from Task import Task

def random_element(prog):
    ''' Generates a random value between -25 and 25 used as a percentage to offset prog.
    '''
    amount = float(random.randint(-25, 25))
    direction = random.choice([-1, 1])
    return prog * (1 + (amount / 100.0))

class Module(object):
    def __init__(self, name, cost):
        self.name = name
        self.expected_cost = cost
        self.actual_cost = random_element(cost)
        self.modules = list()
        self.tasks = list()
        self.completed_tasks = list()

        self.tasks.append(Task('design', self.actual_cost/100*15, self))
        self.tasks.append(Task('implementation', self.actual_cost/100*15, self))
        self.tasks.append(Task('unit_test', self.actual_cost/100*10, self))
        self.tasks.append(Task('integration', self.actual_cost/100*15, self))
        self.tasks.append(Task('system_test', self.actual_cost/100*15, self))
        self.tasks.append(Task('deployment', self.actual_cost/100*15, self))
        self.tasks.append(Task('acceptance_test', self.actual_cost/100*15, self))

        self.progress = 0.0
        self.completed = False
        self.stalled = False
        self.hours_taken = 0 # This is productive time
        self.total_hours = 0 # number of hours from start of project including non productive hours. 

    # TODO: Consider changing tasks to be a dictionary for O(1) lookups
    # by name.
    # Doing a linear search through the list here will be slow and a dict
    # would be preferable.

    # Reason for list is so task have to be performed in order. 
    def get_task(self, name):
        ''' Returns the task object which matches the name specified if it exists, None otherwise.
        '''
        tasks = [task for task in self.tasks if task.name == name]
        if tasks:
            return tasks[0]
        else:
            return None

    def is_on_time(self):
        ''' Returns True if the progress of this task is at least equal to 75% of the expected progress,
        False otherwise
        '''
        return self.progress < (self.actual_cost * .75)

    def expected_cost()
        return self.expected_cost

    def actual_cost()
        return self.actual_cost

    def wall_clock_time()
        return self.total_hours

    def productive_time_on_task()
        return self.hours_taken

>>>>>>> ddaabbd4474c2fa64a6e814b8a93880e410e734b



@@ -2122,24 +2122,25 @@
 ected_cost()
+:
 %0A        ret
@@ -2180,24 +2180,25 @@
 ctual_cost()
+:
 %0A        ret
@@ -2244,16 +2244,17 @@
 k_time()
+:
 %0A       
@@ -2312,16 +2312,17 @@
 n_task()
+:
 %0A       
@@ -2351,55 +2351,7 @@
 en%0A%0A
-%3E%3E%3E%3E%3E%3E%3E ddaabbd4474c2fa64a6e814b8a93880e410e734b
 %0A%0A%0A

fix to syntax declaring Module functions