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