diff --git a/.env b/.env index 439cb04..66ab877 100644 --- a/.env +++ b/.env @@ -1,7 +1,8 @@ -HOST_MYSQL=mysql -HOST_REDIS=redis -MYSQL_ROOT_PASSWORD=r00tJRO -MYSQL_DATABASE=radarsys -MYSQL_USER=developer -MYSQL_PASSWORD=idi2015 -HOST_REDIS=redis \ No newline at end of file +HOST_REDIS=radarsys-redis +POSTGRES_DB_NAME=radarsys +POSTGRES_PORT_5432_TCP_ADDR=radarsys-postgres +POSTGRES_PORT_5432_TCP_PORT=5432 +POSTGRES_USER=docker +POSTGRES_PASSWORD=docker +PGDATA=/var/lib/postgresql/data +LC_ALL=C.UTF-8 \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bb32362 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +migrations/ +.vscode/ +*.pyc +.env diff --git a/Dockerfile b/Dockerfile index 2fc5f25..a5357b1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:2.7.11 +FROM python:2.7-slim # set working directory RUN mkdir /radarsys @@ -6,11 +6,18 @@ WORKDIR /radarsys # Install python dependences ADD requirements.txt ./requirements.txt -RUN pip install -v --timeout 120 -r requirements.txt --no-cache-dir +RUN apt-get clean && apt-get update && apt-get install -y --no-install-recommends \ + gcc \ + g++ \ + && pip install -v --timeout 120 -r requirements.txt --no-cache-dir --index-url http://10.10.20.128:8010/simple --trusted-host 10.10.20.128 \ + && apt-get purge -y --auto-remove gcc g++\ + && rm -rf /var/lib/apt/lists/* # Copy the main application. COPY . ./ +EXPOSE 8000 + RUN python manage.py collectstatic --noinput diff --git a/README.md b/README.md new file mode 100644 index 0000000..1625b8b --- /dev/null +++ b/README.md @@ -0,0 +1,39 @@ +# Integrated Radar System (SIR) + +The Integrated Radar System (SIR) is a web application that allows the configuration of the radar devices as required by the experiment, +This app allows the creation of Campaigns, Experiment and Device Configurations. +For more information visit: http://jro-dev.igp.gob.pe:3000/projects/sistema-integrado-de-radar/wiki + +## Installation + +We recommend use docker/docker-compose for test/production but you can install the aplication as a normal django app. + +### 1. Download + +Download the application *radarsys* to your workspace + + $ cd /path/to/your/workspace + $ git clone http://jro-dev.igp.gob.pe/rhodecode/radarsys && cd radarsys + +### 2. Config app + +Create enviroment vars (/path/to/radarsys/.env) + + HOST_REDIS=radarsys-redis + POSTGRES_DB_NAME=radarsys + POSTGRES_PORT_5432_TCP_ADDR=radarsys-postgres + POSTGRES_PORT_5432_TCP_PORT=5432 + POSTGRES_USER=docker + POSTGRES_PASSWORD=**** + PGDATA=/var/lib/postgresql/data + LC_ALL=C.UTF-8 + +Set database user/password in /path/to/radarsys/settings.py + +### 3. Build application + + $ docker-compose build + +### 4. Run containers + + $ docker-compose up -d \ No newline at end of file diff --git a/apps/abs/utils/Graphics_OverJro.py b/apps/abs/utils/Graphics_OverJro.py index 457147b..146f265 100644 --- a/apps/abs/utils/Graphics_OverJro.py +++ b/apps/abs/utils/Graphics_OverJro.py @@ -25,7 +25,7 @@ import matplotlib # matplotlib.use("Agg") #else: # matplotlib.use('TKAgg') -#matplotlib.use("Agg") +matplotlib.use("Agg") #matplotlib.interactive(1) import matplotlib.pyplot #import Numeric diff --git a/apps/main/templates/index.html b/apps/main/templates/index.html index cf41105..46695ad 100644 --- a/apps/main/templates/index.html +++ b/apps/main/templates/index.html @@ -5,6 +5,6 @@ {% block content %} -{% lorem %} +
{% lorem %}
{% endblock %} diff --git a/apps/rc/models.py b/apps/rc/models.py index 4c001e1..9747a9a 100644 --- a/apps/rc/models.py +++ b/apps/rc/models.py @@ -72,8 +72,8 @@ ror = lambda val, r_bits: \ class RCConfiguration(Configuration): - ipp = models.FloatField(verbose_name='IPP [Km]', validators=[MinValueValidator(1), MaxValueValidator(9000)], default=300) - ntx = models.PositiveIntegerField(verbose_name='Number of TX', validators=[MinValueValidator(1), MaxValueValidator(400)], default=1) + ipp = models.FloatField(verbose_name='IPP [Km]', validators=[MinValueValidator(1)], default=300) + ntx = models.PositiveIntegerField(verbose_name='Number of TX', validators=[MinValueValidator(1)], default=1) clock_in = models.FloatField(verbose_name='Clock in [MHz]', validators=[MinValueValidator(1), MaxValueValidator(80)], default=1) clock_divider = models.PositiveIntegerField(verbose_name='Clock divider', validators=[MinValueValidator(1), MaxValueValidator(256)], default=1) clock = models.FloatField(verbose_name='Clock Master [MHz]', blank=True, default=1) @@ -109,9 +109,7 @@ class RCConfiguration(Configuration): def clone(self, **kwargs): - lines = self.get_lines() - print 'LINES' - print lines + lines = self.get_lines() self.pk = None self.id = None for attr, value in kwargs.items(): @@ -124,7 +122,7 @@ class RCConfiguration(Configuration): new_lines = self.get_lines() for line in new_lines: line_params = json.loads(line.params) - if 'TX_ref' in line_params: + if 'TX_ref' in line_params and (line_params['TX_ref'] != '0'): ref_line = RCLine.objects.get(pk=line_params['TX_ref']) line_params['TX_ref'] = ['{}'.format(l.pk) for l in new_lines if l.get_name()==ref_line.get_name()][0] line.params = json.dumps(line_params) @@ -242,17 +240,17 @@ class RCConfiguration(Configuration): for x in points: dum = [] for i, tups in enumerate(pulses): - ups = [tup[0] for tup in tups] - dws = [tup[1] for tup in tups] + ups = [tup[0] for tup in tups if tup!=(0,0)] + dws = [tup[1] for tup in tups if tup!=(0,0)] if x in ups: dum.append(1) elif x in dws: dum.append(0) else: dum.append(last[i]) - states.append(dum) + states.append(dum) last = dum - + if binary: ret = [] for flips in states: @@ -351,6 +349,8 @@ class RCConfiguration(Configuration): def plot_pulses2(self, km=False): + import matplotlib + matplotlib.use('Agg') import matplotlib.pyplot as plt from bokeh.resources import CDN from bokeh.embed import components @@ -545,11 +545,17 @@ class RCConfiguration(Configuration): return True - def write_device(self): - - values = zip(self.get_pulses(), - [x-1 for x in self.get_delays()]) - + def write_device(self): + + #values = zip(self.get_pulses(), [x-1 for x in self.get_delays()]) + + values = [] + for pulse, delay in zip(self.get_pulses(), self.get_delays()): + while delay>65535: + values.append((pulse, 65535)) + delay -= 65535 + values.append((pulse, delay-1)) + data = bytearray() #reset data.extend((128, 0)) @@ -570,8 +576,16 @@ class RCConfiguration(Configuration): data.extend((129, 1)) try: + payload = self.request('stop', 'post') + payload = self.request('reset', 'post') + #payload = self.request('divider', 'post', data={'divider': self.clock_divider-1}) + #payload = self.request('write', 'post', data=b64encode(bytearray((139, 62))), timeout=20) + n = len(data) + x = 0 + #while x < n: payload = self.request('write', 'post', data=b64encode(data)) - + # x += 1024 + if payload['write']=='ok': self.device.status = 3 self.device.save() @@ -582,6 +596,8 @@ class RCConfiguration(Configuration): self.message = 'RC write: {}'.format(payload['write']) return False + #payload = self.request('start', 'post') + except Exception as e: if 'No route to host' not in str(e): self.device.status = 4 @@ -641,7 +657,7 @@ class RCLine(models.Model): def __str__(self): if self.rc_configuration: - return u'%s - %s' % (self.rc_configuration, self.get_name()) + return u'{}|{} - {}'.format(self.pk, self.get_name(), self.rc_configuration.name) def jsonify(self): @@ -856,12 +872,16 @@ class RCLine(models.Model): elif self.line_type.name=='windows': params = json.loads(self.params) if 'params' in params and len(params['params'])>0: - tr_params = json.loads(self.get_lines(line_type__name='tr')[0].params) - tr_ranges = tr_params['range'].split(',') + tr_lines = self.get_lines(line_type__name='tr') + if tr_lines: + tr_params = json.loads(self.get_lines(line_type__name='tr')[0].params) + tr_ranges = tr_params['range'].split(',') + else: + tr_ranges = [] for p in params['params']: y_win = self.points(ntx, ipp_u, p['resolution']*p['number_of_samples']*km2unit, - before=int(self.rc_configuration.time_before*us2unit), + before=int(self.rc_configuration.time_before*us2unit)+p['first_height']*km2unit, sync=self.rc_configuration.sync+self.get_win_ref(p, params['TX_ref'], km2unit)) diff --git a/devices/rc/api.py b/devices/rc/api.py index bdd4d76..b7380b2 100644 --- a/devices/rc/api.py +++ b/devices/rc/api.py @@ -21,7 +21,8 @@ class RCApi(object): def load(self, filename): self.params = json.load(open(filename)) - print 'RC Configuration: {}'.format(self.params['name']) + self.pk = self.params['configurations']['allIds'][0] + print 'RC Configuration: {}'.format(self.params['configurations']['byId'][self.pk]['name']) def status(self): @@ -56,40 +57,45 @@ class RCApi(object): def write(self): url_write = os.path.join(self.url, 'write') - url_divider = os.path.join(self.url, 'divisor') - - values = zip(self.params['pulses'], - [x-1 for x in self.params['delays']]) + url_divider = os.path.join(self.url, 'divider') + + values = zip(self.params['configurations']['byId'][self.pk]['pulses'], + [x-1 for x in self.params['configurations']['byId'][self.pk]['delays']]) payload = '' for tup in values: vals = pack('