Skip to content

Database for storing stats #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Magic-JD
Copy link

@Magic-JD Magic-JD commented Jun 2, 2025

Hello there, I have been really enjoying this tool, I came across it on reddit. I mentioned in the thread that I though that adding stats so you can see your max speed and accuracy would be good - and I have added that feature to my fork. I don't know if this is something that you would want to implement yourself, but in case it is helpful, I thought I would submit a pull request with my changes.

Here's a summary of the changes:

  1. New database Package: I've introduced a new internal/database package to handle database operations. This package manages a single SQLite database connection that initializes on its first use and persists for the application's lifetime.
  2. The SQLite database will be placed in the users OS appropriate directory in a typtea folder,
  3. Stats Table: A new stats table is created within the SQLite database, storing each session's wpm, accuracy, and an added_at timestamp. While the timestamp isn't currently displayed, it's included for potential future features like historical graphs or detailed progress tracking.
  4. Max Stats Calculation: The typing.go file now queries this database to retrieve and display the user's best WPM and best Accuracy directly on the results screen.
  5. UI Integration: The view.go has been updated to show the new "Best WPM" and "Best Accuracy" alongside the current session's results.

There are a couple of issues that might be worth considering but I wanted to get feedback before making further changes, as they are a little more complex to integrate:

  1. Is it valuable to store the language in the db as well? Should the Best WPM be for a specific language or across all languages?
  2. Would it be useful to add a config where the user can configure if they see this information?

Thanks again for creating this! Let me know if you want any changes or if you would rather leave this feature for now.

@ashish0kumar
Copy link
Owner

Hey Joseph,

Thanks a ton for the PR! I really appreciate you taking the time to add the stats feature and explain your approach so clearly.

I’ve thought about this a bit, and for now I’m trying to keep typtea as minimal and stateless as possible, just something you can run anywhere without worrying about files or setup. I totally get the appeal of tracking stats (and your implementation looks solid too!), but I think I’ll hold off on adding a database for now to keep things simple for everyone.

That said, your feature is really valuable for users who want to track their stats, so I’m going to keep this PR open as a reference. If anyone is interested in persistent stats, they can check out your fork and this pull request.

Really appreciate your contribution and the effort you put in!

@Magic-JD
Copy link
Author

Magic-JD commented Jun 3, 2025

No problem! I'll watch your project and keep the fork up to date, thanks for taking the time to reply and update

@elbachir-one
Copy link
Contributor

elbachir-one commented Jun 3, 2025

You can rebase and squash the two commits 24c5a09 and 6328fa3 into a single commit. It would be better to keep the database on a separate branch instead of the main branch. If any issues arise, you can fix them pretty easily. And one more thing — don't update the main branch when you have other commits that haven't been merged yet.

@Magic-JD Magic-JD force-pushed the database_connection branch 2 times, most recently from d80baa9 to 76acefa Compare June 4, 2025 07:50
@Magic-JD Magic-JD closed this Jun 4, 2025
@Magic-JD Magic-JD force-pushed the database_connection branch from 76acefa to 013646b Compare June 4, 2025 07:55
@Magic-JD Magic-JD reopened this Jun 4, 2025
@Magic-JD Magic-JD force-pushed the database_connection branch from fef8553 to cc09e8e Compare June 4, 2025 08:12
@Magic-JD Magic-JD closed this Jun 4, 2025
@Magic-JD Magic-JD force-pushed the database_connection branch from 46f12dc to a18d3a8 Compare June 4, 2025 08:16
@Magic-JD Magic-JD reopened this Jun 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants