@@ -10,11 +10,11 CONF_STATES = ( | |||
|
10 | 10 | ) |
|
11 | 11 | |
|
12 | 12 | EXP_STATES = ( |
|
13 | (0,'Error'), #RED | |
|
14 | (1,'Configurated'), #BLUE | |
|
15 | (2,'Running'), #GREEN | |
|
16 | (3,'Waiting'), #YELLOW | |
|
17 |
(4,'Not |
|
|
13 | (0,'Error'), #RED | |
|
14 | (1,'Configurated'), #BLUE | |
|
15 | (2,'Running'), #GREEN | |
|
16 | (3,'Waiting'), #YELLOW | |
|
17 | (4,'Not Configured'), #WHITE | |
|
18 | 18 | ) |
|
19 | 19 | |
|
20 | 20 | CONF_TYPES = ( |
@@ -50,13 +50,12 DEV_PORTS = { | |||
|
50 | 50 | |
|
51 | 51 | RADAR_STATES = ( |
|
52 | 52 | (0, 'No connected'), |
|
53 |
(1, 'Conn |
|
|
53 | (1, 'Connected'), | |
|
54 | 54 | (2, 'Configured'), |
|
55 | 55 | (3, 'Running'), |
|
56 | 56 | (4, 'Scheduled'), |
|
57 | 57 | ) |
|
58 | 58 | # Create your models here. |
|
59 | ||
|
60 | 59 | |
|
61 | 60 | class Location(models.Model): |
|
62 | 61 | |
@@ -107,6 +106,8 class Campaign(models.Model): | |||
|
107 | 106 | template = models.BooleanField(default=False) |
|
108 | 107 | |
|
109 | 108 | name = models.CharField(max_length=40, unique=True) |
|
109 | experiment = models.ManyToManyField('Experiment') | |
|
110 | ||
|
110 | 111 | start_date = models.DateTimeField(blank=True, null=True) |
|
111 | 112 | end_date = models.DateTimeField(blank=True, null=True) |
|
112 | 113 | tags = models.CharField(max_length=40) |
@@ -131,22 +132,23 class Campaign(models.Model): | |||
|
131 | 132 | # def __unicode__(self): |
|
132 | 133 | # return u'%s' % self.location |
|
133 | 134 | |
|
134 |
|
|
|
135 |
|
|
|
136 |
|
|
|
137 |
|
|
|
135 | class RunningExperiment(models.Model): | |
|
136 | radar = models.OneToOneField('Location', on_delete=models.CASCADE) | |
|
137 | running_experiment = models.ManyToManyField('Experiment') | |
|
138 | status = models.PositiveSmallIntegerField(default=0, choices=RADAR_STATES) | |
|
138 | 139 | |
|
139 | 140 | |
|
140 | 141 | class Experiment(models.Model): |
|
141 | 142 | |
|
142 | 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 | 146 | location = models.ForeignKey('Location', null=True, blank=True, on_delete=models.CASCADE) |
|
146 | 147 | |
|
147 | 148 | name = models.CharField(max_length=40, default='') |
|
148 | 149 | start_time = models.TimeField(default='00:00:00') |
|
149 | 150 | end_time = models.TimeField(default='23:59:59') |
|
151 | status = models.PositiveSmallIntegerField(default=0, choices=EXP_STATES) | |
|
150 | 152 | |
|
151 | 153 | class Meta: |
|
152 | 154 | db_table = 'db_experiments' |
@@ -154,6 +156,48 class Experiment(models.Model): | |||
|
154 | 156 | def __unicode__(self): |
|
155 | 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 | 201 | class Configuration(PolymorphicModel): |
|
158 | 202 | |
|
159 | 203 | template = models.BooleanField(default=False) |
@@ -41,8 +41,10 urlpatterns = ( | |||
|
41 | 41 | url(r'^dev_conf/(?P<id_conf>-?\d+)/status/$', 'apps.main.views.dev_conf_status', name='url_status_dev_conf'), |
|
42 | 42 | |
|
43 | 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 | 45 | url(r'^operation/search/$', 'apps.main.views.operation_search', name='url_operation_search'), |
|
45 | 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 | 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 | 4 | from django.contrib import messages |
|
3 | 5 | |
|
4 | 6 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm |
@@ -10,7 +12,7 from apps.abs.forms import ABSConfigurationForm | |||
|
10 | 12 | from apps.rc.forms import RCConfigurationForm |
|
11 | 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 | 16 | from apps.cgs.models import CGSConfiguration |
|
15 | 17 | from apps.jars.models import JARSConfiguration |
|
16 | 18 | from apps.usrp.models import USRPConfiguration |
@@ -401,7 +403,6 def experiment_new(request, id_camp=None): | |||
|
401 | 403 | |
|
402 | 404 | if form.is_valid(): |
|
403 | 405 | experiment = form.save() |
|
404 | ##AGREGAR! | |
|
405 | 406 | return redirect('url_experiment', id_exp=experiment.id) |
|
406 | 407 | |
|
407 | 408 | kwargs = {} |
@@ -813,6 +814,8 def operation(request, id_camp=None): | |||
|
813 | 814 | return redirect('url_operation', id_camp=campaign.id) |
|
814 | 815 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() |
|
815 | 816 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) |
|
817 | for exs in experiments: | |
|
818 | exs.get_status() | |
|
816 | 819 | locations= Location.objects.filter(experiment=experiments).distinct() |
|
817 | 820 | #experiments = [Experiment.objects.filter(location__pk=location.id).filter(campaign__pk=campaign.id) for location in locations] |
|
818 | 821 | kwargs = {} |
@@ -835,58 +838,69 def operation(request, id_camp=None): | |||
|
835 | 838 | |
|
836 | 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 | 844 | if not id_camp: |
|
842 | 845 | campaigns = Campaign.objects.all().order_by('-start_date') |
|
843 | form = OperationSearchForm() | |
|
844 | 846 | |
|
845 | 847 | if not campaigns: |
|
846 | 848 | return render(request, 'operation.html', {}) |
|
847 | 849 | |
|
848 | 850 | id_camp = campaigns[0].id |
|
849 |
|
|
|
850 | ||
|
851 | kwargs = {} | |
|
852 | kwargs['title'] = 'All Campaigns' | |
|
853 | kwargs['form'] = form | |
|
854 | kwargs['details'] = True | |
|
855 | return render(request, 'operation.html', kwargs) | |
|
851 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
|
856 | 852 | |
|
857 | else: | |
|
858 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
|
859 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() | |
|
860 | #experiments = Experiment.objects.filter(campaign__pk=campaign.id) | |
|
861 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) | |
|
862 | 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] | |
|
853 | if request.method=='GET': | |
|
864 | 854 | form = OperationSearchForm(initial={'campaign': campaign.id}) |
|
865 | 855 | |
|
866 | kwargs = {} | |
|
867 | #---Campaign | |
|
868 | kwargs['campaign'] = campaign | |
|
869 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] | |
|
870 | #---Experiment | |
|
871 | keys = ['id', 'name', 'start_time', 'end_time'] | |
|
872 | kwargs['experiment_keys'] = keys[1:] | |
|
873 | kwargs['experiments'] = experiments | |
|
874 | #---Radar | |
|
875 | kwargs['locations'] = locations | |
|
876 | #---Else | |
|
877 | kwargs['title'] = 'Campaign' | |
|
878 | kwargs['suptitle'] = campaign.name | |
|
879 | kwargs['form'] = form | |
|
880 | kwargs['button'] = 'Select' | |
|
881 | kwargs['details'] = True | |
|
882 | kwargs['search_button'] = False | |
|
883 | ||
|
884 | ||
|
885 | 856 | if request.method=='POST': |
|
886 | 857 | form = OperationSearchForm(request.POST, initial={'campaign':campaign.id}) |
|
887 | 858 | |
|
888 | 859 | if form.is_valid(): |
|
889 |
return redirect('operation |
|
|
860 | return redirect('url_operation', id_camp=campaign.id) | |
|
890 | 861 | |
|
862 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() | |
|
863 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) | |
|
864 | for exs in experiments: | |
|
865 | exs.get_status() | |
|
866 | locations= Location.objects.filter(experiment=experiments).distinct() | |
|
867 | form = OperationSearchForm(initial={'campaign': campaign.id}) | |
|
868 | ||
|
869 | kwargs = {} | |
|
870 | #---Campaign | |
|
871 | kwargs['campaign'] = campaign | |
|
872 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] | |
|
873 | #---Experiment | |
|
874 | keys = ['id', 'name', 'start_time', 'end_time', 'status'] | |
|
875 | kwargs['experiment_keys'] = keys[1:] | |
|
876 | kwargs['experiments'] = experiments | |
|
877 | #---Radar | |
|
878 | kwargs['locations'] = locations | |
|
879 | #---Else | |
|
880 | kwargs['title'] = 'Campaign' | |
|
881 | kwargs['suptitle'] = campaign.name | |
|
882 | kwargs['form'] = form | |
|
883 | kwargs['button'] = 'Select' | |
|
884 | kwargs['details'] = True | |
|
885 | kwargs['search_button'] = False | |
|
886 | ||
|
887 | return render(request, 'operation.html', kwargs) | |
|
888 | ||
|
889 | ||
|
890 | def radar_play(request, id_camp, id_radar): | |
|
891 | 891 | |
|
892 | return render(request, 'operation.html', kwargs) No newline at end of file | |
|
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])) | |
|
898 | ||
|
899 | def radar_stop(request, id_camp, id_radar): | |
|
900 | ||
|
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