Skip to content

Instantly share code, notes, and snippets.

@vaslabs
Last active August 29, 2015 14:00
Show Gist options
  • Save vaslabs/11245113 to your computer and use it in GitHub Desktop.
Save vaslabs/11245113 to your computer and use it in GitHub Desktop.
import json
import sys
def old2new(oldjs):
newjs = []
for entry in oldjs:
newEntry = {"name":entry["name"], "grades":[]}
for key in entry:
if key == "name":
continue
if key.split()[0] == "term":
termIndex = int(key.split()[1])
termEntry = {"term": termIndex, "actual":None, "predicted": None, "target": None}
grade = parseGrade(entry[key])
termEntry["target"] = grade['target']
if termIndex < 8:
termEntry["actual"] = grade['grade']
else:
termEntry["predicted"] = grade['grade']
newEntry['grades'].append(termEntry)
if key.split()[0] == "exit":
exitIndex = key.split()[1]
exitEntry = {"exit": exitIndex, "actual":None, "predicted": None, "target": None}
grade = parseGrade(entry[key])
exitEntry["target"] = grade["target"]
if exitIndex == "ks1":
termEntry["actual"] = grade['grade']
else:
termEntry["predicted"] = grade['grade']
newEntry['grades'].append(exitEntry)
newjs.append(newEntry)
return newjs
def parseGrade(full_grade):
grade = full_grade.split('/')[0]
target = full_grade.split('/')[1]
return {'grade': grade, 'target':target}
def main(args):
jfile = open(args[0])
oldjs = json.load(jfile)
jfile.close()
newjs = old2new(oldjs)
print newjs
ofile = open(args[1], "w")
json.dump(newjs, ofile)
ofile.close()
if __name__ == "__main__":
main(sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment