Skip to content

Commit

Permalink
Merge pull request #87 from Capstone-Projects-2024-Spring/Gao
Browse files Browse the repository at this point in the history
Fixed endpoints, db errors, and updated dashboard and redirections.
  • Loading branch information
Dem0nMaxwell committed May 1, 2024
2 parents b57451b + d212c23 commit ebd6e03
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 48 deletions.
26 changes: 3 additions & 23 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def authenticate():
# Stores the Player object in the session
session["user"] = playerObj.__json__()
# Redirects to a desired page when authentication success
return redirect("/")
return redirect("/#/menu")
else:
# Raises an error for wrong match
raise ValueError("Invalid username or password")
Expand Down Expand Up @@ -267,7 +267,7 @@ def register():
session["user"] = playerObj.__json__()

# Redirects to the result page
return redirect("/")
return redirect("/#/menu")

@_app.route("/logout", methods=["GET", "POST"])
def logout():
Expand All @@ -279,26 +279,6 @@ def logout():
session.pop("user", None)
return redirect("/")

@_app.route("/custom-page")
def custom_page():
return render_template("custompage.html")

@_app.route("/generate_text/", methods=["GET"])
def generate_text():
"""
Sends back text for the requestor to use
:param difficulty
:param form : Specifies the form of text generated. Values: 'sentences' or 'word_list'
:param amount : Specifies the amount of text to generate.
:param genre : Specifies the genre of the text. Optional.
"""
difficulty = request.args.get("difficulty", "")
form = request.args.get("form")
amount = request.args.get("amount")
# Retrieve genre from request, default to None if not provided
genre = request.args.get("genre", None)
return Text_Generator.generate_text(difficulty, form, amount, genre)

@_app.route("/get_avg_txt_len/", methods=["GET"])
def get_avg_txt_len():
"""
Expand Down Expand Up @@ -371,7 +351,7 @@ def update_db():
Database.update(usr, "UserData", _accuracy=(game_data["accuracy"]+float(user_data._accuracy)*num_races)/(num_races+1), _num_races=num_races+1,
_total_playing_time=user_data._total_playing_time+game_data["elapsedTime"], _top_wpm=game_wpm if game_wpm > int(user_data._top_wpm) else int(user_data._top_wpm))
last_user_race = UserRace.query.filter_by(
_username=usr).order_by(UserRace._date_played.desc()).first()
_username=usr).order_by(UserRace._game_num.desc()).first()
if last_user_race:
Database.insert(UserRace, _game_num=int(last_user_race._game_num)+1, _username=usr, _email=str(user_data._email), _average_wpm=game_wpm,
_selected_mode=game_data["mode"], _time_limit=game_data.get("timeLimit"), _date_played=parser.parse(game_data["date"]))
Expand Down
Binary file modified requirements.txt
Binary file not shown.
1 change: 1 addition & 0 deletions sentence_generator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import openai
import string
import os

#OpenAI Key
openai.api_key = os.getenv('CHAT_API_KEY')
Expand Down
44 changes: 22 additions & 22 deletions static/js/content/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,29 +85,29 @@ function Dashboard({ userSession }) {
Losses: {userData.losses} games
</p> */}
<table>
<tr>
<th>
Mode
</th>
<th>
WPM
</th>
<th>
Time Limit
</th>
<th>
Date Played
</th>
</tr>
{raceData.map((record, index) => (
<tr key={index}>
<td>{record.selected_mode}</td>
<td>{record.average_wpm}</td>
<td>{record.time_limit}</td>
<td>{record.date_played}</td>
<thead>
<tr>
<th>
Mode
</th>
<th>
WPM
</th>
<th>
Date Played
</th>
</tr>
)
)}
</thead>
<tbody>
{raceData.map((record, index) => (
<tr key={index}>
<td>{record.selected_mode}</td>
<td>{record.average_wpm}</td>
<td>{record.date_played}</td>
</tr>
)
)}
</tbody>
</table>
</section>
</div>
Expand Down
2 changes: 1 addition & 1 deletion static/js/content/HomePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function HomePage(){
Hello World ! <span class="cursor"></span>
<br/>
<br/>
<a href id="homePageButton"><span>Start Here</span></a>
<Link to="/menu" id="homePageButton"><span>Start Here</span></Link>

{/* cloud */}
<div id="clouds3" class="clouds"></div>
Expand Down
12 changes: 10 additions & 2 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ def client():
yield client

# --------------------------------------------------------------------------------App Tests-----------------------------------------------------------------------------

def test_raceData(client):
"""
Test: That the user can retrive race data
Result: True if the response with 200 status code
"""
assert client.post("/raceData/user1").status_code == 200

def test_registration(client):
"""
Expand Down Expand Up @@ -155,7 +160,10 @@ def test_matchmaking(client):
assert response_data=="Matching successful." or response_data=="Match could not be found."

def test_socketio_connection(client):
"""Test SocketIO connection."""
"""
Test SocketIO connection
Result: True if the client can receive messages
"""
sok = App.socketio
# Connect the SocketIO client
socketio_test_client = sok.test_client(App._app)
Expand Down

0 comments on commit ebd6e03

Please sign in to comment.