diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ccfd65dfb..433c332ac 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/src/backend/apps/webcam/serializers.py b/src/backend/apps/webcam/serializers.py index 75ff0a1d2..b58f5dbac 100644 --- a/src/backend/apps/webcam/serializers.py +++ b/src/backend/apps/webcam/serializers.py @@ -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 @@ -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' diff --git a/src/backend/apps/webcam/tasks.py b/src/backend/apps/webcam/tasks.py index b3a0b9305..05e474527 100644 --- a/src/backend/apps/webcam/tasks.py +++ b/src/backend/apps/webcam/tasks.py @@ -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__) @@ -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(): @@ -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) diff --git a/src/frontend/src/Components/cameras/CameraList.js b/src/frontend/src/Components/cameras/CameraList.js index 4d7887c89..e23416388 100644 --- a/src/frontend/src/Components/cameras/CameraList.js +++ b/src/frontend/src/Components/cameras/CameraList.js @@ -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] = []; } diff --git a/src/frontend/src/Components/cameras/HighwayGroup.js b/src/frontend/src/Components/cameras/HighwayGroup.js index 604c32e8b..a675e4baa 100644 --- a/src/frontend/src/Components/cameras/HighwayGroup.js +++ b/src/frontend/src/Components/cameras/HighwayGroup.js @@ -16,17 +16,19 @@ export default function HighwayGroup(props) {
-
- {highwayShield(highway)} -
+ {!isNaN(highway.charAt(0)) && +
+ {highwayShield(highway)} +
+ }
-

Highway {highway}

+

{!isNaN(highway.charAt(0)) ? 'Highway' : ''} {highway}

{highway === '1' &&

Trans Canada

} {highway !== '1' && -

Highway {highway}

+

{!isNaN(highway.charAt(0)) ? 'Highway' : ''} {highway}

}
diff --git a/src/frontend/src/Components/events/EventsTable.js b/src/frontend/src/Components/events/EventsTable.js index d1bae6233..d50be66d2 100644 --- a/src/frontend/src/Components/events/EventsTable.js +++ b/src/frontend/src/Components/events/EventsTable.js @@ -131,7 +131,7 @@ export default function EventsTable(props) { } useEffect(() => { - sortingHandler(sortingKey); + sortingHandler(); }, [sortingKey]); // Rendering - loader