views.py
1.59 KB
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("plan_start")[0]
sequences = schedule.sequences.order_by('tsp') # pas certain que ça fonctionne
nb_scheduled_sequences = len(sequences)
executed_sequences = len([sequence for sequence in sequences if sequence.status == Sequence.EXECUTED])
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.status != Sequence.OBSERVABLE])
executed_sequences = len([sequence for sequence in sequences if sequence.status == Sequence.EXECUTED])
sequences.sort(key=attrgetter("tsp"))
return render(request, 'scheduler/current_schedule.html', {'sequences' : sequences, 'schedule' : schedule, 'nb_scheduled_sequences' : nb_scheduled_sequences, 'executed_sequences' : executed_sequences})