|
1 | NO CONTENT: new file 100644, binary diff hidden |
@@ -420,9 +420,10 class ABSConfiguration(Configuration): | |||
|
420 | 420 | try: |
|
421 | 421 | data, address = sock.recvfrom(1024) |
|
422 | 422 | print (address, data) |
|
423 | ||
|
423 | data = data.decode("utf-8") | |
|
424 | 424 | if data == '1': |
|
425 | 425 | status[int(address[0][10:])-1] = '3' |
|
426 | #print (int(address[0][10:])-1) | |
|
426 | 427 | elif data == '0': |
|
427 | 428 | status[int(address[0][10:])-1] = '1' |
|
428 | 429 | except socket.timeout: |
@@ -477,6 +478,7 class ABSConfiguration(Configuration): | |||
|
477 | 478 | print('Inicia intento de salvar device.status') |
|
478 | 479 | self.device.status = 3 |
|
479 | 480 | self.module_status = ''.join(status) |
|
481 | #print(status) | |
|
480 | 482 | self.save() |
|
481 | 483 | print('Estatus salvado') |
|
482 | 484 | conf_active, __ = ABSActive.objects.get_or_create(pk=1) |
@@ -6,6 +6,9 import json | |||
|
6 | 6 | from datetime import timedelta, datetime |
|
7 | 7 | from celery.task import task |
|
8 | 8 | |
|
9 | from celery.utils.log import get_task_logger | |
|
10 | logger = get_task_logger(__name__) | |
|
11 | ||
|
9 | 12 | @task(name='task_change_beam') |
|
10 | 13 | def task_change_beam(id_conf): |
|
11 | 14 | |
@@ -37,12 +40,12 def task_change_beam(id_conf): | |||
|
37 | 40 | abs_conf.send_beam_num(i+1) |
|
38 | 41 | next_beam.set_as_activebeam() |
|
39 | 42 | task = task_change_beam.apply_async((abs_conf.pk,), eta=date) |
|
40 | print next_beam | |
|
43 | print (next_beam) | |
|
41 | 44 | else: |
|
42 | 45 | abs_conf.send_beam_num(1) |
|
43 | 46 | beams_list[0].set_as_activebeam() |
|
44 | 47 | task = task_change_beam.apply_async((abs_conf.pk,), eta=date) |
|
45 | print beams_list[0] | |
|
48 | print (beams_list[0]) | |
|
46 | 49 | i=0 |
|
47 | 50 | |
|
48 | 51 | else: |
@@ -69,7 +69,7 class CampaignForm(forms.ModelForm): | |||
|
69 | 69 | def __init__(self, *args, **kwargs): |
|
70 | 70 | super(CampaignForm, self).__init__(*args, **kwargs) |
|
71 | 71 | self.fields['start_date'].widget = DatepickerWidget(self.fields['start_date'].widget.attrs) |
|
72 | self.fields['end_date'].widget = DatepickerWidget(self.fields['end_date'].widget.attrs) | |
|
72 | self.fields['end_date'].widget = DatepickerWidget(self.fields['end_date'].widget.attrs) | |
|
73 | 73 | self.fields['description'].widget.attrs = {'rows': 2} |
|
74 | 74 | |
|
75 | 75 | if self.instance.pk: |
@@ -85,10 +85,10 class ExperimentForm(forms.ModelForm): | |||
|
85 | 85 | def __init__(self, *args, **kwargs): |
|
86 | 86 | super(ExperimentForm, self).__init__(*args, **kwargs) |
|
87 | 87 | self.fields['start_time'].widget = TimepickerWidget(self.fields['start_time'].widget.attrs) |
|
88 | self.fields['end_time'].widget = TimepickerWidget(self.fields['end_time'].widget.attrs) | |
|
88 | self.fields['end_time'].widget = TimepickerWidget(self.fields['end_time'].widget.attrs) | |
|
89 | 89 | |
|
90 | 90 | def save(self, *args, **kwargs): |
|
91 | exp = super(ExperimentForm, self).save(*args, **kwargs) | |
|
91 | exp = super(ExperimentForm, self).save(*args, **kwargs) | |
|
92 | 92 | exp.name = exp.name.replace(' ', '') |
|
93 | 93 | exp.save() |
|
94 | 94 | return exp |
@@ -153,7 +153,7 class OperationForm(forms.Form): | |||
|
153 | 153 | |
|
154 | 154 | campaigns = kwargs.pop('campaigns') |
|
155 | 155 | super(OperationForm, self).__init__(*args, **kwargs) |
|
156 | self.fields['campaign'].label = 'Current Campaigns' | |
|
156 | self.fields['campaign'].label = 'Current Campaigns' | |
|
157 | 157 | self.fields['campaign'].choices = add_empty_choice(campaigns.values_list('id', 'name')) |
|
158 | 158 | |
|
159 | 159 | |
@@ -201,6 +201,6 class FilterForm(forms.Form): | |||
|
201 | 201 | class ChangeIpForm(forms.Form): |
|
202 | 202 | |
|
203 | 203 | ip_address = forms.GenericIPAddressField() |
|
204 | mask = forms.GenericIPAddressField(initial='255.255.255.0') | |
|
205 | gateway = forms.GenericIPAddressField(initial='0.0.0.0') | |
|
206 | dns = forms.GenericIPAddressField(initial='0.0.0.0') | |
|
204 | mask = forms.GenericIPAddressField(initial='255.255.255.0') | |
|
205 | gateway = forms.GenericIPAddressField(initial='0.0.0.0') | |
|
206 | dns = forms.GenericIPAddressField(initial='0.0.0.0') |
@@ -132,13 +132,13 class DeviceType(models.Model): | |||
|
132 | 132 | |
|
133 | 133 | class Device(models.Model): |
|
134 | 134 | |
|
135 | device_type = models.ForeignKey('DeviceType', on_delete=models.CASCADE) | |
|
136 | location = models.ForeignKey('Location', on_delete=models.CASCADE) | |
|
137 | ip_address = models.GenericIPAddressField(protocol='IPv4', default='0.0.0.0') | |
|
135 | device_type = models.ForeignKey('DeviceType', on_delete=models.CASCADE) | |
|
136 | location = models.ForeignKey('Location', on_delete=models.CASCADE) | |
|
137 | ip_address = models.GenericIPAddressField(protocol='IPv4', default='0.0.0.0') | |
|
138 | 138 | port_address = models.PositiveSmallIntegerField(default=2000) |
|
139 | description = models.TextField(blank=True, null=True) | |
|
140 | status = models.PositiveSmallIntegerField(default=4, choices=DEV_STATES) | |
|
141 | conf_active = models.PositiveIntegerField(default=0, verbose_name='Current configuration') | |
|
139 | description = models.TextField(blank=True, null=True) | |
|
140 | status = models.PositiveSmallIntegerField(default=4, choices=DEV_STATES) | |
|
141 | conf_active = models.PositiveIntegerField(default=0, verbose_name='Current configuration') | |
|
142 | 142 | |
|
143 | 143 | class Meta: |
|
144 | 144 | db_table = 'db_devices' |
@@ -209,10 +209,10 class Device(models.Model): | |||
|
209 | 209 | headers = {'content-type': "application/json", |
|
210 | 210 | 'cache-control': "no-cache"} |
|
211 | 211 | |
|
212 | ip = [int(x) for x in ip_address.split('.')] | |
|
213 | dns = [int(x) for x in dns.split('.')] | |
|
212 | ip = [int(x) for x in ip_address.split('.')] | |
|
213 | dns = [int(x) for x in dns.split('.')] | |
|
214 | 214 | gateway = [int(x) for x in gateway.split('.')] |
|
215 | subnet = [int(x) for x in mask.split('.')] | |
|
215 | subnet = [int(x) for x in mask.split('.')] | |
|
216 | 216 | |
|
217 | 217 | payload = { |
|
218 | 218 | "ip": ip, |
@@ -225,7 +225,7 class Device(models.Model): | |||
|
225 | 225 | try: |
|
226 | 226 | answer = req.json() |
|
227 | 227 | if answer['changeip']=='ok': |
|
228 | self.message = '25|IP succesfully changed' | |
|
228 | self.message = '25|IP succesfully changed' | |
|
229 | 229 | self.ip_address = ip_address |
|
230 | 230 | self.save() |
|
231 | 231 | else: |
@@ -241,14 +241,14 class Device(models.Model): | |||
|
241 | 241 | |
|
242 | 242 | class Campaign(models.Model): |
|
243 | 243 | |
|
244 | template = models.BooleanField(default=False) | |
|
245 | name = models.CharField(max_length=60, unique=True) | |
|
246 | start_date = models.DateTimeField(blank=True, null=True) | |
|
247 | end_date = models.DateTimeField(blank=True, null=True) | |
|
248 | tags = models.CharField(max_length=40, blank=True, null=True) | |
|
244 | template = models.BooleanField(default=False) | |
|
245 | name = models.CharField(max_length=60, unique=True) | |
|
246 | start_date = models.DateTimeField(blank=True, null=True) | |
|
247 | end_date = models.DateTimeField(blank=True, null=True) | |
|
248 | tags = models.CharField(max_length=40, blank=True, null=True) | |
|
249 | 249 | description = models.TextField(blank=True, null=True) |
|
250 | 250 | experiments = models.ManyToManyField('Experiment', blank=True) |
|
251 | author = models.ForeignKey(User, null=True, blank=True,on_delete=models.CASCADE) | |
|
251 | author = models.ForeignKey(User, null=True, blank=True,on_delete=models.CASCADE) | |
|
252 | 252 | |
|
253 | 253 | class Meta: |
|
254 | 254 | db_table = 'db_campaigns' |
@@ -272,7 +272,7 class Campaign(models.Model): | |||
|
272 | 272 | data[field.name] = field.value_from_object(self) |
|
273 | 273 | |
|
274 | 274 | data['start_date'] = data['start_date'].strftime('%Y-%m-%d') |
|
275 | data['end_date'] = data['end_date'].strftime('%Y-%m-%d') | |
|
275 | data['end_date'] = data['end_date'].strftime('%Y-%m-%d') | |
|
276 | 276 | |
|
277 | 277 | return data |
|
278 | 278 | |
@@ -311,10 +311,10 class Campaign(models.Model): | |||
|
311 | 311 | |
|
312 | 312 | camp_parms = parms['campaigns']['byId'][parms['campaigns']['allIds'][0]] |
|
313 | 313 | |
|
314 | self.name = '{}-{}'.format(camp_parms['name'], datetime.now().strftime('%y%m%d')) | |
|
314 | self.name = '{}-{}'.format(camp_parms['name'], datetime.now().strftime('%y%m%d')) | |
|
315 | 315 | self.start_date = camp_parms['start_date'] |
|
316 | self.end_date = camp_parms['end_date'] | |
|
317 | self.tags = camp_parms['tags'] | |
|
316 | self.end_date = camp_parms['end_date'] | |
|
317 | self.tags = camp_parms['tags'] | |
|
318 | 318 | self.save() |
|
319 | 319 | |
|
320 | 320 | return self |
@@ -329,8 +329,8 class Campaign(models.Model): | |||
|
329 | 329 | |
|
330 | 330 | for loc in locations: |
|
331 | 331 | dum = {} |
|
332 | dum['name'] = loc.name | |
|
333 | dum['id'] = loc.pk | |
|
332 | dum['name'] = loc.name | |
|
333 | dum['id'] = loc.pk | |
|
334 | 334 | dum['experiments'] = [e for e in self.experiments.all() if e.location==loc] |
|
335 | 335 | ret.append(dum) |
|
336 | 336 | |
@@ -353,23 +353,23 class Campaign(models.Model): | |||
|
353 | 353 | |
|
354 | 354 | |
|
355 | 355 | class RunningExperiment(models.Model): |
|
356 | radar = models.OneToOneField('Location', on_delete=models.CASCADE) | |
|
356 | radar = models.OneToOneField('Location', on_delete=models.CASCADE) | |
|
357 | 357 | running_experiment = models.ManyToManyField('Experiment', blank = True) |
|
358 | status = models.PositiveSmallIntegerField(default=0, choices=RADAR_STATES) | |
|
358 | status = models.PositiveSmallIntegerField(default=0, choices=RADAR_STATES) | |
|
359 | 359 | |
|
360 | 360 | |
|
361 | 361 | class Experiment(models.Model): |
|
362 | 362 | |
|
363 | template = models.BooleanField(default=False) | |
|
364 | name = models.CharField(max_length=40, default='', unique=True) | |
|
365 | location = models.ForeignKey('Location', null=True, blank=True, on_delete=models.CASCADE) | |
|
366 | freq = models.FloatField(verbose_name='Operating Freq. (MHz)', validators=[MinValueValidator(1), MaxValueValidator(10000)], default=49.9200) | |
|
363 | template = models.BooleanField(default=False) | |
|
364 | name = models.CharField(max_length=40, default='', unique=True) | |
|
365 | location = models.ForeignKey('Location', null=True, blank=True, on_delete=models.CASCADE) | |
|
366 | freq = models.FloatField(verbose_name='Operating Freq. (MHz)', validators=[MinValueValidator(1), MaxValueValidator(10000)], default=49.9200) | |
|
367 | 367 | start_time = models.TimeField(default='00:00:00') |
|
368 | end_time = models.TimeField(default='23:59:59') | |
|
369 | task = models.CharField(max_length=36, default='', blank=True, null=True) | |
|
370 | status = models.PositiveSmallIntegerField(default=4, choices=EXP_STATES) | |
|
371 | author = models.ForeignKey(User, null=True, blank=True,on_delete=models.CASCADE) | |
|
372 | hash = models.CharField(default='', max_length=64, null=True, blank=True) | |
|
368 | end_time = models.TimeField(default='23:59:59') | |
|
369 | task = models.CharField(max_length=36, default='', blank=True, null=True) | |
|
370 | status = models.PositiveSmallIntegerField(default=4, choices=EXP_STATES) | |
|
371 | author = models.ForeignKey(User, null=True, blank=True,on_delete=models.CASCADE) | |
|
372 | hash = models.CharField(default='', max_length=64, null=True, blank=True) | |
|
373 | 373 | |
|
374 | 374 | class Meta: |
|
375 | 375 | db_table = 'db_experiments' |
@@ -393,8 +393,8 class Experiment(models.Model): | |||
|
393 | 393 | data[field.name] = field.value_from_object(self) |
|
394 | 394 | |
|
395 | 395 | data['start_time'] = data['start_time'].strftime('%H:%M:%S') |
|
396 | data['end_time'] = data['end_time'].strftime('%H:%M:%S') | |
|
397 | data['location'] = self.location.name | |
|
396 | data['end_time'] = data['end_time'].strftime('%H:%M:%S') | |
|
397 | data['location'] = self.location.name | |
|
398 | 398 | data['configurations'] = ['{}'.format(conf.pk) for |
|
399 | 399 | conf in Configuration.objects.filter(experiment=self, type=0)] |
|
400 | 400 | |
@@ -427,7 +427,7 class Experiment(models.Model): | |||
|
427 | 427 | |
|
428 | 428 | confs = [] |
|
429 | 429 | allconfs = Configuration.objects.filter(experiment=self, type = 0).order_by('-device__device_type__sequence') |
|
430 | rc_mix = [conf for conf in allconfs if conf.device.device_type.name=='rc' and conf.mix] | |
|
430 | rc_mix = [conf for conf in allconfs if conf.device.device_type.name=='rc' and conf.mix] | |
|
431 | 431 | if rc_mix: |
|
432 | 432 | for conf in allconfs: |
|
433 | 433 | if conf.device.device_type.name == 'rc' and not conf.mix: |
@@ -456,7 +456,7 class Experiment(models.Model): | |||
|
456 | 456 | ''' |
|
457 | 457 | |
|
458 | 458 | confs = Configuration.objects.filter(experiment=self, type = 0).order_by('device__device_type__sequence') |
|
459 | confs=confs.exclude(device__device_type__name='cgs') | |
|
459 | confs = confs.exclude(device__device_type__name='cgs') | |
|
460 | 460 | try: |
|
461 | 461 | for conf in confs: |
|
462 | 462 | conf.stop_device() |
@@ -529,8 +529,8 class Experiment(models.Model): | |||
|
529 | 529 | |
|
530 | 530 | for id_conf in exp_parms['configurations']: |
|
531 | 531 | conf_parms = parms['configurations']['byId'][id_conf] |
|
532 | device = Device.objects.filter(device_type__name=conf_parms['device_type'])[0] | |
|
533 | model = CONF_MODELS[conf_parms['device_type']] | |
|
532 | device = Device.objects.filter(device_type__name=conf_parms['device_type'])[0] | |
|
533 | model = CONF_MODELS[conf_parms['device_type']] | |
|
534 | 534 | conf = model( |
|
535 | 535 | experiment = self, |
|
536 | 536 | device = device, |
@@ -540,9 +540,9 class Experiment(models.Model): | |||
|
540 | 540 | |
|
541 | 541 | location, created = Location.objects.get_or_create(name=exp_parms['location']) |
|
542 | 542 | self.name = '{}-{}'.format(exp_parms['name'], datetime.now().strftime('%y%m%d')) |
|
543 | self.location = location | |
|
543 | self.location = location | |
|
544 | 544 | self.start_time = exp_parms['start_time'] |
|
545 | self.end_time = exp_parms['end_time'] | |
|
545 | self.end_time = exp_parms['end_time'] | |
|
546 | 546 | self.save() |
|
547 | 547 | |
|
548 | 548 | return self |
@@ -571,17 +571,17 class Experiment(models.Model): | |||
|
571 | 571 | |
|
572 | 572 | class Configuration(PolymorphicModel): |
|
573 | 573 | |
|
574 | template = models.BooleanField(default=False) | |
|
575 | # name = models.CharField(verbose_name="Configuration Name", max_length=40, default='') | |
|
576 | device = models.ForeignKey('Device', verbose_name='Device', null=True, on_delete=models.CASCADE) | |
|
577 | label = models.CharField(verbose_name="Label", max_length=40, default='', blank=True, null=True) | |
|
578 | experiment = models.ForeignKey('Experiment', verbose_name='Experiment', null=True, blank=True, on_delete=models.CASCADE) | |
|
579 | type = models.PositiveSmallIntegerField(default=0, choices=CONF_TYPES) | |
|
580 | created_date = models.DateTimeField(auto_now_add=True) | |
|
574 | template = models.BooleanField(default=False) | |
|
575 | # name = models.CharField(verbose_name="Configuration Name", max_length=40, default='') | |
|
576 | device = models.ForeignKey('Device', verbose_name='Device', null=True, on_delete=models.CASCADE) | |
|
577 | label = models.CharField(verbose_name="Label", max_length=40, default='', blank=True, null=True) | |
|
578 | experiment = models.ForeignKey('Experiment', verbose_name='Experiment', null=True, blank=True, on_delete=models.CASCADE) | |
|
579 | type = models.PositiveSmallIntegerField(default=0, choices=CONF_TYPES) | |
|
580 | created_date = models.DateTimeField(auto_now_add=True) | |
|
581 | 581 | programmed_date = models.DateTimeField(auto_now=True) |
|
582 | parameters = models.TextField(default='{}') | |
|
583 | author = models.ForeignKey(User, null=True, blank=True,on_delete=models.CASCADE) | |
|
584 | hash = models.CharField(default='', max_length=64, null=True, blank=True) | |
|
582 | parameters = models.TextField(default='{}') | |
|
583 | author = models.ForeignKey(User, null=True, blank=True,on_delete=models.CASCADE) | |
|
584 | hash = models.CharField(default='', max_length=64, null=True, blank=True) | |
|
585 | 585 | message = "" |
|
586 | 586 | |
|
587 | 587 | class Meta: |
@@ -5,18 +5,28 from celery import task | |||
|
5 | 5 | from datetime import timedelta, datetime |
|
6 | 6 | |
|
7 | 7 | from .models import Experiment |
|
8 | from celery import Celery | |
|
9 | ||
|
10 | from celery.utils.log import get_task_logger | |
|
11 | ||
|
12 | from django.utils import timezone | |
|
13 | ||
|
14 | logger = get_task_logger(__name__) | |
|
8 | 15 | |
|
9 | 16 | @task |
|
10 | 17 | def task_start(id_exp): |
|
11 | exp = Experiment.objects.get(pk=id_exp) | |
|
18 | exp = Experiment.objects.get(pk=id_exp) | |
|
12 | 19 | status = exp.status |
|
13 | 20 | if exp.status == 2: |
|
14 | 21 | print('Experiment {} already running start task not executed'.format(exp)) |
|
15 | 22 | return 2 |
|
16 | 23 | if status == 3: |
|
17 | now = datetime.now() | |
|
24 | now = datetime.now() | |
|
18 | 25 | start = datetime.combine(now.date(), exp.start_time) |
|
19 | end = datetime.combine(now.date(), exp.end_time) | |
|
26 | end = datetime.combine(now.date(), exp.end_time) | |
|
27 | print(now) | |
|
28 | print(start) | |
|
29 | print(end) | |
|
20 | 30 | if end < start: |
|
21 | 31 | end += timedelta(1) |
|
22 | 32 | try: |
@@ -26,7 +36,7 def task_start(id_exp): | |||
|
26 | 36 | print('Error') |
|
27 | 37 | exp.status = 0 |
|
28 | 38 | if exp.status == 2: |
|
29 |
task = task_stop.apply_async((id_exp,), |
|
|
39 | task = task_stop.apply_async((id_exp,),eta=end) #Antiguo eta=end+timedelta(hours=5)) | |
|
30 | 40 | exp.task = task.id |
|
31 | 41 | exp.save() |
|
32 | 42 | return exp.status |
@@ -42,10 +52,10 def task_stop(id_exp): | |||
|
42 | 52 | print('Error') |
|
43 | 53 | exp.status = 0 |
|
44 | 54 | |
|
45 | now = datetime.now() | |
|
46 | start = datetime.combine(now.date()+timedelta(1), exp.start_time) | |
|
47 |
task = task_start.apply_async((id_exp, ), eta=start |
|
|
48 | exp.task = task.id | |
|
55 | now = datetime.now() | |
|
56 | start = datetime.combine(now.date()+timedelta(1), exp.start_time) | |
|
57 | task = task_start.apply_async((id_exp, ), eta=start) #Antiguo eta=start+timedelta(hours=5)) | |
|
58 | exp.task = task.id | |
|
49 | 59 | exp.status = 3 |
|
50 | 60 | exp.save() |
|
51 | 61 | return exp.status |
@@ -53,12 +63,12 def task_stop(id_exp): | |||
|
53 | 63 | #Task to get status |
|
54 | 64 | @task |
|
55 | 65 | def task_status(id_exp): |
|
56 | ||
|
66 | print ("task status"+str(id_exp)) | |
|
57 | 67 | exp = Experiment.objects.get(pk=id_exp) |
|
58 | 68 | if exp.status==2: |
|
59 | 69 | run_every = timedelta(minutes=1) |
|
60 | now = datetime.utcnow() | |
|
61 | date = now + run_every | |
|
70 | now = datetime.utcnow() | |
|
71 | date = now + run_every | |
|
62 | 72 | task_status.apply_async((id_exp,), eta=date) |
|
63 | 73 | print ("Monitoring...") |
|
64 | 74 | exp.get_status() |
@@ -46,6 +46,7 urlpatterns = ( | |||
|
46 | 46 | |
|
47 | 47 | path('experiment/<int:id_exp>/new_dev_conf/', views.dev_conf_new, name='url_add_dev_conf'), |
|
48 | 48 | path('experiment/<int:id_exp>/new_dev_conf/<int:id_dev>/', views.dev_conf_new, name='url_add_dev_conf'), |
|
49 | ||
|
49 | 50 | path('dev_conf/', views.dev_confs, name='url_dev_confs'), |
|
50 | 51 | path('dev_conf/<int:id_conf>/', views.dev_conf, name='url_dev_conf'), |
|
51 | 52 | path('dev_conf/<int:id_conf>/edit/', views.dev_conf_edit, name='url_edit_dev_conf'), |
@@ -13,6 +13,8 from django.contrib import messages | |||
|
13 | 13 | from django.http.request import QueryDict |
|
14 | 14 | from django.contrib.auth.decorators import login_required, user_passes_test |
|
15 | 15 | |
|
16 | from django.utils.timezone import is_aware | |
|
17 | ||
|
16 | 18 | try: |
|
17 | 19 | from urllib.parse import urlencode |
|
18 | 20 | except ImportError: |
@@ -21,8 +23,6 except ImportError: | |||
|
21 | 23 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm, NewForm |
|
22 | 24 | from .forms import OperationSearchForm, FilterForm, ChangeIpForm |
|
23 | 25 | |
|
24 | from .tasks import task_start | |
|
25 | ||
|
26 | 26 | from apps.rc.forms import RCConfigurationForm, RCLineCode, RCMixConfigurationForm |
|
27 | 27 | from apps.dds.forms import DDSConfigurationForm |
|
28 | 28 | from apps.jars.forms import JARSConfigurationForm |
@@ -32,18 +32,19 from apps.usrp.forms import USRPConfigurationForm | |||
|
32 | 32 | from apps.dds_rest.forms import DDSRestConfigurationForm |
|
33 | 33 | from .utils import Params |
|
34 | 34 | |
|
35 | from .models import Campaign, Experiment, Device, Configuration, Location, RunningExperiment, DEV_STATES | |
|
36 | from apps.cgs.models import CGSConfiguration | |
|
37 | from apps.jars.models import JARSConfiguration, EXPERIMENT_TYPE | |
|
38 | from apps.usrp.models import USRPConfiguration | |
|
39 | from apps.abs.models import ABSConfiguration | |
|
40 | from apps.rc.models import RCConfiguration, RCLine, RCLineType, RCClock | |
|
41 | from apps.dds.models import DDSConfiguration | |
|
35 | from .models import Campaign, Experiment, Device, Configuration, Location, RunningExperiment, DEV_STATES | |
|
36 | from apps.cgs.models import CGSConfiguration | |
|
37 | from apps.jars.models import JARSConfiguration, EXPERIMENT_TYPE | |
|
38 | from apps.usrp.models import USRPConfiguration | |
|
39 | from apps.abs.models import ABSConfiguration | |
|
40 | from apps.rc.models import RCConfiguration, RCLine, RCLineType, RCClock | |
|
41 | from apps.dds.models import DDSConfiguration | |
|
42 | 42 | from apps.dds_rest.models import DDSRestConfiguration |
|
43 | 43 | |
|
44 | from .tasks import task_start | |
|
44 | 45 | from radarsys.celery import app |
|
45 | 46 | |
|
46 | ||
|
47 | #comentario test | |
|
47 | 48 | CONF_FORMS = { |
|
48 | 49 | 'rc': RCConfigurationForm, |
|
49 | 50 | 'dds': DDSConfigurationForm, |
@@ -442,9 +443,9 def campaign_new(request): | |||
|
442 | 443 | campaign.save() |
|
443 | 444 | return redirect('url_campaign', id_camp=campaign.id) |
|
444 | 445 | |
|
445 | kwargs['form'] = form | |
|
446 | kwargs['title'] = 'Campaign' | |
|
447 | kwargs['suptitle'] = 'New' | |
|
446 | kwargs['form'] = form | |
|
447 | kwargs['title'] = 'Campaign' | |
|
448 | kwargs['suptitle'] = 'New' | |
|
448 | 449 | kwargs['menu_campaigns'] = 'active' |
|
449 | 450 | |
|
450 | 451 | return render(request, 'campaign_edit.html', kwargs) |
@@ -459,11 +460,11 def campaign_edit(request, id_camp): | |||
|
459 | 460 | form = CampaignForm(instance=campaign) |
|
460 | 461 | |
|
461 | 462 | if request.method == 'POST': |
|
462 | exps = campaign.experiments.all().values_list('pk', flat=True) | |
|
463 | post = request.POST.copy() | |
|
463 | exps = campaign.experiments.all().values_list('pk', flat=True) | |
|
464 | post = request.POST.copy() | |
|
464 | 465 | new_exps = post.getlist('experiments') |
|
465 | 466 | post.setlist('experiments', []) |
|
466 | form = CampaignForm(post, instance=campaign) | |
|
467 | form = CampaignForm(post, instance=campaign) | |
|
467 | 468 | |
|
468 | 469 | if form.is_valid(): |
|
469 | 470 | camp = form.save() |
@@ -482,11 +483,11 def campaign_edit(request, id_camp): | |||
|
482 | 483 | |
|
483 | 484 | return redirect('url_campaign', id_camp=id_camp) |
|
484 | 485 | |
|
485 | kwargs = {} | |
|
486 | kwargs['form'] = form | |
|
487 | kwargs['title'] = 'Campaign' | |
|
488 | kwargs['suptitle'] = 'Edit' | |
|
489 | kwargs['button'] = 'Update' | |
|
486 | kwargs = {} | |
|
487 | kwargs['form'] = form | |
|
488 | kwargs['title'] = 'Campaign' | |
|
489 | kwargs['suptitle'] = 'Edit' | |
|
490 | kwargs['button'] = 'Update' | |
|
490 | 491 | kwargs['menu_campaigns'] = 'active' |
|
491 | 492 | |
|
492 | 493 | return render(request, 'campaign_edit.html', kwargs) |
@@ -694,11 +695,11 def experiment_edit(request, id_exp): | |||
|
694 | 695 | experiment = form.save() |
|
695 | 696 | return redirect('url_experiment', id_exp=experiment.id) |
|
696 | 697 | |
|
697 | kwargs = {} | |
|
698 | kwargs['form'] = form | |
|
699 | kwargs['title'] = 'Experiment' | |
|
700 | kwargs['suptitle'] = 'Edit' | |
|
701 | kwargs['button'] = 'Update' | |
|
698 | kwargs = {} | |
|
699 | kwargs['form'] = form | |
|
700 | kwargs['title'] = 'Experiment' | |
|
701 | kwargs['suptitle'] = 'Edit' | |
|
702 | kwargs['button'] = 'Update' | |
|
702 | 703 | kwargs['menu_experiments'] = 'active' |
|
703 | 704 | |
|
704 | 705 | return render(request, 'experiment_edit.html', kwargs) |
@@ -1790,12 +1791,24 def operation(request, id_camp=None): | |||
|
1790 | 1791 | @login_required |
|
1791 | 1792 | def radar_start(request, id_camp, id_radar): |
|
1792 | 1793 | |
|
1793 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
|
1794 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
|
1794 | 1795 | experiments = campaign.get_experiments_by_radar(id_radar)[0]['experiments'] |
|
1795 | now = datetime.now() | |
|
1796 | now = datetime.now() | |
|
1797 | ||
|
1796 | 1798 | for exp in experiments: |
|
1799 | #app.control.revoke(exp.task) | |
|
1800 | print(exp.status) | |
|
1797 | 1801 | start = datetime.combine(datetime.now().date(), exp.start_time) |
|
1798 | end = datetime.combine(datetime.now().date(), exp.end_time) | |
|
1802 | end = datetime.combine(datetime.now().date(), exp.end_time) | |
|
1803 | print(exp.start_time) | |
|
1804 | print(exp.end_time) | |
|
1805 | ||
|
1806 | print(start) | |
|
1807 | print(end) | |
|
1808 | print(is_aware(start)) | |
|
1809 | print(campaign.start_date) | |
|
1810 | print(campaign.end_date) | |
|
1811 | print(is_aware(campaign.start_date)) | |
|
1799 | 1812 | if end < start: |
|
1800 | 1813 | end += timedelta(1) |
|
1801 | 1814 | |
@@ -1814,8 +1827,9 def radar_start(request, id_camp, id_radar): | |||
|
1814 | 1827 | continue |
|
1815 | 1828 | |
|
1816 | 1829 | app.control.revoke(exp.task) |
|
1817 | ||
|
1830 | print("Llego luego del revoke") | |
|
1818 | 1831 | if now > start and now <= end: |
|
1832 | print("Caso now >start and <end") | |
|
1819 | 1833 | task = task_start.delay(exp.id) |
|
1820 | 1834 | exp.status = task.wait() |
|
1821 | 1835 | if exp.status == 0: |
@@ -1823,12 +1837,11 def radar_start(request, id_camp, id_radar): | |||
|
1823 | 1837 | if exp.status == 2: |
|
1824 | 1838 | messages.success(request, 'Experiment {} started'.format(exp)) |
|
1825 | 1839 | else: |
|
1826 | task = task_start.apply_async( | |
|
1827 |
|
|
|
1828 | exp.task = task.id | |
|
1840 | print("Caso now < start o >end") | |
|
1841 | task = task_start.apply_async((exp.pk, ), eta=start)#start+timedelta(hours=5)) | |
|
1842 | exp.task = task.id | |
|
1829 | 1843 | exp.status = 3 |
|
1830 | messages.success( | |
|
1831 | request, 'Experiment {} programmed to start at {}'.format(exp, start)) | |
|
1844 | messages.success(request, 'Experiment {} programmed to start at {}'.format(exp, start)) | |
|
1832 | 1845 | |
|
1833 | 1846 | exp.save() |
|
1834 | 1847 | |
@@ -1838,14 +1851,18 def radar_start(request, id_camp, id_radar): | |||
|
1838 | 1851 | @login_required |
|
1839 | 1852 | def radar_stop(request, id_camp, id_radar): |
|
1840 | 1853 | |
|
1841 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
|
1854 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
|
1842 | 1855 | experiments = campaign.get_experiments_by_radar(id_radar)[0]['experiments'] |
|
1843 | ||
|
1856 | print("Ingreso en stop radar_stop") | |
|
1844 | 1857 | for exp in experiments: |
|
1845 | 1858 | |
|
1846 | 1859 | if exp.task: |
|
1860 | print("Ingreso antes de revoke stop") | |
|
1847 | 1861 | app.control.revoke(exp.task) |
|
1848 | if exp.status == 2: | |
|
1862 | ||
|
1863 | ||
|
1864 | if exp.status == 2: #status 2 es started | |
|
1865 | print("llama a exp.stop") | |
|
1849 | 1866 | exp.stop() |
|
1850 | 1867 | messages.warning(request, 'Experiment {} stopped'.format(exp)) |
|
1851 | 1868 | exp.status = 1 |
@@ -1857,12 +1874,15 def radar_stop(request, id_camp, id_radar): | |||
|
1857 | 1874 | @login_required |
|
1858 | 1875 | def radar_refresh(request, id_camp, id_radar): |
|
1859 | 1876 | |
|
1860 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
|
1877 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
|
1861 | 1878 | experiments = campaign.get_experiments_by_radar(id_radar)[0]['experiments'] |
|
1862 | 1879 | |
|
1863 | i = app.control.inspect() | |
|
1864 | scheduled = i.scheduled().values()[0] | |
|
1865 | revoked = i.revoked().values()[0] | |
|
1880 | i = app.control.inspect() | |
|
1881 | print(i) | |
|
1882 | print(i.scheduled()) | |
|
1883 | print(i.scheduled().values()) | |
|
1884 | scheduled = list(i.scheduled().values())[0] | |
|
1885 | revoked = list(i.revoked().values())[0] | |
|
1866 | 1886 | |
|
1867 | 1887 | for exp in experiments: |
|
1868 | 1888 | if exp.task in revoked: |
@@ -1879,16 +1899,16 def radar_refresh(request, id_camp, id_radar): | |||
|
1879 | 1899 | @login_required |
|
1880 | 1900 | def revoke_tasks(request, id_camp): |
|
1881 | 1901 | |
|
1882 | i = app.control.inspect() | |
|
1883 | scheduled = i.scheduled().values()[0] | |
|
1884 | revoked = i.revoked().values()[0] | |
|
1902 | i = app.control.inspect() | |
|
1903 | scheduled = list(i.scheduled().values())[0] | |
|
1904 | revoked = list(i.revoked().values())[0] | |
|
1885 | 1905 | |
|
1886 | 1906 | for t in scheduled: |
|
1887 | 1907 | if t['request']['id'] in revoked: |
|
1888 | 1908 | continue |
|
1889 | 1909 | app.control.revoke(t['request']['id']) |
|
1890 | exp = Experiment.objects.get(pk=eval(t['request']['args'])[0]) | |
|
1891 | eta = t['eta'] | |
|
1910 | exp = Experiment.objects.get(pk=eval(str(t['request']['args']))[0]) | |
|
1911 | eta = t['eta'] | |
|
1892 | 1912 | task = t['request']['name'].split('.')[-1] |
|
1893 | 1913 | messages.warning(request, 'Scheduled {} at {} for experiment {} revoked'.format(task, eta, exp.name)) |
|
1894 | 1914 | |
@@ -1897,14 +1917,14 def revoke_tasks(request, id_camp): | |||
|
1897 | 1917 | @login_required |
|
1898 | 1918 | def show_tasks(request, id_camp): |
|
1899 | 1919 | |
|
1900 | i = app.control.inspect() | |
|
1901 | scheduled = i.scheduled().values()[0] | |
|
1902 | revoked = i.revoked().values()[0] | |
|
1920 | i = app.control.inspect() | |
|
1921 | scheduled = list(i.scheduled().values())[0] | |
|
1922 | revoked = list(i.revoked().values())[0] | |
|
1903 | 1923 | |
|
1904 | 1924 | for t in scheduled: |
|
1905 | 1925 | if t['request']['id'] in revoked: |
|
1906 | 1926 | continue |
|
1907 | exp = Experiment.objects.get(pk=eval(t['request']['args'])[0]) | |
|
1927 | exp = Experiment.objects.get(pk=eval(str(t['request']['args']))[0]) | |
|
1908 | 1928 | eta = t['eta'] |
|
1909 | 1929 | task = t['request']['name'].split('.')[-1] |
|
1910 | 1930 | messages.success(request, 'Task {} scheduled at {} for experiment {}'.format(task, eta, exp.name)) |
@@ -6,7 +6,7 from django.conf import settings | |||
|
6 | 6 | # set the default Django settings module for the 'celery' program. |
|
7 | 7 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'radarsys.settings') |
|
8 | 8 | app = Celery('radarsys') |
|
9 | ||
|
9 | app.conf.timezone = 'America/Lima' | |
|
10 | 10 | # Using a string here means the worker will not have to |
|
11 | 11 | # pickle the object when using Windows. |
|
12 | 12 | app.config_from_object('django.conf:settings') |
@@ -105,14 +105,14 DATABASES = { | |||
|
105 | 105 | |
|
106 | 106 | LANGUAGE_CODE = 'en-us' |
|
107 | 107 | |
|
108 | USE_TZ = False | |
|
109 | ||
|
108 | 110 | TIME_ZONE = os.environ.get('TZ', 'America/Lima') |
|
109 | 111 | |
|
110 | 112 | USE_I18N = True |
|
111 | 113 | |
|
112 | 114 | USE_L10N = True |
|
113 | 115 | |
|
114 | USE_TZ = False | |
|
115 | ||
|
116 | 116 | # Static files (CSS, JavaScript, Images) |
|
117 | 117 | # https://docs.djangoproject.com/en/1.8/howto/static-files/ |
|
118 | 118 | |
@@ -129,7 +129,7 STATICFILES_FINDERS = ( | |||
|
129 | 129 | |
|
130 | 130 | # Celery stuff |
|
131 | 131 | REDIS_HOST = os.environ.get('REDIS_HOST', '127.0.0.1') |
|
132 |
REDIS_PORT = os.environ.get('REDIS_PORT', 63 |
|
|
132 | REDIS_PORT = os.environ.get('REDIS_PORT', 6379) | |
|
133 | 133 | |
|
134 | 134 | BROKER_TRANSPORT = 'redis' |
|
135 | 135 | BROKER_URL = 'redis://{}:{}/0'.format(REDIS_HOST, REDIS_PORT) |
@@ -140,3 +140,4 CELERY_ACCEPT_CONTENT = ['application/json'] | |||
|
140 | 140 | CELERY_TASK_SERIALIZER = 'json' |
|
141 | 141 | CELERY_RESULT_SERIALIZER = 'json' |
|
142 | 142 | CELERY_ENABLE_UTC = False |
|
143 | CELERY_TIMEZONE = 'America/Lima' |
General Comments 0
You need to be logged in to leave comments.
Login now