backend/model_api/views.py
def scores(request):
    """
    This endpoint will return a list of quarantine score data points of
    for a specific area from 2020-3-11 to a given date. The expected
    query params are "country", "state" and "weeks" where "weeks" denoting
    the number of weeks after 2020-3-11.
    """
    country = request.query_params.get("country")
    state = request.query_params.get("state")
    weeks = int(float(request.query_params.get("weeks")))

    # Get the area and raise an API exception if we can't.
    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_rt": [],
        "observed_mrf": []

    }

    score_start_date = QuarantineScoreDataPoint.objects.first().date
    score_end_date = score_start_date + timedelta(days=7*weeks)

    quarantine_scores = QuarantineScoreDataPoint.objects.filter(
        area=area,
        #date__range=(score_start_date, score_end_date)
        date__lte=score_end_date
    )
    for d in quarantine_scores:
        response["observed_rt"].append({
            "date": d.date,
            "value": d.val,
            "conf": d.conf
        })

    mrf_scores = MRFScoreDataPoint.objects.filter(
        area=area,
    )
    for d in mrf_scores:
        response["observed_mrf"].append({
            "date":d.date,
            "value":d.val,
            "conf":d.conf
        })

    return Response(response)

    This endpoint will return a list of quarantine score data points of
    for a specific area from 2020-3-11 to a given date. The expected
    query params are "country", "state" and "weeks" where "weeks" denoting
    the number of weeks after 2020-3-11.
    
This endpoint will return a list of quarantine score data points of
for a specific area from 2020-3-11 to a given date.
This endpoint will return a list of quarantine score data points of for a specific area from 2020 - 3 - 11 to a given date .
def scores(request):
    country = request.query_params.get("country")
    state = request.query_params.get("state")
    weeks = int(float(request.query_params.get("weeks")))
    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_rt": [],
        "observed_mrf": []
    }
    score_start_date = QuarantineScoreDataPoint.objects.first().date
    score_end_date = score_start_date + timedelta(days=7*weeks)
    quarantine_scores = QuarantineScoreDataPoint.objects.filter(
        area=area,
        date__lte=score_end_date
    )
    for d in quarantine_scores:
        response["observed_rt"].append({
            "date": d.date,
            "value": d.val,
            "conf": d.conf
        })
    mrf_scores = MRFScoreDataPoint.objects.filter(
        area=area,
    )
    for d in mrf_scores:
        response["observed_mrf"].append({
            "date":d.date,
            "value":d.val,
            "conf":d.conf
        })
    return Response(response)
def scores ( request ) : country = request . query_params . get ( "country" ) state = request . query_params . get ( "state" ) weeks = int ( float ( request . query_params . get ( "weeks" ) ) ) 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_rt" : [ ] , "observed_mrf" : [ ] } score_start_date = QuarantineScoreDataPoint . objects . first ( ) . date score_end_date = score_start_date + timedelta ( days = 7 * weeks ) quarantine_scores = QuarantineScoreDataPoint . objects . filter ( area = area , date__lte = score_end_date ) for d in quarantine_scores : response [ "observed_rt" ] . append ( { "date" : d . date , "value" : d . val , "conf" : d . conf } ) mrf_scores = MRFScoreDataPoint . objects . filter ( area = area , ) for d in mrf_scores : response [ "observed_mrf" ] . append ( { "date" : d . date , "value" : d . val , "conf" : d . conf } ) return Response ( response )
This endpoint will return a list of quarantine score data points of
for a specific area from 2020-3-11 to a given date.
This endpoint will return a list of quarantine score data points of for a specific area from 2020 - 3 - 11 to a given date .
"""
    This endpoint will return a list of quarantine score data points of
    for a specific area from 2020-3-11 to a given date. The expected
    query params are "country", "state" and "weeks" where "weeks" denoting
    the number of weeks after 2020-3-11.
    """ # Get the area and raise an API exception if we can't. #date__range=(score_start_date, score_end_date)
request