Ejemplo n.º 1
0
def main(filename, sort_f, size):
    visualize.setup(size)
    arr = [i for i in range(1, size + 1)]
    shuffle(arr)
    for i in sort_f(arr):
        visualize.add_step(arr, highlight=i)
    visualize.render(filename, delay=30)
Ejemplo n.º 2
0
def show_unit_tasks(path, parameters, env):
    group_container = parameters['groups']
    group_path = model.parent(path)+'/'+group_container
    groups = model.load(group_path)
    person_groups = {}
    for g in groups: 
        model.traverse(group_path+'/'+g, lambda (path, task, d): collect_persons(g, path, person_groups), all_nodes=True )    
    persons = set()
    for group in person_groups.values():
        for p in group:
            persons.add(p)        
    dates, slots, s = prepare_people_tasks( persons ) 
    schedules = {}
    for i in s:
        schedules[i[0]]=i
    group_schedules = []    
    for g in person_groups.keys():        
        group_sched = [ g, len(slots)*[0.0], 0, 0, {'url': group_path+'/'+g+'/planning/'} ]
        for _, person in person_groups[g]:
            group_sched[1] = [ group_sched[1][i] + schedules[person][1][i] for i in range(0,len(slots)) ]  
            group_sched[2] += schedules[person][2]
            group_sched[3] += schedules[person][3]
        n = len(person_groups[g])*1.0    
        group_sched[1] = [ i/n for i in group_sched[1] ]
        group_sched[2] /= n
        group_sched[3] /= n
        group_schedules.append(group_sched)    
    return visualize.render(dates, slots, sorted(group_schedules), variables={'qs':urlparse.parse_qs(env['QUERY_STRING']), 'context':'/', 'path':path, 'sum':True, 'url': path+'/', 'refreshable': False }), "text/html"    
Ejemplo n.º 3
0
def show_project(path, parameters, env):
    m=re.match(r"^.*projects/[^/]+/+([^/]+)$", path)
    project=m.group(1)
    # Find people planned on this project
    persons = set()
    model.traverse( '/', lambda p : add_if_working_on(model.normalize(p[0]), project, persons) )     
    dates, slots, s = prepare_people_tasks(  persons, project )
    return visualize.render(dates, slots, sorted(s), variables={'qs':urlparse.parse_qs(env['QUERY_STRING']), 'context':'/', 'path':path, 'sum':True, 'url': path+'/', 'refreshable': False }), "text/html"
Ejemplo n.º 4
0
def render(tasks,
           variables={
               'qs': {},
               'context': '/',
               'path': '/'
           },
           resolution=week,
           expand=[]):
    dates, slots, sched = prepare_schedule(tasks, resolution)
    return visualize.render(dates, slots, sched, variables, resolution, expand)
Ejemplo n.º 5
0
def show_unit_tasks(path, parameters, env):
    group_container = parameters['groups']
    group_path = model.parent(path) + '/' + group_container
    groups = model.load(group_path)
    person_groups = {}
    for g in groups:
        model.traverse(
            group_path + '/' + g,
            lambda (path, task, d): collect_persons(g, path, person_groups),
            all_nodes=True)
    persons = set()
    for group in person_groups.values():
        for p in group:
            persons.add(p)
    dates, slots, s = prepare_people_tasks(persons)
    schedules = {}
    for i in s:
        schedules[i[0]] = i
    group_schedules = []
    for g in person_groups.keys():
        group_sched = [
            g,
            len(slots) * [0.0], 0, 0, {
                'url': group_path + '/' + g + '/planning/'
            }
        ]
        for _, person in person_groups[g]:
            group_sched[1] = [
                group_sched[1][i] + schedules[person][1][i]
                for i in range(0, len(slots))
            ]
            group_sched[2] += schedules[person][2]
            group_sched[3] += schedules[person][3]
        n = len(person_groups[g]) * 1.0
        group_sched[1] = [i / n for i in group_sched[1]]
        group_sched[2] /= n
        group_sched[3] /= n
        group_schedules.append(group_sched)
    return visualize.render(dates,
                            slots,
                            sorted(group_schedules),
                            variables={
                                'qs': urlparse.parse_qs(env['QUERY_STRING']),
                                'context': '/',
                                'path': path,
                                'sum': True,
                                'url': path + '/',
                                'refreshable': False
                            }), "text/html"
Ejemplo n.º 6
0
def show_team_tasks(path, parameters, env):
    people = model.parent(path) + '/people'
    person_list = model.load(people)
    dates, slots, s = prepare_people_tasks([(people, person)
                                            for person in person_list])
    return visualize.render(dates,
                            slots,
                            sorted(s),
                            variables={
                                'qs': urlparse.parse_qs(env['QUERY_STRING']),
                                'context': '/',
                                'path': path,
                                'sum': True,
                                'url': path + '/',
                                'refreshable': True
                            }), "text/html"
Ejemplo n.º 7
0
def show_project(path, parameters, env):
    m = re.match(r"^.*projects/[^/]+/+([^/]+)$", path)
    project = m.group(1)
    # Find people planned on this project
    persons = set()
    model.traverse(
        '/',
        lambda p: add_if_working_on(model.normalize(p[0]), project, persons))
    dates, slots, s = prepare_people_tasks(persons, project)
    return visualize.render(dates,
                            slots,
                            sorted(s),
                            variables={
                                'qs': urlparse.parse_qs(env['QUERY_STRING']),
                                'context': '/',
                                'path': path,
                                'sum': True,
                                'url': path + '/',
                                'refreshable': False
                            }), "text/html"
Ejemplo n.º 8
0
	def plot(self):
		visualize.render(self.terrain, self.cameras, self.pointclouds)
Ejemplo n.º 9
0
    def DQNepisode(self, save_chkpt=False, N_steps=10**4, vid=False):

        R_tot = 0
        self.agent.__init__()

        s = self.agent.observation()
        a = self.epsGreedyAction(s)

        self.agent.action(a)
        r = self.agent.reward
        at = []
        loss = list()

        for i in range(N_steps):

            if i % self.Tau == 0 and i > self.N_batch:
                self.updateTargetNetwork()

            if self.agent.done:
                if self.epsilon > 0.015:
                    self.epsilon *= self.epsdecay
                break

            R_tot += r
            s_next = self.agent.observation()
            a_next = self.epsGreedyAction(s_next)

            experience = (s, a, r, s_next)
            self.samples_Q.append(experience)

            if len(self.samples_Q) >= 2 * self.N_batch:
                #t1=time.time()

                batch_Q_samples = sample(self.samples_Q, self.N_batch)
                states = torch.Tensor(
                    np.array([samp[0] for samp in batch_Q_samples]))
                actions = [samp[1] for samp in batch_Q_samples]
                rewards = torch.Tensor([samp[2] for samp in batch_Q_samples])
                states_next = torch.Tensor(
                    [samp[3] for samp in batch_Q_samples])

                #Get current Q value and target value
                Q_cur = self.forwardPassQ(states)[list(range(len(actions))),
                                                  actions]
                Q_next = torch.max(self.forwardPassQFrozen(states_next),
                                   dim=1)[0]

                TD0_error = F.smooth_l1_loss(
                    Q_cur, (rewards + self.gamma * Q_next).detach())
                loss.append(TD0_error.item())

                self.optimizer.zero_grad()
                TD0_error.backward()
                for param in self.policy_NN.parameters():
                    param.grad.data.clamp_(-1, 1)
                self.optimizer.step()

            s = s_next
            a = a_next

            self.agent.action(a)
            r = self.agent.reward

        if vid:
            env.render(self.agent.loc_history)

        if loss == list():
            return (self.agent.reason, R_tot, 0)
        return (self.agent.reason, R_tot, np.mean(loss))
Ejemplo n.º 10
0
def render(tasks, variables={'qs':{}, 'context':'/', 'path':'/'}, resolution=week, expand=[]):
    dates, slots, sched = prepare_schedule(tasks, resolution)
    return visualize.render(dates, slots, sched, variables, resolution, expand)
Ejemplo n.º 11
0
def show_team_tasks(path, parameters, env):    
    people = model.parent(path)+'/people'
    person_list = model.load(people)
    dates, slots, s = prepare_people_tasks(  [ ( people, person) for person in person_list ] )
    return visualize.render(dates, slots, sorted(s), variables={'qs':urlparse.parse_qs(env['QUERY_STRING']), 'context':'/', 'path':path, 'sum':True, 'url': path+'/', 'refreshable': True }), "text/html"