Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #94 from Amsterdam/feature/hotfix-15min-endpoint
Browse files Browse the repository at this point in the history
Switched the query for the 15minaggregate to the cmsa_15min_view_v7_r…
  • Loading branch information
kramer65 authored Dec 31, 2020
2 parents eb0b2d0 + 8e9f3fe commit 039af78
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 229 deletions.
219 changes: 0 additions & 219 deletions src/peoplemeasurement/queries.py

This file was deleted.

7 changes: 1 addition & 6 deletions src/peoplemeasurement/views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import logging
from datetime import timedelta

from datapunt_api.pagination import HALCursorPagination, HALPagination
from datapunt_api.rest import DatapuntViewSetWritable
from django.db import connection
from django.utils import timezone
from django_filters.rest_framework import DjangoFilterBackend, FilterSet
from rest_framework import exceptions, mixins, viewsets
from rest_framework.permissions import IsAuthenticated
Expand All @@ -13,7 +11,6 @@
from contrib.rest_framework.authentication import SimpleGetTokenAuthentication
from . import serializers
from .models import PeopleMeasurement
from .queries import get_today_15min_aggregation_sql

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -91,9 +88,7 @@ def dictfetchall(self, cursor):

def list(self, request, *args, **kwargs):
with connection.cursor() as cursor:
startdate = (timezone.now() - timedelta(days=1)).astimezone().isoformat()
raw_sql = get_today_15min_aggregation_sql(datestr=startdate)
cursor.execute(raw_sql)
cursor.execute("SELECT * FROM cmsa_15min_view_v7_realtime_predict;")
queryset = self.dictfetchall(cursor)
serializer = serializers.Today15minAggregationSerializer(queryset, many=True)
return Response(serializer.data)
7 changes: 3 additions & 4 deletions tests/test_peoplemeasurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,6 @@ def test_get_15min_aggregation_timezone_with_both_v1_and_v2_records(self):
timestamp_str = datetime.now().replace(hour=i, minute=0, second=0).astimezone().replace(
microsecond=0).isoformat()

# Insert some v1 records for each hour
create_new_v1_object(timestamp_str=timestamp_str)

# Insert some v2 records for each hour
self.client.post(
self.POST_URL_V2,
Expand All @@ -272,10 +269,12 @@ def test_get_15min_aggregation_timezone_with_both_v1_and_v2_records(self):
format='json'
)

# Refresh cmsa_15min_view_v7_materialized because the query in the endpoint depends on it
call_man_command('refresh_materialized_view', 'cmsa_15min_view_v7_materialized')

# test whether the endpoint responds correctly
response = self.client.get(self.URL, **GET_AUTHORIZATION_HEADER)
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 24)

def test_get_15min_aggregation_records_fails_without_token(self):
response = self.client.get(self.URL)
Expand Down

0 comments on commit 039af78

Please sign in to comment.