diff --git a/castellum/geofilters-example/__init__.py b/castellum/geofilters-example/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/castellum/geofilters-example/custom_filters.py b/castellum/geofilters-example/custom_filters.py new file mode 100644 index 0000000000000000000000000000000000000000..3c0e2bfdd1159f11b6cf1e55372032fd9366a214 --- /dev/null +++ b/castellum/geofilters-example/custom_filters.py @@ -0,0 +1,29 @@ +# (c) 2018-2020 +# MPIB , +# MPI-CBS , +# MPIP +# +# This file is part of Castellum. +# +# Castellum is free software; you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Castellum is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with Castellum. If not, see +# . + +from django.db import models + +from castellum.recruitment import filter_registry + + +@filter_registry.register('example_geofilter') +def example_geofilter(**kwargs): + return models.Q(exampleresult__is_match=True) diff --git a/castellum/geofilters-example/management/__init__.py b/castellum/geofilters-example/management/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/castellum/geofilters-example/management/commands/__init__.py b/castellum/geofilters-example/management/commands/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/castellum/geofilters-example/management/commands/geo_example.py b/castellum/geofilters-example/management/commands/geo_example.py new file mode 100644 index 0000000000000000000000000000000000000000..c3cbbc57189f1f6bc9f5a3f5822be219f72b107b --- /dev/null +++ b/castellum/geofilters-example/management/commands/geo_example.py @@ -0,0 +1,42 @@ +# (c) 2018-2020 +# MPIB , +# MPI-CBS , +# MPIP +# +# This file is part of Castellum. +# +# Castellum is free software; you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Castellum is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with Castellum. If not, see +# . + +from django.core.management.base import BaseCommand + +from geopy.distance import distance + +from castellum.geofilters.models import Geolocation + +from ...models import ExampleResult + + +class Command(BaseCommand): + def handle(self, *args, **kwargs): + center = (52.4685095, 13.3037248) + results = [] + for loc in Geolocation.objects: + d = distance((loc.lat, loc.lng), center) + results.append(ExampleResult( + subject_id=loc.contact.subject_id, + is_match=d.km < 3, + )) + ExampleResult.objects.bulk_create(results) + print('Create %i results' % len(results)) diff --git a/castellum/geofilters-example/migrations/0001_initial.py b/castellum/geofilters-example/migrations/0001_initial.py new file mode 100644 index 0000000000000000000000000000000000000000..8e92c87d7b133944465cd3d6764360804b6bea8a --- /dev/null +++ b/castellum/geofilters-example/migrations/0001_initial.py @@ -0,0 +1,24 @@ +# Generated by Django 3.0.6 on 2020-06-10 12:03 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('subjects', '0016_consentdocument_is_deprecated'), + ] + + operations = [ + migrations.CreateModel( + name='ExampleResult', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('is_match', models.BooleanField()), + ('subject', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='subjects.Subject')), + ], + ), + ] diff --git a/castellum/geofilters-example/migrations/__init__.py b/castellum/geofilters-example/migrations/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/castellum/geofilters-example/models.py b/castellum/geofilters-example/models.py new file mode 100644 index 0000000000000000000000000000000000000000..b69582315d47d1c5b1b6513bb0a97f46d71faffc --- /dev/null +++ b/castellum/geofilters-example/models.py @@ -0,0 +1,29 @@ +# (c) 2018-2020 +# MPIB , +# MPI-CBS , +# MPIP +# +# This file is part of Castellum. +# +# Castellum is free software; you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Castellum is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with Castellum. If not, see +# . + +from django.db import models + +from castellum.subjects.models import Subject + + +class ExampleResult(models.Model): + subject = models.OneToOneField(Subject, on_delete=models.CASCADE) + is_match = models.BooleanField() diff --git a/castellum/settings/development.py b/castellum/settings/development.py index d63abc18359b24c8c33ab0afe6cb1664d227cf2a..cf59337f7ef471c0f522f52dd408f012dd438aaf 100644 --- a/castellum/settings/development.py +++ b/castellum/settings/development.py @@ -51,4 +51,5 @@ CASTELLUM_DELETE_NOTIFICATION_TO = 'data-protection@example.com' # Setup geofilters INSTALLED_APPS.append('castellum.geofilters') +INSTALLED_APPS.append('castellum.geofilters-example') NOMINATIM = {'user_agent': 'castellum'}