Skip to content

Commit a036cf1

Browse files
committed
Migrate to Grout
Migration instructions: 1. For safety, comment out the migrations task in deployment/ansible/roles/driver.app/tasks/main.yml 2. `vagrant provision` (it will probably fail) 3. `./scripts/manage.sh migrate grout 0022 --fake` 4. `./scripts/manage.sh migrate data 0011` 5. `./scripts/manage.sh migrate grout 0025` 6. `./scripts/manage.sh migrate data` 7. `vagrant provision` (it should work)
1 parent e3624ed commit a036cf1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+466
-225
lines changed

README.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,6 @@ DRIVER - Data for Road Incident Visualization, Evaluation, and Reporting
4646
sudo apt-get install nfs-common nfs-kernel-server
4747
```
4848

49-
1. Clone the [Ashlar](https://github.com/azavea/ashlar) project such that it is a sibling of DRIVER (Ashlar is needed for generating dynamic schemas used by DRIVER).
50-
51-
An example setup might be as follows:
52-
```bash
53-
/home/username/
54-
git
55-
DRIVER
56-
ashlar
57-
```
58-
5949
1. Start the Vagrant VM
6050
```bash
6151
vagrant up

Vagrantfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ Vagrant.configure("2") do |config|
9090
app.vm.synced_folder "./web", "/opt/web", type: "nfs", mount_options: MOUNT_OPTIONS
9191
app.vm.synced_folder "./windshaft", "/opt/windshaft", type: "nfs", mount_options: MOUNT_OPTIONS
9292
app.vm.synced_folder "./schema_editor", "/opt/schema_editor", type: "nfs", mount_options: MOUNT_OPTIONS
93-
app.vm.synced_folder "../ashlar", "/opt/ashlar", type: "nfs", mount_options: MOUNT_OPTIONS
9493

9594
# nginx
9695
app.vm.network "forwarded_port", guest: 80, host: Integer(ENV.fetch("DRIVER_WEB_PORT_80", 7000))
@@ -136,7 +135,6 @@ Vagrant.configure("2") do |config|
136135
celery.vm.synced_folder "./web", "/opt/web", type: "nfs", mount_options: MOUNT_OPTIONS
137136
celery.vm.synced_folder "./analysis_tasks", "/opt/analysis_tasks", type: "nfs", mount_options: MOUNT_OPTIONS
138137
celery.vm.synced_folder "./schema_editor", "/opt/schema_editor", type: "nfs", mount_options: MOUNT_OPTIONS
139-
celery.vm.synced_folder "../ashlar", "/opt/ashlar", type: "nfs", mount_options: MOUNT_OPTIONS
140138
# jar build task on celery vm
141139
celery.vm.synced_folder "./gradle", "/opt/gradle", type: "nfs", mount_options: MOUNT_OPTIONS
142140

app/black_spots/filters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
from django.db.models import Q
66

7-
from ashlar.exceptions import QueryParameterException
8-
from ashlar.models import BoundaryPolygon
7+
from grout.exceptions import QueryParameterException
8+
from grout.models import BoundaryPolygon
99

1010
from black_spots.models import (BlackSpot, BlackSpotSet)
1111

app/black_spots/migrations/0001_initial.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class Migration(migrations.Migration):
1010

1111
dependencies = [
12-
('ashlar', '0021_add_weather_fields'),
12+
('grout', '0021_add_weather_fields'),
1313
]
1414

1515
operations = [
@@ -36,7 +36,7 @@ class Migration(migrations.Migration):
3636
('modified', models.DateTimeField(auto_now=True)),
3737
('effective_start', models.DateTimeField()),
3838
('effective_end', models.DateTimeField(null=True, blank=True)),
39-
('record_type', models.ForeignKey(to='ashlar.RecordType')),
39+
('record_type', models.ForeignKey(to='grout.RecordType')),
4040
],
4141
options={
4242
'abstract': False,

app/black_spots/models.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
from django.conf import settings
22
from django.contrib.gis.db import models
33
from django.core.validators import MaxValueValidator, MinValueValidator
4-
from ashlar.models import AshlarModel
4+
from grout.models import GroutModel
55

66

7-
class BlackSpot(AshlarModel):
7+
class BlackSpot(GroutModel):
88
"""A black spot -- an area where there is an historical/statistical
99
concentration of records
1010
"""
1111

1212
#: Buffered road segment polygon where black spot analysis is performed
13-
geom = models.PolygonField(srid=settings.ASHLAR['SRID'])
13+
geom = models.PolygonField(srid=settings.GROUT['SRID'])
1414

1515
#: Number that determines the severity of this black spot. May be used for color-coding on map.
1616
severity_score = models.FloatField()
@@ -37,7 +37,7 @@ def longitude(self):
3737
return self.geom.centroid.x
3838

3939

40-
class BlackSpotSet(AshlarModel):
40+
class BlackSpotSet(GroutModel):
4141
"""A grouping of black spots generated at one time"""
4242

4343
#: DateTime when the black spots become effective
@@ -48,10 +48,10 @@ class BlackSpotSet(AshlarModel):
4848
effective_end = models.DateTimeField(null=True, blank=True)
4949

5050
#: The record type these black spots are associated with
51-
record_type = models.ForeignKey('ashlar.RecordType')
51+
record_type = models.ForeignKey('grout.RecordType')
5252

5353

54-
class BlackSpotConfig(AshlarModel):
54+
class BlackSpotConfig(GroutModel):
5555
"""Holds user-configurable settings for how black spot generation should work"""
5656
#: Blackspot severity percentile cutoff; segments with forecast severity above this threshold
5757
#: will be considered blackspots.
@@ -60,27 +60,27 @@ class BlackSpotConfig(AshlarModel):
6060
MinValueValidator(0.0)])
6161

6262

63-
class BlackSpotRecordsFile(AshlarModel):
63+
class BlackSpotRecordsFile(GroutModel):
6464
"""Model to track blackspot record csvs"""
6565
#: Path to csvs
6666
csv = models.FileField(upload_to='blackspot_records/')
6767

6868

69-
class RoadSegmentsShapefile(AshlarModel):
69+
class RoadSegmentsShapefile(GroutModel):
7070
"""Model to track gzipped shapefile for road segments training input"""
7171

7272
#: Path to gzipped shapefile
7373
shp_tgz = models.FileField(upload_to='road_segments/')
7474

7575

76-
class BlackSpotTrainingCsv(AshlarModel):
76+
class BlackSpotTrainingCsv(GroutModel):
7777
"""Model to track blackspot training csvs"""
7878

7979
#: Path to csvs
8080
csv = models.FileField(upload_to='training/blackspot/')
8181

8282

83-
class LoadForecastTrainingCsv(AshlarModel):
83+
class LoadForecastTrainingCsv(GroutModel):
8484
"""Model to track forecast training csvs"""
8585
#: Path to csvs
8686
csv = models.FileField(upload_to='training/forecast')

app/black_spots/serializers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from rest_framework.exceptions import ParseError, NotFound
33
from rest_framework.serializers import ModelSerializer
44

5-
from ashlar.models import BoundaryPolygon
5+
from grout.models import BoundaryPolygon
66
from black_spots.models import (BlackSpot, BlackSpotSet, BlackSpotConfig)
77
from black_spots.filters import parse_and_validate_dt
88

@@ -37,6 +37,7 @@ class Meta:
3737
fields = ('black_spot_set', 'geom', 'latitude', 'longitude', 'severity_score',)
3838
read_only_fields = ('uuid',)
3939

40+
4041
class EnforcerAssignmentInputSerializer():
4142
"""Serializer for enforcer assignment inputs"""
4243

app/black_spots/tasks/calculate_black_spots.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from celery import shared_task, chain
1111
from celery.utils.log import get_task_logger
1212

13-
from ashlar.models import RecordType
13+
from grout.models import RecordType
1414

1515
from black_spots.tasks import (forecast_segment_incidents, load_blackspot_geoms,
1616
load_road_network, get_training_noprecip)

app/black_spots/tasks/load_blackspot_geoms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from django.contrib.gis.geos import GEOSGeometry
1818
from django.utils import timezone
1919

20-
from ashlar.models import RecordType
20+
from grout.models import RecordType
2121
from black_spots.models import BlackSpot, BlackSpotSet
2222

2323
logger = get_task_logger(__name__)
@@ -200,7 +200,7 @@ def blackspot_from_feature(feature, black_spot_set, src_srid, score_prop=None, r
200200
"""
201201
blackspot = BlackSpot()
202202
geometry = GEOSGeometry(buffer(shape(feature['geometry']).wkb), srid=src_srid)
203-
geometry.transform(settings.ASHLAR['SRID'])
203+
geometry.transform(settings.GROUT['SRID'])
204204
blackspot.geom = geometry
205205
blackspot.black_spot_set = black_spot_set
206206
blackspot.severity_score = feature['properties'][score_prop] if score_prop else 0.0

app/black_spots/tests/tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from rest_framework.test import APIClient, APITestCase, APIRequestFactory
99

10-
from ashlar.models import RecordType
10+
from grout.models import RecordType
1111

1212
from black_spots.models import (BlackSpot, BlackSpotSet)
1313

app/black_spots/views.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from django_redis import get_redis_connection
55
from django.utils import timezone
66

7-
from ashlar.models import Record
7+
from data.models import DriverRecord
88
from black_spots.models import (BlackSpot, BlackSpotSet, BlackSpotConfig)
99
from black_spots.serializers import (BlackSpotSerializer, BlackSpotSetSerializer,
1010
BlackSpotConfigSerializer, EnforcerAssignmentInputSerializer,
@@ -14,9 +14,12 @@
1414

1515
from driver_auth.permissions import IsAdminOrReadOnly
1616
from driver import mixins
17-
import datetime, random, uuid
17+
import datetime
18+
import random
19+
import uuid
1820
from dateutil import rrule
1921

22+
2023
class BlackSpotViewSet(viewsets.ModelViewSet, mixins.GenerateViewsetQuery):
2124
"""ViewSet for black spots"""
2225
queryset = BlackSpot.objects.all()
@@ -132,7 +135,7 @@ def scale_by_toddow(self, assignments, shift_start, shift_end, record_type, geom
132135
num_days_events = 365
133136
max_dt = timezone.now()
134137
min_dt = max_dt - datetime.timedelta(days=num_days_events)
135-
records = Record.objects.filter(
138+
records = DriverRecord.objects.filter(
136139
occurred_from__gte=min_dt,
137140
occurred_to__lte=max_dt,
138141
schema__record_type_id=record_type

0 commit comments

Comments
 (0)