Fix bugs in model, Add pretty model

This commit is contained in:
Dominic Zimmer 2020-07-17 22:31:09 +02:00
parent b03f91a8d4
commit 66150f524a
2 changed files with 32 additions and 92 deletions

View File

@ -30,9 +30,9 @@ class Model(object):
def __init__(self, model = dict()): def __init__(self, model = dict()):
self.filename = "scoreboard.json" self.filename = "scoreboard.json"
if "users" not in model: if "users" not in model:
model["users"] = list() model["users"] = {}
print(f"loaded model: {model}") print(f"loaded model: {model}")
self.users = { User(modelstring).uuid : User(modelstring) for modelstring in model["users"]} self.users = { uuid : User(model=model["users"][uuid]) for uuid in model["users"]}
#for _ in range(5): #for _ in range(5):
# newuser = User() # newuser = User()
@ -40,12 +40,12 @@ class Model(object):
self.secretlookup = { self.users[uuid].get_secret() : uuid for uuid in self.users } self.secretlookup = { self.users[uuid].get_secret() : uuid for uuid in self.users }
print(self.secretlookup) print(self.secretlookup)
#print(self.users)
def to_json(self): def to_json(self):
model = { model = {
"users": [self.users[user].to_json() for user in self.users ], "users": { uuid: self.users[uuid].to_json() for uuid in self.users },
} }
print(model)
return model return model
def verify_user(self, authtoken): def verify_user(self, authtoken):

View File

@ -1,99 +1,39 @@
{ {
"users": [ "users": {
{ "zgzbbdf5ulagy5md": {
"uuid": "bnqkcmu3vd3fq5fu", "uuid": "zgzbbdf5ulagy5md",
"name": { "name": "Andi",
"uuid": "t55sfdftsozzy3mi", "score": 78,
"name": { "maxscore": 100,
"uuid": "sprnnogu3cvzzsqf",
"name": "Default User Name",
"score": 0,
"maxscore": 0,
"timeout": 0
},
"score": 0,
"maxscore": 0,
"timeout": 0
},
"score": 0,
"maxscore": 0,
"timeout": 0 "timeout": 0
}, },
{ "zjik7wdl7yrm6bb3": {
"uuid": "sywskga5s3m6wxuq", "uuid": "zjik7wdl7yrm6bb3",
"name": { "name": "Felix",
"uuid": "zq2tratnuyfbfrx2", "score": 52,
"name": { "maxscore": 75,
"uuid": "c5lrovzryckbxgwg",
"name": "Default User Name",
"score": 0,
"maxscore": 0,
"timeout": 0
},
"score": 0,
"maxscore": 0,
"timeout": 0
},
"score": 0,
"maxscore": 0,
"timeout": 0 "timeout": 0
}, },
{ "zp7v3lnpapnndclk": {
"uuid": "ytpvp4dopx54gfld", "uuid": "zp7v3lnpapnndclk",
"name": { "name": "Daki",
"uuid": "snmtkzofojtqma3a", "score": 62,
"name": { "maxscore": 100,
"uuid": "wxl42rw4zdghjgve",
"name": "Default User Name",
"score": 0,
"maxscore": 0,
"timeout": 0
},
"score": 0,
"maxscore": 0,
"timeout": 0
},
"score": 0,
"maxscore": 0,
"timeout": 0 "timeout": 0
}, },
{ "2vsxkkw3d547jhqk": {
"uuid": "dxkahhq65uo63xqp", "uuid": "2vsxkkw3d547jhqk",
"name": { "name": "Cindy",
"uuid": "6u5z6po6gtmh52fr", "score": 91,
"name": { "maxscore": 100,
"uuid": "shnisaos4vxnfcvq",
"name": "Default User Name",
"score": 0,
"maxscore": 0,
"timeout": 0
},
"score": 0,
"maxscore": 0,
"timeout": 0
},
"score": 0,
"maxscore": 0,
"timeout": 0 "timeout": 0
}, },
{ "66w5o44yc7wf7y27": {
"uuid": "3uw4wif2heales72", "uuid": "66w5o44yc7wf7y27",
"name": { "name": "Dominik",
"uuid": "fg7kxyv36ls6a6w5", "score": 46,
"name": { "maxscore": 50,
"uuid": "72onbiw4phvtd54y",
"name": "Default User Name",
"score": 0,
"maxscore": 0,
"timeout": 0
},
"score": 0,
"maxscore": 0,
"timeout": 0
},
"score": 0,
"maxscore": 0,
"timeout": 0 "timeout": 0
} }
] }
} }