@@ -188,8 +188,8 class FilterForm(forms.Form): | |||||
188 | if 'initial' in kwargs: |
|
188 | if 'initial' in kwargs: | |
189 | self.fields[field].widget.attrs = {'start_date':kwargs['initial'].get('start_date', ''), |
|
189 | self.fields[field].widget.attrs = {'start_date':kwargs['initial'].get('start_date', ''), | |
190 | 'end_date':kwargs['initial'].get('end_date', '')} |
|
190 | 'end_date':kwargs['initial'].get('end_date', '')} | |
191 |
elif 'template' |
|
191 | elif field in ('template', 'historical'): | |
192 |
self.fields[ |
|
192 | self.fields[field] = forms.BooleanField(required=False) | |
193 | else: |
|
193 | else: | |
194 | self.fields[field] = forms.CharField(required=False) |
|
194 | self.fields[field] = forms.CharField(required=False) | |
195 |
|
195 |
@@ -361,7 +361,7 class Experiment(models.Model): | |||||
361 | data['end_time'] = data['end_time'].strftime('%H:%M:%S') |
|
361 | data['end_time'] = data['end_time'].strftime('%H:%M:%S') | |
362 | data['location'] = self.location.name |
|
362 | data['location'] = self.location.name | |
363 | data['configurations'] = ['{}'.format(conf.pk) for |
|
363 | data['configurations'] = ['{}'.format(conf.pk) for | |
364 | conf in Configuration.objects.filter(experiment=self)] |
|
364 | conf in Configuration.objects.filter(experiment=self, type=0)] | |
365 |
|
365 | |||
366 | return data |
|
366 | return data | |
367 |
|
367 | |||
@@ -392,23 +392,17 class Experiment(models.Model): | |||||
392 |
|
392 | |||
393 | result = 2 |
|
393 | result = 2 | |
394 |
|
394 | |||
395 |
confs = Configuration.objects.filter(experiment=self |
|
395 | confs = Configuration.objects.filter(experiment=self, type = 0).order_by('-device__device_type__sequence') | |
396 | #Only Configured Devices. |
|
396 | #Only Configured Devices. | |
397 | for conf in confs: |
|
397 | for conf in confs: | |
398 |
|
|
398 | if conf.device.status in (0, 4): | |
399 | if dev_status in [0,4]: |
|
|||
400 | result = 0 |
|
399 | result = 0 | |
401 | return result |
|
400 | return result | |
402 |
|
|
401 | for conf in confs: | |
403 | if conf.device.device_type.name != 'jars': |
|
402 | conf.stop_device() | |
404 |
|
|
403 | #conf.write_device() | |
405 | time.sleep(1) |
|
404 | conf.start_device() | |
406 |
|
|
405 | print conf.device.name+' has started...' | |
407 | else: |
|
|||
408 | conf.stop_device() |
|
|||
409 | conf.write_device() |
|
|||
410 | conf.start_device() |
|
|||
411 | print conf.device.name+' has started...' |
|
|||
412 |
|
406 | |||
413 | return result |
|
407 | return result | |
414 |
|
408 | |||
@@ -421,21 +415,13 class Experiment(models.Model): | |||||
421 |
|
415 | |||
422 | result = 1 |
|
416 | result = 1 | |
423 |
|
417 | |||
424 |
confs = Configuration.objects.filter(experiment=self |
|
418 | confs = Configuration.objects.filter(experiment=self, type = 0).order_by('device__device_type__sequence') | |
425 |
|
||||
426 | for conf in confs: |
|
|||
427 | dev_status = conf.device.status |
|
|||
428 | if dev_status in [0,4]: |
|
|||
429 | result = 0 |
|
|||
430 | return result |
|
|||
431 |
|
||||
432 | #Stop Device |
|
|||
433 | confs=confs.exclude(device__device_type__name='cgs') |
|
419 | confs=confs.exclude(device__device_type__name='cgs') | |
434 | for conf in confs: |
|
420 | for conf in confs: | |
435 |
if conf.device. |
|
421 | if conf.device.status in (0, 4): | |
436 |
|
|
422 | result = 0 | |
437 |
e |
|
423 | continue | |
438 |
|
|
424 | conf.stop_device() | |
439 | print conf.device.name+' has stopped...' |
|
425 | print conf.device.name+' has stopped...' | |
440 |
|
426 | |||
441 | return result |
|
427 | return result | |
@@ -443,7 +429,10 class Experiment(models.Model): | |||||
443 |
|
429 | |||
444 | def get_status(self): |
|
430 | def get_status(self): | |
445 |
|
431 | |||
446 | confs = Configuration.objects.filter(experiment=self) |
|
432 | if self.status == 3: | |
|
433 | return | |||
|
434 | ||||
|
435 | confs = Configuration.objects.filter(experiment=self, type=0) | |||
447 |
|
436 | |||
448 | for conf in confs: |
|
437 | for conf in confs: | |
449 | conf.status_device() |
|
438 | conf.status_device() | |
@@ -457,9 +446,8 class Experiment(models.Model): | |||||
457 | else: |
|
446 | else: | |
458 | status = 0 |
|
447 | status = 0 | |
459 |
|
448 | |||
460 |
|
|
449 | self.status = status | |
461 | self.status = status |
|
450 | self.save() | |
462 | self.save() |
|
|||
463 |
|
451 | |||
464 | def status_color(self): |
|
452 | def status_color(self): | |
465 | color = 'muted' |
|
453 | color = 'muted' |
@@ -19,6 +19,13 def task_stop(id_exp): | |||||
19 |
|
19 | |||
20 | return exp.stop() |
|
20 | return exp.stop() | |
21 |
|
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]) | |||
22 |
|
29 | |||
23 | #Task to get status |
|
30 | #Task to get status | |
24 | @task |
|
31 | @task |
@@ -12,12 +12,42 | |||||
12 |
|
12 | |||
13 | {% block content %} |
|
13 | {% block content %} | |
14 |
|
14 | |||
15 | {% bootstrap_form form layout='horizontal' size='medium' %} |
|
15 | <div class="clearfix"></div> | |
16 | <div style="clear: both;"></div> |
|
16 | ||
|
17 | {% if campaigns %} | |||
|
18 | ||||
|
19 | <h3>Current Campaigns</h3> | |||
|
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 | <p class="list-group-item-text">From: {{item.start_date}}</p> | |||
|
35 | <p class="list-group-item-text">To: {{item.end_date}}</p> | |||
|
36 | </div> | |||
|
37 | </div> | |||
|
38 | </a> | |||
|
39 | {% endfor %} | |||
|
40 | </div> | |||
|
41 | </div> | |||
|
42 | </div> | |||
|
43 | ||||
|
44 | ||||
|
45 | ||||
|
46 | {% endif %} | |||
|
47 | ||||
17 |
|
48 | |||
18 | {% if campaign %} |
|
49 | {% if campaign %} | |
19 |
|
50 | |||
20 | <div class="clearfix"></div> |
|
|||
21 | <h3>Systems</h3> |
|
51 | <h3>Systems</h3> | |
22 | <br> |
|
52 | <br> | |
23 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true" > |
|
53 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true" > |
@@ -1,6 +1,6 | |||||
1 | import ast |
|
1 | import ast | |
2 | import json |
|
2 | import json | |
3 | from datetime import datetime |
|
3 | from datetime import datetime, timedelta | |
4 |
|
4 | |||
5 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse |
|
5 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse | |
6 | from django.utils.safestring import mark_safe |
|
6 | from django.utils.safestring import mark_safe | |
@@ -19,7 +19,7 except ImportError: | |||||
19 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm, NewForm |
|
19 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm, NewForm | |
20 | from .forms import OperationSearchForm, FilterForm, ChangeIpForm |
|
20 | from .forms import OperationSearchForm, FilterForm, ChangeIpForm | |
21 |
|
21 | |||
22 | from .tasks import task_start, task_stop, task_status |
|
22 | from .tasks import task_start, task_stop, task_status, kill_tasks | |
23 |
|
23 | |||
24 | from apps.rc.forms import RCConfigurationForm, RCLineCode, RCMixConfigurationForm |
|
24 | from apps.rc.forms import RCConfigurationForm, RCLineCode, RCMixConfigurationForm | |
25 | from apps.dds.forms import DDSConfigurationForm |
|
25 | from apps.dds.forms import DDSConfigurationForm | |
@@ -363,7 +363,7 def campaign_new(request): | |||||
363 | kwargs['experiment_keys'] = ['name', 'start_time', 'end_time'] |
|
363 | kwargs['experiment_keys'] = ['name', 'start_time', 'end_time'] | |
364 | camp = Campaign.objects.get(pk=request.GET['template']) |
|
364 | camp = Campaign.objects.get(pk=request.GET['template']) | |
365 | form = CampaignForm(instance=camp, |
|
365 | form = CampaignForm(instance=camp, | |
366 |
initial={'name':'{} |
|
366 | initial={'name':'{}_{:%Y%m%d}'.format(camp.name, datetime.now()), | |
367 | 'template':False}) |
|
367 | 'template':False}) | |
368 | elif 'blank' in request.GET: |
|
368 | elif 'blank' in request.GET: | |
369 | kwargs['button'] = 'Create' |
|
369 | kwargs['button'] = 'Create' | |
@@ -1198,7 +1198,7 def dev_confs(request): | |||||
1198 |
|
1198 | |||
1199 | kwargs = get_paginator(Configuration, page, order, filters) |
|
1199 | kwargs = get_paginator(Configuration, page, order, filters) | |
1200 |
|
1200 | |||
1201 | form = FilterForm(initial=request.GET, extra_fields=['tags','template']) |
|
1201 | form = FilterForm(initial=request.GET, extra_fields=['tags', 'template', 'historical']) | |
1202 | kwargs['keys'] = ['name', 'experiment', 'type', 'programmed_date'] |
|
1202 | kwargs['keys'] = ['name', 'experiment', 'type', 'programmed_date'] | |
1203 | kwargs['title'] = 'Configuration' |
|
1203 | kwargs['title'] = 'Configuration' | |
1204 | kwargs['suptitle'] = 'List' |
|
1204 | kwargs['suptitle'] = 'List' | |
@@ -1392,7 +1392,7 def dev_conf_write(request, id_conf): | |||||
1392 | else: |
|
1392 | else: | |
1393 | messages.error(request, conf.message) |
|
1393 | messages.error(request, conf.message) | |
1394 |
|
1394 | |||
1395 | return redirect(conf.get_absolute_url()) |
|
1395 | return redirect(get_object_or_404(Configuration, pk=id_conf).get_absolute_url()) | |
1396 |
|
1396 | |||
1397 |
|
1397 | |||
1398 | @user_passes_test(lambda u:u.is_staff) |
|
1398 | @user_passes_test(lambda u:u.is_staff) | |
@@ -1577,16 +1577,21 def get_paginator(model, page, order, filters={}, n=10): | |||||
1577 | [filters.pop(key) for key in filters.keys() if filters[key] in ('', ' ')] |
|
1577 | [filters.pop(key) for key in filters.keys() if filters[key] in ('', ' ')] | |
1578 | filters.pop('page', None) |
|
1578 | filters.pop('page', None) | |
1579 |
|
1579 | |||
|
1580 | fields = [f.name for f in model._meta.get_fields()] | |||
|
1581 | ||||
1580 | if 'template' in filters: |
|
1582 | if 'template' in filters: | |
1581 | filters['template'] = True |
|
1583 | filters['template'] = True | |
|
1584 | if 'historical' in filters: | |||
|
1585 | filters.pop('historical') | |||
|
1586 | filters['type'] = 1 | |||
|
1587 | elif 'type' in fields: | |||
|
1588 | filters['type'] = 0 | |||
1582 | if 'start_date' in filters: |
|
1589 | if 'start_date' in filters: | |
1583 | filters['start_date__gte'] = filters.pop('start_date') |
|
1590 | filters['start_date__gte'] = filters.pop('start_date') | |
1584 | if 'end_date' in filters: |
|
1591 | if 'end_date' in filters: | |
1585 | filters['start_date__lte'] = filters.pop('end_date') |
|
1592 | filters['start_date__lte'] = filters.pop('end_date') | |
1586 | if 'tags' in filters: |
|
1593 | if 'tags' in filters: | |
1587 | tags = filters.pop('tags') |
|
1594 | tags = filters.pop('tags') | |
1588 | fields = [f.name for f in model._meta.get_fields()] |
|
|||
1589 |
|
||||
1590 | if 'tags' in fields: |
|
1595 | if 'tags' in fields: | |
1591 | query = query | Q(tags__icontains=tags) |
|
1596 | query = query | Q(tags__icontains=tags) | |
1592 | if 'name' in fields: |
|
1597 | if 'name' in fields: | |
@@ -1625,8 +1630,8 def operation(request, id_camp=None): | |||||
1625 | form = OperationForm(initial={'campaign': campaign.id}, campaigns=campaigns) |
|
1630 | form = OperationForm(initial={'campaign': campaign.id}, campaigns=campaigns) | |
1626 | kwargs['campaign'] = campaign |
|
1631 | kwargs['campaign'] = campaign | |
1627 | else: |
|
1632 | else: | |
1628 | form = OperationForm(campaigns=campaigns) |
|
1633 | # form = OperationForm(campaigns=campaigns) | |
1629 |
kwargs[' |
|
1634 | kwargs['campaigns'] = campaigns | |
1630 | return render(request, 'operation.html', kwargs) |
|
1635 | return render(request, 'operation.html', kwargs) | |
1631 |
|
1636 | |||
1632 | #---Experiment |
|
1637 | #---Experiment | |
@@ -1645,11 +1650,13 def radar_start(request, id_camp, id_radar): | |||||
1645 |
|
1650 | |||
1646 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
1651 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
1647 | experiments = campaign.get_experiments_by_radar(id_radar)[0]['experiments'] |
|
1652 | experiments = campaign.get_experiments_by_radar(id_radar)[0]['experiments'] | |
1648 |
now = datetime. |
|
1653 | now = datetime.now() | |
1649 |
|
||||
1650 | for exp in experiments: |
|
1654 | for exp in experiments: | |
1651 |
|
|
1655 | start = datetime.combine(datetime.now().date(), exp.start_time) | |
1652 |
|
1656 | end = datetime.combine(datetime.now().date(), exp.start_time) | ||
|
1657 | if end < start: | |||
|
1658 | end += timedelta(1) | |||
|
1659 | ||||
1653 | if exp.status == 2: |
|
1660 | if exp.status == 2: | |
1654 | messages.warning(request, 'Experiment {} already running'.format(exp)) |
|
1661 | messages.warning(request, 'Experiment {} already running'.format(exp)) | |
1655 | continue |
|
1662 | continue | |
@@ -1658,21 +1665,23 def radar_start(request, id_camp, id_radar): | |||||
1658 | messages.warning(request, 'Experiment {} already programmed'.format(exp)) |
|
1665 | messages.warning(request, 'Experiment {} already programmed'.format(exp)) | |
1659 | continue |
|
1666 | continue | |
1660 |
|
1667 | |||
1661 |
if |
|
1668 | if start > campaign.end_date or start < campaign.start_date: | |
1662 | messages.warning(request, 'Experiment {} out of date'.format(exp)) |
|
1669 | messages.warning(request, 'Experiment {} out of date'.format(exp)) | |
1663 | continue |
|
1670 | continue | |
1664 |
|
1671 | |||
1665 |
if now>= |
|
1672 | if now > start and now <= end: | |
1666 | task = task_start.delay(exp.pk) |
|
1673 | task = task_start.delay(exp.pk) | |
1667 | exp.status = task.wait() |
|
1674 | exp.status = task.wait() | |
1668 | if exp.status==0: |
|
1675 | if exp.status==0: | |
1669 | messages.error(request, 'Experiment {} not start'.format(exp)) |
|
1676 | messages.error(request, 'Experiment {} not start'.format(exp)) | |
1670 | if exp.status==2: |
|
1677 | if exp.status==2: | |
|
1678 | task = task_stop.apply_async((exp.pk,), eta=end+timedelta(hours=5)) | |||
1671 | messages.success(request, 'Experiment {} started'.format(exp)) |
|
1679 | messages.success(request, 'Experiment {} started'.format(exp)) | |
1672 | else: |
|
1680 | else: | |
1673 |
task = task_start.apply_async((exp.pk,), eta= |
|
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)) | |||
1674 | exp.status = 3 |
|
1683 | exp.status = 3 | |
1675 |
messages.success(request, 'Experiment {} programmed to start at {}'.format(exp, |
|
1684 | messages.success(request, 'Experiment {} programmed to start at {}'.format(exp, start)) | |
1676 |
|
1685 | |||
1677 | exp.save() |
|
1686 | exp.save() | |
1678 |
|
1687 | |||
@@ -1694,6 +1703,7 def radar_stop(request, id_camp, id_radar): | |||||
1694 | exp.save() |
|
1703 | exp.save() | |
1695 | else: |
|
1704 | else: | |
1696 | messages.error(request, 'Experiment {} not running'.format(exp)) |
|
1705 | messages.error(request, 'Experiment {} not running'.format(exp)) | |
|
1706 | kill_tasks() | |||
1697 |
|
1707 | |||
1698 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) |
|
1708 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) | |
1699 |
|
1709 |
General Comments 0
You need to be logged in to leave comments.
Login now