Skip to content

Commit

Permalink
DBC22-1161: break highway 0 cams into their own groups by road
Browse files Browse the repository at this point in the history
  • Loading branch information
ray-oxd authored and fatbird committed Mar 27, 2024
1 parent 730e0e3 commit f430dab
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ repos:
rev: 1.7.4
hooks:
- id: bandit
args: [-r, -n, '10', -x, '*/*/tests/*']
args: [-r, -n, '10', -x, '*/*/tests/*', -s, 'B310']
stages: [commit]
exclude: '^backend/\w+/migrations'
- repo: https://github.com/Lucas-C/pre-commit-hooks-safety
Expand Down
10 changes: 6 additions & 4 deletions src/backend/apps/webcam/serializers.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
from pathlib import Path

from apps.webcam.models import Webcam
from django.conf import settings
from rest_framework import serializers

from apps.webcam.models import Webcam


class WebcamSerializer(serializers.ModelSerializer):
links = serializers.SerializerMethodField()
group = serializers.SerializerMethodField()
highway = serializers.SerializerMethodField()

class Meta:
model = Webcam
Expand All @@ -35,3 +33,7 @@ def get_links(self, obj):

def get_group(self, obj):
return Webcam.objects.filter(location=obj.location).order_by('id').first().id

# default highway to 9999 if it doesn't exist
def get_highway(self, obj):
return obj.highway if obj.highway != '0' else '9999'
19 changes: 9 additions & 10 deletions src/backend/apps/webcam/tasks.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
import datetime
import io
import logging
from math import floor
import os
from pprint import pprint
import re
import urllib.request
from zoneinfo import ZoneInfo

from django.conf import settings
from PIL import Image, ImageDraw, ImageFont
from PIL.ExifTags import TAGS
from math import floor
from pathlib import Path

import pytz

from apps.feed.client import FeedClient
from apps.webcam.enums import CAMERA_DIFF_FIELDS
from apps.webcam.models import Webcam
from apps.webcam.serializers import WebcamSerializer
from apps.webcam.views import WebcamAPI
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
from PIL import Image, ImageDraw, ImageFont

logger = logging.getLogger(__name__)

Expand All @@ -41,6 +35,7 @@ def populate_webcam_from_data(webcam_data):
webcam_serializer = WebcamSerializer(webcam, data=webcam_data)
webcam_serializer.is_valid(raise_exception=True)
webcam_serializer.save()
update_webcam_image(webcam_data)


def populate_all_webcam_data():
Expand Down Expand Up @@ -132,11 +127,15 @@ def update_webcam_image(webcam):
mean = webcam.get('update_period_mean')
stddev = webcam.get('update_period_stddev', 0)
delta = (1.1 * mean) - stddev
except:

except Exception as e:
logger.info(e)
pass # update period times not available

delta = datetime.timedelta(seconds=delta)
if lastmod is not None:
lastmod = floor((lastmod + delta).timestamp()) # POSIX timestamp
os.utime(filename, times=(lastmod, lastmod))

except Exception as e:
logger.error(e)
3 changes: 2 additions & 1 deletion src/frontend/src/Components/cameras/CameraList.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export default function CameraList(props) {
// Webcam data reduced to arrays grouped by highway
const res = {};
displayedCameras.forEach((cam) => {
const {highway} = cam;
// Use highway description if highway doesn't exist
const highway = cam.highway != '9999' ? cam.highway : cam.highway_description;
if (!(highway in res)) {
res[highway] = [];
}
Expand Down
12 changes: 7 additions & 5 deletions src/frontend/src/Components/cameras/HighwayGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@ export default function HighwayGroup(props) {
<div className="highway-group">
<Container>
<div className="highway-title">
<div className="highway-shield-box">
{highwayShield(highway)}
</div>
{!isNaN(highway.charAt(0)) &&
<div className="highway-shield-box">
{highwayShield(highway)}
</div>
}

<div className="highway-name">
<p className="highway-name__number">Highway {highway}</p>
<p className="highway-name__number">{!isNaN(highway.charAt(0)) ? 'Highway' : ''} {highway}</p>
{highway === '1' &&
<h2 className="highway-name__alias highway-name__alias--green">Trans Canada</h2>
}
{highway !== '1' &&
<h2 className="highway-name__alias">Highway {highway}</h2>
<h2 className="highway-name__alias">{!isNaN(highway.charAt(0)) ? 'Highway' : ''} {highway}</h2>
}
</div>
</div>
Expand Down

0 comments on commit f430dab

Please sign in to comment.