@@ -0,0 +1,1 | |||
|
1 | {% extends "campaign_edit.html" %} No newline at end of file |
@@ -0,0 +1,1 | |||
|
1 | {% extends "experiment_edit.html" %} No newline at end of file |
@@ -1,173 +1,182 | |||
|
1 | 1 | from django.db import models |
|
2 | 2 | from apps.main.models import Configuration |
|
3 | 3 | from django.core.validators import MinValueValidator, MaxValueValidator |
|
4 | 4 | |
|
5 | 5 | |
|
6 | 6 | from apps.main.models import Device, Experiment |
|
7 | 7 | |
|
8 | 8 | from files import read_json_file |
|
9 | 9 | # Create your models here. validators=[MinValueValidator(62.5e6), MaxValueValidator(450e6)] |
|
10 | 10 | |
|
11 | 11 | class CGSConfiguration(Configuration): |
|
12 | 12 | |
|
13 | 13 | freq0 = models.PositiveIntegerField(verbose_name='Frequency 0',validators=[MaxValueValidator(450e6)], default = 60) |
|
14 | 14 | freq1 = models.PositiveIntegerField(verbose_name='Frequency 1',validators=[MaxValueValidator(450e6)], default = 60) |
|
15 | 15 | freq2 = models.PositiveIntegerField(verbose_name='Frequency 2',validators=[MaxValueValidator(450e6)], default = 60) |
|
16 | 16 | freq3 = models.PositiveIntegerField(verbose_name='Frequency 3',validators=[MaxValueValidator(450e6)], default = 60) |
|
17 | 17 | |
|
18 | 18 | def verify_frequencies(self): |
|
19 | 19 | |
|
20 | 20 | return True |
|
21 | 21 | |
|
22 | 22 | |
|
23 | 23 | def update_from_file(self, fp): |
|
24 | 24 | |
|
25 | 25 | kwargs = read_json_file(fp) |
|
26 | 26 | |
|
27 | 27 | if not kwargs: |
|
28 | 28 | return False |
|
29 | 29 | |
|
30 | 30 | self.freq0 = kwargs['freq0'] |
|
31 | 31 | self.freq1 = kwargs['freq1'] |
|
32 | 32 | self.freq2 = kwargs['freq2'] |
|
33 | 33 | self.freq3 = kwargs['freq3'] |
|
34 | 34 | |
|
35 | 35 | return True |
|
36 | 36 | |
|
37 | 37 | def parms_to_dict(self): |
|
38 | 38 | |
|
39 | 39 | parameters = {} |
|
40 | 40 | |
|
41 | parameters['device_id'] = self.device.id | |
|
42 | ||
|
41 | 43 | if self.freq0 == None or self.freq0 == '': |
|
42 | 44 | parameters['freq0'] = 0 |
|
43 | 45 | else: |
|
44 | 46 | parameters['freq0'] = self.freq0 |
|
45 | 47 | |
|
46 | 48 | if self.freq1 == None or self.freq1 == '': |
|
47 | 49 | parameters['freq1'] = 0 |
|
48 | 50 | else: |
|
49 | 51 | parameters['freq1'] = self.freq1 |
|
50 | 52 | |
|
51 | 53 | if self.freq2 == None or self.freq2 == '': |
|
52 | 54 | parameters['freq2'] = 0 |
|
53 | 55 | else: |
|
54 | 56 | parameters['freq2'] = self.freq2 |
|
55 | 57 | |
|
56 | 58 | if self.freq3 == None or self.freq3 == '': |
|
57 | 59 | parameters['freq3'] = 0 |
|
58 | 60 | else: |
|
59 | 61 | parameters['freq3'] = self.freq3 |
|
60 | 62 | |
|
61 | ||
|
62 | 63 | return parameters |
|
63 | 64 | |
|
64 | 65 | |
|
66 | def dict_to_parms(self, parameters): | |
|
67 | ||
|
68 | self.freq0 = parameters['freq0'] | |
|
69 | self.freq1 = parameters['freq1'] | |
|
70 | self.freq2 = parameters['freq2'] | |
|
71 | self.freq3 = parameters['freq3'] | |
|
72 | ||
|
73 | ||
|
65 | 74 | def status_device(self): |
|
66 | 75 | |
|
67 | 76 | import requests |
|
68 | 77 | |
|
69 | 78 | ip=self.device.ip_address |
|
70 | 79 | port=self.device.port_address |
|
71 | 80 | |
|
72 | 81 | route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548" |
|
73 | 82 | try: |
|
74 | 83 | r = requests.get(route,timeout=0.5) |
|
75 | 84 | except: |
|
76 | 85 | self.device.status = 0 |
|
77 | 86 | self.device.save() |
|
78 | 87 | return self.device.status |
|
79 | 88 | |
|
80 | 89 | response = str(r.text) |
|
81 | 90 | response = response.split(";") |
|
82 | 91 | icon = response[0] |
|
83 | 92 | status = response[-1] |
|
84 | 93 | |
|
85 | 94 | print icon, status |
|
86 | 95 | #"icon" could be: "alert" or "okay" |
|
87 | 96 | if "alert" in icon: |
|
88 | 97 | if "Starting Up" in status: #No Esta conectado |
|
89 | 98 | self.device.status = 0 |
|
90 | 99 | else: |
|
91 | 100 | self.device.status = 1 |
|
92 | 101 | elif "okay" in icon: |
|
93 | 102 | self.device.status = 3 |
|
94 | 103 | else: |
|
95 | 104 | self.device.status = 1 |
|
96 | 105 | |
|
97 | 106 | self.message = status |
|
98 | 107 | self.device.save() |
|
99 | 108 | |
|
100 | 109 | |
|
101 | 110 | return self.device.status |
|
102 | 111 | |
|
103 | 112 | |
|
104 | 113 | def read_device(self): |
|
105 | 114 | |
|
106 | 115 | import requests |
|
107 | 116 | |
|
108 | 117 | ip=self.device.ip_address |
|
109 | 118 | port=self.device.port_address |
|
110 | 119 | |
|
111 | 120 | route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" |
|
112 | 121 | try: |
|
113 | 122 | frequencies = requests.get(route,timeout=0.5) |
|
114 | 123 | |
|
115 | 124 | except: |
|
116 | 125 | self.message = "Could not read CGS parameters from this device" |
|
117 | 126 | return None |
|
118 | 127 | |
|
119 | 128 | frequencies = frequencies.json() |
|
120 | 129 | frequencies = frequencies.get("Frecuencias") |
|
121 | 130 | f0 = frequencies.get("f0") |
|
122 | 131 | f1 = frequencies.get("f1") |
|
123 | 132 | f2 = frequencies.get("f2") |
|
124 | 133 | f3 = frequencies.get("f3") |
|
125 | 134 | |
|
126 | 135 | parms = {'freq0': f0, |
|
127 | 136 | 'freq1': f1, |
|
128 | 137 | 'freq2': f2, |
|
129 | 138 | 'freq3': f3} |
|
130 | 139 | |
|
131 | 140 | self.message = "" |
|
132 | 141 | return parms |
|
133 | 142 | |
|
134 | 143 | |
|
135 | 144 | def write_device(self): |
|
136 | 145 | |
|
137 | 146 | import requests |
|
138 | 147 | |
|
139 | 148 | ip=self.device.ip_address |
|
140 | 149 | port=self.device.port_address |
|
141 | 150 | |
|
142 | 151 | #---Frequencies from form |
|
143 | 152 | f0 = self.freq0 |
|
144 | 153 | f1 = self.freq1 |
|
145 | 154 | f2 = self.freq2 |
|
146 | 155 | f3 = self.freq3 |
|
147 | 156 | post_data = {"f0":f0, "f1":f1, "f2":f2, "f3":f3} |
|
148 | 157 | route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" |
|
149 | 158 | |
|
150 | 159 | try: |
|
151 | 160 | r = requests.post(route, post_data, timeout=0.5) |
|
152 | 161 | except: |
|
153 | 162 | self.message = "Could not write CGS parameters" |
|
154 | 163 | return None |
|
155 | 164 | |
|
156 | 165 | text = r.text |
|
157 | 166 | text = text.split(',') |
|
158 | 167 | |
|
159 | 168 | if len(text)>1: |
|
160 | 169 | title = text[0] |
|
161 | 170 | status = text[1] |
|
162 | 171 | if title == "okay": |
|
163 | 172 | self.message = status |
|
164 | 173 | return 3 |
|
165 | 174 | else: |
|
166 | 175 | self.message = title + ", " + status |
|
167 | 176 | return 1 |
|
168 | 177 | |
|
169 | 178 | return 1 |
|
170 | 179 | |
|
171 | 180 | |
|
172 | 181 | class Meta: |
|
173 | 182 | db_table = 'cgs_configurations' |
@@ -1,228 +1,230 | |||
|
1 | 1 | from django.db import models |
|
2 | 2 | from apps.main.models import Configuration |
|
3 | 3 | # Create your models here. |
|
4 | 4 | |
|
5 | 5 | from django.core.validators import MinValueValidator, MaxValueValidator |
|
6 | 6 | from django.core.exceptions import ValidationError |
|
7 | 7 | |
|
8 | 8 | from devices.dds import api, data |
|
9 | 9 | |
|
10 | 10 | ENABLE_TYPE = ( |
|
11 | 11 | (False, 'Disabled'), |
|
12 | 12 | (True, 'Enabled'), |
|
13 | 13 | ) |
|
14 | 14 | MOD_TYPES = ( |
|
15 | 15 | (0, 'Single Tone'), |
|
16 | 16 | (1, 'FSK'), |
|
17 | 17 | (2, 'Ramped FSK'), |
|
18 | 18 | (3, 'Chirp'), |
|
19 | 19 | (4, 'BPSK'), |
|
20 | 20 | ) |
|
21 | 21 | |
|
22 | 22 | class DDSConfiguration(Configuration): |
|
23 | 23 | |
|
24 | 24 | DDS_NBITS = 48 |
|
25 | 25 | |
|
26 | 26 | clock = models.FloatField(verbose_name='Clock Input (MHz)',validators=[MinValueValidator(5), MaxValueValidator(75)], null=True, default=60) |
|
27 | 27 | multiplier = models.PositiveIntegerField(verbose_name='Multiplier',validators=[MinValueValidator(1), MaxValueValidator(20)], default=4) |
|
28 | 28 | |
|
29 | 29 | frequencyA_Mhz = models.DecimalField(verbose_name='Frequency A (MHz)', validators=[MinValueValidator(0), MaxValueValidator(150)], max_digits=19, decimal_places=16, null=True, default=49.9200) |
|
30 | 30 | frequencyA = models.BigIntegerField(verbose_name='Frequency A (Decimal)',validators=[MinValueValidator(0), MaxValueValidator(2**DDS_NBITS-1)], blank=True, null=True) |
|
31 | 31 | |
|
32 | 32 | frequencyB_Mhz = models.DecimalField(verbose_name='Frequency B (MHz)', validators=[MinValueValidator(0), MaxValueValidator(150)], max_digits=19, decimal_places=16, blank=True, null=True) |
|
33 | 33 | frequencyB = models.BigIntegerField(verbose_name='Frequency B (Decimal)',validators=[MinValueValidator(0), MaxValueValidator(2**DDS_NBITS-1)], blank=True, null=True) |
|
34 | 34 | |
|
35 | 35 | phaseA_degrees = models.FloatField(verbose_name='Phase A (Degrees)', validators=[MinValueValidator(0), MaxValueValidator(360)], default=0) |
|
36 | 36 | |
|
37 | 37 | phaseB_degrees = models.FloatField(verbose_name='Phase B (Degrees)', validators=[MinValueValidator(0), MaxValueValidator(360)], blank=True, null=True) |
|
38 | 38 | |
|
39 | 39 | modulation = models.PositiveIntegerField(verbose_name='Modulation Type', choices = MOD_TYPES, default = 0) |
|
40 | 40 | |
|
41 | 41 | amplitude_enabled = models.BooleanField(verbose_name='Amplitude Control', choices=ENABLE_TYPE, default=False) |
|
42 | 42 | |
|
43 | 43 | amplitudeI = models.PositiveIntegerField(verbose_name='Amplitude CH1',validators=[MinValueValidator(0), MaxValueValidator(2**12-1)], blank=True, null=True) |
|
44 | 44 | amplitudeQ = models.PositiveIntegerField(verbose_name='Amplitude CH2',validators=[MinValueValidator(0), MaxValueValidator(2**12-1)], blank=True, null=True) |
|
45 | 45 | |
|
46 | 46 | |
|
47 | 47 | def get_nbits(self): |
|
48 | 48 | |
|
49 | 49 | return self.DDS_NBITS |
|
50 | 50 | |
|
51 | 51 | def clean(self): |
|
52 | 52 | |
|
53 | 53 | if self.modulation in [1,2,3]: |
|
54 | 54 | if self.frequencyB is None or self.frequencyB_Mhz is None: |
|
55 | 55 | raise ValidationError({ |
|
56 | 56 | 'frequencyB': 'Frequency modulation has to be defined when FSK or Chirp modulation is selected' |
|
57 | 57 | }) |
|
58 | 58 | |
|
59 | 59 | if self.modulation in [4,]: |
|
60 | 60 | if self.phaseB_degrees is None: |
|
61 | 61 | raise ValidationError({ |
|
62 | 62 | 'phaseB': 'Phase modulation has to be defined when BPSK modulation is selected' |
|
63 | 63 | }) |
|
64 | 64 | |
|
65 | 65 | self.frequencyA_Mhz = data.binary_to_freq(self.frequencyA, self.clock*self.multiplier) |
|
66 | 66 | self.frequencyB_Mhz = data.binary_to_freq(self.frequencyB, self.clock*self.multiplier) |
|
67 | 67 | |
|
68 | 68 | def verify_frequencies(self): |
|
69 | 69 | |
|
70 | 70 | return True |
|
71 | 71 | |
|
72 | 72 | def parms_to_dict(self): |
|
73 | 73 | |
|
74 | 74 | parameters = {} |
|
75 | 75 | |
|
76 | parameters['device_id'] = self.device.id | |
|
77 | ||
|
76 | 78 | parameters['clock'] = float(self.clock) |
|
77 | 79 | parameters['multiplier'] = int(self.multiplier) |
|
78 | 80 | |
|
79 | 81 | parameters['frequencyA'] = int(self.frequencyA) |
|
80 | 82 | parameters['frequencyA_Mhz'] = float(self.frequencyA_Mhz) |
|
81 | 83 | |
|
82 | 84 | parameters['phaseA'] = data.phase_to_binary(self.phaseA_degrees) |
|
83 | 85 | parameters['phaseA_degrees'] = float(self.phaseA_degrees) |
|
84 | 86 | |
|
85 | 87 | parameters['modulation'] = int(self.modulation) |
|
86 | 88 | parameters['amplitude_enabled'] = bool(self.amplitude_enabled) |
|
87 | 89 | |
|
88 | 90 | if self.frequencyB: |
|
89 | 91 | parameters['frequencyB'] = int(self.frequencyB) |
|
90 | 92 | parameters['frequencyB_Mhz'] = float(self.frequencyB_Mhz) |
|
91 | 93 | else: |
|
92 | 94 | parameters['frequencyB'] = 0 |
|
93 | 95 | parameters['frequencyB_Mhz'] = 0 |
|
94 | 96 | |
|
95 | 97 | if self.phaseB_degrees: |
|
96 | 98 | parameters['phaseB_degrees'] = float(self.phaseB_degrees) |
|
97 | 99 | parameters['phaseB'] = data.phase_to_binary(self.phaseB_degrees) |
|
98 | 100 | else: |
|
99 | 101 | parameters['phaseB_degrees'] = 0 |
|
100 | 102 | parameters['phaseB'] = 0 |
|
101 | 103 | |
|
102 | 104 | if self.amplitudeI: |
|
103 | 105 | parameters['amplitudeI'] = int(self.amplitudeI) |
|
104 | 106 | else: |
|
105 | 107 | parameters['amplitudeI'] = 0 |
|
106 | 108 | |
|
107 | 109 | if self.amplitudeQ: |
|
108 | 110 | parameters['amplitudeQ'] = int(self.amplitudeQ) |
|
109 | 111 | else: |
|
110 | 112 | parameters['amplitudeQ'] = 0 |
|
111 | 113 | |
|
112 | 114 | return parameters |
|
113 | 115 | |
|
114 | 116 | def parms_to_text(self): |
|
115 | 117 | |
|
116 | 118 | my_dict = self.parms_to_dict() |
|
117 | 119 | |
|
118 | 120 | text = data.dict_to_text(my_dict) |
|
119 | 121 | |
|
120 | 122 | return text |
|
121 | 123 | |
|
122 | 124 | def dict_to_parms(self, parameters): |
|
123 | 125 | |
|
124 | 126 | self.clock = parameters['clock'] |
|
125 | 127 | self.multiplier = parameters['multiplier'] |
|
126 | 128 | self.frequencyA = parameters['frequencyA'] |
|
127 | 129 | self.frequencyB = parameters['frequencyB'] |
|
128 | 130 | self.frequencyA_Mhz = parameters['frequencyA_Mhz'] |
|
129 | 131 | self.frequencyB_Mhz = parameters['frequencyB_Mhz'] |
|
130 | 132 | self.phaseA_degrees = parameters['phaseA_degrees'] |
|
131 | 133 | self.phaseB_degrees = parameters['phaseB_degrees'] |
|
132 | 134 | self.modulation = parameters['modulation'] |
|
133 | 135 | self.amplitude_enabled = parameters['amplitude_enabled'] |
|
134 | 136 | |
|
135 | 137 | def import_from_file(self, fp): |
|
136 | 138 | |
|
137 | 139 | import os, json |
|
138 | 140 | |
|
139 | 141 | parms = {} |
|
140 | 142 | |
|
141 | 143 | path, ext = os.path.splitext(fp.name) |
|
142 | 144 | |
|
143 | 145 | if ext == '.json': |
|
144 | 146 | parms = json.load(fp) |
|
145 | 147 | |
|
146 | 148 | if ext == '.dds': |
|
147 | 149 | lines = fp.readlines() |
|
148 | 150 | parms = data.text_to_dict(lines) |
|
149 | 151 | |
|
150 | 152 | return parms |
|
151 | 153 | |
|
152 | 154 | def status_device(self): |
|
153 | 155 | |
|
154 | 156 | answer = api.status(ip = self.device.ip_address, |
|
155 | 157 | port = self.device.port_address) |
|
156 | 158 | |
|
157 | 159 | self.device.status = int(answer[0]) |
|
158 | 160 | self.message = answer[2:] |
|
159 | 161 | |
|
160 | 162 | self.device.save() |
|
161 | 163 | |
|
162 | 164 | return self.device.status |
|
163 | 165 | |
|
164 | 166 | def reset_device(self): |
|
165 | 167 | |
|
166 | 168 | answer = api.reset(ip = self.device.ip_address, |
|
167 | 169 | port = self.device.port_address) |
|
168 | 170 | |
|
169 | 171 | if answer[0] != "1": |
|
170 | 172 | self.message = answer[0:] |
|
171 | 173 | return 0 |
|
172 | 174 | |
|
173 | 175 | self.message = answer[2:] |
|
174 | 176 | return 1 |
|
175 | 177 | |
|
176 | 178 | def stop_device(self): |
|
177 | 179 | |
|
178 | 180 | answer = api.disable_rf(ip = self.device.ip_address, |
|
179 | 181 | port = self.device.port_address) |
|
180 | 182 | |
|
181 | 183 | if answer[0] != "1": |
|
182 | 184 | self.message = answer[0:] |
|
183 | 185 | return 0 |
|
184 | 186 | |
|
185 | 187 | self.message = answer[2:] |
|
186 | 188 | return 1 |
|
187 | 189 | |
|
188 | 190 | def start_device(self): |
|
189 | 191 | |
|
190 | 192 | answer = api.enable_rf(ip = self.device.ip_address, |
|
191 | 193 | port = self.device.port_address) |
|
192 | 194 | |
|
193 | 195 | if answer[0] != "1": |
|
194 | 196 | self.message = answer[0:] |
|
195 | 197 | return 0 |
|
196 | 198 | |
|
197 | 199 | self.message = answer[2:] |
|
198 | 200 | return 1 |
|
199 | 201 | |
|
200 | 202 | def read_device(self): |
|
201 | 203 | |
|
202 | 204 | parms = api.read_config(ip = self.device.ip_address, |
|
203 | 205 | port = self.device.port_address) |
|
204 | 206 | |
|
205 | 207 | if not parms: |
|
206 | 208 | self.message = "Could not read DDS parameters from this device" |
|
207 | 209 | return parms |
|
208 | 210 | |
|
209 | 211 | self.message = "" |
|
210 | 212 | return parms |
|
211 | 213 | |
|
212 | 214 | |
|
213 | 215 | def write_device(self): |
|
214 | 216 | |
|
215 | 217 | answer = api.write_config(ip = self.device.ip_address, |
|
216 | 218 | port = self.device.port_address, |
|
217 | 219 | parms = self.parms_to_dict()) |
|
218 | 220 | |
|
219 | 221 | if answer[0] != "1": |
|
220 | 222 | self.message = answer[0:] |
|
221 | 223 | return 0 |
|
222 | 224 | |
|
223 | 225 | self.message = answer[2:] |
|
224 | 226 | return 1 |
|
225 | 227 | |
|
226 | 228 | class Meta: |
|
227 | 229 | db_table = 'dds_configurations' |
|
228 | 230 | No newline at end of file |
@@ -1,449 +1,541 | |||
|
1 | 1 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse |
|
2 | 2 | from datetime import datetime |
|
3 | 3 | |
|
4 | 4 | from django.db import models |
|
5 | 5 | from polymorphic import PolymorphicModel |
|
6 | 6 | |
|
7 | 7 | from django.core.urlresolvers import reverse |
|
8 | 8 | |
|
9 | ||
|
9 | 10 | CONF_STATES = ( |
|
10 | 11 | (0, 'Disconnected'), |
|
11 | 12 | (1, 'Connected'), |
|
12 | 13 | (2, 'Running'), |
|
13 | 14 | ) |
|
14 | 15 | |
|
15 | 16 | EXP_STATES = ( |
|
16 | 17 | (0,'Error'), #RED |
|
17 | 18 | (1,'Configurated'), #BLUE |
|
18 | 19 | (2,'Running'), #GREEN |
|
19 | 20 | (3,'Waiting'), #YELLOW |
|
20 | 21 | (4,'Not Configured'), #WHITE |
|
21 | 22 | ) |
|
22 | 23 | |
|
23 | 24 | CONF_TYPES = ( |
|
24 | 25 | (0, 'Active'), |
|
25 | 26 | (1, 'Historical'), |
|
26 | 27 | ) |
|
27 | 28 | |
|
28 | 29 | DEV_STATES = ( |
|
29 | 30 | (0, 'No connected'), |
|
30 | 31 | (1, 'Connected'), |
|
31 | 32 | (2, 'Configured'), |
|
32 | 33 | (3, 'Running'), |
|
33 | 34 | ) |
|
34 | 35 | |
|
35 | 36 | DEV_TYPES = ( |
|
36 | 37 | ('', 'Select a device type'), |
|
37 | 38 | ('rc', 'Radar Controller'), |
|
38 | 39 | ('rc_mix', 'Radar Controller (Mix)'), |
|
39 | 40 | ('dds', 'Direct Digital Synthesizer'), |
|
40 | 41 | ('jars', 'Jicamarca Radar Acquisition System'), |
|
41 | 42 | ('usrp', 'Universal Software Radio Peripheral'), |
|
42 | 43 | ('cgs', 'Clock Generator System'), |
|
43 | 44 | ('abs', 'Automatic Beam Switching'), |
|
44 | 45 | ) |
|
45 | 46 | |
|
46 | 47 | DEV_PORTS = { |
|
47 | 48 | 'rc' : 2000, |
|
48 | 49 | 'rc_mix': 2000, |
|
49 | 50 | 'dds' : 2000, |
|
50 | 51 | 'jars' : 2000, |
|
51 | 52 | 'usrp' : 2000, |
|
52 | 53 | 'cgs' : 8080, |
|
53 | 54 | 'abs' : 8080 |
|
54 | 55 | } |
|
55 | 56 | |
|
56 | 57 | RADAR_STATES = ( |
|
57 | 58 | (0, 'No connected'), |
|
58 | 59 | (1, 'Connected'), |
|
59 | 60 | (2, 'Configured'), |
|
60 | 61 | (3, 'Running'), |
|
61 | 62 | (4, 'Scheduled'), |
|
62 | 63 | ) |
|
63 | 64 | # Create your models here. |
|
64 | 65 | |
|
65 | 66 | class Location(models.Model): |
|
66 | 67 | |
|
67 | 68 | name = models.CharField(max_length = 30) |
|
68 | 69 | description = models.TextField(blank=True, null=True) |
|
69 | 70 | |
|
70 | 71 | class Meta: |
|
71 | 72 | db_table = 'db_location' |
|
72 | 73 | |
|
73 | 74 | def __unicode__(self): |
|
74 | 75 | return u'%s' % self.name |
|
75 | 76 | |
|
76 | 77 | def get_absolute_url(self): |
|
77 | 78 | return reverse('url_device', args=[str(self.id)]) |
|
78 | 79 | |
|
79 | 80 | |
|
80 | 81 | class DeviceType(models.Model): |
|
81 | 82 | |
|
82 | 83 | name = models.CharField(max_length = 10, choices = DEV_TYPES, default = 'rc') |
|
83 | 84 | description = models.TextField(blank=True, null=True) |
|
84 | 85 | |
|
85 | 86 | class Meta: |
|
86 | 87 | db_table = 'db_device_types' |
|
87 | 88 | |
|
88 | 89 | def __unicode__(self): |
|
89 | 90 | return u'%s' % self.get_name_display() |
|
90 | 91 | |
|
91 | 92 | class Device(models.Model): |
|
92 | 93 | |
|
93 | 94 | device_type = models.ForeignKey(DeviceType, on_delete=models.CASCADE) |
|
94 | 95 | location = models.ForeignKey(Location, on_delete=models.CASCADE) |
|
95 | 96 | |
|
96 | 97 | name = models.CharField(max_length=40, default='') |
|
97 | 98 | ip_address = models.GenericIPAddressField(protocol='IPv4', default='0.0.0.0') |
|
98 | 99 | port_address = models.PositiveSmallIntegerField(default=2000) |
|
99 | 100 | description = models.TextField(blank=True, null=True) |
|
100 | 101 | status = models.PositiveSmallIntegerField(default=0, choices=DEV_STATES) |
|
101 | 102 | |
|
102 | 103 | class Meta: |
|
103 | 104 | db_table = 'db_devices' |
|
104 | 105 | |
|
105 | 106 | def __unicode__(self): |
|
106 | 107 | return u'%s | %s' % (self.name, self.ip_address) |
|
107 | 108 | |
|
108 | 109 | def get_status(self): |
|
109 | 110 | return self.status |
|
110 | 111 | |
|
111 | 112 | def get_absolute_url(self): |
|
112 | 113 | return reverse('url_device', args=[str(self.id)]) |
|
113 | 114 | |
|
114 | 115 | |
|
115 | 116 | class Campaign(models.Model): |
|
116 | 117 | |
|
117 | 118 | template = models.BooleanField(default=False) |
|
118 | 119 | name = models.CharField(max_length=60, unique=True) |
|
119 | 120 | start_date = models.DateTimeField(blank=True, null=True) |
|
120 | 121 | end_date = models.DateTimeField(blank=True, null=True) |
|
121 | 122 | tags = models.CharField(max_length=40) |
|
122 | 123 | description = models.TextField(blank=True, null=True) |
|
123 | 124 | experiments = models.ManyToManyField('Experiment', blank=True) |
|
124 | 125 | |
|
125 | 126 | class Meta: |
|
126 | 127 | db_table = 'db_campaigns' |
|
127 | 128 | ordering = ('name',) |
|
128 | 129 | |
|
129 | 130 | def __unicode__(self): |
|
130 | 131 | return u'%s' % (self.name) |
|
131 | 132 | |
|
132 | 133 | def get_absolute_url(self): |
|
133 | 134 | return reverse('url_campaign', args=[str(self.id)]) |
|
134 | 135 | |
|
135 | 136 | def parms_to_dict(self): |
|
136 | 137 | |
|
137 | 138 | import json |
|
138 | 139 | |
|
139 | 140 | parameters = {} |
|
140 | 141 | exp_parameters = {} |
|
141 | 142 | experiments = Experiment.objects.filter(campaign = self) |
|
142 | 143 | |
|
143 | 144 | i=1 |
|
144 | 145 | for experiment in experiments: |
|
145 | 146 | exp_parameters['experiment-'+str(i)] = json.loads(experiment.parms_to_dict()) |
|
146 | 147 | i += 1 |
|
147 | 148 | |
|
148 | 149 | |
|
149 | parameters['experimets'] =exp_parameters | |
|
150 | parameters['end_date'] = self.end_date.strftime("%Y-%m-%d") | |
|
151 | parameters['start_date'] = self.start_date.strftime("%Y-%m-%d") | |
|
152 | parameters['campaign'] = self.__unicode__() | |
|
150 | parameters['experiments'] = exp_parameters | |
|
151 | parameters['end_date'] = self.end_date.strftime("%Y-%m-%d") | |
|
152 | parameters['start_date'] = self.start_date.strftime("%Y-%m-%d") | |
|
153 | parameters['campaign'] = self.__unicode__() | |
|
154 | parameters['tags'] =self.tags | |
|
153 | 155 | |
|
154 | 156 | parameters = json.dumps(parameters, indent=2, sort_keys=False) |
|
155 | 157 | |
|
156 | 158 | return parameters |
|
157 | 159 | |
|
160 | def import_from_file(self, fp): | |
|
161 | ||
|
162 | import os, json | |
|
163 | ||
|
164 | parms = {} | |
|
165 | ||
|
166 | path, ext = os.path.splitext(fp.name) | |
|
167 | ||
|
168 | if ext == '.json': | |
|
169 | parms = json.load(fp) | |
|
170 | ||
|
171 | return parms | |
|
172 | ||
|
173 | def get_absolute_url(self): | |
|
174 | return reverse('url_campaign', args=[str(self.id)]) | |
|
175 | ||
|
176 | def get_absolute_url_edit(self): | |
|
177 | return reverse('url_edit_campaign', args=[str(self.id)]) | |
|
178 | ||
|
158 | 179 | def get_absolute_url_export(self): |
|
159 | 180 | return reverse('url_export_campaign', args=[str(self.id)]) |
|
160 | 181 | |
|
182 | def get_absolute_url_import(self): | |
|
183 | return reverse('url_import_campaign', args=[str(self.id)]) | |
|
184 | ||
|
161 | 185 | |
|
162 | 186 | |
|
163 | 187 | class RunningExperiment(models.Model): |
|
164 | 188 | radar = models.OneToOneField('Location', on_delete=models.CASCADE) |
|
165 | 189 | running_experiment = models.ManyToManyField('Experiment', blank = True) |
|
166 | 190 | status = models.PositiveSmallIntegerField(default=0, choices=RADAR_STATES) |
|
167 | 191 | |
|
168 | 192 | |
|
169 | 193 | class Experiment(models.Model): |
|
170 | 194 | |
|
171 | 195 | template = models.BooleanField(default=False) |
|
172 | location = models.ForeignKey('Location', null=True, blank=True, on_delete=models.CASCADE) | |
|
173 | 196 | name = models.CharField(max_length=40, default='', unique=True) |
|
174 | 197 | location = models.ForeignKey('Location', null=True, blank=True, on_delete=models.CASCADE) |
|
175 | 198 | start_time = models.TimeField(default='00:00:00') |
|
176 | 199 | end_time = models.TimeField(default='23:59:59') |
|
177 | 200 | status = models.PositiveSmallIntegerField(default=0, choices=EXP_STATES) |
|
178 | 201 | |
|
179 | 202 | class Meta: |
|
180 | 203 | db_table = 'db_experiments' |
|
181 | 204 | ordering = ('template', 'name') |
|
182 | 205 | |
|
183 | 206 | def __unicode__(self): |
|
184 | 207 | if self.template: |
|
185 | 208 | return u'%s (template)' % (self.name) |
|
186 | 209 | else: |
|
187 | 210 | return u'%s' % (self.name) |
|
188 | 211 | |
|
189 | 212 | @property |
|
190 | 213 | def radar(self): |
|
191 | 214 | return self.location |
|
192 | 215 | |
|
193 | 216 | def clone(self, **kwargs): |
|
194 | 217 | |
|
195 | 218 | confs = Configuration.objects.filter(experiment=self, type=0) |
|
196 | 219 | self.pk = None |
|
197 | 220 | self.name = '{} [{:%Y/%m/%d}]'.format(self.name, datetime.now()) |
|
198 | 221 | for attr, value in kwargs.items(): |
|
199 | 222 | setattr(self, attr, value) |
|
200 | 223 | |
|
201 | 224 | self.save() |
|
202 | 225 | |
|
203 | 226 | for conf in confs: |
|
204 | 227 | conf.clone(experiment=self, template=False) |
|
205 | 228 | |
|
206 | 229 | return self |
|
207 | 230 | |
|
208 | 231 | def get_status(self): |
|
209 | 232 | configurations = Configuration.objects.filter(experiment=self) |
|
210 | 233 | exp_status=[] |
|
211 | 234 | for conf in configurations: |
|
212 | 235 | print conf.status_device() |
|
213 | 236 | exp_status.append(conf.status_device()) |
|
214 | 237 | |
|
215 | 238 | if not exp_status: #No Configuration |
|
216 | 239 | self.status = 4 |
|
217 | 240 | self.save() |
|
218 | 241 | return |
|
219 | 242 | |
|
220 | 243 | total = 1 |
|
221 | 244 | for e_s in exp_status: |
|
222 | 245 | total = total*e_s |
|
223 | 246 | |
|
224 | 247 | if total == 0: #Error |
|
225 | 248 | status = 0 |
|
226 | 249 | elif total == (3**len(exp_status)): #Running |
|
227 | 250 | status = 2 |
|
228 | 251 | else: |
|
229 | 252 | status = 1 #Configurated |
|
230 | 253 | |
|
231 | 254 | self.status = status |
|
232 | 255 | self.save() |
|
233 | 256 | |
|
234 | 257 | def status_color(self): |
|
235 | 258 | color = 'danger' |
|
236 | 259 | if self.status == 0: |
|
237 | 260 | color = "danger" |
|
238 | 261 | elif self.status == 1: |
|
239 | 262 | color = "info" |
|
240 | 263 | elif self.status == 2: |
|
241 | 264 | color = "success" |
|
242 | 265 | elif self.status == 3: |
|
243 | 266 | color = "warning" |
|
244 | 267 | else: |
|
245 | 268 | color = "muted" |
|
246 | 269 | |
|
247 | 270 | return color |
|
248 | 271 | |
|
249 | 272 | def get_absolute_url(self): |
|
250 | 273 | return reverse('url_experiment', args=[str(self.id)]) |
|
251 | 274 | |
|
252 | 275 | def parms_to_dict(self): |
|
253 | 276 | |
|
254 | 277 | import json |
|
255 | 278 | |
|
256 | 279 | configurations = Configuration.objects.filter(experiment=self) |
|
257 | 280 | conf_parameters = {} |
|
258 | 281 | parameters={} |
|
259 | 282 | |
|
260 | 283 | for configuration in configurations: |
|
261 | 284 | if 'cgs' in configuration.device.device_type.name: |
|
262 | 285 | conf_parameters['cgs'] = configuration.parms_to_dict() |
|
263 | 286 | if 'dds' in configuration.device.device_type.name: |
|
264 | 287 | conf_parameters['dds'] = configuration.parms_to_dict() |
|
265 | 288 | if 'rc' in configuration.device.device_type.name: |
|
266 | 289 | conf_parameters['rc'] = configuration.parms_to_dict() |
|
267 | 290 | if 'jars' in configuration.device.device_type.name: |
|
268 | 291 | conf_parameters['jars'] = configuration.parms_to_dict() |
|
269 | 292 | if 'usrp' in configuration.device.device_type.name: |
|
270 | 293 | conf_parameters['usrp'] = configuration.parms_to_dict() |
|
271 | 294 | if 'abs' in configuration.device.device_type.name: |
|
272 | 295 | conf_parameters['abs'] = configuration.parms_to_dict() |
|
273 | 296 | |
|
274 | 297 | parameters['configurations'] = conf_parameters |
|
275 |
parameters['end_time'] = self.end_time.strftime("% |
|
|
276 |
parameters['start_time'] = self.start_time.strftime("% |
|
|
277 | parameters['radar'] = self.radar.name | |
|
278 | parameters['experiment'] = self.name | |
|
298 | parameters['end_time'] = self.end_time.strftime("%H:%M:%S") | |
|
299 | parameters['start_time'] = self.start_time.strftime("%H:%M:%S") | |
|
300 | parameters['radar'] = self.radar.name | |
|
301 | parameters['experiment'] = self.name | |
|
279 | 302 | parameters = json.dumps(parameters, indent=2) |
|
280 | #parameters = json.dumps(parameters) | |
|
281 | 303 | |
|
282 | 304 | return parameters |
|
283 | 305 | |
|
306 | def import_from_file(self, fp): | |
|
307 | ||
|
308 | import os, json | |
|
309 | ||
|
310 | parms = {} | |
|
311 | ||
|
312 | path, ext = os.path.splitext(fp.name) | |
|
313 | ||
|
314 | if ext == '.json': | |
|
315 | parms = json.load(fp) | |
|
316 | ||
|
317 | return parms | |
|
318 | ||
|
319 | def dict_to_parms(self, parms, CONF_MODELS): | |
|
320 | ||
|
321 | #self.name = parameters['experiment'] | |
|
322 | #self.location = parameters['radar'] | |
|
323 | #self.start_time = parameters['start_time'] | |
|
324 | #self.end_time = parameters['end_time'] | |
|
325 | ||
|
326 | configurations = Configuration.objects.filter(experiment=self) | |
|
327 | ||
|
328 | if configurations: | |
|
329 | for configuration in configurations: | |
|
330 | configuration.delete() | |
|
331 | ||
|
332 | for conf_type in parms['configurations']: | |
|
333 | #--For ABS Device: | |
|
334 | #--For USRP Device: | |
|
335 | #--For JARS Device: | |
|
336 | #--For RC Device: | |
|
337 | if conf_type == 'rc': | |
|
338 | device = get_object_or_404(Device, pk=parms['configurations']['rc']['device_id']) | |
|
339 | DevConfModel = CONF_MODELS[conf_type] | |
|
340 | confrc_form = DevConfModel( | |
|
341 | experiment = self, | |
|
342 | name = 'RC', | |
|
343 | device=device, | |
|
344 | ) | |
|
345 | confrc_form.dict_to_parms(parms['configurations']['rc']) | |
|
346 | confrc_form.save() | |
|
347 | #--For DDS Device: | |
|
348 | if conf_type == 'dds': | |
|
349 | device = get_object_or_404(Device, pk=parms['configurations']['dds']['device_id']) | |
|
350 | DevConfModel = CONF_MODELS[conf_type] | |
|
351 | confdds_form = DevConfModel( | |
|
352 | experiment = self, | |
|
353 | name = 'DDS', | |
|
354 | device=device, | |
|
355 | ) | |
|
356 | confdds_form.dict_to_parms(parms['configurations']['dds']) | |
|
357 | confdds_form.save() | |
|
358 | #--For CGS Device: | |
|
359 | if conf_type == 'cgs': | |
|
360 | device = get_object_or_404(Device, pk=parms['configurations']['cgs']['device_id']) | |
|
361 | DevConfModel = CONF_MODELS[conf_type] | |
|
362 | confcgs_form = DevConfModel( | |
|
363 | experiment = self, | |
|
364 | name = 'CGS', | |
|
365 | device=device, | |
|
366 | ) | |
|
367 | confcgs_form.dict_to_parms(parms['configurations']['cgs']) | |
|
368 | confcgs_form.save() | |
|
369 | ||
|
370 | def get_absolute_url_edit(self): | |
|
371 | return reverse('url_edit_experiment', args=[str(self.id)]) | |
|
372 | ||
|
373 | def get_absolute_url_import(self): | |
|
374 | return reverse('url_import_experiment', args=[str(self.id)]) | |
|
375 | ||
|
284 | 376 | def get_absolute_url_export(self): |
|
285 | 377 | return reverse('url_export_experiment', args=[str(self.id)]) |
|
286 | 378 | |
|
287 | 379 | |
|
288 | 380 | class Configuration(PolymorphicModel): |
|
289 | 381 | |
|
290 | 382 | template = models.BooleanField(default=False) |
|
291 | 383 | |
|
292 | 384 | name = models.CharField(verbose_name="Configuration Name", max_length=40, default='') |
|
293 | 385 | |
|
294 | 386 | experiment = models.ForeignKey('Experiment', null=True, blank=True, on_delete=models.CASCADE) |
|
295 | 387 | device = models.ForeignKey(Device, null=True, on_delete=models.CASCADE) |
|
296 | 388 | |
|
297 | 389 | type = models.PositiveSmallIntegerField(default=0, choices=CONF_TYPES) |
|
298 | 390 | |
|
299 | 391 | created_date = models.DateTimeField(auto_now_add=True) |
|
300 | 392 | programmed_date = models.DateTimeField(auto_now=True) |
|
301 | 393 | |
|
302 | 394 | parameters = models.TextField(default='{}') |
|
303 | 395 | |
|
304 | 396 | message = "" |
|
305 | 397 | |
|
306 | 398 | class Meta: |
|
307 | 399 | db_table = 'db_configurations' |
|
308 | 400 | |
|
309 | 401 | def __unicode__(self): |
|
310 | 402 | |
|
311 | 403 | return u'[%s]: %s' % (self.device.name, self.name) |
|
312 | 404 | |
|
313 | 405 | def clone(self, **kwargs): |
|
314 | 406 | |
|
315 | 407 | self.pk = None |
|
316 | 408 | self.id = None |
|
317 | 409 | for attr, value in kwargs.items(): |
|
318 | 410 | setattr(self, attr, value) |
|
319 | 411 | |
|
320 | 412 | self.save() |
|
321 | 413 | |
|
322 | 414 | return self |
|
323 | 415 | |
|
324 | 416 | def parms_to_dict(self): |
|
325 | 417 | |
|
326 | 418 | parameters = {} |
|
327 | 419 | |
|
328 | 420 | for key in self.__dict__.keys(): |
|
329 | 421 | parameters[key] = getattr(self, key) |
|
330 | 422 | |
|
331 | 423 | return parameters |
|
332 | 424 | |
|
333 | 425 | def parms_to_text(self): |
|
334 | 426 | |
|
335 | 427 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
336 | 428 | |
|
337 | 429 | return '' |
|
338 | 430 | |
|
339 | 431 | def parms_to_binary(self): |
|
340 | 432 | |
|
341 | 433 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
342 | 434 | |
|
343 | 435 | return '' |
|
344 | 436 | |
|
345 | 437 | def dict_to_parms(self, parameters): |
|
346 | 438 | |
|
347 | 439 | if type(parameters) != type({}): |
|
348 | 440 | return |
|
349 | 441 | |
|
350 | 442 | for key in parameters.keys(): |
|
351 | 443 | setattr(self, key, parameters[key]) |
|
352 | 444 | |
|
353 | 445 | def export_to_file(self, format="json"): |
|
354 | 446 | |
|
355 | 447 | import json |
|
356 | 448 | |
|
357 | 449 | content_type = '' |
|
358 | 450 | |
|
359 | 451 | if format == 'text': |
|
360 | 452 | content_type = 'text/plain' |
|
361 | 453 | filename = '%s_%s.%s' %(self.device.device_type.name, self.name, self.device.device_type.name) |
|
362 | 454 | content = self.parms_to_text() |
|
363 | 455 | |
|
364 | 456 | if format == 'binary': |
|
365 | 457 | content_type = 'application/octet-stream' |
|
366 | 458 | filename = '%s_%s.bin' %(self.device.device_type.name, self.name) |
|
367 | 459 | content = self.parms_to_binary() |
|
368 | 460 | |
|
369 | 461 | if not content_type: |
|
370 | 462 | content_type = 'application/json' |
|
371 | 463 | filename = '%s_%s.json' %(self.device.device_type.name, self.name) |
|
372 | 464 | content = json.dumps(self.parms_to_dict(), indent=2) |
|
373 | 465 | |
|
374 | 466 | fields = {'content_type':content_type, |
|
375 | 467 | 'filename':filename, |
|
376 | 468 | 'content':content |
|
377 | 469 | } |
|
378 | 470 | |
|
379 | 471 | return fields |
|
380 | 472 | |
|
381 | 473 | def import_from_file(self, fp): |
|
382 | 474 | |
|
383 | 475 | import os, json |
|
384 | 476 | |
|
385 | 477 | parms = {} |
|
386 | 478 | |
|
387 | 479 | path, ext = os.path.splitext(fp.name) |
|
388 | 480 | |
|
389 | 481 | if ext == '.json': |
|
390 | 482 | parms = json.load(fp) |
|
391 | 483 | |
|
392 | 484 | return parms |
|
393 | 485 | |
|
394 | 486 | def status_device(self): |
|
395 | 487 | |
|
396 | 488 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
397 | 489 | |
|
398 | 490 | return None |
|
399 | 491 | |
|
400 | 492 | def stop_device(self): |
|
401 | 493 | |
|
402 | 494 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
403 | 495 | |
|
404 | 496 | return None |
|
405 | 497 | |
|
406 | 498 | def start_device(self): |
|
407 | 499 | |
|
408 | 500 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
409 | 501 | |
|
410 | 502 | return None |
|
411 | 503 | |
|
412 | 504 | def write_device(self, parms): |
|
413 | 505 | |
|
414 | 506 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
415 | 507 | |
|
416 | 508 | return None |
|
417 | 509 | |
|
418 | 510 | def read_device(self): |
|
419 | 511 | |
|
420 | 512 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
421 | 513 | |
|
422 | 514 | return None |
|
423 | 515 | |
|
424 | 516 | def get_absolute_url(self): |
|
425 | 517 | return reverse('url_%s_conf' % self.device.device_type.name, args=[str(self.id)]) |
|
426 | 518 | |
|
427 | 519 | def get_absolute_url_edit(self): |
|
428 | 520 | return reverse('url_edit_%s_conf' % self.device.device_type.name, args=[str(self.id)]) |
|
429 | 521 | |
|
430 | 522 | def get_absolute_url_import(self): |
|
431 | 523 | return reverse('url_import_dev_conf', args=[str(self.id)]) |
|
432 | 524 | |
|
433 | 525 | def get_absolute_url_export(self): |
|
434 | 526 | return reverse('url_export_dev_conf', args=[str(self.id)]) |
|
435 | 527 | |
|
436 | 528 | def get_absolute_url_write(self): |
|
437 | 529 | return reverse('url_write_dev_conf', args=[str(self.id)]) |
|
438 | 530 | |
|
439 | 531 | def get_absolute_url_read(self): |
|
440 | 532 | return reverse('url_read_dev_conf', args=[str(self.id)]) |
|
441 | 533 | |
|
442 | 534 | def get_absolute_url_start(self): |
|
443 | 535 | return reverse('url_start_dev_conf', args=[str(self.id)]) |
|
444 | 536 | |
|
445 | 537 | def get_absolute_url_stop(self): |
|
446 | 538 | return reverse('url_stop_dev_conf', args=[str(self.id)]) |
|
447 | 539 | |
|
448 | 540 | def get_absolute_url_status(self): |
|
449 | 541 | return reverse('url_status_dev_conf', args=[str(self.id)]) No newline at end of file |
@@ -1,107 +1,107 | |||
|
1 | 1 | {% extends "base.html" %} |
|
2 | 2 | {% load bootstrap3 %} |
|
3 | 3 | {% load static %} |
|
4 | 4 | {% load main_tags %} |
|
5 | 5 | {% block extra-head %} |
|
6 | 6 | <link href="{% static 'css/bootstrap-datetimepicker.min.css' %}" media="screen" rel="stylesheet"> |
|
7 | 7 | {% endblock %} |
|
8 | 8 | |
|
9 | 9 | {% block camp-active %}active{% endblock %} |
|
10 | 10 | |
|
11 | 11 | {% block content-title %}{{title}}{% endblock %} |
|
12 | 12 | {% block content-suptitle %}{{suptitle}}{% endblock %} |
|
13 | 13 | |
|
14 | 14 | {% block content %} |
|
15 | 15 | |
|
16 | 16 | {% block menu-actions %} |
|
17 | 17 | <span class=" dropdown pull-right"> |
|
18 | 18 | <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-menu-hamburger gi-2x" aria-hidden="true"></span></a> |
|
19 | 19 | <ul class="dropdown-menu" role="menu"> |
|
20 | 20 | <li><a href="{% url 'url_edit_campaign' campaign.id %}"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit</a></li> |
|
21 | 21 | <li><a href="{% url 'url_delete_campaign' campaign.id %}"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Delete</a></li> |
|
22 |
<li><a href="{{ |
|
|
22 | <li><a href="{{ campaign.get_absolute_url_import }}"><span class="glyphicon glyphicon-import" aria-hidden="true"></span> Import </a></li> | |
|
23 | 23 | <li><a href="{{ campaign.get_absolute_url_export }}"><span class="glyphicon glyphicon-export" aria-hidden="true"></span> Export </a></li> |
|
24 | 24 | {% block extra-menu-actions %} |
|
25 | 25 | {% endblock %} |
|
26 | 26 | <li><a>----------------</a></li> |
|
27 | 27 | <!--<li><a href="{{ dev_conf.get_absolute_url_status }}"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Status</a></li> |
|
28 | 28 | {% if not no_play %} |
|
29 | 29 | <li><a href="{{ dev_conf.get_absolute_url_start}}"><span class="glyphicon glyphicon-play" aria-hidden="true"></span> Start</a></li> |
|
30 | 30 | <li><a href="{{ dev_conf.get_absolute_url_stop }}"><span class="glyphicon glyphicon-stop" aria-hidden="true"></span> Stop</a></li> |
|
31 | 31 | {% endif %} |
|
32 | 32 | <li><a href="{{ dev_conf.get_absolute_url_write }}"><span class="glyphicon glyphicon-download" aria-hidden="true"></span> Write</a></li> |
|
33 | 33 | <li><a href="{{ dev_conf.get_absolute_url_read }}"><span class="glyphicon glyphicon-upload" aria-hidden="true"></span> Read</a></li>--> |
|
34 | 34 | </ul> |
|
35 | 35 | </span> |
|
36 | 36 | {% endblock %} |
|
37 | 37 | |
|
38 | 38 | <table class="table table-bordered"> |
|
39 | 39 | {% for key in campaign_keys %} |
|
40 | 40 | <tr><th>{{key|title}}</th><td>{{campaign|attr:key}}</td></tr> |
|
41 | 41 | {% endfor %} |
|
42 | 42 | </table> |
|
43 | 43 | |
|
44 | 44 | <!--<button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_export">Export</button>--> |
|
45 | 45 | <!--<button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_edit">Edit</button>--> |
|
46 | 46 | |
|
47 | 47 | <br></br> |
|
48 | 48 | <br></br> |
|
49 | 49 | |
|
50 | 50 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> |
|
51 | 51 | |
|
52 | 52 | <div class="panel panel-default"> |
|
53 | 53 | <div class="panel-heading" role="tab" id="headingTwo"> |
|
54 | 54 | <h4 class="panel-title"> |
|
55 | 55 | <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo"> |
|
56 | 56 | Experiment List |
|
57 | 57 | </a> |
|
58 | 58 | </h4> |
|
59 | 59 | </div> |
|
60 | 60 | |
|
61 | 61 | <div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo"> |
|
62 | 62 | <div class="panel-body"> |
|
63 | 63 | <table class="table table-hover"> |
|
64 | 64 | <tr> |
|
65 | 65 | <th>#</th> |
|
66 | 66 | {% for header in experiment_keys %} |
|
67 | 67 | <th>{{ header|title }}</th> |
|
68 | 68 | {% endfor%} |
|
69 | 69 | </tr> |
|
70 | 70 | {% for item in experiments %} |
|
71 | 71 | <tr class="clickable-row" data-href="{% url 'url_experiment' item.id %}"> |
|
72 | 72 | <td>{{ forloop.counter }}</td> |
|
73 | 73 | {% for key in experiment_keys %} |
|
74 | 74 | <td>{{ item|attr:key }}</td> |
|
75 | 75 | {% endfor %} |
|
76 | 76 | </tr> |
|
77 | 77 | {% endfor %} |
|
78 | 78 | </table> |
|
79 | 79 | </div> |
|
80 | 80 | </div> |
|
81 | 81 | </div> |
|
82 | 82 | </div> |
|
83 | 83 | <br> |
|
84 | 84 | <!--<button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_mix">Mix Experiments</button>--> |
|
85 | 85 | {% endblock %} |
|
86 | 86 | |
|
87 | 87 | {% block sidebar%} |
|
88 | 88 | {% include "sidebar_devices.html" %} |
|
89 | 89 | {% endblock %} |
|
90 | 90 | |
|
91 | 91 | {% block extra-js%} |
|
92 | 92 | <script type="text/javascript"> |
|
93 | 93 | |
|
94 | 94 | $(".clickable-row").click(function() { |
|
95 | 95 | document.location = $(this).data("href"); |
|
96 | 96 | }); |
|
97 | 97 | |
|
98 | 98 | // $("#bt_edit").click(function() { |
|
99 | 99 | // document.location = "{% url 'url_edit_campaign' campaign.id %}"; |
|
100 | 100 | // }); |
|
101 | 101 | |
|
102 | 102 | $("#bt_mix").click(function() { |
|
103 | 103 | |
|
104 | 104 | }); |
|
105 | 105 | |
|
106 | 106 | </script> |
|
107 | 107 | {% endblock %} No newline at end of file |
@@ -1,95 +1,96 | |||
|
1 | 1 | {% extends "base.html" %} |
|
2 | 2 | {% load bootstrap3 %} |
|
3 | 3 | {% load static %} |
|
4 | 4 | {% load main_tags %} |
|
5 | 5 | {% block extra-head %} |
|
6 | 6 | <link href="{% static 'css/bootstrap-datetimepicker.min.css' %}" media="screen" rel="stylesheet"> |
|
7 | 7 | {% endblock %} |
|
8 | 8 | |
|
9 | 9 | {% block exp-active %}active{% endblock %} |
|
10 | 10 | |
|
11 | 11 | {% block content-title %}{{title}}{% endblock %} |
|
12 | 12 | {% block content-suptitle %}{{suptitle}}{% endblock %} |
|
13 | 13 | |
|
14 | 14 | {% block content %} |
|
15 | 15 | |
|
16 | 16 | {% block menu-actions %} |
|
17 | 17 | <span class=" dropdown pull-right"> |
|
18 | 18 | <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-menu-hamburger gi-2x" aria-hidden="true"></span></a> |
|
19 | 19 | <ul class="dropdown-menu" role="menu"> |
|
20 | 20 | <li><a href="{% url 'url_edit_experiment' experiment.id %}"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit</a></li> |
|
21 | 21 | <li><a href="{% url 'url_delete_experiment' experiment.id %}"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Delete</a></li> |
|
22 |
<li><a href="{{ |
|
|
22 | <li><a href="{{ experiment.get_absolute_url_import }}"><span class="glyphicon glyphicon-import" aria-hidden="true"></span> Import </a></li> | |
|
23 | 23 | <li><a href="{{ experiment.get_absolute_url_export }}"><span class="glyphicon glyphicon-export" aria-hidden="true"></span> Export </a></li> |
|
24 | 24 | {% block extra-menu-actions %} |
|
25 | 25 | {% endblock %} |
|
26 | 26 | <li><a>----------------</a></li> |
|
27 | 27 | <li><a href="{% url 'url_mix_experiment' experiment.id %}"><span class="glyphicon glyphicon-random" aria-hidden="true"></span> Mix RC Configurations </a></li> |
|
28 | 28 | <li><a href="{% url 'url_add_dev_conf' experiment.id %}"><span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span> Add Configuration</a></li> |
|
29 | ||
|
29 | 30 | </ul> |
|
30 | 31 | </span> |
|
31 | 32 | {% endblock %} |
|
32 | 33 | |
|
33 | 34 | <table class="table table-bordered"> |
|
34 | 35 | {% for key in experiment_keys %} |
|
35 | 36 | <tr><th>{{key|title}}</th><td>{{experiment|attr:key}}</td></tr> |
|
36 | 37 | {% endfor %} |
|
37 | 38 | </table> |
|
38 | 39 | <br></br> |
|
39 | 40 | <br></br> |
|
40 | 41 | |
|
41 | 42 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> |
|
42 | 43 | |
|
43 | 44 | <div class="panel panel-default"> |
|
44 | 45 | <div class="panel-heading" role="tab" id="headingTwo"> |
|
45 | 46 | <h4 class="panel-title"> |
|
46 | 47 | <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseThree"> |
|
47 | 48 | Device Configurations |
|
48 | 49 | </a> |
|
49 | 50 | </h4> |
|
50 | 51 | </div> |
|
51 | 52 | <div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo"> |
|
52 | 53 | <div class="panel-body"> |
|
53 | 54 | <table class="table table-hover"> |
|
54 | 55 | <tr> |
|
55 | 56 | <th>#</th> |
|
56 | 57 | {% for key in configuration_keys %} |
|
57 | 58 | <th>{{ key|title }}</th> |
|
58 | 59 | {% endfor%} |
|
59 | 60 | </tr> |
|
60 | 61 | {% for item in configurations %} |
|
61 | 62 | <tr class="clickable-row" data-href="{{item.get_absolute_url}}"> |
|
62 | 63 | <td>{{ forloop.counter }}</td> |
|
63 | 64 | {% for key in configuration_keys %} |
|
64 | 65 | <td>{{ item|value:key }}</td> |
|
65 | 66 | {% endfor %} |
|
66 | 67 | </tr> |
|
67 | 68 | {% endfor %} |
|
68 | 69 | </table> |
|
69 | 70 | </div> |
|
70 | 71 | </div> |
|
71 | 72 | </div> |
|
72 | 73 | </div> |
|
73 | 74 | {% endblock %} |
|
74 | 75 | |
|
75 | 76 | {% block sidebar%} |
|
76 | 77 | {% include "sidebar_devices.html" %} |
|
77 | 78 | {% endblock %} |
|
78 | 79 | |
|
79 | 80 | {% block extra-js%} |
|
80 | 81 | <script type="text/javascript"> |
|
81 | 82 | |
|
82 | 83 | $(".clickable-row").click(function() { |
|
83 | 84 | document.location = $(this).data("href"); |
|
84 | 85 | }); |
|
85 | 86 | |
|
86 | 87 | $("#bt_edit").click(function() { |
|
87 | 88 | document.location = "{% url 'url_edit_experiment' experiment.id%}"; |
|
88 | 89 | }); |
|
89 | 90 | |
|
90 | 91 | $("#bt_add_conf").click(function() { |
|
91 | 92 | document.location = "{% url 'url_add_dev_conf' experiment.id %}"; |
|
92 | 93 | }); |
|
93 | 94 | |
|
94 | 95 | </script> |
|
95 | 96 | {% endblock %} No newline at end of file |
@@ -1,55 +1,57 | |||
|
1 | 1 | from django.conf.urls import url |
|
2 | 2 | |
|
3 | 3 | urlpatterns = ( |
|
4 | 4 | url(r'^location/new/$', 'apps.main.views.location_new', name='url_add_location'), |
|
5 | 5 | url(r'^location/$', 'apps.main.views.locations', name='url_locations'), |
|
6 | 6 | url(r'^location/(?P<id_loc>-?\d+)/$', 'apps.main.views.location', name='url_location'), |
|
7 | 7 | url(r'^location/(?P<id_loc>-?\d+)/edit/$', 'apps.main.views.location_edit', name='url_edit_location'), |
|
8 | 8 | url(r'^location/(?P<id_loc>-?\d+)/delete/$', 'apps.main.views.location_delete', name='url_delete_location'), |
|
9 | 9 | |
|
10 | 10 | url(r'^device/new/$', 'apps.main.views.device_new', name='url_add_device'), |
|
11 | 11 | url(r'^device/$', 'apps.main.views.devices', name='url_devices'), |
|
12 | 12 | url(r'^device/(?P<id_dev>-?\d+)/$', 'apps.main.views.device', name='url_device'), |
|
13 | 13 | url(r'^device/(?P<id_dev>-?\d+)/edit/$', 'apps.main.views.device_edit', name='url_edit_device'), |
|
14 | 14 | url(r'^device/(?P<id_dev>-?\d+)/delete/$', 'apps.main.views.device_delete', name='url_delete_device'), |
|
15 | 15 | |
|
16 | 16 | url(r'^campaign/new/$', 'apps.main.views.campaign_new', name='url_add_campaign'), |
|
17 | 17 | url(r'^campaign/$', 'apps.main.views.campaigns', name='url_campaigns'), |
|
18 | 18 | url(r'^campaign/(?P<id_camp>-?\d+)/$', 'apps.main.views.campaign', name='url_campaign'), |
|
19 | 19 | url(r'^campaign/(?P<id_camp>-?\d+)/edit/$', 'apps.main.views.campaign_edit', name='url_edit_campaign'), |
|
20 | 20 | url(r'^campaign/(?P<id_camp>-?\d+)/delete/$', 'apps.main.views.campaign_delete', name='url_delete_campaign'), |
|
21 | 21 | url(r'^campaign/(?P<id_camp>-?\d+)/export/$', 'apps.main.views.campaign_export', name='url_export_campaign'), |
|
22 | url(r'^campaign/(?P<id_camp>-?\d+)/import/$', 'apps.main.views.campaign_import', name='url_import_campaign'), | |
|
22 | 23 | |
|
23 | 24 | url(r'^experiment/new/$', 'apps.main.views.experiment_new', name='url_add_experiment'), |
|
24 | 25 | url(r'^experiment/$', 'apps.main.views.experiments', name='url_experiments'), |
|
25 | 26 | url(r'^experiment/(?P<id_exp>-?\d+)/$', 'apps.main.views.experiment', name='url_experiment'), |
|
26 | 27 | url(r'^experiment/(?P<id_exp>-?\d+)/edit/$', 'apps.main.views.experiment_edit', name='url_edit_experiment'), |
|
27 | 28 | url(r'^experiment/(?P<id_exp>-?\d+)/delete/$', 'apps.main.views.experiment_delete', name='url_delete_experiment'), |
|
28 | 29 | url(r'^experiment/(?P<id_exp>-?\d+)/export/$', 'apps.main.views.experiment_export', name='url_export_experiment'), |
|
30 | url(r'^experiment/(?P<id_exp>-?\d+)/import/$', 'apps.main.views.experiment_import', name='url_import_experiment'), | |
|
29 | 31 | url(r'^experiment/(?P<id_exp>-?\d+)/mix/$', 'apps.main.views.experiment_mix', name='url_mix_experiment'), |
|
30 | 32 | url(r'^experiment/(?P<id_exp>-?\d+)/mix/delete/$', 'apps.main.views.experiment_mix_delete', name='url_delete_mix_experiment'), |
|
31 | 33 | |
|
32 | 34 | url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/$', 'apps.main.views.dev_conf_new', name='url_add_dev_conf'), |
|
33 | 35 | url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/(?P<id_dev>-?\d+)/$', 'apps.main.views.dev_conf_new', name='url_add_dev_conf'), |
|
34 | 36 | url(r'^dev_conf/$', 'apps.main.views.dev_confs', name='url_dev_confs'), |
|
35 | 37 | url(r'^dev_conf/(?P<id_conf>-?\d+)/$', 'apps.main.views.dev_conf', name='url_dev_conf'), |
|
36 | 38 | url(r'^dev_conf/(?P<id_conf>-?\d+)/edit/$', 'apps.main.views.dev_conf_edit', name='url_edit_dev_conf'), |
|
37 | 39 | url(r'^dev_conf/(?P<id_conf>-?\d+)/delete/$', 'apps.main.views.dev_conf_delete', name='url_delete_dev_conf'), |
|
38 | 40 | |
|
39 | 41 | url(r'^dev_conf/(?P<id_conf>-?\d+)/write/$', 'apps.main.views.dev_conf_write', name='url_write_dev_conf'), |
|
40 | 42 | url(r'^dev_conf/(?P<id_conf>-?\d+)/read/$', 'apps.main.views.dev_conf_read', name='url_read_dev_conf'), |
|
41 | 43 | url(r'^dev_conf/(?P<id_conf>-?\d+)/import/$', 'apps.main.views.dev_conf_import', name='url_import_dev_conf'), |
|
42 | 44 | url(r'^dev_conf/(?P<id_conf>-?\d+)/export/$', 'apps.main.views.dev_conf_export', name='url_export_dev_conf'), |
|
43 | 45 | url(r'^dev_conf/(?P<id_conf>-?\d+)/start/$', 'apps.main.views.dev_conf_start', name='url_start_dev_conf'), |
|
44 | 46 | url(r'^dev_conf/(?P<id_conf>-?\d+)/stop/$', 'apps.main.views.dev_conf_stop', name='url_stop_dev_conf'), |
|
45 | 47 | url(r'^dev_conf/(?P<id_conf>-?\d+)/status/$', 'apps.main.views.dev_conf_status', name='url_status_dev_conf'), |
|
46 | 48 | |
|
47 | 49 | url(r'^operation/$', 'apps.main.views.operation', name='url_operation'), |
|
48 | 50 | url(r'^operation/(?P<id_camp>-?\d+)/$', 'apps.main.views.operation', name='url_operation'), |
|
49 | 51 | url(r'^operation/search/$', 'apps.main.views.operation_search', name='url_operation_search'), |
|
50 | 52 | url(r'^operation/search/(?P<id_camp>-?\d+)/$', 'apps.main.views.operation_search', name='url_operation_search'), |
|
51 | 53 | url(r'^operation/(?P<id_camp>-?\d+)/radar/(?P<id_radar>-?\d+)/play/$', 'apps.main.views.radar_play', name='url_radar_play'), |
|
52 | 54 | url(r'^operation/(?P<id_camp>-?\d+)/radar/(?P<id_radar>-?\d+)/stop/$', 'apps.main.views.radar_stop', name='url_radar_stop'), |
|
53 | 55 | url(r'^operation/(?P<id_camp>-?\d+)/radar/(?P<id_radar>-?\d+)/refresh/$', 'apps.main.views.radar_refresh', name='url_radar_refresh'), |
|
54 | 56 | |
|
55 | 57 | ) |
@@ -1,1294 +1,1405 | |||
|
1 | 1 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse |
|
2 | 2 | from django.utils.safestring import mark_safe |
|
3 | 3 | from django.http import HttpResponseRedirect |
|
4 | 4 | from django.core.urlresolvers import reverse |
|
5 | 5 | from django.contrib import messages |
|
6 | 6 | from datetime import datetime |
|
7 | 7 | |
|
8 | 8 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm, NewForm |
|
9 | 9 | from .forms import OperationSearchForm |
|
10 | 10 | from apps.cgs.forms import CGSConfigurationForm |
|
11 | 11 | from apps.jars.forms import JARSConfigurationForm |
|
12 | 12 | from apps.usrp.forms import USRPConfigurationForm |
|
13 | 13 | from apps.abs.forms import ABSConfigurationForm |
|
14 | 14 | from apps.rc.forms import RCConfigurationForm, RCMixConfigurationForm |
|
15 | 15 | from apps.dds.forms import DDSConfigurationForm |
|
16 | 16 | |
|
17 | 17 | from .models import Campaign, Experiment, Device, Configuration, Location, RunningExperiment |
|
18 | 18 | from apps.cgs.models import CGSConfiguration |
|
19 | 19 | from apps.jars.models import JARSConfiguration |
|
20 | 20 | from apps.usrp.models import USRPConfiguration |
|
21 | 21 | from apps.abs.models import ABSConfiguration |
|
22 | 22 | from apps.rc.models import RCConfiguration, RCLine, RCLineType |
|
23 | 23 | from apps.dds.models import DDSConfiguration |
|
24 | 24 | |
|
25 | 25 | # Create your views here. |
|
26 | 26 | |
|
27 | 27 | CONF_FORMS = { |
|
28 | 28 | 'rc': RCConfigurationForm, |
|
29 | 29 | 'rc_mix': RCMixConfigurationForm, |
|
30 | 30 | 'dds': DDSConfigurationForm, |
|
31 | 31 | 'jars': JARSConfigurationForm, |
|
32 | 32 | 'cgs': CGSConfigurationForm, |
|
33 | 33 | 'abs': ABSConfigurationForm, |
|
34 | 34 | 'usrp': USRPConfigurationForm, |
|
35 | 35 | } |
|
36 | 36 | |
|
37 | 37 | CONF_MODELS = { |
|
38 | 38 | 'rc': RCConfiguration, |
|
39 | 39 | 'dds': DDSConfiguration, |
|
40 | 40 | 'jars': JARSConfiguration, |
|
41 | 41 | 'cgs': CGSConfiguration, |
|
42 | 42 | 'abs': ABSConfiguration, |
|
43 | 43 | 'usrp': USRPConfiguration, |
|
44 | 44 | } |
|
45 | 45 | |
|
46 | 46 | MIX_MODES = { |
|
47 | 47 | '0': 'OR', |
|
48 | 48 | '1': 'XOR', |
|
49 | 49 | '2': 'AND', |
|
50 | 50 | '3': 'NAND' |
|
51 | 51 | } |
|
52 | 52 | |
|
53 | 53 | |
|
54 | 54 | def index(request): |
|
55 | 55 | kwargs = {} |
|
56 | 56 | |
|
57 | 57 | return render(request, 'index.html', kwargs) |
|
58 | 58 | |
|
59 | 59 | |
|
60 | 60 | def locations(request): |
|
61 | 61 | |
|
62 | 62 | locations = Location.objects.all().order_by('name') |
|
63 | 63 | |
|
64 | 64 | keys = ['id', 'name', 'description'] |
|
65 | 65 | |
|
66 | 66 | kwargs = {} |
|
67 | 67 | kwargs['location_keys'] = keys[1:] |
|
68 | 68 | kwargs['locations'] = locations |
|
69 | 69 | kwargs['title'] = 'Location' |
|
70 | 70 | kwargs['suptitle'] = 'List' |
|
71 | 71 | kwargs['button'] = 'New Location' |
|
72 | 72 | |
|
73 | 73 | return render(request, 'locations.html', kwargs) |
|
74 | 74 | |
|
75 | 75 | |
|
76 | 76 | def location(request, id_loc): |
|
77 | 77 | |
|
78 | 78 | location = get_object_or_404(Location, pk=id_loc) |
|
79 | 79 | |
|
80 | 80 | kwargs = {} |
|
81 | 81 | kwargs['location'] = location |
|
82 | 82 | kwargs['location_keys'] = ['name', 'description'] |
|
83 | 83 | |
|
84 | 84 | kwargs['title'] = 'Location' |
|
85 | 85 | kwargs['suptitle'] = 'Details' |
|
86 | 86 | |
|
87 | 87 | return render(request, 'location.html', kwargs) |
|
88 | 88 | |
|
89 | 89 | |
|
90 | 90 | def location_new(request): |
|
91 | 91 | |
|
92 | 92 | if request.method == 'GET': |
|
93 | 93 | form = LocationForm() |
|
94 | 94 | |
|
95 | 95 | if request.method == 'POST': |
|
96 | 96 | form = LocationForm(request.POST) |
|
97 | 97 | |
|
98 | 98 | if form.is_valid(): |
|
99 | 99 | form.save() |
|
100 | 100 | return redirect('url_locations') |
|
101 | 101 | |
|
102 | 102 | kwargs = {} |
|
103 | 103 | kwargs['form'] = form |
|
104 | 104 | kwargs['title'] = 'Location' |
|
105 | 105 | kwargs['suptitle'] = 'New' |
|
106 | 106 | kwargs['button'] = 'Create' |
|
107 | 107 | |
|
108 | 108 | return render(request, 'location_edit.html', kwargs) |
|
109 | 109 | |
|
110 | 110 | |
|
111 | 111 | def location_edit(request, id_loc): |
|
112 | 112 | |
|
113 | 113 | location = get_object_or_404(Location, pk=id_loc) |
|
114 | 114 | |
|
115 | 115 | if request.method=='GET': |
|
116 | 116 | form = LocationForm(instance=location) |
|
117 | 117 | |
|
118 | 118 | if request.method=='POST': |
|
119 | 119 | form = LocationForm(request.POST, instance=location) |
|
120 | 120 | |
|
121 | 121 | if form.is_valid(): |
|
122 | 122 | form.save() |
|
123 | 123 | return redirect('url_locations') |
|
124 | 124 | |
|
125 | 125 | kwargs = {} |
|
126 | 126 | kwargs['form'] = form |
|
127 | 127 | kwargs['title'] = 'Location' |
|
128 | 128 | kwargs['suptitle'] = 'Edit' |
|
129 | 129 | kwargs['button'] = 'Update' |
|
130 | 130 | |
|
131 | 131 | return render(request, 'location_edit.html', kwargs) |
|
132 | 132 | |
|
133 | 133 | |
|
134 | 134 | def location_delete(request, id_loc): |
|
135 | 135 | |
|
136 | 136 | location = get_object_or_404(Location, pk=id_loc) |
|
137 | 137 | |
|
138 | 138 | if request.method=='POST': |
|
139 | 139 | |
|
140 | 140 | if request.user.is_staff: |
|
141 | 141 | location.delete() |
|
142 | 142 | return redirect('url_locations') |
|
143 | 143 | |
|
144 | 144 | messages.error(request, 'Not enough permission to delete this object') |
|
145 | 145 | return redirect(location.get_absolute_url()) |
|
146 | 146 | |
|
147 | 147 | kwargs = { |
|
148 | 148 | 'title': 'Delete', |
|
149 | 149 | 'suptitle': 'Location', |
|
150 | 150 | 'object': location, |
|
151 | 151 | 'previous': location.get_absolute_url(), |
|
152 | 152 | 'delete': True |
|
153 | 153 | } |
|
154 | 154 | |
|
155 | 155 | return render(request, 'confirm.html', kwargs) |
|
156 | 156 | |
|
157 | 157 | |
|
158 | 158 | def devices(request): |
|
159 | 159 | |
|
160 | 160 | devices = Device.objects.all().order_by('device_type__name') |
|
161 | 161 | |
|
162 | 162 | # keys = ['id', 'device_type__name', 'name', 'ip_address'] |
|
163 | 163 | keys = ['id', 'name', 'ip_address', 'port_address', 'device_type'] |
|
164 | 164 | |
|
165 | 165 | kwargs = {} |
|
166 | 166 | kwargs['device_keys'] = keys[1:] |
|
167 | 167 | kwargs['devices'] = devices#.values(*keys) |
|
168 | 168 | kwargs['title'] = 'Device' |
|
169 | 169 | kwargs['suptitle'] = 'List' |
|
170 | 170 | kwargs['button'] = 'New Device' |
|
171 | 171 | |
|
172 | 172 | return render(request, 'devices.html', kwargs) |
|
173 | 173 | |
|
174 | 174 | |
|
175 | 175 | def device(request, id_dev): |
|
176 | 176 | |
|
177 | 177 | device = get_object_or_404(Device, pk=id_dev) |
|
178 | 178 | |
|
179 | 179 | kwargs = {} |
|
180 | 180 | kwargs['device'] = device |
|
181 | 181 | kwargs['device_keys'] = ['device_type', 'name', 'ip_address', 'port_address', 'description'] |
|
182 | 182 | |
|
183 | 183 | kwargs['title'] = 'Device' |
|
184 | 184 | kwargs['suptitle'] = 'Details' |
|
185 | 185 | |
|
186 | 186 | return render(request, 'device.html', kwargs) |
|
187 | 187 | |
|
188 | 188 | |
|
189 | 189 | def device_new(request): |
|
190 | 190 | |
|
191 | 191 | if request.method == 'GET': |
|
192 | 192 | form = DeviceForm() |
|
193 | 193 | |
|
194 | 194 | if request.method == 'POST': |
|
195 | 195 | form = DeviceForm(request.POST) |
|
196 | 196 | |
|
197 | 197 | if form.is_valid(): |
|
198 | 198 | form.save() |
|
199 | 199 | return redirect('url_devices') |
|
200 | 200 | |
|
201 | 201 | kwargs = {} |
|
202 | 202 | kwargs['form'] = form |
|
203 | 203 | kwargs['title'] = 'Device' |
|
204 | 204 | kwargs['suptitle'] = 'New' |
|
205 | 205 | kwargs['button'] = 'Create' |
|
206 | 206 | |
|
207 | 207 | return render(request, 'device_edit.html', kwargs) |
|
208 | 208 | |
|
209 | 209 | |
|
210 | 210 | def device_edit(request, id_dev): |
|
211 | 211 | |
|
212 | 212 | device = get_object_or_404(Device, pk=id_dev) |
|
213 | 213 | |
|
214 | 214 | if request.method=='GET': |
|
215 | 215 | form = DeviceForm(instance=device) |
|
216 | 216 | |
|
217 | 217 | if request.method=='POST': |
|
218 | 218 | form = DeviceForm(request.POST, instance=device) |
|
219 | 219 | |
|
220 | 220 | if form.is_valid(): |
|
221 | 221 | form.save() |
|
222 | 222 | return redirect(device.get_absolute_url()) |
|
223 | 223 | |
|
224 | 224 | kwargs = {} |
|
225 | 225 | kwargs['form'] = form |
|
226 | 226 | kwargs['title'] = 'Device' |
|
227 | 227 | kwargs['suptitle'] = 'Edit' |
|
228 | 228 | kwargs['button'] = 'Update' |
|
229 | 229 | |
|
230 | 230 | return render(request, 'device_edit.html', kwargs) |
|
231 | 231 | |
|
232 | 232 | |
|
233 | 233 | def device_delete(request, id_dev): |
|
234 | 234 | |
|
235 | 235 | device = get_object_or_404(Device, pk=id_dev) |
|
236 | 236 | |
|
237 | 237 | if request.method=='POST': |
|
238 | 238 | |
|
239 | 239 | if request.user.is_staff: |
|
240 | 240 | device.delete() |
|
241 | 241 | return redirect('url_devices') |
|
242 | 242 | |
|
243 | 243 | messages.error(request, 'Not enough permission to delete this object') |
|
244 | 244 | return redirect(device.get_absolute_url()) |
|
245 | 245 | |
|
246 | 246 | kwargs = { |
|
247 | 247 | 'title': 'Delete', |
|
248 | 248 | 'suptitle': 'Device', |
|
249 | 249 | 'object': device, |
|
250 | 250 | 'previous': device.get_absolute_url(), |
|
251 | 251 | 'delete': True |
|
252 | 252 | } |
|
253 | 253 | |
|
254 | 254 | return render(request, 'confirm.html', kwargs) |
|
255 | 255 | |
|
256 | 256 | |
|
257 | 257 | def campaigns(request): |
|
258 | 258 | |
|
259 | 259 | campaigns = Campaign.objects.all().order_by('start_date') |
|
260 | 260 | |
|
261 | 261 | keys = ['id', 'name', 'start_date', 'end_date'] |
|
262 | 262 | |
|
263 | 263 | kwargs = {} |
|
264 | 264 | kwargs['campaign_keys'] = keys[1:] |
|
265 | 265 | kwargs['campaigns'] = campaigns#.values(*keys) |
|
266 | 266 | kwargs['title'] = 'Campaign' |
|
267 | 267 | kwargs['suptitle'] = 'List' |
|
268 | 268 | kwargs['button'] = 'New Campaign' |
|
269 | 269 | |
|
270 | 270 | return render(request, 'campaigns.html', kwargs) |
|
271 | 271 | |
|
272 | 272 | |
|
273 | 273 | def campaign(request, id_camp): |
|
274 | 274 | |
|
275 | 275 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
276 | 276 | experiments = Experiment.objects.filter(campaign=campaign) |
|
277 | 277 | |
|
278 | 278 | form = CampaignForm(instance=campaign) |
|
279 | 279 | |
|
280 | 280 | kwargs = {} |
|
281 | 281 | kwargs['campaign'] = campaign |
|
282 | 282 | kwargs['campaign_keys'] = ['template', 'name', 'start_date', 'end_date', 'tags', 'description'] |
|
283 | 283 | |
|
284 | 284 | kwargs['experiments'] = experiments |
|
285 | 285 | kwargs['experiment_keys'] = ['name', 'radar', 'start_time', 'end_time'] |
|
286 | 286 | |
|
287 | 287 | kwargs['title'] = 'Campaign' |
|
288 | 288 | kwargs['suptitle'] = 'Details' |
|
289 | 289 | |
|
290 | 290 | kwargs['form'] = form |
|
291 | 291 | kwargs['button'] = 'Add Experiment' |
|
292 | 292 | |
|
293 | 293 | return render(request, 'campaign.html', kwargs) |
|
294 | 294 | |
|
295 | 295 | |
|
296 | 296 | def campaign_new(request): |
|
297 | 297 | |
|
298 | 298 | kwargs = {} |
|
299 | 299 | |
|
300 | 300 | if request.method == 'GET': |
|
301 | 301 | |
|
302 | 302 | if 'template' in request.GET: |
|
303 | 303 | if request.GET['template']=='0': |
|
304 | 304 | form = NewForm(initial={'create_from':2}, |
|
305 | 305 | template_choices=Campaign.objects.filter(template=True).values_list('id', 'name')) |
|
306 | 306 | else: |
|
307 | 307 | kwargs['button'] = 'Create' |
|
308 | 308 | kwargs['experiments'] = Configuration.objects.filter(experiment=request.GET['template']) |
|
309 | 309 | kwargs['experiment_keys'] = ['name', 'start_time', 'end_time'] |
|
310 | 310 | camp = Campaign.objects.get(pk=request.GET['template']) |
|
311 | 311 | form = CampaignForm(instance=camp, |
|
312 | 312 | initial={'name':'{} [{:%Y/%m/%d}]'.format(camp.name, datetime.now()), |
|
313 | 313 | 'template':False}) |
|
314 | 314 | elif 'blank' in request.GET: |
|
315 | 315 | kwargs['button'] = 'Create' |
|
316 | 316 | form = CampaignForm() |
|
317 | 317 | else: |
|
318 | 318 | form = NewForm() |
|
319 | 319 | |
|
320 | 320 | if request.method == 'POST': |
|
321 | 321 | kwargs['button'] = 'Create' |
|
322 | 322 | post = request.POST.copy() |
|
323 | 323 | experiments = [] |
|
324 | 324 | |
|
325 | 325 | for id_exp in post.getlist('experiments'): |
|
326 | 326 | exp = Experiment.objects.get(pk=id_exp) |
|
327 | 327 | new_exp = exp.clone(template=False) |
|
328 | 328 | experiments.append(new_exp) |
|
329 | 329 | |
|
330 | 330 | post.setlist('experiments', []) |
|
331 | 331 | |
|
332 | 332 | form = CampaignForm(post) |
|
333 | 333 | |
|
334 | 334 | if form.is_valid(): |
|
335 | 335 | campaign = form.save() |
|
336 | 336 | for exp in experiments: |
|
337 | 337 | campaign.experiments.add(exp) |
|
338 | 338 | campaign.save() |
|
339 | 339 | return redirect('url_campaign', id_camp=campaign.id) |
|
340 | 340 | |
|
341 | 341 | kwargs['form'] = form |
|
342 | 342 | kwargs['title'] = 'Campaign' |
|
343 | 343 | kwargs['suptitle'] = 'New' |
|
344 | 344 | |
|
345 | 345 | return render(request, 'campaign_edit.html', kwargs) |
|
346 | 346 | |
|
347 | 347 | |
|
348 | 348 | def campaign_edit(request, id_camp): |
|
349 | 349 | |
|
350 | 350 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
351 | 351 | |
|
352 | 352 | if request.method=='GET': |
|
353 | 353 | form = CampaignForm(instance=campaign) |
|
354 | 354 | |
|
355 | 355 | if request.method=='POST': |
|
356 | 356 | exps = campaign.experiments.all().values_list('pk', flat=True) |
|
357 | 357 | post = request.POST.copy() |
|
358 | 358 | new_exps = post.getlist('experiments') |
|
359 | 359 | post.setlist('experiments', []) |
|
360 | 360 | form = CampaignForm(post, instance=campaign) |
|
361 | 361 | |
|
362 | 362 | if form.is_valid(): |
|
363 | 363 | camp = form.save() |
|
364 | 364 | for id_exp in new_exps: |
|
365 | 365 | if int(id_exp) in exps: |
|
366 | 366 | exps.pop(id_exp) |
|
367 | 367 | else: |
|
368 | 368 | exp = Experiment.objects.get(pk=id_exp) |
|
369 | 369 | if exp.template: |
|
370 | 370 | camp.experiments.add(exp.clone(template=False)) |
|
371 | 371 | else: |
|
372 | 372 | camp.experiments.add(exp) |
|
373 | 373 | |
|
374 | 374 | for id_exp in exps: |
|
375 | 375 | camp.experiments.remove(Experiment.objects.get(pk=id_exp)) |
|
376 | 376 | |
|
377 | 377 | return redirect('url_campaign', id_camp=id_camp) |
|
378 | 378 | |
|
379 | 379 | kwargs = {} |
|
380 | 380 | kwargs['form'] = form |
|
381 | 381 | kwargs['title'] = 'Campaign' |
|
382 | 382 | kwargs['suptitle'] = 'Edit' |
|
383 | 383 | kwargs['button'] = 'Update' |
|
384 | 384 | |
|
385 | 385 | return render(request, 'campaign_edit.html', kwargs) |
|
386 | 386 | |
|
387 | 387 | |
|
388 | 388 | def campaign_delete(request, id_camp): |
|
389 | 389 | |
|
390 | 390 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
391 | 391 | |
|
392 | 392 | if request.method=='POST': |
|
393 | 393 | if request.user.is_staff: |
|
394 | 394 | |
|
395 | 395 | for exp in campaign.experiments.all(): |
|
396 | 396 | for conf in Configuration.objects.filter(experiment=exp): |
|
397 | 397 | conf.delete() |
|
398 | 398 | exp.delete() |
|
399 | 399 | campaign.delete() |
|
400 | 400 | |
|
401 | 401 | return redirect('url_campaigns') |
|
402 | 402 | |
|
403 | 403 | messages.error(request, 'Not enough permission to delete this object') |
|
404 | 404 | return redirect(campaign.get_absolute_url()) |
|
405 | 405 | |
|
406 | 406 | kwargs = { |
|
407 | 407 | 'title': 'Delete', |
|
408 | 408 | 'suptitle': 'Campaign', |
|
409 | 409 | 'object': campaign, |
|
410 | 410 | 'previous': campaign.get_absolute_url(), |
|
411 | 411 | 'delete': True |
|
412 | 412 | } |
|
413 | 413 | |
|
414 | 414 | return render(request, 'confirm.html', kwargs) |
|
415 | 415 | |
|
416 | 416 | def campaign_export(request, id_camp): |
|
417 | 417 | |
|
418 | 418 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
419 | 419 | content = campaign.parms_to_dict() |
|
420 | 420 | content_type = 'application/json' |
|
421 | 421 | filename = '%s_%s.json' %(campaign.name, campaign.id) |
|
422 | 422 | |
|
423 | 423 | response = HttpResponse(content_type=content_type) |
|
424 | 424 | response['Content-Disposition'] = 'attachment; filename="%s"' %filename |
|
425 | 425 | response.write(content) |
|
426 | 426 | |
|
427 | 427 | return response |
|
428 | 428 | |
|
429 | ||
|
430 | def campaign_import(request, id_camp): | |
|
431 | ###------FALTA CORREGIR!!!!!-----### | |
|
432 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
|
433 | experiments = Experiment.objects.filter(campaign=campaign) | |
|
434 | configurations = Configuration.objects.filter(experiment=experiments) | |
|
435 | ||
|
436 | if request.method == 'GET': | |
|
437 | file_form = UploadFileForm() | |
|
438 | ||
|
439 | if request.method == 'POST': | |
|
440 | file_form = UploadFileForm(request.POST, request.FILES) | |
|
441 | ||
|
442 | if file_form.is_valid(): | |
|
443 | ||
|
444 | parms = campaign.import_from_file(request.FILES['file']) | |
|
445 | ||
|
446 | if parms: | |
|
447 | location = Location.objects.get(name = parms['radar']) | |
|
448 | parms['location'] = location.id | |
|
449 | parms['name'] = parms['experiment'] | |
|
450 | ||
|
451 | campaign.dict_to_parms(parms, CONF_MODELS) | |
|
452 | ||
|
453 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) | |
|
454 | ||
|
455 | form = CampaignForm(initial=parms, instance=campaign) | |
|
456 | ||
|
457 | kwargs = {} | |
|
458 | #kwargs['id_dev'] = conf.id | |
|
459 | kwargs['form'] = form | |
|
460 | kwargs['title'] = 'Campaign' | |
|
461 | kwargs['suptitle'] = 'Parameters imported' | |
|
462 | kwargs['button'] = 'Save' | |
|
463 | kwargs['action'] = campaign.get_absolute_url_edit() | |
|
464 | kwargs['previous'] = campaign.get_absolute_url() | |
|
465 | ||
|
466 | ||
|
467 | ###### SIDEBAR ###### | |
|
468 | #kwargs.update(sidebar(conf=conf)) | |
|
469 | #kwargs.update(sidebar(campaign=campaign)) | |
|
470 | ||
|
471 | return render(request, 'campaign_edit.html', kwargs) | |
|
472 | ||
|
473 | messages.error(request, "Could not import parameters from file") | |
|
474 | ||
|
475 | kwargs = {} | |
|
476 | #kwargs['id_dev'] = conf.id | |
|
477 | kwargs['title'] = 'Campaign' | |
|
478 | kwargs['form'] = file_form | |
|
479 | kwargs['suptitle'] = 'Importing file' | |
|
480 | kwargs['button'] = 'Import' | |
|
481 | ||
|
482 | #kwargs.update(sidebar(campaign=campaign)) | |
|
483 | ||
|
484 | return render(request, 'campaign_import.html', kwargs) | |
|
485 | ||
|
486 | ||
|
429 | 487 | def experiments(request): |
|
430 | 488 | |
|
431 | 489 | experiment_list = Experiment.objects.all() |
|
432 | 490 | |
|
433 | 491 | keys = ['id', 'name', 'start_time', 'end_time'] |
|
434 | 492 | |
|
435 | 493 | kwargs = {} |
|
436 | 494 | |
|
437 | 495 | kwargs['experiment_keys'] = keys[1:] |
|
438 | 496 | kwargs['experiments'] = experiment_list |
|
439 | 497 | |
|
440 | 498 | kwargs['title'] = 'Experiment' |
|
441 | 499 | kwargs['suptitle'] = 'List' |
|
442 | 500 | kwargs['button'] = 'New Experiment' |
|
443 | 501 | |
|
444 | 502 | return render(request, 'experiments.html', kwargs) |
|
445 | 503 | |
|
446 | 504 | |
|
447 | 505 | def experiment(request, id_exp): |
|
448 | 506 | |
|
449 | 507 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
450 | 508 | |
|
451 | 509 | configurations = Configuration.objects.filter(experiment=experiment, type=0) |
|
452 | 510 | |
|
453 | 511 | kwargs = {} |
|
454 | 512 | |
|
455 | 513 | kwargs['experiment_keys'] = ['template', 'radar', 'name', 'start_time', 'end_time'] |
|
456 | 514 | kwargs['experiment'] = experiment |
|
457 | 515 | |
|
458 | 516 | kwargs['configuration_keys'] = ['name', 'device__device_type', 'device__ip_address', 'device__port_address'] |
|
459 | 517 | kwargs['configurations'] = configurations |
|
460 | 518 | |
|
461 | 519 | kwargs['title'] = 'Experiment' |
|
462 | 520 | kwargs['suptitle'] = 'Details' |
|
463 | 521 | |
|
464 | 522 | kwargs['button'] = 'Add Configuration' |
|
465 | 523 | |
|
466 | 524 | ###### SIDEBAR ###### |
|
467 | 525 | kwargs.update(sidebar(experiment=experiment)) |
|
468 | 526 | |
|
469 | 527 | return render(request, 'experiment.html', kwargs) |
|
470 | 528 | |
|
471 | 529 | |
|
472 | 530 | def experiment_new(request, id_camp=None): |
|
473 | 531 | |
|
474 | 532 | kwargs = {} |
|
475 | 533 | |
|
476 | 534 | if request.method == 'GET': |
|
477 | 535 | if 'template' in request.GET: |
|
478 | 536 | if request.GET['template']=='0': |
|
479 | 537 | form = NewForm(initial={'create_from':2}, |
|
480 | 538 | template_choices=Experiment.objects.filter(template=True).values_list('id', 'name')) |
|
481 | 539 | else: |
|
482 | 540 | kwargs['button'] = 'Create' |
|
483 | 541 | kwargs['configurations'] = Configuration.objects.filter(experiment=request.GET['template']) |
|
484 | 542 | kwargs['configuration_keys'] = ['name', 'device__name', 'device__ip_address', 'device__port_address'] |
|
485 | 543 | exp=Experiment.objects.get(pk=request.GET['template']) |
|
486 | 544 | form = ExperimentForm(instance=exp, |
|
487 | 545 | initial={'name': '{} [{:%Y/%m/%d}]'.format(exp.name, datetime.now()), |
|
488 | 546 | 'template': False}) |
|
489 | 547 | elif 'blank' in request.GET: |
|
490 | 548 | kwargs['button'] = 'Create' |
|
491 | 549 | form = ExperimentForm() |
|
492 | 550 | else: |
|
493 | 551 | form = NewForm() |
|
494 | 552 | |
|
495 | 553 | if request.method == 'POST': |
|
496 | 554 | form = ExperimentForm(request.POST) |
|
497 | 555 | if form.is_valid(): |
|
498 | 556 | experiment = form.save() |
|
499 | 557 | |
|
500 | 558 | if 'template' in request.GET: |
|
501 | 559 | configurations = Configuration.objects.filter(experiment=request.GET['template'], type=0) |
|
502 | 560 | for conf in configurations: |
|
503 | 561 | conf.clone(experiment=experiment, template=False) |
|
504 | 562 | |
|
505 | 563 | return redirect('url_experiment', id_exp=experiment.id) |
|
506 | 564 | |
|
507 | 565 | kwargs['form'] = form |
|
508 | 566 | kwargs['title'] = 'Experiment' |
|
509 | 567 | kwargs['suptitle'] = 'New' |
|
510 | 568 | |
|
511 | 569 | return render(request, 'experiment_edit.html', kwargs) |
|
512 | 570 | |
|
513 | 571 | |
|
514 | 572 | def experiment_edit(request, id_exp): |
|
515 | 573 | |
|
516 | 574 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
517 | 575 | |
|
518 | 576 | if request.method == 'GET': |
|
519 | 577 | form = ExperimentForm(instance=experiment) |
|
520 | 578 | |
|
521 | 579 | if request.method=='POST': |
|
522 | 580 | form = ExperimentForm(request.POST, instance=experiment) |
|
523 | 581 | |
|
524 | 582 | if form.is_valid(): |
|
525 | 583 | experiment = form.save() |
|
526 | 584 | return redirect('url_experiment', id_exp=experiment.id) |
|
527 | 585 | |
|
528 | 586 | kwargs = {} |
|
529 | 587 | kwargs['form'] = form |
|
530 | 588 | kwargs['title'] = 'Experiment' |
|
531 | 589 | kwargs['suptitle'] = 'Edit' |
|
532 | 590 | kwargs['button'] = 'Update' |
|
533 | 591 | |
|
534 | 592 | return render(request, 'experiment_edit.html', kwargs) |
|
535 | 593 | |
|
536 | 594 | |
|
537 | 595 | def experiment_delete(request, id_exp): |
|
538 | 596 | |
|
539 | 597 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
540 | 598 | |
|
541 | 599 | if request.method=='POST': |
|
542 | 600 | if request.user.is_staff: |
|
543 | 601 | for conf in Configuration.objects.filter(experiment=experiment): |
|
544 | 602 | conf.delete() |
|
545 | 603 | experiment.delete() |
|
546 | 604 | return redirect('url_experiments') |
|
547 | 605 | |
|
548 | 606 | messages.error(request, 'Not enough permission to delete this object') |
|
549 | 607 | return redirect(experiment.get_absolute_url()) |
|
550 | 608 | |
|
551 | 609 | kwargs = { |
|
552 | 610 | 'title': 'Delete', |
|
553 | 611 | 'suptitle': 'Experiment', |
|
554 | 612 | 'object': experiment, |
|
555 | 613 | 'previous': experiment.get_absolute_url(), |
|
556 | 614 | 'delete': True |
|
557 | 615 | } |
|
558 | 616 | |
|
559 | 617 | return render(request, 'confirm.html', kwargs) |
|
560 | 618 | |
|
561 | 619 | |
|
562 | 620 | def experiment_export(request, id_exp): |
|
563 | 621 | |
|
564 | 622 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
565 | 623 | content = experiment.parms_to_dict() |
|
566 | 624 | content_type = 'application/json' |
|
567 | 625 | filename = '%s_%s.json' %(experiment.name, experiment.id) |
|
568 | 626 | |
|
569 | 627 | response = HttpResponse(content_type=content_type) |
|
570 | 628 | response['Content-Disposition'] = 'attachment; filename="%s"' %filename |
|
571 | 629 | response.write(content) |
|
572 | 630 | |
|
573 | 631 | return response |
|
574 | 632 | |
|
633 | def experiment_import(request, id_exp): | |
|
634 | ||
|
635 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
|
636 | configurations = Configuration.objects.filter(experiment=experiment) | |
|
637 | ||
|
638 | if request.method == 'GET': | |
|
639 | file_form = UploadFileForm() | |
|
640 | ||
|
641 | if request.method == 'POST': | |
|
642 | file_form = UploadFileForm(request.POST, request.FILES) | |
|
643 | ||
|
644 | if file_form.is_valid(): | |
|
645 | ||
|
646 | parms = experiment.import_from_file(request.FILES['file']) | |
|
647 | ||
|
648 | if parms: | |
|
649 | location = Location.objects.get(name = parms['radar']) | |
|
650 | parms['location'] = location.id | |
|
651 | parms['name'] = parms['experiment'] | |
|
652 | ||
|
653 | experiment.dict_to_parms(parms, CONF_MODELS) | |
|
654 | ||
|
655 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) | |
|
656 | ||
|
657 | form = ExperimentForm(initial=parms, instance=experiment) | |
|
658 | ||
|
659 | kwargs = {} | |
|
660 | #kwargs['id_dev'] = conf.id | |
|
661 | kwargs['form'] = form | |
|
662 | kwargs['title'] = 'Experiment' | |
|
663 | kwargs['suptitle'] = 'Parameters imported' | |
|
664 | kwargs['button'] = 'Save' | |
|
665 | kwargs['action'] = experiment.get_absolute_url_edit() | |
|
666 | kwargs['previous'] = experiment.get_absolute_url() | |
|
667 | ||
|
668 | ###### SIDEBAR ###### | |
|
669 | #kwargs.update(sidebar(conf=conf)) | |
|
670 | kwargs.update(sidebar(experiment=experiment)) | |
|
671 | ||
|
672 | return render(request, 'experiment_edit.html', kwargs) | |
|
673 | ||
|
674 | messages.error(request, "Could not import parameters from file") | |
|
675 | ||
|
676 | kwargs = {} | |
|
677 | #kwargs['id_dev'] = conf.id | |
|
678 | kwargs['title'] = 'Experiment' | |
|
679 | kwargs['form'] = file_form | |
|
680 | kwargs['suptitle'] = 'Importing file' | |
|
681 | kwargs['button'] = 'Import' | |
|
682 | ||
|
683 | kwargs.update(sidebar(experiment=experiment)) | |
|
684 | ||
|
685 | return render(request, 'experiment_import.html', kwargs) | |
|
575 | 686 | |
|
576 | 687 | def experiment_mix(request, id_exp): |
|
577 | 688 | |
|
578 | 689 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
579 | 690 | rc_confs = [conf for conf in RCConfiguration.objects.filter(experiment=id_exp, |
|
580 | 691 | mix=False)] |
|
581 | 692 | |
|
582 | 693 | if len(rc_confs)<2: |
|
583 | 694 | messages.warning(request, 'You need at least two RC Configurations to make a mix') |
|
584 | 695 | return redirect(experiment.get_absolute_url()) |
|
585 | 696 | |
|
586 | 697 | mix_confs = RCConfiguration.objects.filter(experiment=id_exp, mix=True) |
|
587 | 698 | |
|
588 | 699 | if mix_confs: |
|
589 | 700 | mix = mix_confs[0] |
|
590 | 701 | else: |
|
591 | 702 | mix = RCConfiguration(experiment=experiment, |
|
592 | 703 | device=rc_confs[0].device, |
|
593 | 704 | ipp=rc_confs[0].ipp, |
|
594 | 705 | clock_in=rc_confs[0].clock_in, |
|
595 | 706 | clock_divider=rc_confs[0].clock_divider, |
|
596 | 707 | mix=True, |
|
597 | 708 | parameters='') |
|
598 | 709 | mix.save() |
|
599 | 710 | |
|
600 | 711 | line_type = RCLineType.objects.get(name='mix') |
|
601 | 712 | for i in range(len(rc_confs[0].get_lines())): |
|
602 | 713 | line = RCLine(rc_configuration=mix, line_type=line_type, channel=i) |
|
603 | 714 | line.save() |
|
604 | 715 | |
|
605 | 716 | initial = {'name': mix.name, |
|
606 | 717 | 'result': parse_mix_result(mix.parameters), |
|
607 | 718 | 'delay': 0, |
|
608 | 719 | 'mask': [0,1,2,3,4,5,6,7] |
|
609 | 720 | } |
|
610 | 721 | |
|
611 | 722 | if request.method=='GET': |
|
612 | 723 | form = RCMixConfigurationForm(confs=rc_confs, initial=initial) |
|
613 | 724 | |
|
614 | 725 | if request.method=='POST': |
|
615 | 726 | |
|
616 | 727 | result = mix.parameters |
|
617 | 728 | |
|
618 | 729 | if '{}|'.format(request.POST['experiment']) in result: |
|
619 | 730 | messages.error(request, 'Configuration already added') |
|
620 | 731 | else: |
|
621 | 732 | if result: |
|
622 | 733 | result = '{}-{}|{}|{}|{}'.format(mix.parameters, |
|
623 | 734 | request.POST['experiment'], |
|
624 | 735 | MIX_MODES[request.POST['operation']], |
|
625 | 736 | float(request.POST['delay']), |
|
626 | 737 | parse_mask(request.POST.getlist('mask')) |
|
627 | 738 | ) |
|
628 | 739 | else: |
|
629 | 740 | result = '{}|{}|{}|{}'.format(request.POST['experiment'], |
|
630 | 741 | MIX_MODES[request.POST['operation']], |
|
631 | 742 | float(request.POST['delay']), |
|
632 | 743 | parse_mask(request.POST.getlist('mask')) |
|
633 | 744 | ) |
|
634 | 745 | |
|
635 | 746 | mix.parameters = result |
|
636 | 747 | mix.name = request.POST['name'] |
|
637 | 748 | mix.save() |
|
638 | 749 | mix.update_pulses() |
|
639 | 750 | |
|
640 | 751 | |
|
641 | 752 | initial['result'] = parse_mix_result(result) |
|
642 | 753 | initial['name'] = mix.name |
|
643 | 754 | |
|
644 | 755 | form = RCMixConfigurationForm(initial=initial, confs=rc_confs) |
|
645 | 756 | |
|
646 | 757 | |
|
647 | 758 | kwargs = { |
|
648 | 759 | 'title': 'Experiment', |
|
649 | 760 | 'suptitle': 'Mix Configurations', |
|
650 | 761 | 'form' : form, |
|
651 | 762 | 'extra_button': 'Delete', |
|
652 | 763 | 'button': 'Add', |
|
653 | 764 | 'cancel': 'Back', |
|
654 | 765 | 'previous': experiment.get_absolute_url(), |
|
655 | 766 | 'id_exp':id_exp, |
|
656 | 767 | |
|
657 | 768 | } |
|
658 | 769 | |
|
659 | 770 | return render(request, 'experiment_mix.html', kwargs) |
|
660 | 771 | |
|
661 | 772 | |
|
662 | 773 | def experiment_mix_delete(request, id_exp): |
|
663 | 774 | |
|
664 | 775 | conf = RCConfiguration.objects.get(experiment=id_exp, mix=True) |
|
665 | 776 | values = conf.parameters.split('-') |
|
666 | 777 | conf.parameters = '-'.join(values[:-1]) |
|
667 | 778 | conf.save() |
|
668 | 779 | |
|
669 | 780 | return redirect('url_mix_experiment', id_exp=id_exp) |
|
670 | 781 | |
|
671 | 782 | |
|
672 | 783 | def parse_mix_result(s): |
|
673 | 784 | |
|
674 | 785 | values = s.split('-') |
|
675 | 786 | html = '' |
|
676 | 787 | |
|
677 | 788 | |
|
678 | 789 | for i, value in enumerate(values): |
|
679 | 790 | if not value: |
|
680 | 791 | continue |
|
681 | 792 | pk, mode, delay, mask = value.split('|') |
|
682 | 793 | conf = RCConfiguration.objects.get(pk=pk) |
|
683 | 794 | if i==0: |
|
684 | 795 | html += '{:20.18}{:4}{:9}km{:>6}\r\n'.format( |
|
685 | 796 | conf.name[:18], |
|
686 | 797 | '---', |
|
687 | 798 | delay, |
|
688 | 799 | mask) |
|
689 | 800 | else: |
|
690 | 801 | html += '{:20.18}{:4}{:9}km{:>6}\r\n'.format( |
|
691 | 802 | conf.name[:18], |
|
692 | 803 | mode, |
|
693 | 804 | delay, |
|
694 | 805 | mask) |
|
695 | 806 | |
|
696 | 807 | return mark_safe(html) |
|
697 | 808 | |
|
698 | 809 | def parse_mask(l): |
|
699 | 810 | |
|
700 | 811 | values = [] |
|
701 | 812 | |
|
702 | 813 | for x in range(8): |
|
703 | 814 | if '{}'.format(x) in l: |
|
704 | 815 | values.append(1) |
|
705 | 816 | else: |
|
706 | 817 | values.append(0) |
|
707 | 818 | |
|
708 | 819 | values.reverse() |
|
709 | 820 | |
|
710 | 821 | return int(''.join([str(x) for x in values]), 2) |
|
711 | 822 | |
|
712 | 823 | |
|
713 | 824 | def dev_confs(request): |
|
714 | 825 | |
|
715 | 826 | configurations = Configuration.objects.all().order_by('type', 'device__device_type', 'experiment') |
|
716 | 827 | |
|
717 | 828 | kwargs = {} |
|
718 | 829 | |
|
719 | 830 | kwargs['configuration_keys'] = ['device', 'name', 'experiment', 'type', 'programmed_date'] |
|
720 | 831 | kwargs['configurations'] = configurations |
|
721 | 832 | |
|
722 | 833 | kwargs['title'] = 'Configuration' |
|
723 | 834 | kwargs['suptitle'] = 'List' |
|
724 | 835 | |
|
725 | 836 | return render(request, 'dev_confs.html', kwargs) |
|
726 | 837 | |
|
727 | 838 | |
|
728 | 839 | def dev_conf(request, id_conf): |
|
729 | 840 | |
|
730 | 841 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
731 | 842 | |
|
732 | 843 | return redirect(conf.get_absolute_url()) |
|
733 | 844 | |
|
734 | 845 | |
|
735 | 846 | def dev_conf_new(request, id_exp=0, id_dev=0): |
|
736 | 847 | |
|
737 | 848 | initial = {} |
|
738 | 849 | kwargs = {} |
|
739 | 850 | |
|
740 | 851 | if id_exp<>0: |
|
741 | 852 | initial['experiment'] = id_exp |
|
742 | 853 | |
|
743 | 854 | if id_dev<>0: |
|
744 | 855 | initial['device'] = id_dev |
|
745 | 856 | |
|
746 | 857 | if request.method == 'GET': |
|
747 | 858 | |
|
748 | 859 | if id_dev: |
|
749 | 860 | kwargs['button'] = 'Create' |
|
750 | 861 | device = Device.objects.get(pk=id_dev) |
|
751 | 862 | DevConfForm = CONF_FORMS[device.device_type.name] |
|
752 | 863 | initial['name'] = request.GET['name'] |
|
753 | 864 | form = DevConfForm(initial=initial) |
|
754 | 865 | else: |
|
755 | 866 | if 'template' in request.GET: |
|
756 | 867 | if request.GET['template']=='0': |
|
757 | 868 | form = NewForm(initial={'create_from':2}, |
|
758 | 869 | template_choices=Configuration.objects.filter(template=True).values_list('id', 'name')) |
|
759 | 870 | else: |
|
760 | 871 | kwargs['button'] = 'Create' |
|
761 | 872 | conf = Configuration.objects.get(pk=request.GET['template']) |
|
762 | 873 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
763 | 874 | form = DevConfForm(instance=conf, |
|
764 | 875 | initial={'name': '{} [{:%Y/%m/%d}]'.format(conf.name, datetime.now()), |
|
765 | 876 | 'template': False}) |
|
766 | 877 | elif 'blank' in request.GET: |
|
767 | 878 | kwargs['button'] = 'Create' |
|
768 | 879 | form = ConfigurationForm(initial=initial) |
|
769 | 880 | else: |
|
770 | 881 | form = NewForm() |
|
771 | 882 | |
|
772 | 883 | if request.method == 'POST': |
|
773 | 884 | |
|
774 | 885 | device = Device.objects.get(pk=request.POST['device']) |
|
775 | 886 | DevConfForm = CONF_FORMS[device.device_type.name] |
|
776 | 887 | |
|
777 | 888 | form = DevConfForm(request.POST) |
|
778 | 889 | |
|
779 | 890 | if form.is_valid(): |
|
780 | 891 | conf = form.save() |
|
781 | 892 | |
|
782 | 893 | if 'template' in request.GET and conf.device.device_type.name=='rc': |
|
783 | 894 | lines = RCLine.objects.filter(rc_configuration=request.GET['template']) |
|
784 | 895 | for line in lines: |
|
785 | 896 | line.clone(rc_configuration=conf) |
|
786 | 897 | |
|
787 | 898 | return redirect('url_dev_conf', id_conf=conf.pk) |
|
788 | 899 | |
|
789 | 900 | |
|
790 | 901 | kwargs['id_exp'] = id_exp |
|
791 | 902 | kwargs['form'] = form |
|
792 | 903 | kwargs['title'] = 'Configuration' |
|
793 | 904 | kwargs['suptitle'] = 'New' |
|
794 | 905 | |
|
795 | 906 | |
|
796 | 907 | if id_dev != 0: |
|
797 | 908 | device = Device.objects.get(pk=id_dev) |
|
798 | 909 | if 'dds' in device.device_type.name: |
|
799 | 910 | kwargs['dds_device'] = True |
|
800 | 911 | |
|
801 | 912 | return render(request, 'dev_conf_edit.html', kwargs) |
|
802 | 913 | |
|
803 | 914 | |
|
804 | 915 | def dev_conf_edit(request, id_conf): |
|
805 | 916 | |
|
806 | 917 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
807 | 918 | |
|
808 | 919 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
809 | 920 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
810 | 921 | |
|
811 | 922 | dev_conf = DevConfModel.objects.get(pk=id_conf) |
|
812 | 923 | |
|
813 | 924 | if request.method=='GET': |
|
814 | 925 | form = DevConfForm(instance=dev_conf) |
|
815 | 926 | |
|
816 | 927 | if request.method=='POST': |
|
817 | 928 | form = DevConfForm(request.POST, instance=dev_conf) |
|
818 | 929 | |
|
819 | 930 | if form.is_valid(): |
|
820 | 931 | form.save() |
|
821 | 932 | return redirect('url_dev_conf', id_conf=id_conf) |
|
822 | 933 | |
|
823 | 934 | kwargs = {} |
|
824 | 935 | kwargs['form'] = form |
|
825 | 936 | kwargs['title'] = 'Device Configuration' |
|
826 | 937 | kwargs['suptitle'] = 'Edit' |
|
827 | 938 | kwargs['button'] = 'Update' |
|
828 | 939 | |
|
829 | 940 | ###### SIDEBAR ###### |
|
830 | 941 | kwargs.update(sidebar(conf=conf)) |
|
831 | 942 | |
|
832 | 943 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) |
|
833 | 944 | |
|
834 | 945 | |
|
835 | 946 | def dev_conf_start(request, id_conf): |
|
836 | 947 | |
|
837 | 948 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
838 | 949 | |
|
839 | 950 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
840 | 951 | |
|
841 | 952 | conf = DevConfModel.objects.get(pk=id_conf) |
|
842 | 953 | |
|
843 | 954 | if conf.start_device(): |
|
844 | 955 | messages.success(request, conf.message) |
|
845 | 956 | else: |
|
846 | 957 | messages.error(request, conf.message) |
|
847 | 958 | |
|
848 | 959 | conf.status_device() |
|
849 | 960 | |
|
850 | 961 | return redirect(conf.get_absolute_url()) |
|
851 | 962 | |
|
852 | 963 | |
|
853 | 964 | def dev_conf_stop(request, id_conf): |
|
854 | 965 | |
|
855 | 966 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
856 | 967 | |
|
857 | 968 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
858 | 969 | |
|
859 | 970 | conf = DevConfModel.objects.get(pk=id_conf) |
|
860 | 971 | |
|
861 | 972 | if conf.stop_device(): |
|
862 | 973 | messages.success(request, conf.message) |
|
863 | 974 | else: |
|
864 | 975 | messages.error(request, conf.message) |
|
865 | 976 | |
|
866 | 977 | conf.status_device() |
|
867 | 978 | |
|
868 | 979 | return redirect(conf.get_absolute_url()) |
|
869 | 980 | |
|
870 | 981 | |
|
871 | 982 | def dev_conf_status(request, id_conf): |
|
872 | 983 | |
|
873 | 984 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
874 | 985 | |
|
875 | 986 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
876 | 987 | |
|
877 | 988 | conf = DevConfModel.objects.get(pk=id_conf) |
|
878 | 989 | |
|
879 | 990 | if conf.status_device(): |
|
880 | 991 | messages.success(request, conf.message) |
|
881 | 992 | else: |
|
882 | 993 | messages.error(request, conf.message) |
|
883 | 994 | |
|
884 | 995 | return redirect(conf.get_absolute_url()) |
|
885 | 996 | |
|
886 | 997 | |
|
887 | 998 | def dev_conf_write(request, id_conf): |
|
888 | 999 | |
|
889 | 1000 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
890 | 1001 | |
|
891 | 1002 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
892 | 1003 | |
|
893 | 1004 | conf = DevConfModel.objects.get(pk=id_conf) |
|
894 | 1005 | |
|
895 | 1006 | answer = conf.write_device() |
|
896 | 1007 | conf.status_device() |
|
897 | 1008 | |
|
898 | 1009 | if answer: |
|
899 | 1010 | messages.success(request, conf.message) |
|
900 | 1011 | |
|
901 | 1012 | #Creating a historical configuration |
|
902 | 1013 | conf.clone(type=0, template=False) |
|
903 | 1014 | |
|
904 | 1015 | #Original configuration |
|
905 | 1016 | conf = DevConfModel.objects.get(pk=id_conf) |
|
906 | 1017 | else: |
|
907 | 1018 | messages.error(request, conf.message) |
|
908 | 1019 | |
|
909 | 1020 | return redirect(conf.get_absolute_url()) |
|
910 | 1021 | |
|
911 | 1022 | |
|
912 | 1023 | def dev_conf_read(request, id_conf): |
|
913 | 1024 | |
|
914 | 1025 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
915 | 1026 | |
|
916 | 1027 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
917 | 1028 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
918 | 1029 | |
|
919 | 1030 | conf = DevConfModel.objects.get(pk=id_conf) |
|
920 | 1031 | |
|
921 | 1032 | if request.method=='GET': |
|
922 | 1033 | |
|
923 | 1034 | parms = conf.read_device() |
|
924 | 1035 | conf.status_device() |
|
925 | 1036 | |
|
926 | 1037 | if not parms: |
|
927 | 1038 | messages.error(request, conf.message) |
|
928 | 1039 | return redirect(conf.get_absolute_url()) |
|
929 | 1040 | |
|
930 | 1041 | form = DevConfForm(initial=parms, instance=conf) |
|
931 | 1042 | |
|
932 | 1043 | if request.method=='POST': |
|
933 | 1044 | form = DevConfForm(request.POST, instance=conf) |
|
934 | 1045 | |
|
935 | 1046 | if form.is_valid(): |
|
936 | 1047 | form.save() |
|
937 | 1048 | return redirect(conf.get_absolute_url()) |
|
938 | 1049 | |
|
939 | 1050 | messages.error(request, "Parameters could not be saved") |
|
940 | 1051 | |
|
941 | 1052 | kwargs = {} |
|
942 | 1053 | kwargs['id_dev'] = conf.id |
|
943 | 1054 | kwargs['form'] = form |
|
944 | 1055 | kwargs['title'] = 'Device Configuration' |
|
945 | 1056 | kwargs['suptitle'] = 'Parameters read from device' |
|
946 | 1057 | kwargs['button'] = 'Save' |
|
947 | 1058 | |
|
948 | 1059 | ###### SIDEBAR ###### |
|
949 | 1060 | kwargs.update(sidebar(conf=conf)) |
|
950 | 1061 | |
|
951 | 1062 | return render(request, '%s_conf_edit.html' %conf.device.device_type.name, kwargs) |
|
952 | 1063 | |
|
953 | 1064 | |
|
954 | 1065 | def dev_conf_import(request, id_conf): |
|
955 | 1066 | |
|
956 | 1067 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
957 | 1068 | |
|
958 | 1069 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
959 | 1070 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
960 | 1071 | conf = DevConfModel.objects.get(pk=id_conf) |
|
961 | 1072 | |
|
962 | 1073 | if request.method == 'GET': |
|
963 | 1074 | file_form = UploadFileForm() |
|
964 | 1075 | |
|
965 | 1076 | if request.method == 'POST': |
|
966 | 1077 | file_form = UploadFileForm(request.POST, request.FILES) |
|
967 | 1078 | |
|
968 | 1079 | if file_form.is_valid(): |
|
969 | 1080 | |
|
970 | 1081 | parms = conf.import_from_file(request.FILES['file']) |
|
971 | 1082 | |
|
972 | 1083 | if parms: |
|
973 | 1084 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) |
|
974 | 1085 | form = DevConfForm(initial=parms, instance=conf) |
|
975 | 1086 | |
|
976 | 1087 | kwargs = {} |
|
977 | 1088 | kwargs['id_dev'] = conf.id |
|
978 | 1089 | kwargs['form'] = form |
|
979 | 1090 | kwargs['title'] = 'Device Configuration' |
|
980 | 1091 | kwargs['suptitle'] = 'Parameters imported' |
|
981 | 1092 | kwargs['button'] = 'Save' |
|
982 | 1093 | kwargs['action'] = conf.get_absolute_url_edit() |
|
983 | 1094 | kwargs['previous'] = conf.get_absolute_url() |
|
984 | 1095 | |
|
985 | 1096 | ###### SIDEBAR ###### |
|
986 | 1097 | kwargs.update(sidebar(conf=conf)) |
|
987 | 1098 | |
|
988 | 1099 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) |
|
989 | 1100 | |
|
990 | 1101 | messages.error(request, "Could not import parameters from file") |
|
991 | 1102 | |
|
992 | 1103 | kwargs = {} |
|
993 | 1104 | kwargs['id_dev'] = conf.id |
|
994 | 1105 | kwargs['title'] = 'Device Configuration' |
|
995 | 1106 | kwargs['form'] = file_form |
|
996 | 1107 | kwargs['suptitle'] = 'Importing file' |
|
997 | 1108 | kwargs['button'] = 'Import' |
|
998 | 1109 | |
|
999 | 1110 | kwargs.update(sidebar(conf=conf)) |
|
1000 | 1111 | |
|
1001 | 1112 | return render(request, 'dev_conf_import.html', kwargs) |
|
1002 | 1113 | |
|
1003 | 1114 | |
|
1004 | 1115 | def dev_conf_export(request, id_conf): |
|
1005 | 1116 | |
|
1006 | 1117 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1007 | 1118 | |
|
1008 | 1119 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
1009 | 1120 | |
|
1010 | 1121 | conf = DevConfModel.objects.get(pk=id_conf) |
|
1011 | 1122 | |
|
1012 | 1123 | if request.method == 'GET': |
|
1013 | 1124 | file_form = DownloadFileForm(conf.device.device_type.name) |
|
1014 | 1125 | |
|
1015 | 1126 | if request.method == 'POST': |
|
1016 | 1127 | file_form = DownloadFileForm(conf.device.device_type.name, request.POST) |
|
1017 | 1128 | |
|
1018 | 1129 | if file_form.is_valid(): |
|
1019 | 1130 | fields = conf.export_to_file(format = file_form.cleaned_data['format']) |
|
1020 | 1131 | |
|
1021 | 1132 | response = HttpResponse(content_type=fields['content_type']) |
|
1022 | 1133 | response['Content-Disposition'] = 'attachment; filename="%s"' %fields['filename'] |
|
1023 | 1134 | response.write(fields['content']) |
|
1024 | 1135 | |
|
1025 | 1136 | return response |
|
1026 | 1137 | |
|
1027 | 1138 | messages.error(request, "Could not export parameters") |
|
1028 | 1139 | |
|
1029 | 1140 | kwargs = {} |
|
1030 | 1141 | kwargs['id_dev'] = conf.id |
|
1031 | 1142 | kwargs['title'] = 'Device Configuration' |
|
1032 | 1143 | kwargs['form'] = file_form |
|
1033 | 1144 | kwargs['suptitle'] = 'Exporting file' |
|
1034 | 1145 | kwargs['button'] = 'Export' |
|
1035 | 1146 | |
|
1036 | 1147 | return render(request, 'dev_conf_export.html', kwargs) |
|
1037 | 1148 | |
|
1038 | 1149 | |
|
1039 | 1150 | def dev_conf_delete(request, id_conf): |
|
1040 | 1151 | |
|
1041 | 1152 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1042 | 1153 | |
|
1043 | 1154 | if request.method=='POST': |
|
1044 | 1155 | if request.user.is_staff: |
|
1045 | 1156 | conf.delete() |
|
1046 | 1157 | return redirect('url_dev_confs') |
|
1047 | 1158 | |
|
1048 | 1159 | messages.error(request, 'Not enough permission to delete this object') |
|
1049 | 1160 | return redirect(conf.get_absolute_url()) |
|
1050 | 1161 | |
|
1051 | 1162 | kwargs = { |
|
1052 | 1163 | 'title': 'Delete', |
|
1053 | 1164 | 'suptitle': 'Experiment', |
|
1054 | 1165 | 'object': conf, |
|
1055 | 1166 | 'previous': conf.get_absolute_url(), |
|
1056 | 1167 | 'delete': True |
|
1057 | 1168 | } |
|
1058 | 1169 | |
|
1059 | 1170 | return render(request, 'confirm.html', kwargs) |
|
1060 | 1171 | |
|
1061 | 1172 | |
|
1062 | 1173 | def sidebar(**kwargs): |
|
1063 | 1174 | |
|
1064 | 1175 | side_data = {} |
|
1065 | 1176 | |
|
1066 | 1177 | conf = kwargs.get('conf', None) |
|
1067 | 1178 | experiment = kwargs.get('experiment', None) |
|
1068 | 1179 | |
|
1069 | 1180 | if not experiment: |
|
1070 | 1181 | experiment = conf.experiment |
|
1071 | 1182 | |
|
1072 | 1183 | if experiment: |
|
1073 | 1184 | side_data['experiment'] = experiment |
|
1074 | 1185 | campaign = experiment.campaign_set.all() |
|
1075 | 1186 | if campaign: |
|
1076 | 1187 | side_data['campaign'] = campaign[0] |
|
1077 | 1188 | experiments = campaign[0].experiments.all() |
|
1078 | 1189 | else: |
|
1079 | 1190 | experiments = [experiment] |
|
1080 | 1191 | configurations = experiment.configuration_set.filter(type=0) |
|
1081 | 1192 | side_data['side_experiments'] = experiments |
|
1082 | 1193 | side_data['side_configurations'] = configurations |
|
1083 | 1194 | |
|
1084 | 1195 | return side_data |
|
1085 | 1196 | |
|
1086 | 1197 | |
|
1087 | 1198 | def operation(request, id_camp=None): |
|
1088 | 1199 | |
|
1089 | 1200 | if not id_camp: |
|
1090 | 1201 | campaigns = Campaign.objects.all().order_by('-start_date') |
|
1091 | 1202 | |
|
1092 | 1203 | if not campaigns: |
|
1093 | 1204 | kwargs = {} |
|
1094 | 1205 | kwargs['title'] = 'No Campaigns' |
|
1095 | 1206 | kwargs['suptitle'] = 'Empty' |
|
1096 | 1207 | return render(request, 'operation.html', kwargs) |
|
1097 | 1208 | |
|
1098 | 1209 | id_camp = campaigns[0].id |
|
1099 | 1210 | |
|
1100 | 1211 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
1101 | 1212 | |
|
1102 | 1213 | if request.method=='GET': |
|
1103 | 1214 | form = OperationForm(initial={'campaign': campaign.id}, length = 5) |
|
1104 | 1215 | |
|
1105 | 1216 | if request.method=='POST': |
|
1106 | 1217 | form = OperationForm(request.POST, initial={'campaign':campaign.id}, length = 5) |
|
1107 | 1218 | |
|
1108 | 1219 | if form.is_valid(): |
|
1109 | 1220 | return redirect('url_operation', id_camp=campaign.id) |
|
1110 | 1221 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() |
|
1111 | 1222 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) |
|
1112 | 1223 | #for exs in experiments: |
|
1113 | 1224 | # exs.get_status() |
|
1114 | 1225 | locations= Location.objects.filter(experiment=experiments).distinct() |
|
1115 | 1226 | #experiments = [Experiment.objects.filter(location__pk=location.id).filter(campaign__pk=campaign.id) for location in locations] |
|
1116 | 1227 | kwargs = {} |
|
1117 | 1228 | #---Campaign |
|
1118 | 1229 | kwargs['campaign'] = campaign |
|
1119 | 1230 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
1120 | 1231 | #---Experiment |
|
1121 | 1232 | keys = ['id', 'name', 'start_time', 'end_time', 'status'] |
|
1122 | 1233 | kwargs['experiment_keys'] = keys[1:] |
|
1123 | 1234 | kwargs['experiments'] = experiments |
|
1124 | 1235 | #---Radar |
|
1125 | 1236 | kwargs['locations'] = locations |
|
1126 | 1237 | #---Else |
|
1127 | 1238 | kwargs['title'] = 'Campaign' |
|
1128 | 1239 | kwargs['suptitle'] = campaign.name |
|
1129 | 1240 | kwargs['form'] = form |
|
1130 | 1241 | kwargs['button'] = 'Search' |
|
1131 | 1242 | kwargs['details'] = True |
|
1132 | 1243 | kwargs['search_button'] = True |
|
1133 | 1244 | |
|
1134 | 1245 | return render(request, 'operation.html', kwargs) |
|
1135 | 1246 | |
|
1136 | 1247 | |
|
1137 | 1248 | def operation_search(request, id_camp=None): |
|
1138 | 1249 | |
|
1139 | 1250 | |
|
1140 | 1251 | if not id_camp: |
|
1141 | 1252 | campaigns = Campaign.objects.all().order_by('-start_date') |
|
1142 | 1253 | |
|
1143 | 1254 | if not campaigns: |
|
1144 | 1255 | return render(request, 'operation.html', {}) |
|
1145 | 1256 | |
|
1146 | 1257 | id_camp = campaigns[0].id |
|
1147 | 1258 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
1148 | 1259 | |
|
1149 | 1260 | if request.method=='GET': |
|
1150 | 1261 | form = OperationSearchForm(initial={'campaign': campaign.id}) |
|
1151 | 1262 | |
|
1152 | 1263 | if request.method=='POST': |
|
1153 | 1264 | form = OperationSearchForm(request.POST, initial={'campaign':campaign.id}) |
|
1154 | 1265 | |
|
1155 | 1266 | if form.is_valid(): |
|
1156 | 1267 | return redirect('url_operation', id_camp=campaign.id) |
|
1157 | 1268 | |
|
1158 | 1269 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() |
|
1159 | 1270 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) |
|
1160 | 1271 | #for exs in experiments: |
|
1161 | 1272 | # exs.get_status() |
|
1162 | 1273 | locations= Location.objects.filter(experiment=experiments).distinct() |
|
1163 | 1274 | form = OperationSearchForm(initial={'campaign': campaign.id}) |
|
1164 | 1275 | |
|
1165 | 1276 | kwargs = {} |
|
1166 | 1277 | #---Campaign |
|
1167 | 1278 | kwargs['campaign'] = campaign |
|
1168 | 1279 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
1169 | 1280 | #---Experiment |
|
1170 | 1281 | keys = ['id', 'name', 'start_time', 'end_time', 'status'] |
|
1171 | 1282 | kwargs['experiment_keys'] = keys[1:] |
|
1172 | 1283 | kwargs['experiments'] = experiments |
|
1173 | 1284 | #---Radar |
|
1174 | 1285 | kwargs['locations'] = locations |
|
1175 | 1286 | #---Else |
|
1176 | 1287 | kwargs['title'] = 'Campaign' |
|
1177 | 1288 | kwargs['suptitle'] = campaign.name |
|
1178 | 1289 | kwargs['form'] = form |
|
1179 | 1290 | kwargs['button'] = 'Select' |
|
1180 | 1291 | kwargs['details'] = True |
|
1181 | 1292 | kwargs['search_button'] = False |
|
1182 | 1293 | |
|
1183 | 1294 | return render(request, 'operation.html', kwargs) |
|
1184 | 1295 | |
|
1185 | 1296 | |
|
1186 | 1297 | def radar_play(request, id_camp, id_radar): |
|
1187 | 1298 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
1188 | 1299 | radar = get_object_or_404(Location, pk = id_radar) |
|
1189 | 1300 | today = datetime.today() |
|
1190 | 1301 | now = today.time() |
|
1191 | 1302 | |
|
1192 | 1303 | #--Clear Old Experiments From RunningExperiment Object |
|
1193 | 1304 | running_experiment = RunningExperiment.objects.filter(radar=radar) |
|
1194 | 1305 | if running_experiment: |
|
1195 | 1306 | running_experiment = running_experiment[0] |
|
1196 | 1307 | running_experiment.running_experiment.clear() |
|
1197 | 1308 | running_experiment.save() |
|
1198 | 1309 | |
|
1199 | 1310 | #--If campaign datetime is ok: |
|
1200 | 1311 | if today >= campaign.start_date and today <= campaign.end_date: |
|
1201 | 1312 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) |
|
1202 | 1313 | for exp in experiments: |
|
1203 | 1314 | #--If experiment time is ok: |
|
1204 | 1315 | if now >= exp.start_time and now <= exp.end_time: |
|
1205 | 1316 | configurations = Configuration.objects.filter(experiment = exp) |
|
1206 | 1317 | for conf in configurations: |
|
1207 | 1318 | if 'cgs' in conf.device.device_type.name: |
|
1208 | 1319 | conf.status_device() |
|
1209 | 1320 | else: |
|
1210 | 1321 | answer = conf.start_device() |
|
1211 | 1322 | conf.status_device() |
|
1212 | 1323 | #--Running Experiment |
|
1213 | 1324 | old_running_experiment = RunningExperiment.objects.filter(radar=radar) |
|
1214 | 1325 | #--If RunningExperiment element exists |
|
1215 | 1326 | if old_running_experiment: |
|
1216 | 1327 | old_running_experiment = old_running_experiment[0] |
|
1217 | 1328 | old_running_experiment.running_experiment.add(exp) |
|
1218 | 1329 | old_running_experiment.status = 3 |
|
1219 | 1330 | old_running_experiment.save() |
|
1220 | 1331 | #--Create a new Running_Experiment Object |
|
1221 | 1332 | else: |
|
1222 | 1333 | new_running_experiment = RunningExperiment( |
|
1223 | 1334 | radar = radar, |
|
1224 | 1335 | status = 3, |
|
1225 | 1336 | ) |
|
1226 | 1337 | new_running_experiment.save() |
|
1227 | 1338 | new_running_experiment.running_experiment.add(exp) |
|
1228 | 1339 | new_running_experiment.save() |
|
1229 | 1340 | |
|
1230 | 1341 | if answer: |
|
1231 | 1342 | messages.success(request, conf.message) |
|
1232 | 1343 | exp.status=2 |
|
1233 | 1344 | exp.save() |
|
1234 | 1345 | else: |
|
1235 | 1346 | messages.error(request, conf.message) |
|
1236 | 1347 | else: |
|
1237 | 1348 | if exp.status == 1 or exp.status == 3: |
|
1238 | 1349 | exp.status=3 |
|
1239 | 1350 | exp.save() |
|
1240 | 1351 | |
|
1241 | 1352 | |
|
1242 | 1353 | route = request.META['HTTP_REFERER'] |
|
1243 | 1354 | route = str(route) |
|
1244 | 1355 | if 'search' in route: |
|
1245 | 1356 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) |
|
1246 | 1357 | else: |
|
1247 | 1358 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) |
|
1248 | 1359 | |
|
1249 | 1360 | |
|
1250 | 1361 | def radar_stop(request, id_camp, id_radar): |
|
1251 | 1362 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
1252 | 1363 | radar = get_object_or_404(Location, pk = id_radar) |
|
1253 | 1364 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) |
|
1254 | 1365 | |
|
1255 | 1366 | for exp in experiments: |
|
1256 | 1367 | configurations = Configuration.objects.filter(experiment = exp) |
|
1257 | 1368 | for conf in configurations: |
|
1258 | 1369 | if 'cgs' in conf.device.device_type.name: |
|
1259 | 1370 | conf.status_device() |
|
1260 | 1371 | else: |
|
1261 | 1372 | answer = conf.stop_device() |
|
1262 | 1373 | conf.status_device() |
|
1263 | 1374 | |
|
1264 | 1375 | if answer: |
|
1265 | 1376 | messages.success(request, conf.message) |
|
1266 | 1377 | exp.status=1 |
|
1267 | 1378 | exp.save() |
|
1268 | 1379 | else: |
|
1269 | 1380 | messages.error(request, conf.message) |
|
1270 | 1381 | |
|
1271 | 1382 | |
|
1272 | 1383 | route = request.META['HTTP_REFERER'] |
|
1273 | 1384 | route = str(route) |
|
1274 | 1385 | if 'search' in route: |
|
1275 | 1386 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) |
|
1276 | 1387 | else: |
|
1277 | 1388 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) |
|
1278 | 1389 | |
|
1279 | 1390 | |
|
1280 | 1391 | def radar_refresh(request, id_camp, id_radar): |
|
1281 | 1392 | |
|
1282 | 1393 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
1283 | 1394 | radar = get_object_or_404(Location, pk = id_radar) |
|
1284 | 1395 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) |
|
1285 | 1396 | for exs in experiments: |
|
1286 | 1397 | exs.get_status() |
|
1287 | 1398 | |
|
1288 | 1399 | route = request.META['HTTP_REFERER'] |
|
1289 | 1400 | route = str(route) |
|
1290 | 1401 | if 'search' in route: |
|
1291 | 1402 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) |
|
1292 | 1403 | else: |
|
1293 | 1404 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) |
|
1294 | 1405 |
General Comments 0
You need to be logged in to leave comments.
Login now