Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHANGE geolocation em formato geoJson #93

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions geolocations_service/service/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
run:
python manage.py runserver 0.0.0.0:5002

test:
python manage.py test brumadinho.tests
24 changes: 23 additions & 1 deletion geolocations_service/service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ Instale os requerimentos para o servidor funcionar (preferencialmente em um ambi

Acesse o servidor local em `localhost:5002/api/`

## Testes

#### Rodar todos os testes
Para rodar os testes de maneira geral basta executar

make test

#### Rodar testes indiviualmente
Para rodar um testes específico execute o comando `python manage.py test brumadinho.tests.<test_name>` onde `<test_name>` é o nome do arquivo contendo o teste que deseja executar. i.e:

python manage.py test brumadinho.tests.test_geolocation

## HELP NEEDED

Tem muita coisa que pode ser feita aqui ainda, toda ajuda é necessária.
Expand Down Expand Up @@ -64,7 +76,7 @@ Clone repo to a workspace.
Install requeriments (preferably in a virtual environment)

### Development
pip install -r service.requirements.develop.txt
pip install -r service.requirements.txt

### Migrate the database

Expand All @@ -78,7 +90,17 @@ Install requeriments (preferably in a virtual environment)

Acess local server at `localhost:5002/api/`

## Tests

#### Run all tests
To run all tests just execute:

make test

#### Running tests individually
To run an single especific test execute `python manage.py test brumadinho.tests.<test_name>` where `<test_name>` is the filename which is the one you want to execute i.e:

python manage.py test brumadinho.tests.test_geolocation

## HELP NEEDED

Expand Down
28 changes: 23 additions & 5 deletions geolocations_service/service/brumadinho/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by Django 2.1.3 on 2019-01-29 02:11
# Generated by Django 2.1.3 on 2019-01-31 23:29

import django.contrib.gis.db.models.fields
from django.db import migrations, models
import django.db.models.deletion

Expand All @@ -12,20 +13,37 @@ class Migration(migrations.Migration):
]

operations = [
migrations.CreateModel(
name='FoundPeople',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('full_name', models.CharField(blank=True, help_text='Full name of the found people.', max_length=150)),
('gender', models.CharField(blank=True, choices=[('M', 'Male'), ('F', 'Female')], default=None, help_text='Gender of the found people.', max_length=2, null=True)),
('status_condition', models.CharField(blank=True, choices=[('Alive', 'Alive'), ('Dead', 'Dead')], default=None, help_text='Status condition of the found people.', max_length=5, null=True)),
],
),
migrations.CreateModel(
name='Geolocation',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('latitude', models.FloatField()),
('longitude', models.FloatField()),
('coordinates', django.contrib.gis.db.models.fields.PointField(srid=4326)),
],
),
migrations.CreateModel(
name='VisitedLocation',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('reference', models.CharField(max_length=100)),
('location', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='brumadinho.Geolocation')),
('reference', models.CharField(help_text='Reference and information.', max_length=100)),
('visitation_date', models.DateTimeField(blank=True, help_text='Datetime of the location analysis.', null=True)),
('encounter_number', models.IntegerField(help_text='Number of people found in this location.')),
('radius', models.FloatField(default=1, help_text='Radial área range of search.')),
('observations', models.CharField(blank=True, help_text='Observations', max_length=2000, null=True)),
('location', models.ForeignKey(help_text='Geoposition of the visited area.', on_delete=django.db.models.deletion.PROTECT, to='brumadinho.Geolocation')),
],
),
migrations.AddField(
model_name='foundpeople',
name='location',
field=models.ForeignKey(blank=True, help_text='Found location.', null=True, on_delete=django.db.models.deletion.PROTECT, to='brumadinho.Geolocation'),
),
]

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 2.1.3 on 2019-02-01 02:06

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('brumadinho', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='geolocation',
name='latitude',
field=models.FloatField(default=0.0),
preserve_default=False,
),
migrations.AddField(
model_name='geolocation',
name='longitude',
field=models.FloatField(default=0.0),
preserve_default=False,
),
]

This file was deleted.

This file was deleted.

13 changes: 2 additions & 11 deletions geolocations_service/service/brumadinho/models.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
from django.db import models

from django.contrib.gis.db import models as gis_models

class Geolocation(models.Model):

class Meta:
unique_together = ['latitude', 'longitude']

coordinates = gis_models.PointField(null=True, blank=True)
latitude = models.FloatField()
longitude = models.FloatField()

def __str__(self):
return str("lat: {} long: {}".format(
self.latitude,
self.longitude
))


class VisitedLocation(models.Model):

reference = models.CharField(
Expand Down
40 changes: 38 additions & 2 deletions geolocations_service/service/brumadinho/serializers.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,49 @@
# from django.contrib.auth.models import Group
from brumadinho.models import Geolocation, VisitedLocation, FoundPeople
from rest_framework import serializers
from rest_framework_gis import serializers as gis_serializer
# from django.core.serializers import serialize
from django.contrib.gis.geos import Point


class GeolocationSerializer(serializers.ModelSerializer):
class GeolocationSerializer(gis_serializer.GeoFeatureModelSerializer):

# TODO corrigir para que coordinates NÃO SEJA exibido como valor de input na tela
# nem seja possível de ser recebido na requisição.

class Meta:
model = Geolocation
fields = "__all__"
fields = ("latitude", "longitude")
geo_field = "coordinates"
read_only_fields = ("coordinates",)
write_only_fields = ("latitude", "longitude")

def create(self, data):

data['coordinates'] = Point(
data.get('longitude'),
data.get('latitude')
)
Geolocation.objects.create(**data)
return data

def update(self, location, data):

# geolocation = Geolocation.objects.get(id=location.id)

latitude = data.get('latitude')
longitude = data.get('longitude')

location.latitude = latitude
location.longitude = longitude

location.coordinates = Point(
longitude,
latitude
)

super(GeolocationSerializer, self).update(location, data)
return location

class VisitedLocationSerializer(serializers.ModelSerializer):
class Meta:
Expand Down
Empty file.
Loading