-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feature/dbc22 1884 / dbc22 1885 combined for rest stop BE and FE implementation #345
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from apps.rest.models import RestStop | ||
from django.contrib import admin | ||
from django.contrib.admin import ModelAdmin | ||
|
||
|
||
class RestStopAdmin(ModelAdmin): | ||
readonly_fields = ('id', ) | ||
|
||
|
||
admin.site.register(RestStop, RestStopAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class RestConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'apps.rest' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Generated by Django 4.2.3 on 2024-03-15 20:15 | ||
|
||
import django.contrib.gis.db.models.fields | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='RestStop', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('created_at', models.DateTimeField(auto_now_add=True)), | ||
('modified_at', models.DateTimeField(auto_now=True)), | ||
('rest_stop_id', models.CharField(max_length=100, null=True)), | ||
('location', django.contrib.gis.db.models.fields.PointField(null=True, srid=4326)), | ||
('geometry', models.JSONField(null=True)), | ||
('properties', models.JSONField(null=True)), | ||
('bbox', models.JSONField(null=True)), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from apps.shared.models import BaseModel | ||
from django.contrib.gis.db import models | ||
from django.contrib.gis.geos import Point | ||
|
||
|
||
class RestStop(BaseModel): | ||
rest_stop_id = models.CharField(max_length=100, null=True) | ||
location = models.PointField(null=True) | ||
geometry = models.JSONField(null=True) | ||
properties = models.JSONField(null=True) | ||
bbox = models.JSONField(null=True) | ||
|
||
def __str__(self): | ||
return f"Rest Stop for {self.pk}" | ||
|
||
def save(self, *args, **kwargs): | ||
latitude, longitude = self.geometry.get("coordinates")[0], self.geometry.get("coordinates")[1] | ||
self.location = Point(longitude, latitude) | ||
super().save(*args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from apps.rest.models import RestStop | ||
from rest_framework import serializers | ||
|
||
|
||
class RestStopSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = RestStop | ||
exclude = ['geometry'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import logging | ||
|
||
from apps.feed.client import FeedClient | ||
from apps.shared.enums import CacheKey | ||
from apps.rest.models import RestStop | ||
from django.core.cache import cache | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def populate_rest_stop_from_data(new_rest_stop_data): | ||
rest_stop_id = new_rest_stop_data.get('rest_stop_id') | ||
geometry = new_rest_stop_data.get('geometry') | ||
|
||
existing_record = RestStop.objects.filter(rest_stop_id=rest_stop_id).first() | ||
data = { | ||
'rest_stop_id': rest_stop_id, | ||
'geometry': geometry, | ||
'properties': new_rest_stop_data.get('properties'), | ||
'bbox': new_rest_stop_data.get('bbox'), | ||
} | ||
|
||
if existing_record: | ||
existing_record.__dict__.update(data) | ||
existing_record.save() | ||
else: | ||
RestStop.objects.create(**data) | ||
|
||
|
||
def populate_all_rest_stop_data(): | ||
client = FeedClient() | ||
feed_data = client.get_rest_stop_list() | ||
|
||
for rest_stop_data in feed_data: | ||
populate_rest_stop_from_data(rest_stop_data) | ||
|
||
# Rebuild cache | ||
cache.delete(CacheKey.REGIONAL_WEATHER_LIST) |
Empty file.
57 changes: 57 additions & 0 deletions
57
src/backend/apps/rest/tests/test_data/rest_stop_feed_list_of_one.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
[ | ||
{ | ||
"id": 2, | ||
"created_at": "2024-03-15T11:10:29.518958-07:00", | ||
"modified_at": "2024-03-15T11:10:29.518958-07:00", | ||
"rest_stop_id": "DBC_RIM_REST_AREA_V.fid-59dfb4f6_18e433c4f15_-52d9", | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [ | ||
54.66828166, | ||
-126.99686259 | ||
] | ||
}, | ||
"properties": { | ||
"WI_FI": "No", | ||
"OBJECTID": 4381, | ||
"OPEN_DATE": null, | ||
"CLOSE_DATE": null, | ||
"POWER_TYPE": "No Power", | ||
"TOILET_TYPE": "Pit", | ||
"DIRECT_ACCESS": "Yes", | ||
"EVENT_LOCATION": 2.129, | ||
"HIGHWAY_NUMBER": "16", | ||
"REST_AREA_NAME": "BULKLEY VIEW", | ||
"ADMIN_UNIT_CODE": "425", | ||
"ADMIN_UNIT_NAME": "Bulkley Nass SA", | ||
"OPEN_YEAR_ROUND": "Yes", | ||
"REST_AREA_CLASS": "RAM Class C", | ||
"NUMBER_OF_TABLES": 4, | ||
"REST_AREA_NUMBER": "R0146", | ||
"ACCELERATION_LANE": "No", | ||
"DECELERATION_LANE": "Yes", | ||
"NUMBER_OF_TOILETS": 1, | ||
"ACCESS_RESTRICTION": "Westbound", | ||
"CHRIS_REST_AREA_ID": "1532673", | ||
"DIRECTION_OF_TRAFFIC": "Eastbound", | ||
"POWER_RESPONSIBILITY": "Not Applicable", | ||
"EV_STATION_25_KW_DCFC": 0, | ||
"EV_STATION_50_KW_DCFC": 0, | ||
"CROSS_SECTION_POSITION": "Right of Way - Right", | ||
"ACCOM_COMMERCIAL_TRUCKS": "Yes", | ||
"CHRIS_ANCHOR_SECTION_ID": 1313674, | ||
"EV_STATION_LEVEL_2_J1772": 0, | ||
"WHEELCHAIR_ACCESS_TOILET": "Yes", | ||
"ASSOCIATED_NUMBERED_ROUTE": "16", | ||
"DISTANCE_FROM_MUNICIPALITY": "4.5 KM EAST OF TELKWA", | ||
"NUMBER_OF_STANDARD_BARRELS": 0, | ||
"NUMBER_OF_BEAR_PROOF_BARRELS": 6 | ||
}, | ||
"bbox": [ | ||
-126.99686259, | ||
54.66828166, | ||
-126.99686259, | ||
54.66828166 | ||
] | ||
} | ||
] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / CodeQL
Information exposure through an exception Medium