views.py
1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from django.shortcuts import render
from pyrosapp.models import Sequence, Schedule
from scheduler.simulator import Simulator
from operator import attrgetter
SIMULATION_FILE = 'file:./scheduler/sequences_cador.html'
def current_schedule(request):
schedule = Schedule.objects.order_by("-created")[0]
shs_list = schedule.shs.all()
sequences = [(shs.sequence, shs) for shs in shs_list]
nb_scheduled_sequences = len(shs_list)
executed_sequences = len([shs for shs in shs_list if shs.status == Sequence.EXECUTED])
# utile ? n'est plus adapté :
# observable_sequences = Sequence.objects.filter(status="OBSERVABLE")
# for sequence in observable_sequences:
# if min(sequence.jd2, schedule.plan_end) - max(sequence.jd1, schedule.plan_start) >= sequence.duration:
# sequences.append(sequence)
return render(request, 'scheduler/current_schedule.html', {'sequences' : sequences, 'schedule' : schedule, 'nb_scheduled_sequences' : nb_scheduled_sequences, 'executed_sequences' : executed_sequences})
def schedule_simulation(request):
simulator = Simulator()
schedule, sequences = simulator.simulate(SIMULATION_FILE)
nb_scheduled_sequences = len([sequence for sequence in sequences if sequence[1].status != Sequence.OBSERVABLE])
executed_sequences = len([sequence for sequence in sequences if sequence[1].status == Sequence.EXECUTED])
sequences.sort(key=lambda seq: seq[1].tsp)
return render(request, 'scheduler/current_schedule.html', {'sequences' : sequences, 'schedule' : schedule, 'nb_scheduled_sequences' : nb_scheduled_sequences, 'executed_sequences' : executed_sequences})