tartiflette/appci/analyze.py

49 lines
978 B
Python
Raw Normal View History

2017-08-26 15:01:31 +02:00
import json
import glob
def main():
apps = []
for f in glob.glob("data/*"):
app = f.replace("data/","")
appdata = open(f).read().strip()
if appdata == "":
continue
data = {}
data["name"] = app
data["statuses"] = []
applevel = appdata.split("\n")[1][0]
appdata = appdata.split("\n")[0]
2017-08-29 00:24:31 +02:00
data["level"] = int(applevel)
2017-08-26 15:01:31 +02:00
2017-08-29 00:24:31 +02:00
statusescore = 0
2017-08-26 15:01:31 +02:00
for c in appdata:
if c == "0":
s = "danger"
2017-08-29 00:24:31 +02:00
statusescore -= 1
2017-08-26 15:01:31 +02:00
elif c == "1":
s = "success"
2017-08-29 00:24:31 +02:00
statusescore += 1
2017-08-26 15:01:31 +02:00
else:
s = "unknown"
data["statuses"].append(s)
2017-08-29 00:24:31 +02:00
data["statusescore"] = statusescore
2017-08-26 15:01:31 +02:00
apps.append(data)
2017-08-29 00:24:31 +02:00
apps.sort(key=lambda a: (a["level"], a["statusescore"], a["name"])), reverse=True)
2017-08-26 15:01:31 +02:00
with open("apps.json", "w") as f:
json.dump(apps, f)
main()