Exemplo n.º 1
0
def update_trips(request):
    """
    Função que atualiza base com avaliação de uma viagem enviada pelo usuário

    :param request: JSON contendo as informações de início e fim da viagem assim como classificação e nota da mesma
    :return: Mensagem e HTTP Status 201 Created
    """

    json_str = ((request.body).decode('utf-8'))
    json_obj = json.loads(json_str)
    nota_json = json_obj['nota']
    if (nota_json < 1 | nota_json > 5):
        data = {"Response": "Nota deve estar entre 1 e 5!"}
        return JsonResponse(data, status=400)
    data_inicio_json = json_obj['data_inicio']
    data_fim_json = json_obj['data_fim']
    classificacao_json = json_obj['classificacao']

    try:
        classificacao = Classification.objects.get(
            classificacao=classificacao_json)
        trip = Trip(user_id=request.user,
                    data_inicio=data_inicio_json,
                    data_fim=data_fim_json,
                    classificacao=classificacao,
                    nota=nota_json)
        trip.save()
        data = {"Response": "Informações da viagen salvas com sucesso"}
        return JsonResponse(data, status=201)
    except:
        data = {"Response": "Não foi possível avaliar a viagem"}
        return JsonResponse(data, status=400)
    def handle(self, *args, **options):
        lat, lon = 37.75377496892, -122.42077080676

        admin_user = User.objects.get(username='******')
        Trip.objects.filter(name='test').delete()
        trip = Trip(name="test", lat=float(lat), lon=float(lon), user=admin_user)
        trip.save()
        trip.find_route(set([
        	273819889375819, 200600219953504, 192511100766680, 133436743388217,
        	209889829023118
        ]))
Exemplo n.º 3
0
def api(request):
    if request.method == 'POST':
        if request.POST.get(
                'type') == 'addTrip' and request.user.is_authenticated:
            start = request.POST.get('start')
            end = request.POST.get('end')
            try:
                distCar, distBus, source, dest = getDistance(start, end)
                costCar = distCar * DEFAULT_CAR_COST
                costBus = distBus * DEFAULT_BUS_COST
                diff = costBus / costCar * 100
            except TooManyRequests:
                diff = 5
            points = 10 if diff >= 100 \
                else 0 if diff <= 0 \
                else int(diff / 10)
            Trip(start=request.POST.get('start'),
                 end=request.POST.get('end'),
                 points=points,
                 date=request.POST.get('date'),
                 user=request.user).save()
            request.user.points += int(points)
            request.user.save()

    return render(request, 'api.html')
Exemplo n.º 4
0
    def handle(self, *args, **options):
        lat, lon, token = (
            37.76745803822967,
            -122.43988037109374,
            "AAACEdEose0cBAMvhh6NH5ZAxaeuRsZB7TUQ0HXTZAkXOdr5JrlftC91WS0UqEm581S3XgDuaiIjiaVi9cO5QNWrbuDhxWQlY2yhSXG18wZDZD",
        )

        admin_user = User.objects.get(username="******")
        trip = Trip(name="test", lat=float(lat), lon=float(lon), user=admin_user)
        trip.save()
        trip.fetch_places()
        trip.find_route(set([273819889375819, 200600219953504, 192511100766680, 133436743388217, 209889829023118]))
Exemplo n.º 5
0
    def handle(self, *args, **options):
        lat, lon, token = 37.76745803822967, -122.43988037109374, \
            "AAACEdEose0cBAMvhh6NH5ZAxaeuRsZB7TUQ0HXTZAkXOdr5JrlftC91WS0UqEm581S3XgDuaiIjiaVi9cO5QNWrbuDhxWQlY2yhSXG18wZDZD"

        admin_user = User.objects.get(username='******')
        trip = Trip(name="test",
                    lat=float(lat),
                    lon=float(lon),
                    user=admin_user)
        trip.save()
        trip.fetch_places()
        trip.find_route(
            set([
                273819889375819, 200600219953504, 192511100766680,
                133436743388217, 209889829023118
            ]))
    def handle(self, *args, **options):
        lat, lon = 37.75377496892, -122.42077080676

        admin_user = User.objects.get(username='******')
        Trip.objects.filter(name='test').delete()
        trip = Trip(name="test",
                    lat=float(lat),
                    lon=float(lon),
                    user=admin_user)
        trip.save()
        trip.find_route(
            set([
                273819889375819, 200600219953504, 192511100766680,
                133436743388217, 209889829023118
            ]))