Skip to content

Commit

Permalink
Added delete game to admin interface
Browse files Browse the repository at this point in the history
Improved behaviour of simulated rfid reader
  • Loading branch information
exomo committed Dec 10, 2017
1 parent cd964bf commit fb9dbc5
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 19 deletions.
29 changes: 23 additions & 6 deletions GUI/database/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,24 @@ def get_games(self, number=None):

return games

def get_game(self, id):
def get_game_ids(self):
""""Get ids of all games"""
cur = self.database.cursor()
cur.execute("SELECT id FROM games ORDER BY id ASC")
ids = []
for entry in cur:
ids.append(entry[0])
return ids

def get_game(self, game_id):
"""Get game with id"""
cur = self.database.cursor()
cur.execute("SELECT timestamp, player1, player2, player3, player4, team1_score, team2_score FROM games WHERE id=?", [id])
cur.execute("SELECT timestamp, player1, player2, player3, player4, team1_score, team2_score FROM games WHERE id=?", [game_id])
result = cur.fetchone()

if result is None:
return None

game = Game.Game()
game.time = result[0]
try:
Expand All @@ -157,10 +169,15 @@ def get_game(self, id):
game.player4.name = "Unregistered Player"
game.scoreTeam1 = result[5]
game.scoreTeam2 = result[6]
game.id = int(id)
game.id = int(game_id)

return game

def delete_game(self, game_id):
print("Delete game:\n {0}".format(game_id))
self.database.execute("DELETE FROM games WHERE id=?", [game_id])
self.database.commit()

def rerank_games(self):
# load players
players = self.get_all_players()
Expand All @@ -170,12 +187,12 @@ def rerank_games(self):
self.update_player_skill(p)

# load games
games = self.get_games() #TODO: Number of games in db would be sufficient
game_ids = self.get_game_ids()

# rate game
for i in range(len(games)):
for gid in game_ids:
# Get game with updated player ratings
g = self.get_game(i+1)
g = self.get_game(gid)
if g.scoreTeam1 > g.scoreTeam2:
winner_team = 1
else:
Expand Down
36 changes: 27 additions & 9 deletions GUI/gui_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,22 +597,35 @@ def __init__(self, parent, controller):
result2 = tk.Entry(self, text="Result Team 2")
result2.pack(side="left", fill="x")

change_button = tk.Button(self, text="Change Result",
command=lambda: self.authenticate(int(result1.get()), int(result2.get())))
change_button = tk.Button(
self,
text="Change Result",
command=lambda: self.authenticate(
action=lambda: self._update_game(int(result1.get()), int(result2.get()))))
change_button.pack(side="left", fill="x")
change_button = tk.Button(
self,
text="Delete Game",
command=lambda: self.authenticate(
action=lambda: self._delete_game()))
change_button.pack(side="left", fill="x")

def show_game(Entry):
game_id = Entry.get()
if game_id is not '':
self.game = db.get_game(game_id)
if self.game is None:
return
team1['text'] = "Team 1: {p1}/{p2}".format(p1=self.game.player1.name, p2=self.game.player2.name)
team2['text'] = "Team 2: {p1}/{p2}".format(p1=self.game.player3.name, p2=self.game.player4.name)
result1.delete(0, tk.END)
result1.insert(0, str(self.game.scoreTeam1))
result2.delete(0, tk.END)
result2.insert(0, str(self.game.scoreTeam2))

def authenticate(self, result1, result2):
def authenticate(self, action):
if self.game == None:
return
self.win = tk.Toplevel()
self.win.wm_title("Authentifizierung")

Expand All @@ -631,22 +644,22 @@ def cancelScan():

self.win.update()

self.after(100, self.SkanToken(result1, result2))
self.after(100, self.SkanToken(action))

def SkanToken(self, result1, result2):
def SkanToken(self, action):
if self.cancelAuthentication:
return
token = rfidReader.TryGetToken()
if token != None:
# Check if token belongs to admin
if adb.get_admin(token):
self._update_game(result1, result2)
action()
else:
self.PopupMsg.set("Kein Admin-Token\n"
"Bitte Admin-Token scannen.")
self.after(100, self.SkanToken(result1, result2))
self.after(100, self.SkanToken(action))
else:
self.after(100, self.SkanToken(result1, result2))
self.after(100, self.SkanToken(action))

def _update_game(self, result1, result2):
self.win.destroy()
Expand All @@ -662,7 +675,12 @@ def _update_game(self, result1, result2):
self.game.scoreTeam2 = result2
db.update_game(self.game)
db.rerank_games()


def _delete_game(self):
self.win.destroy()
db.delete_game(self.game.id)
db.rerank_games()
self.game = None

if __name__ == "__main__":
app = KickerApp()
Expand Down
14 changes: 10 additions & 4 deletions GUI/hardware/rfid.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ def getToken():
return uid
except:
global fakeId
global request_count
fakeId = 42424242424242
request_count = 0
def getToken():
global fakeId
time.sleep(2)
uid = str(fakeId)
fakeId += 1
return uid
global request_count
if request_count >= 15:
uid = str(fakeId)
fakeId += 1
request_count = 0
return uid
else:
request_count += 1

class rfid():
"""
Expand Down

0 comments on commit fb9dbc5

Please sign in to comment.