<commit_before>import math, geopy
from rest_framework import viewsets, generics
from geopy.distance import distance
from geopy.geocoders import GoogleV3

from .models import Truck
from .serializers import TruckSerializer


class TruckViewSet(viewsets.ModelViewSet):
    """DRF default viewset provides basic read/write access to Truck model."""
    queryset = Truck.objects.all()
    serializer_class = TruckSerializer


class NearbyTrucks(generics.ListAPIView):
    """Returns list of trucks within the radius of a given location."""
    serializer_class = TruckSerializer
    model = Truck

    def get_queryset(self):

        # get center location
        if self.request.query_params.get('address', False):
            # this allows searching for a location, rather than passing in coordinates
            # unfortnately, interface hasn't been built yet
            geolocator = GoogleV3()
            loc = geolocator.geocode(self.request.query_params['address']+ " San Francisco, CA")
            center = loc.latitude, loc.longitude
        elif self.request.query_params.get('lat', False) and self.request.query_params.get('long', False):
            # get lat/long from query args
            center = float(self.request.query_params['lat']), float(self.request.query_params['lon'])
        else:
            center = (37.7577, -122.4376)  # set default center (center of SF)

        # get radius
        if self.request.query_params.get('radius', False):
            radius = float(self.request.query_params['radius'])<commit_msg>fixes API bug where center did not change (misspelled argname)<commit_after>import math, geopy
from rest_framework import viewsets, generics
from geopy.distance import distance
from geopy.geocoders import GoogleV3

from .models import Truck
from .serializers import TruckSerializer


class TruckViewSet(viewsets.ModelViewSet):
    """DRF default viewset provides basic read/write access to Truck model."""
    queryset = Truck.objects.all()
    serializer_class = TruckSerializer


class NearbyTrucks(generics.ListAPIView):
    """Returns list of trucks within the radius of a given location."""
    serializer_class = TruckSerializer
    model = Truck

    def get_queryset(self):

        # get center location
        if self.request.query_params.get('address', False):
            # this allows searching for a location, rather than passing in coordinates
            # unfortnately, interface hasn't been built yet
            geolocator = GoogleV3()
            loc = geolocator.geocode(self.request.query_params['address']+ " San Francisco, CA")
            center = loc.latitude, loc.longitude
        elif self.request.query_params.get('lat', False) and self.request.query_params.get('lon', False):
            # get lat/long from query args
            center = float(self.request.query_params['lat']), float(self.request.query_params['lon'])
        else:
            center = (37.7577, -122.4376)  # set default center (center of SF)

        # get radius
        if self.request.query_params.get('radius', False):
            radius = float(self.request.query_params['radius'])
{'fraction_non_alphanumeric': 0.09386973180076628, 'fraction_numerical': 0.009578544061302681, 'mean_word_length': 3.1773333333333333, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1824182', 'n_tokens_mistral': 882, 'n_tokens_neox': 838, 'n_words': 254}