Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ target/
# IPython
profile_default/
ipython_config.py
fir-nik-3c5c6-firebase-adminsdk-fbsvc-3e2bdebf87.json

# pyenv
# For a library or package, you might want to ignore these files since the code is
Expand Down
21 changes: 12 additions & 9 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from flask import Flask, render_template, request, jsonify, redirect, url_for, session
import random
import database
import nltk
from nltk.metrics.distance import edit_distance

app = Flask(__name__)
app.secret_key = 'shashisingh8434thissamplesecret'
Expand All @@ -22,19 +24,20 @@ def home():

@app.route('/submit', methods=['POST'])
def submit():
typed_text = request.json['typedText']
passage = request.json['passage']
typed_text = request.json['typedText'].strip()
passage = request.json['passage'].strip()
time_taken = request.json['timeTaken']

# Calculate WPM
words = len(typed_text.split())
wpm = (words / time_taken) * 60 if time_taken > 0 else 0
typed_words = typed_text.split()
passage_words = passage.split()
correct_words = sum(1 for tw, pw in zip(typed_words, passage_words) if tw == pw)
wpm = (correct_words / time_taken) * 60 if time_taken > 0 else 0

# Calculate accuracy
correct_chars = sum(1 for a, b in zip(typed_text, passage) if a == b)
accuracy = (correct_chars / len(passage)) * 100 if len(passage) > 0 else 0
distance = edit_distance(typed_text, passage)
max_length = max(len(typed_text), len(passage))
accuracy = ((max_length - distance) / max_length) * 100 if max_length > 0 else 0

return jsonify({'wpm': wpm, 'accuracy': accuracy})
return jsonify({'wpm': round(wpm, 2), 'accuracy': round(accuracy, 2)})

@app.route("/login", methods=['GET', 'POST'])
def login():
Expand Down
Binary file modified requirements.txt
Binary file not shown.