Blame view

src/scheduler/views.py 2.75 KB
7a1effdd   haribo   scheduler app cre...
1
from django.shortcuts import render
ddf59dd4   haribo   Remaniement :
2
from common.models import Sequence, Schedule
94082e77   haribo   Date: 03/06/2016
3
from django.contrib.auth.decorators import login_required
715fabb7   haribo   #3430 (100%)
4
5
6
7
8
from scheduler.simulator import Simulator
from operator import attrgetter

SIMULATION_FILE = 'file:./scheduler/sequences_cador.html'

5ab53768   Jeremy   Scheduler view is...
9
def retrieve_schedule(request):
e39312f1   Jeremy   Fix bug on schedu...
10
11
    if (len(Schedule.objects.all()) > 0):                       # checking if the schedule is empty
        schedule = Schedule.objects.order_by("-created")[0]     # Sorting Schedule
ff448d43   Jeremy   Update
12
        shs_list = schedule.shs.order_by("tsp")                 # getting all the schedule has sequences references
e39312f1   Jeremy   Fix bug on schedu...
13
14
15
16
17
18
19
20
21
22
        sequences = [(shs.sequence, shs) for shs in shs_list]   # getting all sequences

        nb_scheduled_sequences = len(shs_list)
        executed_sequences = len([shs for shs in shs_list if shs.status == Sequence.EXECUTED])
    else: # if empty set everything to 0 / None (variables are checked in src/templates/scheduler/current_schedule.html)
        schedule = None
        sequences = None
        shs_list = None
        nb_scheduled_sequences = 0
        executed_sequences = 0
2c61f856   theopuhl   Url change to pat...
23
24
25
    if request.user.is_authenticated:
        return render(request, 'scheduler/retrieve_schedule.html', {'sequences' : sequences, 'schedule' : schedule, 'nb_scheduled_sequences' : nb_scheduled_sequences, 'executed_sequences' : executed_sequences, 'base_template' : "base.html"})
    return render(request, 'scheduler/retrieve_schedule.html', {'sequences' : sequences, 'schedule' : schedule, 'nb_scheduled_sequences' : nb_scheduled_sequences, 'executed_sequences' : executed_sequences, 'base_template' : "base_unlogged.html"})
715fabb7   haribo   #3430 (100%)
26

715fabb7   haribo   #3430 (100%)
27

5ab53768   Jeremy   Scheduler view is...
28
def current_schedule(request):
2c61f856   theopuhl   Url change to pat...
29
30
31
    if request.user.is_authenticated:
        return render(request, 'scheduler/current_schedule.html', {'base_template' : "base.html"})
    return render(request, 'scheduler/current_schedule.html', {'base_template' : "base_unlogged.html"})
715fabb7   haribo   #3430 (100%)
32

715fabb7   haribo   #3430 (100%)
33
34
35
def schedule_simulation(request):
    simulator = Simulator()
    schedule, sequences = simulator.simulate(SIMULATION_FILE)
7a79e25b   haribo   Date: 19/05/2016
36

ff448d43   Jeremy   Update
37
    nb_scheduled_sequences = len([sequence for sequence in sequences if sequence[1].status != Sequence.PLANNED])
7a79e25b   haribo   Date: 19/05/2016
38
39
40
41
    executed_sequences = len([sequence for sequence in sequences if sequence[1].status == Sequence.EXECUTED])


    sequences.sort(key=lambda seq: seq[1].tsp)
2c61f856   theopuhl   Url change to pat...
42
43
44
    if request.user.is_authenticated:
        return render(request, 'scheduler/current_schedule.html', {'sequences' : sequences, 'schedule' : schedule, 'nb_scheduled_sequences' : nb_scheduled_sequences, 'executed_sequences' : executed_sequences, 'base_template' : "base.html"})
    return render(request, 'scheduler/current_schedule.html', {'sequences' : sequences, 'schedule' : schedule, 'nb_scheduled_sequences' : nb_scheduled_sequences, 'executed_sequences' : executed_sequences, 'base_template' : "base_unlogged.html"})