##// END OF EJS Templates
Probando RController 1/?
Renato-TUF -
r369:e24063c0558c
parent child
Show More
@@ -1,1042 +1,1042
1 1
2 2
3 3 import ast
4 4 import json
5 5 import requests
6 6 import numpy as np
7 7 from base64 import b64encode
8 8 from struct import pack
9 9
10 10 from django.db import models
11 11 from django.urls import reverse
12 12 from django.core.validators import MinValueValidator, MaxValueValidator
13 13
14 14 from apps.main.models import Configuration
15 15 from apps.main.utils import Params
16 16 from devices.rc import api
17 17 from apps.rc.utils import RCFile
18 18
19 19
20 20 LINE_TYPES = (
21 21 ('none', 'Not used'),
22 22 ('tr', 'Transmission/reception selector signal'),
23 23 ('tx', 'A modulating signal (Transmission pulse)'),
24 24 ('codes', 'BPSK modulating signal'),
25 25 ('windows', 'Sample window signal'),
26 26 ('sync', 'Synchronizing signal'),
27 27 ('flip', 'IPP related periodic signal'),
28 28 ('prog_pulses', 'Programmable pulse'),
29 29 ('mix', 'Mixed line'),
30 30 )
31 31
32 32
33 33 SAMPLING_REFS = (
34 34 ('none', 'No Reference'),
35 35 ('begin_baud', 'Begin of the first baud'),
36 36 ('first_baud', 'Middle of the first baud'),
37 37 ('sub_baud', 'Middle of the sub-baud')
38 38 )
39 39
40 40 DAT_CMDS = {
41 41 # Pulse Design commands
42 42 'DISABLE' : 0, # Disables pulse generation
43 43 'ENABLE' : 24, # Enables pulse generation
44 44 'DELAY_START' : 40, # Write delay status to memory
45 45 'FLIP_START' : 48, # Write flip status to memory
46 46 'SAMPLING_PERIOD' : 64, # Establish Sampling Period
47 47 'TX_ONE' : 72, # Output '0' in line TX
48 48 'TX_ZERO' : 88, # Output '0' in line TX
49 49 'SW_ONE' : 104, # Output '0' in line SW
50 50 'SW_ZERO' : 112, # Output '1' in line SW
51 51 'RESTART': 120, # Restarts CR8 Firmware
52 52 'CONTINUE' : 253, # Function Unknown
53 53 # Commands available to new controllers
54 54 # In Pulse Design Executable, the clock divisor code is written as 12 at the start, but it should be written as code 22(below) just before the final enable.
55 55 'CLOCK_DIVISOR_INIT' : 12, # Specifies Clock Divisor. Legacy command, ignored in the actual .dat conversion
56 56 'CLOCK_DIVISOR_LAST' : 22, # Specifies Clock Divisor (default 60 if not included) syntax: 255,22 254,N-1.
57 57 'CLOCK_DIVIDER' : 8,
58 58 }
59 59
60 60 MAX_BITS = 8
61 61
62 62 # Rotate left: 0b1001 --> 0b0011
63 63 rol = lambda val, r_bits: \
64 64 (val << r_bits%MAX_BITS) & (2**MAX_BITS-1) | \
65 65 ((val & (2**MAX_BITS-1)) >> (MAX_BITS-(r_bits%MAX_BITS)))
66 66
67 67 # Rotate right: 0b1001 --> 0b1100
68 68 ror = lambda val, r_bits: \
69 69 ((val & (2**MAX_BITS-1)) >> r_bits%MAX_BITS) | \
70 70 (val << (MAX_BITS-(r_bits%MAX_BITS)) & (2**MAX_BITS-1))
71 71
72 72
73 73 class RCConfiguration(Configuration):
74 74
75 75 ipp = models.FloatField(verbose_name='IPP [Km]', validators=[MinValueValidator(1)], default=300)
76 76 ntx = models.PositiveIntegerField(verbose_name='Number of TX', validators=[MinValueValidator(1)], default=1)
77 77 clock_in = models.FloatField(verbose_name='Clock in [MHz]', validators=[MinValueValidator(1), MaxValueValidator(80)], default=1)
78 78 clock_divider = models.PositiveIntegerField(verbose_name='Clock divider', validators=[MinValueValidator(1), MaxValueValidator(256)], default=1)
79 79 clock = models.FloatField(verbose_name='Clock Master [MHz]', blank=True, default=1)
80 80 time_before = models.PositiveIntegerField(verbose_name='Time before [&mu;S]', default=12)
81 81 time_after = models.PositiveIntegerField(verbose_name='Time after [&mu;S]', default=1)
82 82 sync = models.PositiveIntegerField(verbose_name='Synchro delay', default=0)
83 83 sampling_reference = models.CharField(verbose_name='Sampling Reference', choices=SAMPLING_REFS, default='none', max_length=40)
84 84 control_tx = models.BooleanField(verbose_name='Control Switch TX', default=False)
85 85 control_sw = models.BooleanField(verbose_name='Control Switch SW', default=False)
86 86 total_units = models.PositiveIntegerField(default=0)
87 87 mix = models.BooleanField(default=False)
88 88
89 89 class Meta:
90 90 db_table = 'rc_configurations'
91 91
92 92 def get_absolute_url_plot(self):
93 93 return reverse('url_plot_rc_pulses', args=[str(self.id)])
94 94
95 95 @property
96 96 def ipp_unit(self):
97 97
98 98 return '{} ({})'.format(self.ipp, int(self.ipp*self.km2unit))
99 99
100 100 @property
101 101 def us2unit(self):
102 102
103 103 return self.clock_in/self.clock_divider
104 104
105 105 @property
106 106 def km2unit(self):
107 107
108 108 return 20./3*(self.clock_in/self.clock_divider)
109 109
110 110 def clone(self, **kwargs):
111 111
112 112 lines = self.get_lines()
113 113 self.pk = None
114 114 self.id = None
115 115 for attr, value in kwargs.items():
116 116 setattr(self, attr, value)
117 117 self.save()
118 118
119 119 for line in lines:
120 120 line.clone(rc_configuration=self)
121 121
122 122 new_lines = self.get_lines()
123 123 for line in new_lines:
124 124 line_params = json.loads(line.params)
125 125 if 'TX_ref' in line_params and (line_params['TX_ref'] != '0'):
126 126 ref_line = RCLine.objects.get(pk=line_params['TX_ref'])
127 127 line_params['TX_ref'] = ['{}'.format(l.pk) for l in new_lines if l.get_name()==ref_line.get_name()][0]
128 128 line.params = json.dumps(line_params)
129 129 line.save()
130 130
131 131 return self
132 132
133 133 def get_lines(self, **kwargs):
134 134 '''
135 135 Retrieve configuration lines
136 136 '''
137 137
138 138 return RCLine.objects.filter(rc_configuration=self.pk, **kwargs)
139 139
140 140
141 141 def clean_lines(self):
142 142 '''
143 143 '''
144 144
145 145 empty_line = RCLineType.objects.get(name='none')
146 146
147 147 for line in self.get_lines():
148 148 line.line_type = empty_line
149 149 line.params = '{}'
150 150 line.save()
151 151
152 152 def dict_to_parms(self, params, id=None):
153 153 '''
154 154 '''
155 155
156 156 if id:
157 157 data = Params(params).get_conf(id_conf=id)
158 158 else:
159 159 data = Params(params).get_conf(dtype='rc')
160 160
161 161 #print(data)
162 162 # self.name = data['name']
163 163 self.ipp = data['ipp']
164 164 self.ntx = data['ntx']
165 165 self.clock_in = data['clock_in']
166 166 self.clock_divider = data['clock_divider']
167 167 self.clock = data['clock']
168 168 self.time_before = data['time_before']
169 169 self.time_after = data['time_after']
170 170 self.sync = data['sync']
171 171 self.sampling_reference = data['sampling_reference']
172 172 self.total_units = self.ipp*self.ntx*self.km2unit
173 173 self.save()
174 174 self.clean_lines()
175 175
176 176 #print(params)
177 177
178 178 positions = {'tx':0, 'tr':0}
179 179 for i, id in enumerate(data['lines']):
180 180 line_data = params['lines']['byId'][id]
181 181 line_type = RCLineType.objects.get(name=line_data['line_type'])
182 182 if line_type.name == 'codes':
183 183 code = RCLineCode.objects.get(name=line_data['params']['code'])
184 184 line_data['params']['code'] = code.pk
185 185 if line_type.name == 'tx':
186 186 position = positions['tx']
187 187 positions['tx'] += 1
188 188 elif line_type.name == 'tr':
189 189 position = positions['tr']
190 190 positions['tr'] += 1
191 191 else:
192 192 position = 0
193 193 line, dum = RCLine.objects.update_or_create(
194 194 rc_configuration=self,
195 195 channel=i,
196 196 position=position,
197 197 defaults={
198 198 'line_type': line_type,
199 199 'params': json.dumps(line_data['params'])
200 200 }
201 201 )
202 202
203 203 for i, line in enumerate(self.get_lines()):
204 204 line_params = json.loads(line.params)
205 205 if 'TX_ref' in line_params:
206 206 if line_params['TX_ref'] in (0, '0'):
207 207 line_params['TX_ref'] = '0'
208 208 else:
209 209 ref_id = '{}'.format(line_params['TX_ref'])
210 210 ref_line = params['lines']['byId'][ref_id]
211 211 line_params['TX_ref'] = RCLine.objects.get(
212 212 rc_configuration=self,
213 213 params=json.dumps(ref_line['params'])
214 214 ).pk
215 215 line.params = json.dumps(line_params)
216 216 print(line.params)
217 217 line.save()
218 218 print("Fin de dict to param")
219 219
220 220 def get_delays(self):
221 221
222 222 pulses = [line.pulses_as_points() for line in self.get_lines()]
223 223 points = [tup for tups in pulses for tup in tups]
224 224 points = set([x for tup in points for x in tup])
225 225 points = list(points)
226 226 points.sort()
227 227
228 228 if points[0]!=0:
229 229 points.insert(0, 0)
230 230
231 231 return [points[i+1]-points[i] for i in range(len(points)-1)]
232 232
233 233
234 234 def get_pulses(self, binary=True):
235 235
236 236 pulses = [line.pulses_as_points() for line in self.get_lines()]
237 237 tuples = [tup for tups in pulses for tup in tups]
238 238 points = set([x for tup in tuples for x in tup])
239 239 points = list(points)
240 240 points.sort()
241 241 states = []
242 242 last = [0 for x in pulses]
243 243
244 244 for x in points:
245 245 dum = []
246 246 for i, tups in enumerate(pulses):
247 247 ups = [tup[0] for tup in tups if tup!=(0,0)]
248 248 dws = [tup[1] for tup in tups if tup!=(0,0)]
249 249 if x in ups:
250 250 dum.append(1)
251 251 elif x in dws:
252 252 dum.append(0)
253 253 else:
254 254 dum.append(last[i])
255 255 states.append(dum)
256 256 last = dum
257 257
258 258 if binary:
259 259 ret = []
260 260 for flips in states:
261 261 flips.reverse()
262 262 ret.append(int(''.join([str(x) for x in flips]), 2))
263 263 states = ret
264 264
265 265 return states[:-1]
266 266
267 267 def add_cmd(self, cmd):
268 268
269 269 if cmd in DAT_CMDS:
270 270 return (255, DAT_CMDS[cmd])
271 271
272 272 def add_data(self, value):
273 273
274 274 return (254, value-1)
275 275
276 276 def parms_to_binary(self, dat=True):
277 277 '''
278 278 Create "dat" stream to be send to CR
279 279 '''
280 280
281 281 data = bytearray()
282 282 # create header
283 283 data.extend(self.add_cmd('DISABLE'))
284 284 data.extend(self.add_cmd('CONTINUE'))
285 285 data.extend(self.add_cmd('RESTART'))
286 286
287 287 if self.control_sw:
288 288 data.extend(self.add_cmd('SW_ONE'))
289 289 else:
290 290 data.extend(self.add_cmd('SW_ZERO'))
291 291
292 292 if self.control_tx:
293 293 data.extend(self.add_cmd('TX_ONE'))
294 294 else:
295 295 data.extend(self.add_cmd('TX_ZERO'))
296 296
297 297 # write divider
298 298 data.extend(self.add_cmd('CLOCK_DIVIDER'))
299 299 data.extend(self.add_data(self.clock_divider))
300 300
301 301 # write delays
302 302 data.extend(self.add_cmd('DELAY_START'))
303 303 # first delay is always zero
304 304 data.extend(self.add_data(1))
305 305
306 306 delays = self.get_delays()
307 307
308 308 for delay in delays:
309 309 while delay>252:
310 310 data.extend(self.add_data(253))
311 311 delay -= 253
312 312 data.extend(self.add_data(int(delay)))
313 313
314 314 # write flips
315 315 data.extend(self.add_cmd('FLIP_START'))
316 316
317 317 states = self.get_pulses(binary=True)
318 318
319 319
320 320 last = 0
321 321 for flip, delay in zip(states, delays):
322 322 data.extend(self.add_data((flip^last)+1))
323 323 last = flip
324 324 while delay>252:
325 325 data.extend(self.add_data(1))
326 326 delay -= 253
327 327
328 328 # write sampling period
329 329 data.extend(self.add_cmd('SAMPLING_PERIOD'))
330 330 wins = self.get_lines(line_type__name='windows')
331 331 if wins:
332 332 win_params = json.loads(wins[0].params)['params']
333 333 if win_params:
334 334 dh = int(win_params[0]['resolution']*self.km2unit)
335 335 else:
336 336 dh = 1
337 337 else:
338 338 dh = 1
339 339 data.extend(self.add_data(dh))
340 340
341 341 # write enable
342 342 data.extend(self.add_cmd('ENABLE'))
343 343
344 344 if not dat:
345 345 return data
346 346
347 347 return '\n'.join(['{}'.format(x) for x in data])
348 348
349 349 def update_pulses(self):
350 350 contador = 0
351 351 for line in self.get_lines():
352 352 contador=contador+1
353 353 print(contador)
354 354 line.update_pulses()
355 355
356 356 def plot_pulses2(self, km=False):
357 357
358 358 import matplotlib
359 359 matplotlib.use('Agg')
360 360 import matplotlib.pyplot as plt
361 361 from bokeh.resources import CDN
362 362 from bokeh.embed import components
363 363 from bokeh.mpl import to_bokeh
364 364 from bokeh.models.tools import WheelZoomTool, ResetTool, PanTool, HoverTool, SaveTool
365 365
366 366 lines = self.get_lines()
367 367
368 368 N = len(lines)
369 369 npoints = self.total_units/self.km2unit if km else self.total_units
370 370 fig = plt.figure(figsize=(12, 2+N*0.5))
371 371 ax = fig.add_subplot(111)
372 372 labels = ['IPP']
373 373
374 374 for i, line in enumerate(lines):
375 375 labels.append(line.get_name(channel=True))
376 376 l = ax.plot((0, npoints),(N-i-1, N-i-1))
377 377 points = [(tup[0], tup[1]-tup[0]) for tup in line.pulses_as_points(km=km) if tup!=(0,0)]
378 378 ax.broken_barh(points, (N-i-1, 0.5),
379 379 edgecolor=l[0].get_color(), facecolor='none')
380 380
381 381 n = 0
382 382 f = ((self.ntx+50)/100)*5 if ((self.ntx+50)/100)*10>0 else 2
383 383 for x in np.arange(0, npoints, self.ipp if km else self.ipp*self.km2unit):
384 384 if n%f==0:
385 385 ax.text(x, N, '%s' % n, size=10)
386 386 n += 1
387 387
388 388 labels.reverse()
389 389 ax.set_yticks(range(len(labels)))
390 390 ax.set_yticklabels(labels)
391 391 ax.set_xlabel = 'Units'
392 392 plot = to_bokeh(fig, use_pandas=False)
393 393 plot.tools = [PanTool(dimensions="width"), WheelZoomTool(dimensions="width"), ResetTool(), SaveTool()]
394 394 plot.toolbar_location="above"
395 395
396 396 return components(plot, CDN)
397 397
398 398 def plot_pulses(self, km=False):
399 399
400 400 from bokeh.plotting import figure
401 401 from bokeh.resources import CDN
402 402 from bokeh.embed import components
403 403 from bokeh.models import FixedTicker, PrintfTickFormatter
404 404 from bokeh.models.tools import WheelZoomTool, ResetTool, PanTool, HoverTool, SaveTool
405 405 from bokeh.models.sources import ColumnDataSource
406 406
407 407 lines = self.get_lines().reverse()
408 408
409 409 N = len(lines)
410 410 npoints = self.total_units/self.km2unit if km else self.total_units
411 411 ipp = self.ipp if km else self.ipp*self.km2unit
412 412
413 413 hover = HoverTool(tooltips=[("Line", "@name"),
414 414 ("IPP", "@ipp"),
415 415 ("X", "@left")])
416 416
417 417 tools = [PanTool(dimensions="width"),
418 418 WheelZoomTool(dimensions="width"),
419 419 hover, SaveTool()]
420 420
421 421 plot = figure(width=1000,
422 422 height=40+N*50,
423 423 y_range = (0, N),
424 424 tools=tools,
425 425 toolbar_location='above',
426 426 toolbar_sticky=False,)
427 427
428 428 plot.xaxis.axis_label = 'Km' if km else 'Units'
429 429 plot.xaxis[0].formatter = PrintfTickFormatter(format='%d')
430 430 plot.yaxis.axis_label = 'Pulses'
431 431 plot.yaxis[0].ticker=FixedTicker(ticks=list(range(N)))
432 432 plot.yaxis[0].formatter = PrintfTickFormatter(format='Line %d')
433 433
434 434 for i, line in enumerate(lines):
435 435
436 436 points = [tup for tup in line.pulses_as_points(km=km) if tup!=(0,0)]
437 437
438 438 source = ColumnDataSource(data = dict(
439 439 bottom = [i for tup in points],
440 440 top = [i+0.5 for tup in points],
441 441 left = [tup[0] for tup in points],
442 442 right = [tup[1] for tup in points],
443 443 ipp = [int(tup[0]/ipp) for tup in points],
444 444 name = [line.get_name() for tup in points]
445 445 ))
446 446
447 447 plot.quad(
448 448 bottom = 'bottom',
449 449 top = 'top',
450 450 left = 'left',
451 451 right = 'right',
452 452 source = source,
453 453 fill_alpha = 0,
454 454 #line_color = 'blue',
455 455 )
456 456
457 457 plot.line([0, npoints], [i, i])#, color='blue')
458 458
459 459 return components(plot, CDN)
460 460
461 461 def request(self, cmd, method='get', **kwargs):
462 462
463 463 req = getattr(requests, method)(self.device.url(cmd), **kwargs)
464 464 payload = req.json()
465 465
466 466 return payload
467 467
468 468 def status_device(self):
469 469
470 470 try:
471 471 self.device.status = 0
472 472 payload = self.request('status')
473 473 if payload['status']=='enable':
474 474 self.device.status = 3
475 475 elif payload['status']=='disable':
476 476 self.device.status = 2
477 477 else:
478 478 self.device.status = 1
479 479 self.device.save()
480 480 self.message = 'RC status: {}'.format(payload['status'])
481 481 return False
482 482 except Exception as e:
483 483 if 'No route to host' not in str(e):
484 484 self.device.status = 4
485 485 self.device.save()
486 486 self.message = 'RC status: {}'.format(str(e))
487 487 return False
488 488
489 489 self.device.save()
490 490 return True
491 491
492 492 def reset_device(self):
493 493
494 494 try:
495 495 payload = self.request('reset', 'post')
496 496 if payload['reset']=='ok':
497 497 self.message = 'RC restarted OK'
498 498 self.device.status = 2
499 499 self.device.save()
500 500 else:
501 501 self.message = 'RC restart fail'
502 502 self.device.status = 4
503 503 self.device.save()
504 504 except Exception as e:
505 505 self.message = 'RC reset: {}'.format(str(e))
506 506 return False
507 507
508 508 return True
509 509
510 510 def stop_device(self):
511 511
512 512 try:
513 513 payload = self.request('stop', 'post')
514 514 self.message = 'RC stop: {}'.format(payload['stop'])
515 515 if payload['stop']=='ok':
516 516 self.device.status = 2
517 517 self.device.save()
518 518 else:
519 519 self.device.status = 4
520 520 self.device.save()
521 521 return False
522 522 except Exception as e:
523 523 if 'No route to host' not in str(e):
524 524 self.device.status = 4
525 525 else:
526 526 self.device.status = 0
527 527 self.message = 'RC stop: {}'.format(str(e))
528 528 self.device.save()
529 529 return False
530 530
531 531 return True
532 532
533 533 def start_device(self):
534 534
535 535 try:
536 536 payload = self.request('start', 'post')
537 537 self.message = 'RC start: {}'.format(payload['start'])
538 538 if payload['start']=='ok':
539 539 self.device.status = 3
540 540 self.device.save()
541 541 else:
542 542 return False
543 543 except Exception as e:
544 544 if 'No route to host' not in str(e):
545 545 self.device.status = 4
546 546 else:
547 547 self.device.status = 0
548 548 self.message = 'RC start: {}'.format(str(e))
549 549 self.device.save()
550 550 return False
551 551
552 552 return True
553 553
554 554 def write_device(self, raw=False):
555 555 print("write device")
556 556
557 557 if not raw:
558 558 clock = RCClock.objects.get(rc_configuration=self)
559 559 if clock.mode:
560 560 data = {'default': clock.frequency}
561 561 else:
562 562 data = {'manual': [clock.multiplier, clock.divisor, clock.reference]}
563 563 payload = self.request('setfreq', 'post', data=json.dumps(data))
564 if payload['setfreq'] != 'ok':
565 self.message = 'RC write: {}'.format(payload['setfreq'])
564 if payload['command'] != 'ok':
565 self.message = 'RC write: {}'.format(payload['command'])
566 566 else:
567 self.message = payload['setfreq']
568 if payload['setfreq'] == 'fail':
567 self.message = payload['programming']
568 if payload['programming'] == 'fail':
569 569 self.message = 'RC write: error programming CGS chip'
570 570
571 571 values = []
572 572 for pulse, delay in zip(self.get_pulses(), self.get_delays()):
573 573 while delay > 65536:
574 574 values.append((pulse, 65535))
575 575 delay -= 65536
576 576 values.append((pulse, delay-1))
577 577 data = bytearray()
578 578 #reset
579 579 data.extend((128, 0))
580 580 #disable
581 581 data.extend((129, 0))
582 582 #SW switch
583 583 if self.control_sw:
584 584 data.extend((130, 2))
585 585 else:
586 586 data.extend((130, 0))
587 587 #divider
588 588 data.extend((131, self.clock_divider-1))
589 589 #enable writing
590 590 data.extend((139, 62))
591 591
592 592 last = 0
593 593 for tup in values:
594 594 vals = pack('<HH', last^tup[0], tup[1])
595 595 last = tup[0]
596 596 data.extend((133, vals[1], 132, vals[0], 133, vals[3], 132, vals[2]))
597 597
598 598 #enable
599 599 data.extend((129, 1))
600 600
601 601 if raw:
602 602 return b64encode(data)
603 603
604 604 #try:
605 605 payload = self.request('stop', 'post')
606 606 payload = self.request('reset', 'post')
607 607 #payload = self.request('divider', 'post', data={'divider': self.clock_divider-1})
608 608 #payload = self.request('write', 'post', data=b64encode(bytearray((139, 62))), timeout=20)
609 609 n = len(data)
610 610 x = 0
611 611 #while x < n:
612 612 payload = self.request('write', 'post', data=b64encode(data))
613 613 # x += 1024
614 614
615 615 if payload['write']=='ok':
616 616 self.device.status = 3
617 617 self.device.save()
618 618 self.message = 'RC configured and started'
619 619 else:
620 620 self.device.status = 1
621 621 self.device.save()
622 622 self.message = 'RC write: {}'.format(payload['write'])
623 623 return False
624 624
625 625 #payload = self.request('start', 'post')
626 626
627 627 #except Exception as e:
628 628 # if 'No route to host' not in str(e):
629 629 # self.device.status = 4
630 630 # else:
631 631 # self.device.status = 0
632 632 # self.message = 'RC write: {}'.format(str(e))
633 633 # self.device.save()
634 634 # return False
635 635
636 636 return True
637 637
638 638
639 639 def get_absolute_url_import(self):
640 640 return reverse('url_import_rc_conf', args=[str(self.id)])
641 641
642 642
643 643 class RCLineCode(models.Model):
644 644
645 645 name = models.CharField(max_length=40)
646 646 bits_per_code = models.PositiveIntegerField(default=0)
647 647 number_of_codes = models.PositiveIntegerField(default=0)
648 648 codes = models.TextField(blank=True, null=True)
649 649
650 650 class Meta:
651 651 db_table = 'rc_line_codes'
652 652 ordering = ('name',)
653 653
654 654 def __str__(self):
655 655 return u'%s' % self.name
656 656
657 657
658 658 class RCLineType(models.Model):
659 659
660 660 name = models.CharField(choices=LINE_TYPES, max_length=40)
661 661 description = models.TextField(blank=True, null=True)
662 662 params = models.TextField(default='[]')
663 663
664 664 class Meta:
665 665 db_table = 'rc_line_types'
666 666
667 667 def __str__(self):
668 668 return u'%s - %s' % (self.name.upper(), self.get_name_display())
669 669
670 670
671 671 class RCLine(models.Model):
672 672
673 673 rc_configuration = models.ForeignKey('RCConfiguration', on_delete=models.CASCADE)
674 674 line_type = models.ForeignKey('RCLineType',on_delete=models.CASCADE)
675 675 channel = models.PositiveIntegerField(default=0)
676 676 position = models.PositiveIntegerField(default=0)
677 677 params = models.TextField(default='{}')
678 678 pulses = models.TextField(default='')
679 679
680 680 class Meta:
681 681 db_table = 'rc_lines'
682 682 ordering = ['channel']
683 683
684 684 def __str__(self):
685 685 if self.rc_configuration:
686 686 return u'{}|{} - {}'.format(self.pk, self.get_name(), self.rc_configuration.name)
687 687
688 688 def jsonify(self):
689 689
690 690 data = {}
691 691 data['params'] = json.loads(self.params)
692 692 data['id'] = '{}'.format(self.pk)
693 693 data['line_type'] = self.line_type.name
694 694 data['name'] = self.get_name()
695 695 if data['line_type']=='codes':
696 696 data['params']['code'] = RCLineCode.objects.get(pk=data['params']['code']).name
697 697
698 698 return data
699 699
700 700
701 701 def clone(self, **kwargs):
702 702
703 703 self.pk = None
704 704 self.id = None
705 705
706 706 for attr, value in kwargs.items():
707 707 setattr(self, attr, value)
708 708
709 709 self.save()
710 710
711 711 return self
712 712
713 713 def get_name(self, channel=False):
714 714
715 715 chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
716 716 s = ''
717 717
718 718 if self.line_type.name in ('tx',):
719 719 s = chars[self.position]
720 720 elif self.line_type.name in ('codes', 'windows', 'tr'):
721 721 if 'TX_ref' in json.loads(self.params):
722 722 pk = json.loads(self.params)['TX_ref']
723 723 if pk in (0, '0'):
724 724 s = ','.join(chars[l.position] for l in self.rc_configuration.get_lines(line_type__name='tx'))
725 725 else:
726 726 ref = RCLine.objects.get(pk=pk)
727 727 s = chars[ref.position]
728 728 s = '({})'.format(s)
729 729
730 730 s = '{}{}'.format(self.line_type.name.upper(), s)
731 731
732 732 if channel:
733 733 return '{} {}'.format(s, self.channel)
734 734 else:
735 735 return s
736 736
737 737 def get_lines(self, **kwargs):
738 738
739 739 return RCLine.objects.filter(rc_configuration=self.rc_configuration, **kwargs)
740 740
741 741 def pulses_as_array(self):
742 742
743 743 y = np.zeros(self.rc_configuration.total_units)
744 744
745 745 for tup in ast.literal_eval(self.pulses):
746 746 y[tup[0]:tup[1]] = 1
747 747
748 748 return y.astype(np.int8)
749 749
750 750 def pulses_as_points(self, km=False):
751 751
752 752 if km:
753 753 unit2km = 1/self.rc_configuration.km2unit
754 754 return [(tup[0]*unit2km, tup[1]*unit2km) for tup in ast.literal_eval(self.pulses)]
755 755 else:
756 756 return ast.literal_eval(self.pulses)
757 757
758 758 def get_win_ref(self, params, tx_id, km2unit):
759 759
760 760 ref = self.rc_configuration.sampling_reference
761 761 codes = [line for line in self.get_lines(line_type__name='codes') if int(json.loads(line.params)['TX_ref'])==int(tx_id)]
762 762
763 763 if codes:
764 764 tx_width = float(json.loads(RCLine.objects.get(pk=tx_id).params)['pulse_width'])*km2unit/len(json.loads(codes[0].params)['codes'][0])
765 765 else:
766 766 tx_width = float(json.loads(RCLine.objects.get(pk=tx_id).params)['pulse_width'])*km2unit
767 767
768 768 if ref=='first_baud':
769 769 return int(1 + round((tx_width + 1)/2 + params['first_height']*km2unit - params['resolution']*km2unit))
770 770 elif ref=='sub_baud':
771 771 return np.ceil(1 + params['first_height']*km2unit - params['resolution']*km2unit/2)
772 772 else:
773 773 return 0
774 774
775 775 def update_pulses(self):
776 776 '''
777 777 Update pulses field
778 778 '''
779 779
780 780 km2unit = self.rc_configuration.km2unit
781 781 us2unit = self.rc_configuration.us2unit
782 782 ipp = self.rc_configuration.ipp
783 783 ntx = int(self.rc_configuration.ntx)
784 784 ipp_u = int(ipp*km2unit)
785 785 total = ipp_u*ntx if self.rc_configuration.total_units==0 else self.rc_configuration.total_units
786 786 y = []
787 787
788 788 if self.line_type.name=='tr':
789 789 tr_params = json.loads(self.params)
790 790 #print(tr_params)
791 791 #print(tr_params['TX_ref'])
792 792 if tr_params['TX_ref'] in ('0', 0):
793 793 txs = self.get_lines(line_type__name='tx')
794 794 else:
795 795 txs = RCLine.objects.filter(pk=tr_params['TX_ref'])
796 796
797 797 for tx in txs:
798 798 params = json.loads(tx.params)
799 799
800 800 if float(params['pulse_width'])==0:
801 801 continue
802 802 delays = [float(d)*km2unit for d in params['delays'].split(',') if d]
803 803 width = float(params['pulse_width'])*km2unit+int(self.rc_configuration.time_before*us2unit)
804 804 before = 0
805 805 after = int(self.rc_configuration.time_after*us2unit)
806 806
807 807 y_tx = self.points(ntx, ipp_u, width,
808 808 delay=delays,
809 809 before=before,
810 810 after=after,
811 811 sync=self.rc_configuration.sync)
812 812
813 813 ranges = params['range'].split(',')
814 814
815 815 if len(ranges)>0 and ranges[0]!='0':
816 816 y_tx = self.mask_ranges(y_tx, ranges)
817 817
818 818 tr_ranges = tr_params['range'].split(',')
819 819
820 820 if len(tr_ranges)>0 and tr_ranges[0]!='0':
821 821 y_tx = self.mask_ranges(y_tx, tr_ranges)
822 822
823 823 y.extend(y_tx)
824 824
825 825 self.pulses = str(y)
826 826 y = self.array_to_points(self.pulses_as_array())
827 827
828 828 elif self.line_type.name=='tx':
829 829 params = json.loads(self.params)
830 830 delays = [float(d)*km2unit for d in params['delays'].split(',') if d]
831 831 width = float(params['pulse_width'])*km2unit
832 832
833 833 if width>0:
834 834 before = int(self.rc_configuration.time_before*us2unit)
835 835 after = 0
836 836
837 837 y = self.points(ntx, ipp_u, width,
838 838 delay=delays,
839 839 before=before,
840 840 after=after,
841 841 sync=self.rc_configuration.sync)
842 842
843 843 ranges = params['range'].split(',')
844 844
845 845 if len(ranges)>0 and ranges[0]!='0':
846 846 y = self.mask_ranges(y, ranges)
847 847
848 848 elif self.line_type.name=='flip':
849 849 n = float(json.loads(self.params)['number_of_flips'])
850 850 width = n*ipp*km2unit
851 851 y = self.points(int((ntx+1)/(2*n)), ipp_u*n*2, width)
852 852
853 853 elif self.line_type.name=='codes':
854 854 params = json.loads(self.params)
855 855 tx = RCLine.objects.get(pk=params['TX_ref'])
856 856 tx_params = json.loads(tx.params)
857 857 delays = [float(d)*km2unit for d in tx_params['delays'].split(',') if d]
858 858 f = int(float(tx_params['pulse_width'])*km2unit/len(params['codes'][0]))
859 859 codes = [(np.fromstring(''.join([s*f for s in code]), dtype=np.uint8)-48).astype(np.int8) for code in params['codes']]
860 860 codes = [self.array_to_points(code) for code in codes]
861 861 n = len(codes)
862 862
863 863 ranges = tx_params['range'].split(',')
864 864 if len(ranges)>0 and ranges[0]!='0':
865 865 dum = self.mask_ranges(tx.pulses_as_points(), ranges)
866 866 else:
867 867 dum = tx.pulses_as_points()
868 868
869 869 for i, tup in enumerate(dum):
870 870 if tup==(0,0): continue
871 871 code = codes[i%n]
872 872 y.extend([(c[0]+tup[0], c[1]+tup[0]) for c in code])
873 873
874 874 elif self.line_type.name=='sync':
875 875 params = json.loads(self.params)
876 876 n = ipp_u*ntx
877 877 if params['invert'] in ('1', 1):
878 878 y = [(n-1, n)]
879 879 else:
880 880 y = [(0, 1)]
881 881
882 882 elif self.line_type.name=='prog_pulses':
883 883 params = json.loads(self.params)
884 884 if int(params['periodic'])==0:
885 885 nntx = 1
886 886 nipp = ipp_u*ntx
887 887 else:
888 888 nntx = ntx
889 889 nipp = ipp_u
890 890
891 891 if 'params' in params and len(params['params'])>0:
892 892 for p in params['params']:
893 893 y_pp = self.points(nntx, nipp,
894 894 p['end']-p['begin'],
895 895 before=p['begin'])
896 896
897 897 y.extend(y_pp)
898 898
899 899 elif self.line_type.name=='windows':
900 900 params = json.loads(self.params)
901 901 if 'params' in params and len(params['params'])>0:
902 902 tx = RCLine.objects.get(pk=params['TX_ref'])
903 903 tx_params = json.loads(tx.params)
904 904 ranges = tx_params['range'].split(',')
905 905 for p in params['params']:
906 906 y_win = self.points(ntx, ipp_u,
907 907 p['resolution']*p['number_of_samples']*km2unit,
908 908 before=int(self.rc_configuration.time_before*us2unit)+p['first_height']*km2unit,
909 909 sync=self.rc_configuration.sync+self.get_win_ref(p, params['TX_ref'], km2unit))
910 910
911 911
912 912 if len(ranges)>0 and ranges[0]!='0':
913 913 y_win = self.mask_ranges(y_win, ranges)
914 914
915 915 y.extend(y_win)
916 916
917 917 elif self.line_type.name=='mix':
918 918 values = self.rc_configuration.parameters.split('-')
919 919 confs = [RCConfiguration.objects.get(pk=value.split('|')[0]) for value in values]
920 920 modes = [value.split('|')[1] for value in values]
921 921 ops = [value.split('|')[2] for value in values]
922 922 delays = [value.split('|')[3] for value in values]
923 923 masks = [value.split('|')[4] for value in values]
924 924 print("masks")
925 925 print(masks)
926 926 print('{:8b}'.format(int(masks[0])))
927 927 mask = list('{:8b}'.format(int(masks[0])))
928 928 print("mask")
929 929 print(mask)
930 930 mask.reverse()
931 931 print("mask reverse")
932 932 print(mask)
933 933 if mask[self.channel] in ('0', '', ' '):
934 934 y = np.zeros(confs[0].total_units, dtype=np.int8)
935 935 else:
936 936 y = confs[0].get_lines(channel=self.channel)[0].pulses_as_array()
937 937
938 938 for i in range(1, len(values)):
939 939 mask = list('{:8b}'.format(int(masks[i])))
940 940 mask.reverse()
941 941
942 942 if mask[self.channel] in ('0', '', ' '):
943 943 continue
944 944 Y = confs[i].get_lines(channel=self.channel)[0].pulses_as_array()
945 945 delay = float(delays[i])*km2unit
946 946
947 947 if modes[i]=='P':
948 948 if delay>0:
949 949 if delay<self.rc_configuration.ipp*km2unit and len(Y)==len(y):
950 950 y_temp = np.empty_like(Y)
951 951 y_temp[:delay] = 0
952 952 y_temp[delay:] = Y[:-delay]
953 953 elif delay+len(Y)>len(y):
954 954 y_new = np.zeros(delay+len(Y), dtype=np.int8)
955 955 y_new[:len(y)] = y
956 956 y = y_new
957 957 y_temp = np.zeros(delay+len(Y), dtype=np.int8)
958 958 y_temp[-len(Y):] = Y
959 959 elif delay+len(Y)==len(y):
960 960 y_temp = np.zeros(delay+len(Y))
961 961 y_temp[-len(Y):] = Y
962 962 elif delay+len(Y)<len(y):
963 963 y_temp = np.zeros(len(y), dtype=np.int8)
964 964 y_temp[delay:delay+len(Y)] = Y
965 965 else:
966 966 y_temp = Y.copy()
967 967
968 968 if ops[i]=='OR':
969 969 y = y | y_temp
970 970 elif ops[i]=='XOR':
971 971 y = y ^ y_temp
972 972 elif ops[i]=='AND':
973 973 y = y & y_temp
974 974 elif ops[i]=='NAND':
975 975 y = y & ~y_temp
976 976 else:
977 977 y = np.concatenate([y, Y])
978 978
979 979 total = len(y)
980 980 y = self.array_to_points(y)
981 981
982 982 else:
983 983 y = []
984 984
985 985 if self.rc_configuration.total_units != total:
986 986 self.rc_configuration.total_units = total
987 987 self.rc_configuration.save()
988 988
989 989 self.pulses = str(y)
990 990 self.save()
991 991
992 992 @staticmethod
993 993 def array_to_points(X):
994 994
995 995 if X.size==0:
996 996 return []
997 997
998 998 d = X[1:]-X[:-1]
999 999
1000 1000 up = np.where(d==1)[0]
1001 1001 if X[0]==1:
1002 1002 up = np.concatenate((np.array([-1]), up))
1003 1003 up += 1
1004 1004
1005 1005 dw = np.where(d==-1)[0]
1006 1006 if X[-1]==1:
1007 1007 dw = np.concatenate((dw, np.array([len(X)-1])))
1008 1008 dw += 1
1009 1009
1010 1010 return [(tup[0], tup[1]) for tup in zip(up, dw)]
1011 1011
1012 1012 @staticmethod
1013 1013 def mask_ranges(Y, ranges):
1014 1014
1015 1015 y = [(0, 0) for __ in Y]
1016 1016
1017 1017 for index in ranges:
1018 1018 if '-' in index:
1019 1019 args = [int(a) for a in index.split('-')]
1020 1020 y[args[0]-1:args[1]] = Y[args[0]-1:args[1]]
1021 1021 else:
1022 1022 y[int(index)-1] = Y[int(index)-1]
1023 1023
1024 1024 return y
1025 1025
1026 1026 @staticmethod
1027 1027 def points(ntx, ipp, width, delay=[0], before=0, after=0, sync=0):
1028 1028
1029 1029 delays = len(delay)
1030 1030
1031 1031 Y = [(int(ipp*x+before+delay[x%delays]+sync), int(ipp*x+width+before+delay[x%delays]+after+sync)) for x in range(ntx)]
1032 1032
1033 1033 return Y
1034 1034
1035 1035 class RCClock(models.Model):
1036 1036
1037 1037 rc_configuration = models.ForeignKey('RCConfiguration', on_delete=models.CASCADE)
1038 1038 mode = models.BooleanField(default=True, choices=((True, 'Auto'), (False, 'Manual')))
1039 1039 multiplier = models.PositiveIntegerField(default=60)
1040 1040 divisor = models.PositiveIntegerField(default=10)
1041 1041 reference = models.PositiveSmallIntegerField(default=1, choices=((0, 'Internal (25MHz)'), (1, 'External (10MHz)')))
1042 1042 frequency = models.FloatField(default=60.0) No newline at end of file
@@ -1,74 +1,74
1 1 version: '2'
2 2 services:
3 3 # Django app
4 # web:
5 # container_name: 'radarsys'
6 # build: .
7 # restart: always
8 # image: radarsys
9 # command: gunicorn radarsys.wsgi:application -w 2 -b :8000
10 # #command: python manage.py runserver 0.0.0.0:8030
4 web:
5 container_name: 'radarsys'
6 build: .
7 restart: always
8 image: radarsys
9 command: gunicorn radarsys.wsgi:application -w 2 -b :8000
10 #command: python manage.py runserver 0.0.0.0:8000
11 ports:
12 - 8000:8000
11 13 # ports:
12 # - 8000:8000
13 # #ports:
14 # # - 8030:8030
15 # env_file: .env
14 # - 8030:8030
15 env_file: .env
16 16
17 # links:
18 # # - redis
19 # - postgres
20 # volumes:
21 # - './:/radarsys'
22 # - '${DOCKER_DATA}/static:/radarsys/static'
23 # depends_on:
24 # # - redis
25 # - postgres
17 links:
18 # - redis
19 - postgres
20 volumes:
21 - './:/radarsys'
22 - '${DOCKER_DATA}/static:/radarsys/static'
23 depends_on:
24 # - redis
25 - postgres
26 26
27 27 # redis:
28 28 # container_name: 'radarsys-redis'
29 29 # image: 'redis:3.2-alpine'
30 30 # volumes:
31 31 # - '${DOCKER_DATA}/redis:/data'
32 32
33 33 # celery_worker:
34 34 # container_name: 'radarsys-celery'
35 35 # image: radarsys
36 36 # env_file: .env
37 37 # command: celery -A radarsys worker -l info
38 38 # volumes_from:
39 39 # - web
40 40 # depends_on:
41 41 # - web
42 42
43 43 # PostgreSQL
44 44 postgres:
45 45 container_name: 'radarsys-postgres'
46 46 build: ./postgres/
47 47 volumes:
48 48 - ./postgres/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
49 49 - pgdata:/var/lib/postgresql/data
50 50 ports:
51 51 - 5432:5432
52 52 environment:
53 53 - POSTGRES_PASSWORD=docker
54 54 - POSTGRES_USER=docker
55 55 - POSTGRES_DB=radarsys
56 56 env_file: .env
57 57
58 # #Web Server
59 # nginx:
60 # container_name: 'radarsys-nginx'
61 # restart: always
62 # build: ./nginx/
63 # ports:
64 # - '8030:8030'
65 # volumes_from:
66 # - web
67 # links:
68 # - web:web
69 # depends_on:
70 # - web
58 #Web Server
59 nginx:
60 container_name: 'radarsys-nginx'
61 restart: always
62 build: ./nginx/
63 ports:
64 - '8030:8030'
65 volumes_from:
66 - web
67 links:
68 - web:web
69 depends_on:
70 - web
71 71
72 72 volumes:
73 73 pgdata:
74 74 driver: local
@@ -1,3 +1,3
1 FROM nginx:1.13.8-alpine
1 FROM nginx:1.22.1-alpine
2 2 RUN rm /etc/nginx/conf.d/default.conf
3 3 ADD sites-enabled/radarsys.conf /etc/nginx/conf.d/
@@ -1,17 +1,20
1 1 server {
2 2
3 3 listen 8030;
4 4 server_name localhost;
5 5
6 6 access_log /dev/stdout;
7 7 error_log /dev/stdout info;
8 8
9 9 location /static {
10 10 alias /radarsys/static;
11 11 }
12 12
13 13 location / {
14 proxy_set_header Host "localhost";
14 15 proxy_pass http://web:8000;
16 # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
17
15 18 }
16 19
17 20 }
@@ -1,158 +1,163
1 1 """
2 2 Django settings for radarsys project.
3 3
4 4 Generated by 'django-admin startproject' using Django 1.8.6.
5 5
6 6 For more information on this file, see
7 7 https://docs.djangoproject.com/en/1.8/topics/settings/
8 8
9 9 For the full list of settings and their values, see
10 10 https://docs.djangoproject.com/en/1.8/ref/settings/
11 11 """
12 12
13 13 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
14 14 import os
15 15
16 16 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17 17
18 18 # Quick-start development settings - unsuitable for production
19 19 # See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
20 20
21 21 # SECURITY WARNING: keep the secret key used in production secret!
22 22 SECRET_KEY = 'xshb$k5fc-+j16)cvyffj&9u__0q3$l!hieh#+tbzqg)*f^km0'
23 23
24 24 # SECURITY WARNING: don't run with debug turned on in production!
25 25 DEBUG = True
26 26
27 27 ALLOWED_HOSTS = ['*']
28 28
29 CSRF_TRUSTED_ORIGINS=[
30 "http://*.localhost:8030"
31 ]
32 #Si se requiere que la aplicaciΓ³n salga de este entorno, para otros usuarios es necesario hacer una API request https://fractalideas.com/blog/making-react-and-django-play-well-together-single-page-app-model/
33
29 34 # Application definition
30 35
31 36 INSTALLED_APPS = [
32 37 'django.contrib.admin',
33 38 'django.contrib.auth',
34 39 'django.contrib.contenttypes',
35 40 'django.contrib.sessions',
36 41 'django.contrib.messages',
37 42 'django.contrib.staticfiles',
38 43 'apps.accounts',
39 44 'apps.main',
40 45 'apps.misc',
41 46 'apps.rc',
42 47 'apps.dds',
43 48 'apps.jars',
44 49 'apps.usrp',
45 50 'apps.abs',
46 51 'apps.cgs',
47 52 'apps.dds_rest',
48 53 "django_bootstrap5",
49 54 'polymorphic',
50 55 ]
51 56
52 57 MIDDLEWARE = [
53 58 'django.middleware.security.SecurityMiddleware',
54 59 'django.contrib.sessions.middleware.SessionMiddleware',
55 60 'django.middleware.common.CommonMiddleware',
56 61 'django.middleware.csrf.CsrfViewMiddleware',
57 62 'django.contrib.auth.middleware.AuthenticationMiddleware',
58 63 'django.contrib.messages.middleware.MessageMiddleware',
59 64 'django.middleware.clickjacking.XFrameOptionsMiddleware',
60 65
61 66 ]
62 67
63 68 ROOT_URLCONF = 'radarsys.urls'
64 69
65 70 TEMPLATES = [
66 71 {
67 72 'BACKEND': 'django.template.backends.django.DjangoTemplates',
68 73 'DIRS': [os.path.join(BASE_DIR, "templates")],
69 74 'APP_DIRS': True,
70 75 'OPTIONS': {
71 76 'context_processors': [
72 77 'django.template.context_processors.debug',
73 78 'django.template.context_processors.request',
74 79 'django.contrib.auth.context_processors.auth',
75 80 'django.contrib.messages.context_processors.messages',
76 81 'apps.main.processors.radarsys_globals',
77 82 ],
78 83 },
79 84 },
80 85 ]
81 86
82 87 WSGI_APPLICATION = 'radarsys.wsgi.application'
83 88
84 89
85 90 # Database
86 91 # https://docs.djangoproject.com/en/1.8/ref/settings/#databases
87 92
88 93 DATABASES = {
89 94 # 'default': {
90 95 # 'ENGINE': 'django.db.backends.sqlite3',
91 96 # 'NAME': 'radarsys.sqlite',
92 97 # }
93 98 'default': {
94 99 'ENGINE': 'django.db.backends.postgresql_psycopg2',
95 100 'NAME': os.environ.get('DB_NAME', 'radarsys'),
96 101 'USER': os.environ.get('DB_USER', 'docker'),
97 102 'PASSWORD': os.environ.get('DB_PASSWORD', 'docker'),
98 103 'HOST': os.environ.get('POSTGRES_PORT_5432_TCP_ADDR', 'localhost'),
99 104 'PORT': os.environ.get('POSTGRES_PORT_5432_TCP_PORT', '5432'),
100 105 }
101 106 }
102 107
103 108 # Internationalization
104 109 # https://docs.djangoproject.com/en/1.8/topics/i18n/
105 110
106 111 LANGUAGE_CODE = 'en-us'
107 112
108 113 USE_TZ = False #True
109 114
110 115 TIME_ZONE = os.environ.get('TZ', 'America/Lima')
111 116
112 117 USE_I18N = True
113 118
114 119 USE_L10N = True
115 120
116 121 # Static files (CSS, JavaScript, Images)
117 122 # https://docs.djangoproject.com/en/1.8/howto/static-files/
118 123
119 124 MEDIA_URL = '/media/'
120 125 MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
121 126
122 127 STATIC_URL = '/static/'
123 128 STATIC_ROOT = os.path.join(BASE_DIR, 'static')
124 129
125 130 LOGIN_URL = 'login'
126 131 LOGOUT_URL = 'logout'
127 132 LOGIN_REDIRECT_URL = '/admin'
128 133 LOGOUT_REDIRECT_URL = '/'
129 134
130 135 STATICFILES_FINDERS = (
131 136 'django.contrib.staticfiles.finders.FileSystemFinder',
132 137 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
133 138 )
134 139
135 140 # # Celery stuff
136 141
137 142 # REDIS_HOST = os.environ.get('REDIS_HOST', 'localhost')
138 143 # #REDIS_HOST = os.environ.get('REDIS_HOST', '127.0.0.1')
139 144 # REDIS_PORT = os.environ.get('REDIS_PORT', 6379)
140 145
141 146 # BROKER_TRANSPORT = 'redis'
142 147 # #BROKER_URL = 'redis://{}:{}/0'.format(REDIS_HOST, REDIS_PORT)
143 148 # BROKER_URL = 'redis://{}:{}'.format(REDIS_HOST, REDIS_PORT)
144 149
145 150 # CELERY_RESULT_BACKEND = 'redis://{}:{}/0'.format(REDIS_HOST, REDIS_PORT)
146 151 # CELERY_BROKER_TRANSPORT = BROKER_URL
147 152 # CELERY_ACCEPT_CONTENT = ['application/json']
148 153 # CELERY_TASK_SERIALIZER = 'json'
149 154 # CELERY_RESULT_SERIALIZER = 'json'
150 155 # CELERY_ENABLE_UTC = False
151 156 # CELERY_TIMEZONE = 'America/Lima'
152 157
153 158 import django
154 159 from django.utils.encoding import force_str
155 160 django.utils.encoding.force_text = force_str
156 161
157 162 # choose of auto-created primary keys
158 163 DEFAULT_AUTO_FIELD='django.db.models.AutoField'
General Comments 0
You need to be logged in to leave comments. Login now