backend/model_api/views.py
def history_cumulative(request):
    """
    This endpoints returns the number of cumulative infections for each area given a date in history.
    """
    days = int(request.query_params.get("days"))
    observed = Covid19DataPoint.objects.all()
    historyDate = max([d.date for d in observed]) - timedelta(days=-days)
    shownData = observed.filter(date=historyDate)
    deathData = Covid19DeathDataPoint.objects.filter(date=historyDate)
    #total_confirmed = sum([d.val for d in shownData])
    #total_death = sum([d.val for d in deathData])
    greatest_model = Covid19Model.objects.get(name="SI-kJalpha - 40x")

    greatest_predictions = Covid19PredictionDataPoint.objects.filter(model=greatest_model)
    greatest_predictions = greatest_predictions.filter(date=greatest_predictions.last().date, social_distancing=1)
    greatest_vals = [d.val for d in greatest_predictions]
    max_val = max(greatest_vals)
    greatest_death_model = Covid19Model.objects.get(name="SI-kJalpha - 40x (death prediction)")
    greatest_death_predictions = Covid19PredictionDataPoint.objects.filter(model=greatest_death_model)
    greatest_death_predictions = greatest_death_predictions.filter(date=greatest_death_predictions.last().date,
                                                                   social_distancing=1)
    greatest_death_vals = [d.val for d in greatest_death_predictions]
    max_death_val = max(greatest_death_vals)
    response = [{
        'area': {
            'country': d.area.country,
            'state': d.area.state,
            'iso_2': d.area.iso_2,
        },
        'value': d.val,
        #'value_percentage': 1e3*d.val/total_confirmed,
        'max_val_percentage': 1e4*d.val/max_val,
        'date': d.date,
        'deathValue': deathData.filter(area=d.area, date=d.date).first().val,
        'max_death_percentage':1e4*deathData.filter(area=d.area, date=d.date).first().val/max_death_val,
        #'death_percentage': 1e3*deathData.filter(area=d.area, date=d.date).first().val/total_death,
    } for d in shownData]

    return Response(response)

    This endpoints returns the number of cumulative infections for each area given a date in history.
    
This endpoints returns the number of cumulative infections for each area given a date in history.
This endpoints returns the number of cumulative infections for each area given a date in history .
def history_cumulative(request):
    days = int(request.query_params.get("days"))
    observed = Covid19DataPoint.objects.all()
    historyDate = max([d.date for d in observed]) - timedelta(days=-days)
    shownData = observed.filter(date=historyDate)
    deathData = Covid19DeathDataPoint.objects.filter(date=historyDate)
    greatest_model = Covid19Model.objects.get(name="SI-kJalpha - 40x")
    greatest_predictions = Covid19PredictionDataPoint.objects.filter(model=greatest_model)
    greatest_predictions = greatest_predictions.filter(date=greatest_predictions.last().date, social_distancing=1)
    greatest_vals = [d.val for d in greatest_predictions]
    max_val = max(greatest_vals)
    greatest_death_model = Covid19Model.objects.get(name="SI-kJalpha - 40x (death prediction)")
    greatest_death_predictions = Covid19PredictionDataPoint.objects.filter(model=greatest_death_model)
    greatest_death_predictions = greatest_death_predictions.filter(date=greatest_death_predictions.last().date,
                                                                   social_distancing=1)
    greatest_death_vals = [d.val for d in greatest_death_predictions]
    max_death_val = max(greatest_death_vals)
    response = [{
        'area': {
            'country': d.area.country,
            'state': d.area.state,
            'iso_2': d.area.iso_2,
        },
        'value': d.val,
        'max_val_percentage': 1e4*d.val/max_val,
        'date': d.date,
        'deathValue': deathData.filter(area=d.area, date=d.date).first().val,
        'max_death_percentage':1e4*deathData.filter(area=d.area, date=d.date).first().val/max_death_val,
    } for d in shownData]
    return Response(response)
def history_cumulative ( request ) : days = int ( request . query_params . get ( "days" ) ) observed = Covid19DataPoint . objects . all ( ) historyDate = max ( [ d . date for d in observed ] ) - timedelta ( days = - days ) shownData = observed . filter ( date = historyDate ) deathData = Covid19DeathDataPoint . objects . filter ( date = historyDate ) greatest_model = Covid19Model . objects . get ( name = "SI-kJalpha - 40x" ) greatest_predictions = Covid19PredictionDataPoint . objects . filter ( model = greatest_model ) greatest_predictions = greatest_predictions . filter ( date = greatest_predictions . last ( ) . date , social_distancing = 1 ) greatest_vals = [ d . val for d in greatest_predictions ] max_val = max ( greatest_vals ) greatest_death_model = Covid19Model . objects . get ( name = "SI-kJalpha - 40x (death prediction)" ) greatest_death_predictions = Covid19PredictionDataPoint . objects . filter ( model = greatest_death_model ) greatest_death_predictions = greatest_death_predictions . filter ( date = greatest_death_predictions . last ( ) . date , social_distancing = 1 ) greatest_death_vals = [ d . val for d in greatest_death_predictions ] max_death_val = max ( greatest_death_vals ) response = [ { 'area' : { 'country' : d . area . country , 'state' : d . area . state , 'iso_2' : d . area . iso_2 , } , 'value' : d . val , 'max_val_percentage' : 1e4 * d . val / max_val , 'date' : d . date , 'deathValue' : deathData . filter ( area = d . area , date = d . date ) . first ( ) . val , 'max_death_percentage' : 1e4 * deathData . filter ( area = d . area , date = d . date ) . first ( ) . val / max_death_val , } for d in shownData ] return Response ( response )
This endpoints returns the number of cumulative infections for each area given a date in history.
This endpoints returns the number of cumulative infections for each area given a date in history .
"""
    This endpoints returns the number of cumulative infections for each area given a date in history.
    """ #total_confirmed = sum([d.val for d in shownData]) #total_death = sum([d.val for d in deathData]) #'value_percentage': 1e3*d.val/total_confirmed, #'death_percentage': 1e3*deathData.filter(area=d.area, date=d.date).first().val/total_death,
request