Skip to content

Commit 38fcbf3

Browse files
committed
Add new feature to quit location
1 parent ede250f commit 38fcbf3

File tree

10 files changed

+416
-152
lines changed

10 files changed

+416
-152
lines changed

app.py

Lines changed: 278 additions & 118 deletions
Large diffs are not rendered by default.

geo.db

0 Bytes
Binary file not shown.

queries.py

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
161205
def 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 "

static/scripts_map1.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ async function initMap() {
5656
'<form name="submit" action="/game" method="post">' +
5757
'<input type="hidden" name="try-again" class="hidden-field" value="0"></input>' +
5858
'<input type="hidden" name="current-game-id" class="hidden-field" value="0"></input>' +
59+
'<input type="hidden" name="page" class="hidden-field" value="index"></input>' +
60+
'<input type="hidden" name="goto" class="hidden-field" value="game"></input>' +
5961
'<button class="btn btn-primary" type="submit">Start Game</button>' +
6062
'</form>'
6163
'</div>';

static/scripts_map2.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ async function initMap() {
6969
'<input type="hidden" name="answer-long" class="hidden-field" value="' + contentLong + '"></input>' +
7070
'<input type="hidden" name="answer-map-center" class="hidden-field" value="' + contentCenter + '"></input>' +
7171
'<input type="hidden" name="answer-map-zoom" class="hidden-field" value="' + contentZoom + '"></input>' +
72+
'<input type="hidden" name="page" class="hidden-field" value="game"></input>' +
73+
'<input type="hidden" name="goto" class="hidden-field" value="result"></input>' +
7274
'<button class="btn btn-primary btn-sm" type="submit">Submit</button>' +
7375
'</form>' +
7476
'</div>';

static/scripts_map3.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ async function initMap() {
5353
// Content for Info Window on submit.html
5454
let try_again
5555

56-
if (current_game_answer_user_validation == 'incorrect.') {
56+
if (current_game_answer_user_validation == 'incorrect') {
5757
try_again =
5858
'<div class="infowindow-result-footer-try">' +
5959
'<form name="router" action="/traffic" method="post">' +
@@ -64,9 +64,21 @@ async function initMap() {
6464
'</form>' +
6565
'</div>';
6666
} else {
67-
try_again = ''
67+
if (current_game_answer_user_validation == 'quit') {
68+
try_again =
69+
'<div class="infowindow-result-footer-try">' +
70+
'<form name="router" action="/traffic" method="post">' +
71+
'<input type="hidden" name="page" class="hidden-field" value="result"></input>' +
72+
'<input type="hidden" name="goto" class="hidden-field" value="zero"></input>' +
73+
'<button name="router" class="btn btn-primary btn-sm" type="submit" disabled>Try Again</button>' +
74+
'</form>' +
75+
'</div>';
76+
} else {
77+
try_again = ''
78+
}
6879
}
6980

81+
7082
const contentResult =
7183
'<div class="infowindow-result">' +
7284
'<div class="infowindow-result-title">' +
@@ -100,7 +112,7 @@ async function initMap() {
100112
'<input type="hidden" name="page" class="hidden-field" value="result"></input>' +
101113
'<input type="hidden" name="goto" class="hidden-field" value="index"></input>' +
102114
'<input type="hidden" name="try-again" class="hidden-field" value="0"></input>' +
103-
'<button name="router" class="btn btn-link btn-sm" type="submit">Quit Game</button>' +
115+
'<button name="router" class="btn btn-link btn-sm" type="submit">Stop Game</button>' +
104116
'</form>' +
105117
'</div>' +
106118
'</div>' +

static/styles.css

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ li {
427427
}
428428

429429
.container-bottom-image-source a:hover {
430-
color: gray;
430+
color: #ff5645;
431431
text-decoration: none;
432432
}
433433

@@ -439,24 +439,44 @@ li {
439439
.container-bottom-image-buttons {
440440
width: 400px;
441441
display: flex;
442+
justify-content: space-between;
442443
}
443444

444445
.container-bottom-image-buttons-left {
445446
margin: 0;
446-
padding: 0 5px 0 0;
447+
padding: 0;
448+
display: flex;
449+
}
450+
451+
.container-bottom-image-buttons-right {
452+
margin: 0;
453+
padding: 0;
454+
display: flex;
455+
}
456+
457+
.container-bottom-image-buttons-new {
458+
margin: 0;
459+
padding: 0;
447460
display: flex;
448461
justify-content: right;
449462
align-items: center;
450463
}
451464

452-
.container-bottom-image-buttons-right {
465+
.container-bottom-image-buttons-stop {
453466
margin: 0;
454-
padding: 0 0 0 5px;
467+
padding: 0 0 0 15px;
455468
display: flex;
456469
justify-content: left;
457470
align-items: center;
458471
}
459472

473+
.container-bottom-image-buttons-quit {
474+
margin: 0;
475+
padding: 0 0 0 5px;
476+
display: flex;
477+
justify-content: left;
478+
align-items: center;
479+
}
460480

461481

462482

@@ -575,13 +595,24 @@ td {
575595
border-color: #ff5645;
576596
}
577597

578-
.btn-link, .btn-link a, .btn-link a:hover, .btn-link a:visited {
598+
.btn-link {
579599
color: gray;
600+
text-decoration: none;
580601
}
581602

603+
.btn-link:focus {
604+
color: #ff5645;
605+
}
582606

607+
.btn-link:hover {
608+
color: #ff5645;
609+
}
583610

584-
611+
.btn-primary.disabled, .btn-primary:disabled {
612+
color: white;
613+
background-color: silver;
614+
border-color: silver;
615+
}
585616

586617

587618

@@ -770,14 +801,14 @@ td {
770801

771802
.infowindow-result-footer-new {
772803
margin: 0;
773-
padding: 0 15px 0 0;
804+
padding: 0 10px 0 0;
774805
font-size: 12px;
775806
display: flex;
776807
}
777808

778809
.infowindow-result-footer-quit {
779810
margin: 0;
780-
padding: 0;
811+
padding: 0 0 0 5px;
781812
font-size: 12px;
782813
display: flex;
783814
}

templates/game.html

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,29 @@
5555

5656
<div class="container-bottom-image-buttons">
5757
<div class="container-bottom-image-buttons-left">
58-
<form name="submit" action="/traffic" method="post">
59-
<input type="hidden" name="page" class="hidden-field" value="{{ page }}"></input>
60-
<input type="hidden" name="goto" class="hidden-field" value="game"></input>
61-
<button name="router" class="btn btn-primary btn-sm" type="submit">New Search</button>
62-
</form>
63-
</div>
58+
<div class="container-bottom-image-buttons-new">
59+
<form name="submit" action="/traffic" method="post">
60+
<input type="hidden" name="page" class="hidden-field" value="{{ page }}"></input>
61+
<input type="hidden" name="goto" class="hidden-field" value="game"></input>
62+
<button name="router" class="btn btn-primary btn-sm" type="submit">New Search</button>
63+
</form>
64+
</div>
65+
<div class="container-bottom-image-buttons-stop">
66+
<form name="submit" action="/traffic" method="post">
67+
<input type="hidden" name="page" class="hidden-field" value="{{ page }}"></input>
68+
<input type="hidden" name="goto" class="hidden-field" value="index"></input>
69+
<button name="router" class="btn btn-link btn-sm" type="submit">Stop Game</button>
70+
</form>
71+
</div>
72+
</div>
6473
<div class="container-bottom-image-buttons-right">
65-
<form name="submit" action="/traffic" method="post">
66-
<input type="hidden" name="page" class="hidden-field" value="{{ page }}"></input>
67-
<input type="hidden" name="goto" class="hidden-field" value="index"></input>
68-
<button name="router" class="btn btn-link btn-sm" type="submit">Quit Game</button>
69-
</form>
74+
<div class="container-bottom-image-buttons-quit">
75+
<form name="submit" action="/traffic" method="post">
76+
<input type="hidden" name="page" class="hidden-field" value="{{ page }}"></input>
77+
<input type="hidden" name="goto" class="hidden-field" value="zero"></input>
78+
<button name="router" class="btn btn-link btn-sm" type="submit">Quit Location</button>
79+
</form>
80+
</div>
7081
</div>
7182
</div>
7283
</div>

templates/history.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@
7171
<td class="text-start">{{ h.loc_city }}, {{ h.loc_state }}, {{ h.loc_country }}</td>
7272
<td class="text-start-center">{{ h.found.upper() }}</td>
7373
<td class="text-start-center">{{ h.total_attempts }}</td>
74-
<td class="text-start-center">{% if h.score|default("-", True) == "-" %}-{% else %}{{ h.total_duration }}{% endif %}</td>
75-
<td class="text-start-center">{% if h.score|default("-", True) == "-" %}-{% else %}{{ h.avg_time }}{% endif %}</td>
76-
<td class="text-start-center">{% if h.score|default("-", True) == "-" %}-{% else %}{{ h.avg_offset }}{% endif %}</td>
77-
<td class="text-start-center">{{ h.score|default("-", True) }}</td>
74+
<td class="text-start-center">{% if h.found|default("-", True) == "-" %}-{% else %}{{ h.total_duration }}{% endif %}</td>
75+
<td class="text-start-center">{% if h.found|default("-", True) == "-" %}-{% else %}{{ h.avg_time }}{% endif %}</td>
76+
<td class="text-start-center">{% if h.found|default("-", True) == "-" %}-{% else %}{% if h.avg_offset == None %}&#248;{% else %}{{ h.avg_offset }}{% endif %}{% endif %}</td>
77+
<td class="text-start-center">{% if h.found|default("-", True) == "-" %}-{% else %}{{ h.score }}{% endif %}</td>
7878
</tr>
7979
{% endfor %}
8080
</tbody>

templates/howto.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@
8181
<li>On the second attempt, the max base score is lowered to 40.</li>
8282
<li>On the the third attempt, 30.</li>
8383
<li>Further attempts will not lower the max base score.</li>
84-
<li>If you leave the game page such as closing the window or navigating to another page within 10
85-
seconds, the current game will not be counted as an attempt.</li>
84+
<li>If you leave the game page such as stoping the game, navigating to another page or closing the window/tab within
85+
10 seconds, the current game will not be counted as an attempt.</li>
8686
</ol>
8787
</ol>
8888
<li>The max bonus score is 50.</li>
@@ -93,10 +93,11 @@
9393
</li>
9494
<li><i>x</i> is cumulative, so times in previous attempts are included.</li>
9595
<li>Essentially you get the full 50 bonus points if you find the house in 2 minutes or less. You get
96-
1
97-
point if found in 30 minutes. After 30 minutes, no bonus.</li>
96+
1 point if found in 30 minutes. After 30 minutes, no bonus.</li>
9897
</ol>
9998
<li>So if you find the house on your first attempt and in 2 minutes or less, you get 100 points.</li>
99+
<li>If you quit a location, the answer will be revealed as the anchor of the results info window. No further
100+
attempts will be allowed and your total score will be recorded as 0 for that location.</li>
100101
</ol>
101102
</div>
102103
</div>

0 commit comments

Comments
 (0)