@@ -353,7 +353,7 class ABSConfiguration(Configuration): | |||
|
353 | 353 | |
|
354 | 354 | |
|
355 | 355 | def stop_device(self): |
|
356 | ||
|
356 | print("estoy en ABS models") | |
|
357 | 357 | self.device.status = 2 |
|
358 | 358 | self.device.save() |
|
359 | 359 | self.message = 'ABS has been stopped.' |
@@ -13,7 +13,7 lista_ack_dismatching=[ | |||
|
13 | 13 | |
|
14 | 14 | def on_connect(mqtt_client, userdata, flags, rc): |
|
15 | 15 | if rc == 0: |
|
16 | print('Connected successfully') | |
|
16 | # print('Connected successfully') | |
|
17 | 17 | mqtt_client.subscribe(os.environ.get('TOPIC_ABS_ACK','abs/beams_ack')) |
|
18 | 18 | else: |
|
19 | 19 | print('Bad connection. Code:', rc) |
@@ -6,7 +6,7 import numpy as np | |||
|
6 | 6 | |
|
7 | 7 | def on_connect(mqtt_client, userdata, flags, rc): |
|
8 | 8 | if rc == 0: |
|
9 | print('Connected successfully') | |
|
9 | # print('Connected successfully') | |
|
10 | 10 | mqtt_client.subscribe('atrad/test3') |
|
11 | 11 | else: |
|
12 | 12 | print('Bad connection. Code:', rc) |
@@ -1,5 +1,14 | |||
|
1 | 1 | from django.core.management.base import BaseCommand |
|
2 | ||
|
2 | from apps.main.models import Campaign, Location | |
|
3 | from datetime import datetime,timedelta | |
|
4 | from apps.main.views import radar_start | |
|
5 | from django.shortcuts import render, redirect,get_object_or_404, HttpResponse | |
|
6 | from django.urls import reverse | |
|
7 | from django.utils.timezone import is_aware | |
|
8 | from django.contrib import messages | |
|
9 | from django.http import HttpResponseRedirect | |
|
10 | from apps.main.views import experiment_start | |
|
11 | from apps.main.models import Experiment, Configuration | |
|
3 | 12 | |
|
4 | 13 | class Command(BaseCommand): |
|
5 | 14 | """ |
@@ -8,12 +17,87 class Command(BaseCommand): | |||
|
8 | 17 | manage.py restart_experiment |
|
9 | 18 | """ |
|
10 | 19 | def handle(self, *args, **options): |
|
11 |
print(" |
|
|
20 | print("") | |
|
21 | campaigns = Campaign.objects.filter(start_date__lte=datetime.now(), | |
|
22 | end_date__gte=datetime.now()).order_by('-start_date') | |
|
23 | ||
|
24 | if campaigns: | |
|
25 | ||
|
26 | for campaign in campaigns: | |
|
27 | print(campaign.name) | |
|
28 | print(campaign.start_date) | |
|
29 | print(campaign.end_date) | |
|
30 | print(campaign.experiments.all()[0].id) | |
|
31 | print("STATUS: ",campaign.experiments.all()[0].status) | |
|
32 | ||
|
33 | radar=campaign.get_experiments_by_radar(radar=None) | |
|
34 | radar_id=radar[0]["id"] | |
|
35 | print(radar_id) | |
|
36 | ||
|
37 | now = datetime.now() | |
|
38 | if now<campaign.end_date and now >campaign.start_date: | |
|
39 | print("La campaΓ±a",campaign.name ,"se ejecuta!",flush=True) | |
|
40 | radar_start_scheduler(campaign.id,radar_id) | |
|
41 | ||
|
42 | else: | |
|
43 | copy_campaigns=Campaign.objects.all() | |
|
44 | print("-------------Deteniendo procesos-------------") | |
|
45 | for campaign in copy_campaigns: | |
|
46 | print(campaign.name) | |
|
47 | print(campaign.start_date) | |
|
48 | print(campaign.end_date) | |
|
49 | print("ID: ",campaign.experiments.all()[0].id) | |
|
50 | print("STATUS: ",campaign.experiments.all()[0].status) | |
|
51 | print("----,,,---") | |
|
52 | radar=campaign.get_experiments_by_radar(radar=None) | |
|
53 | radar_id=radar[0]["id"] | |
|
54 | ||
|
55 | if campaign.experiments.all()[0].status !=1: | |
|
56 | print("Estoy en :",campaign.experiments.all()[0].status) | |
|
57 | print("Con ID: ",campaign.experiments.all()[0].id) | |
|
58 | print("\n\n") | |
|
59 | a=radar_stop_scheduler(campaign.id,radar_id,campaign.experiments.all()[0].id) | |
|
60 | print("RETURN", a) | |
|
61 | ||
|
62 | ||
|
63 | def radar_start_scheduler(id_camp,id_radar): | |
|
64 | print("-------------------") | |
|
65 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
|
66 | experiments = campaign.get_experiments_by_radar(id_radar)[0]['experiments'] | |
|
67 | now = datetime.now() | |
|
68 | ||
|
69 | for exp in experiments: | |
|
70 | exp = get_object_or_404(Experiment, pk=exp.id) | |
|
12 | 71 | |
|
13 | # def main(): | |
|
14 | # print("Hola") | |
|
72 | if exp.status == 2: | |
|
73 | print('Experiment {} already runnnig'.format(exp)) | |
|
74 | else: | |
|
75 | exp.status = exp.start() | |
|
76 | if exp.status == 0: | |
|
77 | print('Experiment {} not start'.format(exp)) | |
|
78 | if exp.status == 2: | |
|
79 | print('Experiment {} started'.format(exp)) | |
|
80 | exp.save() | |
|
15 | 81 | |
|
16 | # if __name__=='__main__': | |
|
17 | # main() | |
|
82 | def radar_stop_scheduler(id_camp,id_radar,id_experiment): | |
|
83 | print("-------------------") | |
|
84 | ''' | |
|
85 | Stop experiments's devices | |
|
86 | DDS-JARS-RC-CGS-ABS | |
|
87 | ''' | |
|
88 | exp=get_object_or_404(Experiment,pk=id_experiment) | |
|
18 | 89 | |
|
90 | if exp.status == 2: | |
|
91 | confs = Configuration.objects.filter(experiment=id_experiment,type = 0).order_by('device__device_type__sequence') | |
|
92 | confs = confs.exclude(device__device_type__name='cgs') | |
|
93 | try: | |
|
94 | for conf in confs: | |
|
95 | print("Estoy en conf_scheduler") | |
|
96 | print(conf) | |
|
97 | conf.stop_device() | |
|
98 | exp.status= 1 | |
|
99 | except: | |
|
100 | exp.status= 0 | |
|
101 | exp.save() | |
|
19 | 102 | |
|
103 | return exp.status No newline at end of file |
@@ -334,7 +334,6 class Campaign(models.Model): | |||
|
334 | 334 | dum['id'] = loc.pk |
|
335 | 335 | dum['experiments'] = [e for e in self.experiments.all() if e.location==loc] |
|
336 | 336 | ret.append(dum) |
|
337 | ||
|
338 | 337 | return ret |
|
339 | 338 | |
|
340 | 339 | def get_absolute_url(self): |
@@ -12,7 +12,7 lista_ack=[ | |||
|
12 | 12 | |
|
13 | 13 | def on_connect(mqtt_client, userdata, flags, rc): |
|
14 | 14 | if rc == 0: |
|
15 | print('Connected successfully') | |
|
15 | #print('Connected successfully') | |
|
16 | 16 | mqtt_client.subscribe(os.environ.get('TOPIC_ABS_ACK','abs/beams_ack')) |
|
17 | 17 | else: |
|
18 | 18 | print('Bad connection. Code:', rc) |
@@ -1927,7 +1927,7 def operation(request, id_camp=None): | |||
|
1927 | 1927 | |
|
1928 | 1928 | @login_required |
|
1929 | 1929 | def radar_start(request, id_camp, id_radar): |
|
1930 | ||
|
1930 | print("Boton presionados",flush=True) | |
|
1931 | 1931 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
1932 | 1932 | experiments = campaign.get_experiments_by_radar(id_radar)[0]['experiments'] |
|
1933 | 1933 | now = datetime.now() |
@@ -1935,18 +1935,18 def radar_start(request, id_camp, id_radar): | |||
|
1935 | 1935 | for exp in experiments: |
|
1936 | 1936 | #app.control.revoke(exp.task) |
|
1937 | 1937 | print("----------------------") |
|
1938 | print("status:->", exp.status) | |
|
1938 | print("status:->", exp.status,flush=True) | |
|
1939 | 1939 | start = datetime.combine(datetime.now().date(), exp.start_time) |
|
1940 | 1940 | end = datetime.combine(datetime.now().date(), exp.end_time) |
|
1941 | print("start exp: ",exp.start_time) | |
|
1942 | print("end exp: ",exp.end_time) | |
|
1943 | ||
|
1944 | print("start comb: ",start) | |
|
1945 | print("end comb: ",end) | |
|
1946 | print(is_aware(start)) | |
|
1947 | print("start camp",campaign.start_date) | |
|
1948 | print("end camp",campaign.end_date) | |
|
1949 | print(is_aware(campaign.start_date)) | |
|
1941 | print("start exp: ",exp.start_time,flush=True) | |
|
1942 | print("end exp: ",exp.end_time,flush=True) | |
|
1943 | ||
|
1944 | print("start comb: ",start,flush=True) | |
|
1945 | print("end comb: ",end,flush=True) | |
|
1946 | print(is_aware(start),flush=True) | |
|
1947 | print("start camp",campaign.start_date,flush=True) | |
|
1948 | print("end camp",campaign.end_date,flush=True) | |
|
1949 | print(is_aware(campaign.start_date),flush=True) | |
|
1950 | 1950 | if end < start: |
|
1951 | 1951 | end += timedelta(1) |
|
1952 | 1952 | |
@@ -1970,10 +1970,10 def radar_start(request, id_camp, id_radar): | |||
|
1970 | 1970 | request, 'Experiment {} out of date'.format(exp)) |
|
1971 | 1971 | |
|
1972 | 1972 | #app.control.revoke(exp.task) |
|
1973 | print("Llego luego del revoke") | |
|
1973 | print("Llego luego del revoke",flush=True) | |
|
1974 | 1974 | if now >= start and now <= end: |
|
1975 | 1975 | |
|
1976 | print("Caso now > start and < end -- (1)") | |
|
1976 | print("Caso now > start and < end -- (1)",flush=True) | |
|
1977 | 1977 | |
|
1978 | 1978 | # ------------------------------------------- |
|
1979 | 1979 |
General Comments 0
You need to be logged in to leave comments.
Login now