@@ -14,7 +14,7 EXP_STATES = ( | |||||
14 | (1,'Configurated'), #BLUE |
|
14 | (1,'Configurated'), #BLUE | |
15 | (2,'Running'), #GREEN |
|
15 | (2,'Running'), #GREEN | |
16 | (3,'Waiting'), #YELLOW |
|
16 | (3,'Waiting'), #YELLOW | |
17 |
(4,'Not |
|
17 | (4,'Not Configured'), #WHITE | |
18 | ) |
|
18 | ) | |
19 |
|
19 | |||
20 | CONF_TYPES = ( |
|
20 | CONF_TYPES = ( | |
@@ -50,14 +50,13 DEV_PORTS = { | |||||
50 |
|
50 | |||
51 | RADAR_STATES = ( |
|
51 | RADAR_STATES = ( | |
52 | (0, 'No connected'), |
|
52 | (0, 'No connected'), | |
53 |
(1, 'Conn |
|
53 | (1, 'Connected'), | |
54 | (2, 'Configured'), |
|
54 | (2, 'Configured'), | |
55 | (3, 'Running'), |
|
55 | (3, 'Running'), | |
56 | (4, 'Scheduled'), |
|
56 | (4, 'Scheduled'), | |
57 | ) |
|
57 | ) | |
58 | # Create your models here. |
|
58 | # Create your models here. | |
59 |
|
59 | |||
60 |
|
||||
61 | class Location(models.Model): |
|
60 | class Location(models.Model): | |
62 |
|
61 | |||
63 | name = models.CharField(max_length = 30) |
|
62 | name = models.CharField(max_length = 30) | |
@@ -107,6 +106,8 class Campaign(models.Model): | |||||
107 | template = models.BooleanField(default=False) |
|
106 | template = models.BooleanField(default=False) | |
108 |
|
107 | |||
109 | name = models.CharField(max_length=40, unique=True) |
|
108 | name = models.CharField(max_length=40, unique=True) | |
|
109 | experiment = models.ManyToManyField('Experiment') | |||
|
110 | ||||
110 | start_date = models.DateTimeField(blank=True, null=True) |
|
111 | start_date = models.DateTimeField(blank=True, null=True) | |
111 | end_date = models.DateTimeField(blank=True, null=True) |
|
112 | end_date = models.DateTimeField(blank=True, null=True) | |
112 | tags = models.CharField(max_length=40) |
|
113 | tags = models.CharField(max_length=40) | |
@@ -131,22 +132,23 class Campaign(models.Model): | |||||
131 | # def __unicode__(self): |
|
132 | # def __unicode__(self): | |
132 | # return u'%s' % self.location |
|
133 | # return u'%s' % self.location | |
133 |
|
134 | |||
134 |
|
|
135 | class RunningExperiment(models.Model): | |
135 |
|
|
136 | radar = models.OneToOneField('Location', on_delete=models.CASCADE) | |
136 |
|
|
137 | running_experiment = models.ManyToManyField('Experiment') | |
137 |
|
|
138 | status = models.PositiveSmallIntegerField(default=0, choices=RADAR_STATES) | |
138 |
|
139 | |||
139 |
|
140 | |||
140 | class Experiment(models.Model): |
|
141 | class Experiment(models.Model): | |
141 |
|
142 | |||
142 | template = models.BooleanField(default=False) |
|
143 | template = models.BooleanField(default=False) | |
143 |
|
144 | |||
144 | campaign = models.ForeignKey('Campaign', null=True, blank=True, on_delete=models.CASCADE) |
|
145 | #campaign = models.ForeignKey('Campaign', null=True, blank=True, on_delete=models.CASCADE) | |
145 | location = models.ForeignKey('Location', null=True, blank=True, on_delete=models.CASCADE) |
|
146 | location = models.ForeignKey('Location', null=True, blank=True, on_delete=models.CASCADE) | |
146 |
|
147 | |||
147 | name = models.CharField(max_length=40, default='') |
|
148 | name = models.CharField(max_length=40, default='') | |
148 | start_time = models.TimeField(default='00:00:00') |
|
149 | start_time = models.TimeField(default='00:00:00') | |
149 | end_time = models.TimeField(default='23:59:59') |
|
150 | end_time = models.TimeField(default='23:59:59') | |
|
151 | status = models.PositiveSmallIntegerField(default=0, choices=EXP_STATES) | |||
150 |
|
152 | |||
151 | class Meta: |
|
153 | class Meta: | |
152 | db_table = 'db_experiments' |
|
154 | db_table = 'db_experiments' | |
@@ -154,6 +156,48 class Experiment(models.Model): | |||||
154 | def __unicode__(self): |
|
156 | def __unicode__(self): | |
155 | return u'%s' % (self.name) |
|
157 | return u'%s' % (self.name) | |
156 |
|
158 | |||
|
159 | ||||
|
160 | def get_status(self): | |||
|
161 | configurations = Configuration.objects.filter(experiment=self) | |||
|
162 | exp_status=[] | |||
|
163 | for conf in configurations: | |||
|
164 | print conf.status_device() | |||
|
165 | exp_status.append(conf.status_device()) | |||
|
166 | ||||
|
167 | if not exp_status: #No Configuration | |||
|
168 | self.status = 4 | |||
|
169 | self.save() | |||
|
170 | return | |||
|
171 | ||||
|
172 | total = 1 | |||
|
173 | for e_s in exp_status: | |||
|
174 | total = total*e_s | |||
|
175 | ||||
|
176 | if total == 0: #Error | |||
|
177 | status = 0 | |||
|
178 | elif total == (3**len(exp_status)): #Running | |||
|
179 | status = 2 | |||
|
180 | else: | |||
|
181 | status = 1 #Configurated | |||
|
182 | ||||
|
183 | self.status = status | |||
|
184 | self.save() | |||
|
185 | ||||
|
186 | def status_color(self): | |||
|
187 | color = 'danger' | |||
|
188 | if self.status == 0: | |||
|
189 | color = "danger" | |||
|
190 | elif self.status == 1: | |||
|
191 | color = "info" | |||
|
192 | elif self.status == 2: | |||
|
193 | color = "succes" | |||
|
194 | elif self.status == 3: | |||
|
195 | color = "warning" | |||
|
196 | else: | |||
|
197 | color = "muted" | |||
|
198 | ||||
|
199 | return color | |||
|
200 | ||||
157 | class Configuration(PolymorphicModel): |
|
201 | class Configuration(PolymorphicModel): | |
158 |
|
202 | |||
159 | template = models.BooleanField(default=False) |
|
203 | template = models.BooleanField(default=False) |
@@ -41,8 +41,10 urlpatterns = ( | |||||
41 | url(r'^dev_conf/(?P<id_conf>-?\d+)/status/$', 'apps.main.views.dev_conf_status', name='url_status_dev_conf'), |
|
41 | url(r'^dev_conf/(?P<id_conf>-?\d+)/status/$', 'apps.main.views.dev_conf_status', name='url_status_dev_conf'), | |
42 |
|
42 | |||
43 | url(r'^operation/$', 'apps.main.views.operation', name='url_operation'), |
|
43 | url(r'^operation/$', 'apps.main.views.operation', name='url_operation'), | |
|
44 | url(r'^operation/(?P<id_camp>-?\d+)/$', 'apps.main.views.operation', name='url_operation'), | |||
44 | url(r'^operation/search/$', 'apps.main.views.operation_search', name='url_operation_search'), |
|
45 | url(r'^operation/search/$', 'apps.main.views.operation_search', name='url_operation_search'), | |
45 | url(r'^operation/search/(?P<id_camp>-?\d+)/$', 'apps.main.views.operation_search', name='url_operation_search'), |
|
46 | url(r'^operation/search/(?P<id_camp>-?\d+)/$', 'apps.main.views.operation_search', name='url_operation_search'), | |
46 |
url(r'^operation/(?P<id_camp>-?\d+)/$', 'apps.main.views. |
|
47 | url(r'^operation/(?P<id_camp>-?\d+)/radar/(?P<id_radar>-?\d+)/play/$', 'apps.main.views.radar_play', name='url_radar_play'), | |
|
48 | url(r'^operation/(?P<id_camp>-?\d+)/radar/(?P<id_radar>-?\d+)/stop/$', 'apps.main.views.radar_stop', name='url_radar_stop'), | |||
47 |
|
49 | |||
48 | ) |
|
50 | ) |
@@ -1,4 +1,6 | |||||
1 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse |
|
1 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse | |
|
2 | from django.http import HttpResponseRedirect | |||
|
3 | from django.core.urlresolvers import reverse | |||
2 | from django.contrib import messages |
|
4 | from django.contrib import messages | |
3 |
|
5 | |||
4 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm |
|
6 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm | |
@@ -10,7 +12,7 from apps.abs.forms import ABSConfigurationForm | |||||
10 | from apps.rc.forms import RCConfigurationForm |
|
12 | from apps.rc.forms import RCConfigurationForm | |
11 | from apps.dds.forms import DDSConfigurationForm |
|
13 | from apps.dds.forms import DDSConfigurationForm | |
12 |
|
14 | |||
13 |
from .models import Campaign, Experiment, Device, Configuration, Location |
|
15 | from .models import Campaign, Experiment, Device, Configuration, Location, RunningExperiment | |
14 | from apps.cgs.models import CGSConfiguration |
|
16 | from apps.cgs.models import CGSConfiguration | |
15 | from apps.jars.models import JARSConfiguration |
|
17 | from apps.jars.models import JARSConfiguration | |
16 | from apps.usrp.models import USRPConfiguration |
|
18 | from apps.usrp.models import USRPConfiguration | |
@@ -401,7 +403,6 def experiment_new(request, id_camp=None): | |||||
401 |
|
403 | |||
402 | if form.is_valid(): |
|
404 | if form.is_valid(): | |
403 | experiment = form.save() |
|
405 | experiment = form.save() | |
404 | ##AGREGAR! |
|
|||
405 | return redirect('url_experiment', id_exp=experiment.id) |
|
406 | return redirect('url_experiment', id_exp=experiment.id) | |
406 |
|
407 | |||
407 | kwargs = {} |
|
408 | kwargs = {} | |
@@ -813,6 +814,8 def operation(request, id_camp=None): | |||||
813 | return redirect('url_operation', id_camp=campaign.id) |
|
814 | return redirect('url_operation', id_camp=campaign.id) | |
814 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() |
|
815 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() | |
815 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) |
|
816 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) | |
|
817 | for exs in experiments: | |||
|
818 | exs.get_status() | |||
816 | locations= Location.objects.filter(experiment=experiments).distinct() |
|
819 | locations= Location.objects.filter(experiment=experiments).distinct() | |
817 | #experiments = [Experiment.objects.filter(location__pk=location.id).filter(campaign__pk=campaign.id) for location in locations] |
|
820 | #experiments = [Experiment.objects.filter(location__pk=location.id).filter(campaign__pk=campaign.id) for location in locations] | |
818 | kwargs = {} |
|
821 | kwargs = {} | |
@@ -835,12 +838,11 def operation(request, id_camp=None): | |||||
835 |
|
838 | |||
836 | return render(request, 'operation.html', kwargs) |
|
839 | return render(request, 'operation.html', kwargs) | |
837 |
|
840 | |||
838 |
def operation_search(request, id_camp=None |
|
841 | def operation_search(request, id_camp=None): | |
839 |
|
842 | |||
840 |
|
843 | |||
841 | if not id_camp: |
|
844 | if not id_camp: | |
842 | campaigns = Campaign.objects.all().order_by('-start_date') |
|
845 | campaigns = Campaign.objects.all().order_by('-start_date') | |
843 | form = OperationSearchForm() |
|
|||
844 |
|
846 | |||
845 | if not campaigns: |
|
847 | if not campaigns: | |
846 | return render(request, 'operation.html', {}) |
|
848 | return render(request, 'operation.html', {}) | |
@@ -848,19 +850,20 def operation_search(request, id_camp=None, location_play = None): | |||||
848 | id_camp = campaigns[0].id |
|
850 | id_camp = campaigns[0].id | |
849 |
|
|
851 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
850 |
|
|
852 | ||
851 | kwargs = {} |
|
853 | if request.method=='GET': | |
852 | kwargs['title'] = 'All Campaigns' |
|
854 | form = OperationSearchForm(initial={'campaign': campaign.id}) | |
853 | kwargs['form'] = form |
|
855 | ||
854 | kwargs['details'] = True |
|
856 | if request.method=='POST': | |
855 | return render(request, 'operation.html', kwargs) |
|
857 | form = OperationSearchForm(request.POST, initial={'campaign':campaign.id}) | |
|
858 | ||||
|
859 | if form.is_valid(): | |||
|
860 | return redirect('url_operation', id_camp=campaign.id) | |||
856 |
|
861 | |||
857 | else: |
|
|||
858 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
|||
859 |
|
|
862 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() | |
860 | #experiments = Experiment.objects.filter(campaign__pk=campaign.id) |
|
|||
861 |
|
|
863 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) | |
|
864 | for exs in experiments: | |||
|
865 | exs.get_status() | |||
862 |
|
|
866 | locations= Location.objects.filter(experiment=experiments).distinct() | |
863 | #experiments = [Experiment.objects.filter(location__pk=location.id).filter(campaign__pk=campaign.id) for location in locations] |
|
|||
864 |
|
|
867 | form = OperationSearchForm(initial={'campaign': campaign.id}) | |
865 |
|
868 | |||
866 |
|
|
869 | kwargs = {} | |
@@ -868,7 +871,7 def operation_search(request, id_camp=None, location_play = None): | |||||
868 |
|
|
871 | kwargs['campaign'] = campaign | |
869 |
|
|
872 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] | |
870 |
|
|
873 | #---Experiment | |
871 |
|
|
874 | keys = ['id', 'name', 'start_time', 'end_time', 'status'] | |
872 |
|
|
875 | kwargs['experiment_keys'] = keys[1:] | |
873 |
|
|
876 | kwargs['experiments'] = experiments | |
874 |
|
|
877 | #---Radar | |
@@ -881,12 +884,23 def operation_search(request, id_camp=None, location_play = None): | |||||
881 |
|
|
884 | kwargs['details'] = True | |
882 |
|
|
885 | kwargs['search_button'] = False | |
883 |
|
|
886 | ||
|
887 | return render(request, 'operation.html', kwargs) | |||
884 |
|
888 | |||
885 | if request.method=='POST': |
|
|||
886 | form = OperationSearchForm(request.POST, initial={'campaign':campaign.id}) |
|
|||
887 |
|
889 | |||
888 | if form.is_valid(): |
|
890 | def radar_play(request, id_camp, id_radar): | |
889 | return redirect('operation.html', id_camp=campaign.id) |
|
891 | ||
|
892 | route = request.META['HTTP_REFERER'] | |||
|
893 | route = str(route) | |||
|
894 | if 'search' in route: | |||
|
895 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) | |||
|
896 | else: | |||
|
897 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) | |||
890 |
|
898 | |||
|
899 | def radar_stop(request, id_camp, id_radar): | |||
891 |
|
900 | |||
892 | return render(request, 'operation.html', kwargs) No newline at end of file |
|
901 | route = request.META['HTTP_REFERER'] | |
|
902 | route = str(route) | |||
|
903 | if 'search' in route: | |||
|
904 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) | |||
|
905 | else: | |||
|
906 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now