Skip to content

Commit

Permalink
Add autoscaler for ymax because gnuplot's is broken
Browse files Browse the repository at this point in the history
  • Loading branch information
mhandley committed Mar 30, 2020
1 parent 861b799 commit 00e7441
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 117 deletions.
117 changes: 0 additions & 117 deletions gnuplot/plot-eu-lom

This file was deleted.

Binary file removed graphs/covid-eu-lom.png
Binary file not shown.
72 changes: 72 additions & 0 deletions set_ymax.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import subprocess
import sys

norm = False
def extract_countries(filename):
global norm
file = open(filename, "r")
plot = False
datafiles = []
for line in file:
if "per million" in line:
norm = True
if "plot" == line[:4]:
plot = True
if line.strip() == "" or line[0] == "#":
plot = False
if plot:
for curve in line.split(","):
for part in curve.split('"'):
if "../" in part:
datafiles.append(part)
print(datafiles)
countries = []
for path in datafiles:
parts = path.split("/")
fname = parts[len(parts)-1].lower()
prefix = fname.split("-")[0]
countries.append((path,prefix))
file.close()
return countries

assert(len(sys.argv) == 2 or len(sys.argv) == 3)
filename = sys.argv[1]
scale = 2
if len(sys.argv) == 3:
scale = float(sys.argv[2])

countries = extract_countries(filename)

pfile = open("populations", "r")
sizes = {}
for line in pfile:
parts = line.split("#")
country = "".join(parts[1].strip().split(" ")).lower()
size = float(parts[0].split("=")[1].strip())
print(country, size)
if country == "usa":
country = "us"
if ":" in country:
country = country.split(":")[1].strip()
sizes[country] = size

cases_max = 0
for country,short in countries:
if country[:3] == "../":
country = country[3:]
file = open(country, "r")
for line in file:
if line.strip() == "":
continue
parts = line.split()
date = parts[0]
cases = int(parts[1])
if norm:
cases /= sizes[short]
if cases > cases_max:
cases_max = cases
file.close()

ymax = cases_max * scale
subprocess.call("cat " + filename + ' | sed -e "s/YMAX/' + str(ymax) + '/g" >' + filename + ".tmp", shell = True)
subprocess.call("mv " + filename + ".tmp " + filename, shell = True)

0 comments on commit 00e7441

Please sign in to comment.