diff options
author | jacopo grandi <jak.sk8@hotmail.it> | 2021-02-20 00:11:23 +0100 |
---|---|---|
committer | jacopo grandi <jak.sk8@hotmail.it> | 2021-02-20 00:11:23 +0100 |
commit | 2eef87c8970db643c4ef09e0fd9e8110c8193043 (patch) | |
tree | 78a9bcc7932ab8edb8669ded755ee2c81afc0912 /build/content/autolevel.py | |
parent | c135f85fcdc1eeedd04e0c9e9f626b907500f20a (diff) |
finish condition and bad cost function
Diffstat (limited to 'build/content/autolevel.py')
-rw-r--r-- | build/content/autolevel.py | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/build/content/autolevel.py b/build/content/autolevel.py index eac6e09..345bccf 100644 --- a/build/content/autolevel.py +++ b/build/content/autolevel.py @@ -1,6 +1,6 @@ import json -def vectorize (obj, forbidlist): +def vectorize (obj, forbidlist, _): for c in obj: for key in c: if not(key in forbidlist): @@ -10,13 +10,18 @@ def vectorize (obj, forbidlist): try: val = float(val); except: pass c[key] = [val for i in range(3)] - return obj + +def query (obj, allowlist, op): + for c in obj: + for key in c: + if key in allowlist: + c[key] = op(c[key]) -def comp(filename, forbidlist): +def comp(filename, l, fun, op=None): with open(filename+".txt", "r") as f: obj = json.loads(f.read()) - obj = vectorize(obj, forbidlist) - with open(filename+".txt", "w") as f: + fun(obj, l, op) + with open(filename+"-new"+".txt", "w") as f: f.write(json.dumps(obj, indent=4)) if __name__ == "__main__": @@ -25,4 +30,7 @@ if __name__ == "__main__": #comp("batteries", ["name"]) #comp("armor", ["name"]) #comp("chassis", ["name"]) - comp("brains", ["name"]) + #comp("brains", ["name"]) + #comp("brains", ["name"]) + + #comp("armor", ["weight"], query, lambda x: [x[i]/5 for i in range(3)]) |