backend/model_api/views.py
def check_history(request):
    """
    return the data for a region in a certain time in history
    """
    country = request.query_params.get("country")
    state = request.query_params.get("state")
    #days should be negative
    days = int(request.query_params.get("days"))
    try:
        area = Area.objects.get(country=country, state=state)
    except Area.DoesNotExist:
        msg = "Could not find the area for country '{0}'".format(country)
        if state:
            msg += " and state '{0}'".format(state)
        raise APIException(msg)
    except Area.MultipleObjectsReturned:
        msg = "Found multiple areas for country '{0}'".format(country)
        if state:
            msg += " and state '{0}'".format(state)
        msg += ". This is most likely an error with data cleansing."
        raise APIException(msg)

    #currentDate = max([d.date for d in observed])
    response = {
        "observed": [],
        "predictions": [],
        "observed_deaths": [],
    }
    observed = Covid19DataPoint.objects.filter(area=area)
    currentDate = max([d.date for d in observed])
    lastShownDate = currentDate - timedelta(days=-days)
    shown = observed.filter(date__lte=lastShownDate)
    for d in shown:
        response["observed"].append({
            "date": d.date,
            "value": d.val,
        })

    observed_deaths = Covid19DeathDataPoint.objects.filter(
        area = area,
        date__lte=lastShownDate
    )

    for d in observed_deaths:
        response["observed_deaths"].append({
            "date": d.date,
            "value": d.val,
        })

    return Response(response)

    return the data for a region in a certain time in history
    
return the data for a region in a certain time in history
return the data for a region in a certain time in history
def check_history(request):
    country = request.query_params.get("country")
    state = request.query_params.get("state")
    days = int(request.query_params.get("days"))
    try:
        area = Area.objects.get(country=country, state=state)
    except Area.DoesNotExist:
        msg = "Could not find the area for country '{0}'".format(country)
        if state:
            msg += " and state '{0}'".format(state)
        raise APIException(msg)
    except Area.MultipleObjectsReturned:
        msg = "Found multiple areas for country '{0}'".format(country)
        if state:
            msg += " and state '{0}'".format(state)
        msg += ". This is most likely an error with data cleansing."
        raise APIException(msg)
    response = {
        "observed": [],
        "predictions": [],
        "observed_deaths": [],
    }
    observed = Covid19DataPoint.objects.filter(area=area)
    currentDate = max([d.date for d in observed])
    lastShownDate = currentDate - timedelta(days=-days)
    shown = observed.filter(date__lte=lastShownDate)
    for d in shown:
        response["observed"].append({
            "date": d.date,
            "value": d.val,
        })
    observed_deaths = Covid19DeathDataPoint.objects.filter(
        area = area,
        date__lte=lastShownDate
    )
    for d in observed_deaths:
        response["observed_deaths"].append({
            "date": d.date,
            "value": d.val,
        })
    return Response(response)
def check_history ( request ) : country = request . query_params . get ( "country" ) state = request . query_params . get ( "state" ) days = int ( request . query_params . get ( "days" ) ) try : area = Area . objects . get ( country = country , state = state ) except Area . DoesNotExist : msg = "Could not find the area for country '{0}'" . format ( country ) if state : msg += " and state '{0}'" . format ( state ) raise APIException ( msg ) except Area . MultipleObjectsReturned : msg = "Found multiple areas for country '{0}'" . format ( country ) if state : msg += " and state '{0}'" . format ( state ) msg += ". This is most likely an error with data cleansing." raise APIException ( msg ) response = { "observed" : [ ] , "predictions" : [ ] , "observed_deaths" : [ ] , } observed = Covid19DataPoint . objects . filter ( area = area ) currentDate = max ( [ d . date for d in observed ] ) lastShownDate = currentDate - timedelta ( days = - days ) shown = observed . filter ( date__lte = lastShownDate ) for d in shown : response [ "observed" ] . append ( { "date" : d . date , "value" : d . val , } ) observed_deaths = Covid19DeathDataPoint . objects . filter ( area = area , date__lte = lastShownDate ) for d in observed_deaths : response [ "observed_deaths" ] . append ( { "date" : d . date , "value" : d . val , } ) return Response ( response )
return the data for a region in a certain time in history
return the data for a region in a certain time in history
"""
    return the data for a region in a certain time in history
    """ #days should be negative #currentDate = max([d.date for d in observed])
request