@@ -79,7 +79,13 @@ def get_playable_location(db, user_id):
7979 # Get playable locations
8080 query = "SELECT * "
8181 query = query + "FROM locs "
82- query = query + "WHERE id NOT IN (SELECT DISTINCT loc_id FROM games WHERE user_id = ? AND game_answer_validation = 1) "
82+ query = query + "WHERE id NOT IN "
83+ query = query + "( "
84+ query = query + "SELECT DISTINCT loc_id "
85+ query = query + "FROM games "
86+ query = query + "WHERE user_id = ? "
87+ query = query + "AND game_answer_validation > 0 "
88+ query = query + ") "
8389 query = query + "AND loc_active = 1; "
8490 cursor .execute (query , (user_id ,))
8591 locs_playable = cursor .fetchall ()
@@ -158,6 +164,44 @@ def start_game(db, user_id, loc_id):
158164 return (game_id , now )
159165
160166
167+ def get_game_info (db , id ):
168+
169+ # Create connection and cursor
170+ connection = sqlite3 .connect (db , check_same_thread = False )
171+ connection .row_factory = sqlite3 .Row
172+ cursor = connection .cursor ()
173+
174+ # Insert values from get_playable_location to games table
175+ query = "SELECT * FROM games WHERE id = ?; "
176+ cursor .execute (query , (id ,))
177+ results = cursor .fetchone ()
178+
179+ # Close cursor and connection
180+ cursor .close ()
181+ connection .close ()
182+
183+ return (results )
184+
185+
186+ def get_locs_info (db , id ):
187+
188+ # Create connection and cursor
189+ connection = sqlite3 .connect (db , check_same_thread = False )
190+ connection .row_factory = sqlite3 .Row
191+ cursor = connection .cursor ()
192+
193+ # Insert values from get_playable_location to games table
194+ query = "SELECT * FROM locs WHERE id = ?; "
195+ cursor .execute (query , (id ,))
196+ results = cursor .fetchone ()
197+
198+ # Close cursor and connection
199+ cursor .close ()
200+ connection .close ()
201+
202+ return (results )
203+
204+
161205def update_current_game (db , id , game_end , game_lat , game_lng , game_user_quit , game_answer_off , game_answer_validation , game_duration , game_score ):
162206
163207 # (db, id, game_end, game_lat, game_lng, game_user_quit, game_answer_off, game_answer_validation, game_duration, game_score)
@@ -184,7 +228,7 @@ def update_current_game(db, id, game_end, game_lat, game_lng, game_user_quit, ga
184228 game_id = cursor .lastrowid
185229
186230 # Print to debug
187- print ("game_id:" , game_id )
231+ # print("game_id:", game_id)
188232
189233 # Commit update
190234 connection .commit ()
@@ -381,7 +425,7 @@ def get_history(db, user_id):
381425 # Get playable locations count
382426 query = "SELECT * "
383427 query = query + "FROM locs "
384- query = query + "WHERE id NOT IN (SELECT DISTINCT loc_id FROM games WHERE user_id = ? AND game_answer_validation = 1 ) "
428+ query = query + "WHERE id NOT IN (SELECT DISTINCT loc_id FROM games WHERE user_id = ? AND game_answer_validation > 0 ) "
385429 query = query + "AND loc_active = 1; "
386430 cursor .execute (query , (user_id ,))
387431 locs_playable = cursor .fetchall ()
@@ -392,7 +436,8 @@ def get_history(db, user_id):
392436 query = query + "( "
393437 query = query + "SELECT "
394438 query = query + "DISTINCT loc_id "
395- query = query + ",CASE WHEN game_score = 0 THEN '-' ELSE 'yes' END AS found "
439+ query = query + ",CASE WHEN sum(game_answer_validation) OVER (PARTITION BY loc_id) > 1 THEN 'N' WHEN game_score = 0 THEN '-' ELSE 'Y' END AS found "
440+ query = query + ",sum(game_answer_validation) OVER (PARTITION BY loc_id) AS total_game_answer_validation "
396441 query = query + ",count(*) OVER (PARTITION BY loc_id) AS total_attempts "
397442 query = query + ",sum(game_duration) OVER (PARTITION BY loc_id) AS total_duration "
398443 query = query + ",sum(game_duration) OVER (PARTITION BY loc_id) / count(*) OVER (PARTITION BY loc_id) AS avg_time "
0 commit comments