@@ -8,5 +8,5 POSTGRES_PASSWORD=docker | |||
|
8 | 8 | PGDATA=/var/lib/postgresql/data |
|
9 | 9 | LC_ALL=C.UTF-8 |
|
10 | 10 | TZ=America/Lima |
|
11 |
DOCKER_DATA=/ |
|
|
11 | DOCKER_DATA=/data/dockers/radarsys/ | |
|
12 | 12 | LOCAL_IP=192.168.1.128 |
@@ -256,24 +256,16 class JARSConfiguration(Configuration): | |||
|
256 | 256 | if data['configurations']['byId'][key]['device_type'] in ('dds', 'cgs'): |
|
257 | 257 | data['configurations']['allIds'].remove(key) |
|
258 | 258 | data['configurations']['byId'].pop(key) |
|
259 | elif data['configurations']['byId'][key]['device_type'] == 'jars': | |
|
260 | data['configurations']['byId'][key] = self.parms_to_dict()['configurations']['byId'][str(self.pk)] | |
|
261 | 259 | elif data['configurations']['byId'][key]['device_type'] == 'rc': |
|
262 | 260 | data['configurations']['byId'][key]['pulses'] = '' |
|
263 | 261 | data['configurations']['byId'][key]['delays'] = '' |
|
264 | 262 | rc_ids = [pk for pk in data['configurations']['allIds'] if data['configurations']['byId'][pk]['device_type']=='rc'] |
|
265 | mix_ids = [pk for pk in rc_ids if data['configurations']['byId'][pk]['mix']] | |
|
266 | if mix_ids: | |
|
267 | params = data['configurations']['byId'][mix_ids[0]]['parameters'] | |
|
268 | rc = data['configurations']['byId'][params.split('-')[0].split('|')[0]] | |
|
269 | rc['mix'] = True | |
|
270 | data['configurations']['byId'][rc['id']] = rc | |
|
271 | elif len(rc_ids)==0: | |
|
263 | if len(rc_ids)==0: | |
|
272 | 264 | self.message = 'Missing RC configuration' |
|
273 | 265 | return False |
|
274 | 266 | |
|
275 | 267 | json_data = json.dumps(data) |
|
276 | ||
|
268 | ||
|
277 | 269 | try: |
|
278 | 270 | payload = self.request('write', 'post', json=json_data) |
|
279 | 271 | self.device.status = payload['status'] |
@@ -93,7 +93,7 class ExperimentForm(forms.ModelForm): | |||
|
93 | 93 | |
|
94 | 94 | class Meta: |
|
95 | 95 | model = Experiment |
|
96 | exclude = ['status'] | |
|
96 | exclude = ['task', 'status'] | |
|
97 | 97 | |
|
98 | 98 | class LocationForm(forms.ModelForm): |
|
99 | 99 | class Meta: |
@@ -248,7 +248,7 class Campaign(models.Model): | |||
|
248 | 248 | |
|
249 | 249 | def parms_to_dict(self): |
|
250 | 250 | |
|
251 | params = Params() | |
|
251 | params = Params({}) | |
|
252 | 252 | params.add(self.jsonify(), 'campaigns') |
|
253 | 253 | |
|
254 | 254 | for exp in Experiment.objects.filter(campaign = self): |
@@ -334,6 +334,7 class Experiment(models.Model): | |||
|
334 | 334 | freq = models.FloatField(verbose_name='Operating Freq. (MHz)', validators=[MinValueValidator(1), MaxValueValidator(10000)], default=49.9200) |
|
335 | 335 | start_time = models.TimeField(default='00:00:00') |
|
336 | 336 | end_time = models.TimeField(default='23:59:59') |
|
337 | task = models.CharField(max_length=36, default='', blank=True, null=True) | |
|
337 | 338 | status = models.PositiveSmallIntegerField(default=4, choices=EXP_STATES) |
|
338 | 339 | |
|
339 | 340 | class Meta: |
@@ -373,7 +374,7 class Experiment(models.Model): | |||
|
373 | 374 | |
|
374 | 375 | confs = Configuration.objects.filter(experiment=self, type=0) |
|
375 | 376 | self.pk = None |
|
376 |
self.name = '{} [{:%Y |
|
|
377 | self.name = '{} [{:%Y-%m-%d}]'.format(self.name, datetime.now()) | |
|
377 | 378 | for attr, value in kwargs.items(): |
|
378 | 379 | setattr(self, attr, value) |
|
379 | 380 | |
@@ -391,8 +392,16 class Experiment(models.Model): | |||
|
391 | 392 | ''' |
|
392 | 393 | |
|
393 | 394 | result = 2 |
|
394 | ||
|
395 | confs = Configuration.objects.filter(experiment=self, type = 0).order_by('-device__device_type__sequence') | |
|
395 | confs = [] | |
|
396 | allconfs = Configuration.objects.filter(experiment=self, type = 0).order_by('-device__device_type__sequence') | |
|
397 | rc_mix = [conf for conf in allconfs if conf.device.device_type.name=='rc' and conf.mix] | |
|
398 | if rc_mix: | |
|
399 | for conf in allconfs: | |
|
400 | if conf.device.device_type.name == 'rc' and not conf.mix: | |
|
401 | continue | |
|
402 | confs.append(conf) | |
|
403 | else: | |
|
404 | confs = allconfs | |
|
396 | 405 | #Only Configured Devices. |
|
397 | 406 | for conf in confs: |
|
398 | 407 | if conf.device.status in (0, 4): |
@@ -400,9 +409,9 class Experiment(models.Model): | |||
|
400 | 409 | return result |
|
401 | 410 | for conf in confs: |
|
402 | 411 | conf.stop_device() |
|
403 |
|
|
|
412 | conf.write_device() | |
|
404 | 413 | conf.start_device() |
|
405 | print conf.device.name+' has started...' | |
|
414 | time.sleep(1) | |
|
406 | 415 | |
|
407 | 416 | return result |
|
408 | 417 | |
@@ -422,7 +431,6 class Experiment(models.Model): | |||
|
422 | 431 | result = 0 |
|
423 | 432 | continue |
|
424 | 433 | conf.stop_device() |
|
425 | print conf.device.name+' has stopped...' | |
|
426 | 434 | |
|
427 | 435 | return result |
|
428 | 436 | |
@@ -464,7 +472,7 class Experiment(models.Model): | |||
|
464 | 472 | |
|
465 | 473 | def parms_to_dict(self): |
|
466 | 474 | |
|
467 | params = Params() | |
|
475 | params = Params({}) | |
|
468 | 476 | params.add(self.jsonify(), 'experiments') |
|
469 | 477 | |
|
470 | 478 | configurations = Configuration.objects.filter(experiment=self, type=0) |
@@ -532,19 +540,13 class Experiment(models.Model): | |||
|
532 | 540 | class Configuration(PolymorphicModel): |
|
533 | 541 | |
|
534 | 542 | template = models.BooleanField(default=False) |
|
535 | ||
|
536 | 543 | name = models.CharField(verbose_name="Configuration Name", max_length=40, default='') |
|
537 | ||
|
538 | 544 | experiment = models.ForeignKey('Experiment', verbose_name='Experiment', null=True, blank=True, on_delete=models.CASCADE) |
|
539 | 545 | device = models.ForeignKey('Device', verbose_name='Device', null=True, on_delete=models.CASCADE) |
|
540 | ||
|
541 | 546 | type = models.PositiveSmallIntegerField(default=0, choices=CONF_TYPES) |
|
542 | ||
|
543 | 547 | created_date = models.DateTimeField(auto_now_add=True) |
|
544 | 548 | programmed_date = models.DateTimeField(auto_now=True) |
|
545 | ||
|
546 | 549 | parameters = models.TextField(default='{}') |
|
547 | ||
|
548 | 550 | message = "" |
|
549 | 551 | |
|
550 | 552 | class Meta: |
@@ -607,7 +609,7 class Configuration(PolymorphicModel): | |||
|
607 | 609 | |
|
608 | 610 | def parms_to_dict(self): |
|
609 | 611 | |
|
610 | params = Params() | |
|
612 | params = Params({}) | |
|
611 | 613 | params.add(self.jsonify(), 'configurations') |
|
612 | 614 | |
|
613 | 615 | if self.device.device_type.name=='rc': |
@@ -1,5 +1,6 | |||
|
1 | 1 | from __future__ import absolute_import |
|
2 | 2 | |
|
3 | from radarsys.celery import app | |
|
3 | 4 | from celery import task |
|
4 | 5 | from datetime import timedelta, datetime |
|
5 | 6 | |
@@ -7,25 +8,47 from .models import Experiment | |||
|
7 | 8 | |
|
8 | 9 | @task |
|
9 | 10 | def task_start(id_exp): |
|
10 | ||
|
11 | 11 | exp = Experiment.objects.get(pk=id_exp) |
|
12 | ||
|
13 | return exp.start() | |
|
12 | status = exp.status | |
|
13 | if exp.status == 2: | |
|
14 | print('Experiment {} already running start task not executed'.format(exp)) | |
|
15 | return 2 | |
|
16 | if status == 3: | |
|
17 | now = datetime.now() | |
|
18 | start = datetime.combine(now.date(), exp.start_time) | |
|
19 | end = datetime.combine(now.date(), exp.end_time) | |
|
20 | if end < start: | |
|
21 | end += timedelta(1) | |
|
22 | try: | |
|
23 | print('Starting exp:{}'.format(exp)) | |
|
24 | exp.status = exp.start() | |
|
25 | except: | |
|
26 | print('Error') | |
|
27 | exp.status = 0 | |
|
28 | if exp.status == 2: | |
|
29 | task = task_stop.apply_async((id_exp,), eta=end+timedelta(hours=5)) | |
|
30 | exp.task = task.id | |
|
31 | exp.save() | |
|
32 | return exp.status | |
|
14 | 33 | |
|
15 | 34 | @task |
|
16 | 35 | def task_stop(id_exp): |
|
17 | ||
|
18 | 36 | exp = Experiment.objects.get(pk=id_exp) |
|
37 | if exp.status == 2: | |
|
38 | try: | |
|
39 | print('Stopping exp:{}'.format(exp)) | |
|
40 | exp.status = exp.stop() | |
|
41 | except: | |
|
42 | print('Error') | |
|
43 | exp.status = 0 | |
|
19 | 44 | |
|
20 | return exp.stop() | |
|
21 | ||
|
22 | def kill_tasks(): | |
|
23 | ||
|
24 | i = task.control.inspect() | |
|
25 | tasks = i.scheduled() | |
|
26 | print tasks | |
|
27 | #if tasks: | |
|
28 | # print dir(tasks[0]) | |
|
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+timedelta(hours=5)) | |
|
48 | exp.task = task.id | |
|
49 | exp.status = 3 | |
|
50 | exp.save() | |
|
51 | return exp.status | |
|
29 | 52 | |
|
30 | 53 | #Task to get status |
|
31 | 54 | @task |
@@ -70,8 +70,12 | |||
|
70 | 70 | <i class="fa fa-3x fa-puzzle-piece"></i> |
|
71 | 71 | {%endif%} |
|
72 | 72 | <h4>{{item}}<br><small>{{item.device.ip_address}}</small> |
|
73 | <span class="label label-{{item.device.status_color}}">{{item.device.get_status_display}}</span> | |
|
74 | </h4> | |
|
73 | {%if experiment.status == 3 %} | |
|
74 | <span class="label label-info">Configured</span> | |
|
75 | {%else%} | |
|
76 | <span class="label label-{{item.device.status_color}}">{{item.device.get_status_display}}</span> | |
|
77 | {%endif%} | |
|
78 | </h4> | |
|
75 | 79 | </a> |
|
76 | 80 | </div> |
|
77 | 81 | {% endfor %} |
@@ -18,30 +18,28 | |||
|
18 | 18 | |
|
19 | 19 | <h3>Current Campaigns</h3> |
|
20 | 20 | <br> |
|
21 | ||
|
22 | <div class="bootcards-list"> | |
|
23 | <div class="panel panel-default"> | |
|
24 | <div class="list-group"> | |
|
25 | {% for item in campaigns %} | |
|
26 | <a class="list-group-item" href="{{item.pk}}"> | |
|
27 | <div class="row"> | |
|
28 | <div class="col-sm-6"> | |
|
29 | <i class="fa fa-3x fa-calendar pull-left"></i> | |
|
30 | <h4 class="list-group-item-heading">{{item.name}}</h4> | |
|
31 | <p class="list-group-item-text">Radar: {% for radar in item.get_experiments_by_radar %}{{radar.name}},{% endfor %}</p> | |
|
32 | </div> | |
|
33 | <div class="col-sm-6"> | |
|
34 |
|
|
|
35 | <p class="list-group-item-text">To: {{item.end_date}}</p> | |
|
36 | </div> | |
|
37 | </div> | |
|
38 | </a> | |
|
39 | {% endfor %} | |
|
40 | </div> | |
|
41 | </div> | |
|
21 | <div class="bootcards-list"> | |
|
22 | <div class="panel panel-default"> | |
|
23 | <div class="list-group"> | |
|
24 | {% for item in campaigns %} | |
|
25 | <a class="list-group-item" href="{{item.pk}}"> | |
|
26 | <div class="row"> | |
|
27 | <div class="col-sm-6"> | |
|
28 | <i class="fa fa-3x fa-calendar pull-left"></i> | |
|
29 | <h4 class="list-group-item-heading">{{item.name}}</h4> | |
|
30 | <p class="list-group-item-text">Radar: {% for radar in item.get_experiments_by_radar %}{{radar.name}},{% endfor %}</p> | |
|
31 | </div> | |
|
32 | <div class="col-sm-6"> | |
|
33 | <p class="list-group-item-text">From: {{item.start_date}}</p> | |
|
34 | <p class="list-group-item-text">To: {{item.end_date}}</p> | |
|
42 | 35 | </div> |
|
43 | ||
|
44 | 36 | |
|
37 | </div> | |
|
38 | </a> | |
|
39 | {% endfor %} | |
|
40 | </div> | |
|
41 | </div> | |
|
42 | </div> | |
|
45 | 43 | |
|
46 | 44 | {% endif %} |
|
47 | 45 |
@@ -19,7 +19,7 except ImportError: | |||
|
19 | 19 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm, NewForm |
|
20 | 20 | from .forms import OperationSearchForm, FilterForm, ChangeIpForm |
|
21 | 21 | |
|
22 |
from .tasks import task_start |
|
|
22 | from .tasks import task_start | |
|
23 | 23 | |
|
24 | 24 | from apps.rc.forms import RCConfigurationForm, RCLineCode, RCMixConfigurationForm |
|
25 | 25 | from apps.dds.forms import DDSConfigurationForm |
@@ -37,6 +37,8 from apps.abs.models import ABSConfiguration | |||
|
37 | 37 | from apps.rc.models import RCConfiguration, RCLine, RCLineType |
|
38 | 38 | from apps.dds.models import DDSConfiguration |
|
39 | 39 | |
|
40 | from radarsys.celery import app | |
|
41 | ||
|
40 | 42 | from django.contrib.auth.decorators import login_required |
|
41 | 43 | from django.contrib.auth.decorators import user_passes_test |
|
42 | 44 | from django.contrib.admin.views.decorators import staff_member_required |
@@ -836,7 +838,7 def experiment_mix(request, id_exp): | |||
|
836 | 838 | @user_passes_test(lambda u:u.is_staff) |
|
837 | 839 | def experiment_mix_delete(request, id_exp): |
|
838 | 840 | |
|
839 | conf = RCConfiguration.objects.get(experiment=id_exp, mix=True) | |
|
841 | conf = RCConfiguration.objects.get(experiment=id_exp, mix=True, type=0) | |
|
840 | 842 | values = conf.parameters.split('-') |
|
841 | 843 | conf.parameters = '-'.join(values[:-1]) |
|
842 | 844 | conf.save() |
@@ -1653,7 +1655,7 def radar_start(request, id_camp, id_radar): | |||
|
1653 | 1655 | now = datetime.now() |
|
1654 | 1656 | for exp in experiments: |
|
1655 | 1657 | start = datetime.combine(datetime.now().date(), exp.start_time) |
|
1656 |
end = datetime.combine(datetime.now().date(), exp. |
|
|
1658 | end = datetime.combine(datetime.now().date(), exp.end_time) | |
|
1657 | 1659 | if end < start: |
|
1658 | 1660 | end += timedelta(1) |
|
1659 | 1661 | |
@@ -1670,16 +1672,17 def radar_start(request, id_camp, id_radar): | |||
|
1670 | 1672 | continue |
|
1671 | 1673 | |
|
1672 | 1674 | if now > start and now <= end: |
|
1673 | task = task_start.delay(exp.pk) | |
|
1675 | exp.status = 3 | |
|
1676 | exp.save() | |
|
1677 | task = task_start.delay(exp.id) | |
|
1674 | 1678 | exp.status = task.wait() |
|
1675 | 1679 | if exp.status==0: |
|
1676 | 1680 | messages.error(request, 'Experiment {} not start'.format(exp)) |
|
1677 | 1681 | if exp.status==2: |
|
1678 | task = task_stop.apply_async((exp.pk,), eta=end+timedelta(hours=5)) | |
|
1679 | 1682 | messages.success(request, 'Experiment {} started'.format(exp)) |
|
1680 | 1683 | else: |
|
1681 | task = task_start.apply_async((exp.pk,), eta=start+timedelta(hours=5)) | |
|
1682 | task = task_stop.apply_async((exp.pk,), eta=end+timedelta(hours=5)) | |
|
1684 | task = task_start.apply_async((exp.pk, ), eta=start+timedelta(hours=5)) | |
|
1685 | exp.task = task.id | |
|
1683 | 1686 | exp.status = 3 |
|
1684 | 1687 | messages.success(request, 'Experiment {} programmed to start at {}'.format(exp, start)) |
|
1685 | 1688 | |
@@ -1696,14 +1699,13 def radar_stop(request, id_camp, id_radar): | |||
|
1696 | 1699 | |
|
1697 | 1700 | for exp in experiments: |
|
1698 | 1701 | |
|
1702 | if exp.task: | |
|
1703 | app.control.revoke(exp.task) | |
|
1699 | 1704 | if exp.status == 2: |
|
1700 | task = task_stop.delay(exp.pk) | |
|
1701 | exp.status = task.wait() | |
|
1705 | exp.stop() | |
|
1702 | 1706 | messages.warning(request, 'Experiment {} stopped'.format(exp)) |
|
1703 |
|
|
|
1704 |
e |
|
|
1705 | messages.error(request, 'Experiment {} not running'.format(exp)) | |
|
1706 | kill_tasks() | |
|
1707 | exp.status = 1 | |
|
1708 | exp.save() | |
|
1707 | 1709 | |
|
1708 | 1710 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) |
|
1709 | 1711 | |
@@ -1731,4 +1733,4 def real_time(request): | |||
|
1731 | 1733 | kwargs['graphic_path'] = graphic_path |
|
1732 | 1734 | kwargs['graphic1_path'] = 'http://www.bluemaize.net/im/girls-accessories/shark-beanie-11.jpg' |
|
1733 | 1735 | |
|
1734 | return render(request, 'real_time.html', kwargs) No newline at end of file | |
|
1736 | return render(request, 'real_time.html', kwargs) |
@@ -10,6 +10,7 app = Celery('radarsys') | |||
|
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') |
|
13 | app.conf.broker_transport_options = {'visibility_timeout': 86400} | |
|
13 | 14 | app.autodiscover_tasks(lambda: settings.INSTALLED_APPS) |
|
14 | 15 | |
|
15 | 16 |
General Comments 0
You need to be logged in to leave comments.
Login now