-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add autoscaler for ymax because gnuplot's is broken
- Loading branch information
Showing
3 changed files
with
72 additions
and
117 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |