Skip to content

Commit

Permalink
Add new feature to quit location
Browse files Browse the repository at this point in the history
  • Loading branch information
ggeerraarrdd committed Oct 27, 2023
1 parent ede250f commit 38fcbf3
Show file tree
Hide file tree
Showing 10 changed files with 416 additions and 152 deletions.
396 changes: 278 additions & 118 deletions app.py

Large diffs are not rendered by default.

Binary file modified geo.db
Binary file not shown.
53 changes: 49 additions & 4 deletions queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,13 @@ def get_playable_location(db, user_id):
# Get playable locations
query = "SELECT * "
query = query + "FROM locs "
query = query + "WHERE id NOT IN (SELECT DISTINCT loc_id FROM games WHERE user_id = ? AND game_answer_validation = 1) "
query = query + "WHERE id NOT IN "
query = query + "( "
query = query + "SELECT DISTINCT loc_id "
query = query + "FROM games "
query = query + "WHERE user_id = ? "
query = query + "AND game_answer_validation > 0 "
query = query + ") "
query = query + "AND loc_active = 1; "
cursor.execute(query, (user_id,))
locs_playable = cursor.fetchall()
Expand Down Expand Up @@ -158,6 +164,44 @@ def start_game(db, user_id, loc_id):
return(game_id, now)


def get_game_info(db, id):

# Create connection and cursor
connection = sqlite3.connect(db, check_same_thread=False)
connection.row_factory = sqlite3.Row
cursor = connection.cursor()

# Insert values from get_playable_location to games table
query = "SELECT * FROM games WHERE id = ?; "
cursor.execute(query, (id,))
results = cursor.fetchone()

# Close cursor and connection
cursor.close()
connection.close()

return(results)


def get_locs_info(db, id):

# Create connection and cursor
connection = sqlite3.connect(db, check_same_thread=False)
connection.row_factory = sqlite3.Row
cursor = connection.cursor()

# Insert values from get_playable_location to games table
query = "SELECT * FROM locs WHERE id = ?; "
cursor.execute(query, (id,))
results = cursor.fetchone()

# Close cursor and connection
cursor.close()
connection.close()

return(results)


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):

# (db, id, game_end, game_lat, game_lng, game_user_quit, game_answer_off, game_answer_validation, game_duration, game_score)
Expand All @@ -184,7 +228,7 @@ def update_current_game(db, id, game_end, game_lat, game_lng, game_user_quit, ga
game_id = cursor.lastrowid

# Print to debug
print("game_id:", game_id)
# print("game_id:", game_id)

# Commit update
connection.commit()
Expand Down Expand Up @@ -381,7 +425,7 @@ def get_history(db, user_id):
# Get playable locations count
query = "SELECT * "
query = query + "FROM locs "
query = query + "WHERE id NOT IN (SELECT DISTINCT loc_id FROM games WHERE user_id = ? AND game_answer_validation = 1) "
query = query + "WHERE id NOT IN (SELECT DISTINCT loc_id FROM games WHERE user_id = ? AND game_answer_validation > 0) "
query = query + "AND loc_active = 1; "
cursor.execute(query, (user_id,))
locs_playable = cursor.fetchall()
Expand All @@ -392,7 +436,8 @@ def get_history(db, user_id):
query = query + "( "
query = query + "SELECT "
query = query + "DISTINCT loc_id "
query = query + ",CASE WHEN game_score = 0 THEN '-' ELSE 'yes' END AS found "
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 "
query = query + ",sum(game_answer_validation) OVER (PARTITION BY loc_id) AS total_game_answer_validation "
query = query + ",count(*) OVER (PARTITION BY loc_id) AS total_attempts "
query = query + ",sum(game_duration) OVER (PARTITION BY loc_id) AS total_duration "
query = query + ",sum(game_duration) OVER (PARTITION BY loc_id) / count(*) OVER (PARTITION BY loc_id) AS avg_time "
Expand Down
2 changes: 2 additions & 0 deletions static/scripts_map1.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ async function initMap() {
'<form name="submit" action="/game" method="post">' +
'<input type="hidden" name="try-again" class="hidden-field" value="0"></input>' +
'<input type="hidden" name="current-game-id" class="hidden-field" value="0"></input>' +
'<input type="hidden" name="page" class="hidden-field" value="index"></input>' +
'<input type="hidden" name="goto" class="hidden-field" value="game"></input>' +
'<button class="btn btn-primary" type="submit">Start Game</button>' +
'</form>'
'</div>';
Expand Down
2 changes: 2 additions & 0 deletions static/scripts_map2.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ async function initMap() {
'<input type="hidden" name="answer-long" class="hidden-field" value="' + contentLong + '"></input>' +
'<input type="hidden" name="answer-map-center" class="hidden-field" value="' + contentCenter + '"></input>' +
'<input type="hidden" name="answer-map-zoom" class="hidden-field" value="' + contentZoom + '"></input>' +
'<input type="hidden" name="page" class="hidden-field" value="game"></input>' +
'<input type="hidden" name="goto" class="hidden-field" value="result"></input>' +
'<button class="btn btn-primary btn-sm" type="submit">Submit</button>' +
'</form>' +
'</div>';
Expand Down
18 changes: 15 additions & 3 deletions static/scripts_map3.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async function initMap() {
// Content for Info Window on submit.html
let try_again

if (current_game_answer_user_validation == 'incorrect.') {
if (current_game_answer_user_validation == 'incorrect') {
try_again =
'<div class="infowindow-result-footer-try">' +
'<form name="router" action="/traffic" method="post">' +
Expand All @@ -64,9 +64,21 @@ async function initMap() {
'</form>' +
'</div>';
} else {
try_again = ''
if (current_game_answer_user_validation == 'quit') {
try_again =
'<div class="infowindow-result-footer-try">' +
'<form name="router" action="/traffic" method="post">' +
'<input type="hidden" name="page" class="hidden-field" value="result"></input>' +
'<input type="hidden" name="goto" class="hidden-field" value="zero"></input>' +
'<button name="router" class="btn btn-primary btn-sm" type="submit" disabled>Try Again</button>' +
'</form>' +
'</div>';
} else {
try_again = ''
}
}


const contentResult =
'<div class="infowindow-result">' +
'<div class="infowindow-result-title">' +
Expand Down Expand Up @@ -100,7 +112,7 @@ async function initMap() {
'<input type="hidden" name="page" class="hidden-field" value="result"></input>' +
'<input type="hidden" name="goto" class="hidden-field" value="index"></input>' +
'<input type="hidden" name="try-again" class="hidden-field" value="0"></input>' +
'<button name="router" class="btn btn-link btn-sm" type="submit">Quit Game</button>' +
'<button name="router" class="btn btn-link btn-sm" type="submit">Stop Game</button>' +
'</form>' +
'</div>' +
'</div>' +
Expand Down
47 changes: 39 additions & 8 deletions static/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ li {
}

.container-bottom-image-source a:hover {
color: gray;
color: #ff5645;
text-decoration: none;
}

Expand All @@ -439,24 +439,44 @@ li {
.container-bottom-image-buttons {
width: 400px;
display: flex;
justify-content: space-between;
}

.container-bottom-image-buttons-left {
margin: 0;
padding: 0 5px 0 0;
padding: 0;
display: flex;
}

.container-bottom-image-buttons-right {
margin: 0;
padding: 0;
display: flex;
}

.container-bottom-image-buttons-new {
margin: 0;
padding: 0;
display: flex;
justify-content: right;
align-items: center;
}

.container-bottom-image-buttons-right {
.container-bottom-image-buttons-stop {
margin: 0;
padding: 0 0 0 5px;
padding: 0 0 0 15px;
display: flex;
justify-content: left;
align-items: center;
}

.container-bottom-image-buttons-quit {
margin: 0;
padding: 0 0 0 5px;
display: flex;
justify-content: left;
align-items: center;
}



Expand Down Expand Up @@ -575,13 +595,24 @@ td {
border-color: #ff5645;
}

.btn-link, .btn-link a, .btn-link a:hover, .btn-link a:visited {
.btn-link {
color: gray;
text-decoration: none;
}

.btn-link:focus {
color: #ff5645;
}

.btn-link:hover {
color: #ff5645;
}


.btn-primary.disabled, .btn-primary:disabled {
color: white;
background-color: silver;
border-color: silver;
}



Expand Down Expand Up @@ -770,14 +801,14 @@ td {

.infowindow-result-footer-new {
margin: 0;
padding: 0 15px 0 0;
padding: 0 10px 0 0;
font-size: 12px;
display: flex;
}

.infowindow-result-footer-quit {
margin: 0;
padding: 0;
padding: 0 0 0 5px;
font-size: 12px;
display: flex;
}
Expand Down
33 changes: 22 additions & 11 deletions templates/game.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,29 @@

<div class="container-bottom-image-buttons">
<div class="container-bottom-image-buttons-left">
<form name="submit" action="/traffic" method="post">
<input type="hidden" name="page" class="hidden-field" value="{{ page }}"></input>
<input type="hidden" name="goto" class="hidden-field" value="game"></input>
<button name="router" class="btn btn-primary btn-sm" type="submit">New Search</button>
</form>
</div>
<div class="container-bottom-image-buttons-new">
<form name="submit" action="/traffic" method="post">
<input type="hidden" name="page" class="hidden-field" value="{{ page }}"></input>
<input type="hidden" name="goto" class="hidden-field" value="game"></input>
<button name="router" class="btn btn-primary btn-sm" type="submit">New Search</button>
</form>
</div>
<div class="container-bottom-image-buttons-stop">
<form name="submit" action="/traffic" method="post">
<input type="hidden" name="page" class="hidden-field" value="{{ page }}"></input>
<input type="hidden" name="goto" class="hidden-field" value="index"></input>
<button name="router" class="btn btn-link btn-sm" type="submit">Stop Game</button>
</form>
</div>
</div>
<div class="container-bottom-image-buttons-right">
<form name="submit" action="/traffic" method="post">
<input type="hidden" name="page" class="hidden-field" value="{{ page }}"></input>
<input type="hidden" name="goto" class="hidden-field" value="index"></input>
<button name="router" class="btn btn-link btn-sm" type="submit">Quit Game</button>
</form>
<div class="container-bottom-image-buttons-quit">
<form name="submit" action="/traffic" method="post">
<input type="hidden" name="page" class="hidden-field" value="{{ page }}"></input>
<input type="hidden" name="goto" class="hidden-field" value="zero"></input>
<button name="router" class="btn btn-link btn-sm" type="submit">Quit Location</button>
</form>
</div>
</div>
</div>
</div>
Expand Down
8 changes: 4 additions & 4 deletions templates/history.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@
<td class="text-start">{{ h.loc_city }}, {{ h.loc_state }}, {{ h.loc_country }}</td>
<td class="text-start-center">{{ h.found.upper() }}</td>
<td class="text-start-center">{{ h.total_attempts }}</td>
<td class="text-start-center">{% if h.score|default("-", True) == "-" %}-{% else %}{{ h.total_duration }}{% endif %}</td>
<td class="text-start-center">{% if h.score|default("-", True) == "-" %}-{% else %}{{ h.avg_time }}{% endif %}</td>
<td class="text-start-center">{% if h.score|default("-", True) == "-" %}-{% else %}{{ h.avg_offset }}{% endif %}</td>
<td class="text-start-center">{{ h.score|default("-", True) }}</td>
<td class="text-start-center">{% if h.found|default("-", True) == "-" %}-{% else %}{{ h.total_duration }}{% endif %}</td>
<td class="text-start-center">{% if h.found|default("-", True) == "-" %}-{% else %}{{ h.avg_time }}{% endif %}</td>
<td class="text-start-center">{% if h.found|default("-", True) == "-" %}-{% else %}{% if h.avg_offset == None %}&#248;{% else %}{{ h.avg_offset }}{% endif %}{% endif %}</td>
<td class="text-start-center">{% if h.found|default("-", True) == "-" %}-{% else %}{{ h.score }}{% endif %}</td>
</tr>
{% endfor %}
</tbody>
Expand Down
9 changes: 5 additions & 4 deletions templates/howto.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@
<li>On the second attempt, the max base score is lowered to 40.</li>
<li>On the the third attempt, 30.</li>
<li>Further attempts will not lower the max base score.</li>
<li>If you leave the game page such as closing the window or navigating to another page within 10
seconds, the current game will not be counted as an attempt.</li>
<li>If you leave the game page such as stoping the game, navigating to another page or closing the window/tab within
10 seconds, the current game will not be counted as an attempt.</li>
</ol>
</ol>
<li>The max bonus score is 50.</li>
Expand All @@ -93,10 +93,11 @@
</li>
<li><i>x</i> is cumulative, so times in previous attempts are included.</li>
<li>Essentially you get the full 50 bonus points if you find the house in 2 minutes or less. You get
1
point if found in 30 minutes. After 30 minutes, no bonus.</li>
1 point if found in 30 minutes. After 30 minutes, no bonus.</li>
</ol>
<li>So if you find the house on your first attempt and in 2 minutes or less, you get 100 points.</li>
<li>If you quit a location, the answer will be revealed as the anchor of the results info window. No further
attempts will be allowed and your total score will be recorded as 0 for that location.</li>
</ol>
</div>
</div>
Expand Down

0 comments on commit 38fcbf3

Please sign in to comment.