forked from MapComplete/MapComplete
Full code cleanup
This commit is contained in:
parent
8e6ee8c87f
commit
bd21212eba
246 changed files with 19418 additions and 11729 deletions
|
@ -1,7 +1,7 @@
|
|||
from datetime import datetime
|
||||
from matplotlib import pyplot
|
||||
import json
|
||||
import sys
|
||||
from datetime import datetime
|
||||
from matplotlib import pyplot
|
||||
|
||||
|
||||
def pyplot_init():
|
||||
|
@ -9,54 +9,55 @@ def pyplot_init():
|
|||
pyplot.figure(figsize=(14, 8), dpi=200)
|
||||
pyplot.xticks(rotation='vertical')
|
||||
pyplot.grid()
|
||||
|
||||
|
||||
|
||||
def genKeys(data, type):
|
||||
keys = map(lambda kv: kv["key"], data)
|
||||
if type == "date":
|
||||
keys = map(lambda key : datetime.strptime(key, "%Y-%m-%dT%H:%M:%S.000Z"), keys)
|
||||
keys = map(lambda key: datetime.strptime(key, "%Y-%m-%dT%H:%M:%S.000Z"), keys)
|
||||
return list(keys)
|
||||
|
||||
|
||||
def createPie(options):
|
||||
data = options["plot"]["count"]
|
||||
keys = genKeys(data, options["interpetKeysAs"])
|
||||
values = list(map(lambda kv: kv["value"], data))
|
||||
|
||||
total = sum(map(lambda kv : kv["value"], data))
|
||||
|
||||
total = sum(map(lambda kv: kv["value"], data))
|
||||
first_pct = data[0]["value"] / total
|
||||
|
||||
|
||||
pyplot_init()
|
||||
pyplot.pie(values, labels=keys, startangle=(90 - 360 * first_pct / 2))
|
||||
|
||||
|
||||
|
||||
def createBar(options):
|
||||
data = options["plot"]["count"]
|
||||
keys = genKeys(data, options["interpetKeysAs"])
|
||||
values = list(map(lambda kv: kv["value"], data))
|
||||
|
||||
|
||||
pyplot.bar(keys, values, label=options["name"])
|
||||
pyplot.legend()
|
||||
|
||||
|
||||
|
||||
pyplot_init()
|
||||
title = sys.argv[1]
|
||||
pyplot.title = title
|
||||
names = []
|
||||
while(True):
|
||||
while (True):
|
||||
line = sys.stdin.readline()
|
||||
if line == "" or line == "\n":
|
||||
if(len(names) > 1):
|
||||
pyplot.legend(loc="upper left", ncol=3)
|
||||
pyplot.savefig(title+".png", dpi=400, facecolor='w', edgecolor='w',
|
||||
if (len(names) > 1):
|
||||
pyplot.legend(loc="upper left", ncol=3)
|
||||
pyplot.savefig(title + ".png", dpi=400, facecolor='w', edgecolor='w',
|
||||
bbox_inches='tight')
|
||||
break
|
||||
|
||||
|
||||
options = json.loads(line)
|
||||
print("Creating "+options["plot"]["type"]+" '"+options["name"]+"'")
|
||||
print("Creating " + options["plot"]["type"] + " '" + options["name"] + "'")
|
||||
names.append(options["name"])
|
||||
if(options["plot"]["type"] == "pie"):
|
||||
if (options["plot"]["type"] == "pie"):
|
||||
createPie(options)
|
||||
elif(options["plot"]["type"] == "bar"):
|
||||
elif (options["plot"]["type"] == "bar"):
|
||||
createBar(options)
|
||||
else:
|
||||
print("Unkown type: "+options.type)
|
||||
print("Unkown type: " + options.type)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue