Commit 06408bcf authored by Daniel Kullmann's avatar Daniel Kullmann

Simplifies code

parent 88204b22
......@@ -4,6 +4,8 @@ import datetime
import json
import copy
AVERAGE_OVER_DAYS = 14
(data, all_countries, all_dates, population_data) = corona.load_corona_data()
values_per_1m = corona.calculate_per_1m(data, population_data)
......@@ -46,14 +48,8 @@ def make_rank_data(input_data):
def get_rank(rank_data, country, key):
return rank_data[key][country]
def update_average(average_object, value):
average_object["sum"] += value
average_object["count"] += 1
AVERAGE_OVER_DAYS = 14
def calculate_moving_average(values, all_countries, all_dates):
result = {}
for country in all_countries:
result[country] = {}
# Accumulate values for average
......@@ -67,7 +63,9 @@ def calculate_moving_average(values, all_countries, all_dates):
value = values[country][average_date][key]
if key not in result[country][average_date]:
result[country][average_date][key] = {"sum": 0, "count": 0}
update_average(result[country][average_date][key], value)
result[country][average_date][key]["sum"] += value
result[country][average_date][key]["count"] += 1
# Calculate average
for date in list(result[country].keys()):
for (key, average_object) in result[country][date].items():
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment