Skip to content

Instantly share code, notes, and snippets.

@fuwiak
Created October 2, 2020 10:20
Show Gist options
  • Save fuwiak/b64b65c33753313353db4e7c372a179b to your computer and use it in GitHub Desktop.
Save fuwiak/b64b65c33753313353db4e7c372a179b to your computer and use it in GitHub Desktop.
import json, math
# Напишите ваш код ниже
with open("data/covid.json") as a:
dane = json.load(a)
from datetime import datetime
def calc_mean_sigma(data):
sx, sx2, n = 0.0, 0.0, 0
for x in data:
sx += x
sx2 += x*x
n += 1
return (sx / n, math.sqrt(max(sx2 / n - sx / n * sx / n, 0)))
def sigma_norm (country_code, value_name):
out= []
temp= dane[country_code]['data']
N = len(temp)
for i in range(N):
datestring=dane[country_code]['data'][i]['date']
dt = datetime.strptime(datestring, '%Y-%m-%d')
x = dane[country_code]['data'][i][value_name]
x = float(x)
if dt.month==8:
out.append(x)
n = len(out)
mean = sum(out)/n
return float(calc_mean_sigma(out)[1])/mean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment