##// END OF EJS Templates
ATRAD actualizando títulos
ATRAD actualizando títulos

File last commit:

r397:e40954e05ac0
r397:e40954e05ac0
Show More
scheduler.py
112 lines | 4.8 KiB | text/x-python | PythonLexer
Renato Huallpa
Prototipo de Servidor ABS concluido en SIR
r387 from django.core.management.base import BaseCommand
Renato Huallpa
Avance scheduler
r388 from apps.main.models import Campaign, Location
from datetime import datetime,timedelta
from apps.main.views import radar_start
from django.shortcuts import render, redirect,get_object_or_404, HttpResponse
from django.urls import reverse
from django.utils.timezone import is_aware
from django.contrib import messages
from django.http import HttpResponseRedirect
from apps.main.views import experiment_start
from apps.main.models import Experiment, Configuration
Renato Huallpa
Prototipo de Servidor ABS concluido en SIR
r387
class Command(BaseCommand):
"""
Renato Huallpa
Se actualizo SIR con ATRAD
r391 Restart experiment_number every night at 05:00 am.
Renato Huallpa
Prototipo de Servidor ABS concluido en SIR
r387 Example:
manage.py restart_experiment
"""
def handle(self, *args, **options):
Renato Huallpa
Se consiguió el scheduler
r389 print("\n\n")
all_campaigns=Campaign.objects.all()
Renato Huallpa
Avance scheduler
r388 campaigns = Campaign.objects.filter(start_date__lte=datetime.now(),
end_date__gte=datetime.now()).order_by('-start_date')
Renato Huallpa
Se consiguió el scheduler
r389 for campaign in all_campaigns:
if campaign.start_date<datetime.now() and campaign.end_date > datetime.now():
Renato Huallpa
Avance scheduler
r388
radar=campaign.get_experiments_by_radar(radar=None)
Renato Huallpa
Se consiguió el scheduler
r389 for rad in radar:
# print("RADR", rad)
radar_id=rad["id"]
# print("RADR_",radar_id)
Renato Huallpa
Se resolvió plot pattern de ABS
r390 radar_write_start_scheduler(campaign.id,radar_id)
Renato Huallpa
Se consiguió el scheduler
r389 print(campaign.name, "\t\t Campaign already running")
Renato Huallpa
Avance scheduler
r388
Renato Huallpa
Se consiguió el scheduler
r389 else:
Renato Huallpa
Avance scheduler
r388 radar=campaign.get_experiments_by_radar(radar=None)
Renato Huallpa
Se actualizo SIR con ATRAD
r391 # print(campaign.name)
for rad in radar:
radar_id=rad["id"]
# print(radar_id, " ", rad["name"])
for exp in range(len(rad["experiments"])):
experiment=rad["experiments"][exp]
experiment_id= experiment.id
if experiment.status!=1:
print("Stopping Campaign {}, located on {}, the experiment {} with ID {}".format(campaign.name,rad["name"],experiment.name,experiment.id))
status=radar_stop_scheduler(campaign.id,radar_id,experiment.id)
if status == 0:
print("ERROR, status= {}".format(status))
# print("New Status: ", status)
else:
print("{} Experiment of the Campaign {} already stooped".format(experiment.name,campaign.name))
print("\n")
# radar_id=radar[0]["id"]
# if campaign.experiments.all()[0].status !=1:
# print(campaign.name, "\t\t Stopping Campaign...")
# a=radar_stop_scheduler(campaign.id,radar_id,campaign.experiments.all()[0].id)
# print("New Status: ", a)
# else:
# print(campaign.name,"\t\t\t Campaign already stooped")
# EXP_STATES = (
# (0,'Error'), #RED
# (1,'Cancelled'), #YELLOW
# (2,'Running'), #GREEN
# (3,'Scheduled'), #BLUE
# (4,'Unknown'), #WHITE
Renato Huallpa
Avance scheduler
r388
Renato Huallpa
Se resolvió plot pattern de ABS
r390 def radar_write_start_scheduler(id_camp,id_radar):
Renato Huallpa
Avance scheduler
r388 campaign = get_object_or_404(Campaign, pk=id_camp)
experiments = campaign.get_experiments_by_radar(id_radar)[0]['experiments']
Renato Huallpa
Se consiguió el scheduler
r389 # print(campaign)
# print(experiments)
Renato Huallpa
Avance scheduler
r388 for exp in experiments:
exp = get_object_or_404(Experiment, pk=exp.id)
Renato Huallpa
Se consiguió el scheduler
r389 # print("---------DEBUGG-------------")
# print(exp)
Renato Huallpa
Avance scheduler
r388 if exp.status == 2:
Renato Huallpa
Se consiguió el scheduler
r389 print('\t\t\t {} \t\t Experiment already runnnig'.format(exp))
Renato Huallpa
Se actualizo SIR con ATRAD
r391 elif exp.status==5:
print('Experiment {} busy'.format(exp))
Renato Huallpa
Avance scheduler
r388 else:
exp.status = exp.start()
if exp.status == 0:
Renato Huallpa
Se consiguió el scheduler
r389 print('\t\t\t {} \t\tExperiment not start'.format(exp))
Renato Huallpa
Avance scheduler
r388 if exp.status == 2:
Renato Huallpa
Se consiguió el scheduler
r389 print('\t\t\t {} \t\tExperiment started'.format(exp))
if exp.status == 4:
Renato Huallpa
Se resolvió plot pattern de ABS
r390 print('\t\t\t {} \t\tExperiment with state uknown, please reset (Stop and start manually)'.format(exp))
Renato Huallpa
Avance scheduler
r388 exp.save()
Renato Huallpa
Prototipo de Servidor ABS concluido en SIR
r387
Renato Huallpa
Avance scheduler
r388 def radar_stop_scheduler(id_camp,id_radar,id_experiment):
'''
Stop experiments's devices
DDS-JARS-RC-CGS-ABS
'''
exp=get_object_or_404(Experiment,pk=id_experiment)
Renato Huallpa
Prototipo de Servidor ABS concluido en SIR
r387
Renato Huallpa
Avance scheduler
r388 if exp.status == 2:
confs = Configuration.objects.filter(experiment=id_experiment,type = 0).order_by('device__device_type__sequence')
confs = confs.exclude(device__device_type__name='cgs')
try:
for conf in confs:
Renato Huallpa
Se consiguió el scheduler
r389 # print(conf)
Renato Huallpa
Avance scheduler
r388 conf.stop_device()
exp.status= 1
except:
exp.status= 0
exp.save()
Renato Huallpa
Prototipo de Servidor ABS concluido en SIR
r387
Renato Huallpa
Avance scheduler
r388 return exp.status