Skip to content

Commit

Permalink
Cleaned up incorrect comments and removed print statements
Browse files Browse the repository at this point in the history
  • Loading branch information
Gary Ruben committed Oct 11, 2024
1 parent 75e25df commit 019221c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 55 deletions.
20 changes: 0 additions & 20 deletions openday_scavenger/puzzles/imagereveal/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,9 @@ <h1 class="type-h1 text-center">X-ray Fluorescence Microscopy (XFM) Images Puzzl
Remaining guesses: <b>{{ state["remaining_guesses"] }}</b>
</p>

<!-- {% if state["remaining_guesses"] %} -->

<img src="static/im{{ state['animal_id'] }}_{{ state['fraction'] }}.jpg"
alt="Animal {{ state['animal_id'] }}" style="max-width: 800px; width:100%" class="my-3 mx-auto">

<!-- {% else %} -->

<!-- <img src="static/im{{ state['animal_id'] }}_10.jpg" alt="Animal {{ state['animal_id'] }}" style="width:100%;"><br> -->

<!-- {% endif %} -->

<!-- <input type="text" id="answer" name="answer"> -->
<!-- <select class="form-select" id="animal" name="animal">
<option value="0">Wasp</option>
<option value="1">Millipede</option>
<option value="2">Mosquito</option>
<option value="3">Giraffe</option>
<option value="4">Lobster larva</option>
<option value="5">Ant</option>
</select><br>
<button class="form-button">
Submit your guess
</button> -->
<input type="hidden" id="animal" name="animal" value="">

<div>
Expand Down
38 changes: 3 additions & 35 deletions openday_scavenger/puzzles/imagereveal/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ async def index(
db: Annotated["Session", Depends(get_db)],
visitor: Annotated[VisitorAuth, Depends(get_auth_visitor)],
):
# We demonstrate the use of state by incrementing a counter each time a user
# access this puzzle endpoint.
# Use this to store any intermediate state of the visitor while completing a puzzle.
# state stores the intermediate state of the visitor while completing a puzzle.
state = get_puzzle_state(db, puzzle_name=PUZZLE_NAME, visitor_auth=visitor)
state["complete"] = False
state["answer"] = 0
Expand All @@ -82,44 +80,17 @@ async def index(
)


# @router.post("/reset_puzzle")
# async def reset_puzzle(
# request: Request,
# db: Annotated["Session", Depends(get_db)],
# visitor: Annotated[VisitorAuth, Depends(get_auth_visitor)],
# ):
# state = get_puzzle_state(db, puzzle_name=PUZZLE_NAME, visitor_auth=visitor)
# state["complete"] = False
# state["state_access_count"] = 0
# state["correct_guesses"] = 0
# state["remaining_guesses"] = INITIAL_GUESSES
# state["animal_id"] = 1
# state["fraction_ix"] = 0
# state["fraction"] = FRACTIONS[0]
# set_puzzle_state(db, puzzle_name=PUZZLE_NAME, visitor_auth=visitor, state=state)

# print("Reset endpoint")

# return 0


@router.post("/partsubmission")
async def partsubmission(
animal: Annotated[str, Form()],
request: Request,
db: Annotated["Session", Depends(get_db)],
visitor: Annotated[VisitorAuth, Depends(get_auth_visitor)],
):
# We demonstrate the use of state by incrementing a counter each time a user
# access this puzzle endpoint.
# Use this to store any intermediate state of the visitor while completing a puzzle.
state = get_puzzle_state(db, puzzle_name=PUZZLE_NAME, visitor_auth=visitor)
animal_id = state.get("animal_id")
# print(f"### animal: {animal}, animal_id:{animal_id}, MATCHES[animal_id - 1]: {MATCHES[animal_id - 1]}, clause: {int(animal) == MATCHES[animal_id - 1]}")
if int(animal) == MATCHES[animal_id - 1]:
# correct guess
print("Correct guess")

# A correct guess
state["correct_guesses"] = state.get("correct_guesses", 0) + 1
state["remaining_guesses"] = state.get("remaining_guesses", INITIAL_GUESSES)
state["fraction_ix"] = 0
Expand All @@ -141,15 +112,12 @@ async def partsubmission(
context={"puzzle": PUZZLE_NAME, "state": state},
)
else:
# incorrect guess
print("Incorrect guess")

# An incorrect guess
state["correct_guesses"] = state.get("correct_guesses", 0)
state["remaining_guesses"] = state.get("remaining_guesses", INITIAL_GUESSES) - 1
if state["remaining_guesses"] < 1:
# failed to solve puzzle
# Do something if there are no remaining guesses
print("No remaining guesses")
state["complete"] = True
state["answer"] = 0

Expand Down

0 comments on commit 019221c

Please sign in to comment.