Skip to content

A simple ball game stats for common players. Including adding players, recording games, rating players, leadership boards and AI grouping by ratings.

Notifications You must be signed in to change notification settings

TalentBoys/BallGameStats

Repository files navigation

RBA Stats - Player Statistics Tracking System

A web application for ordinary basketball enthusiasts who often play together in teams. It can add players, record game results, rating for players, AI groupings, leadership boards.

Since this is for daily playing practice, we won't record advanced data such as individual scores, assists, rebounds, etc. Instead, we will only record the game results. Then, the players will rate each other after the game, and the next time, the groups will be formed based on the ratings.

The project is built with Next.js 14, Tailwind CSS, shadcn/ui, and SAP HANA Cloud. If you want to change the data base to sqlite or other DBs, reach the part Switching to SQLite Database

Features

Homepage

Homepage

Players

Players

Player Details

Player Details Player Details 2

Game Records

Game Records

AI Team Grouping

AI Grouping

Post-Game Player Rating

Rating Players

Leaderboards

Leaderboards Configure Leaderboards

Installation

  1. Clone the repository:
git clone <repository-url>
cd RBAStats
  1. Install dependencies:
npm install
  1. Set up environment variables:
cp .env.example .env.local

Edit .env.local and fill in your credentials:

  • HANA_HOST: Your HANA Cloud instance host
  • HANA_USER: Your HANA database username
  • HANA_PASSWORD: Your HANA database password
  • ADMIN_SECRET: A secure secret string for admin authentication
  1. Run the development server:
npm run dev
  1. Open http://localhost:3000 in your browser

Usage

This is just a simple software designed for ordinary basketball enthusiasts who often play together in teams. Its purpose is to record their performance in each game. The usage is very simple and no special tutorials are required.

Database Schema

The application uses SAP HANA Cloud as the database. Main tables:

  • players: Stores player information and statistics
  • games: Stores game results and scores
  • game_players: Junction table linking players to games and teams
  • player_ratings: Player performance ratings
  • player_tags: Player tags/labels
  • tag_votes: Tag voting records
  • game_share_links: Shareable game links
  • leaderboard_config: Leaderboard configuration

Switching to SQLite Database

If you need to switch to SQLite for local development, you can send the following instructions to an AI assistant:

Please help me add SQLite support to this project. Key changes needed:

  1. Create a database abstraction layer in lib/:

    • db-adapter.js - unified interface
    • db-hana.js - current HANA implementation
    • db-sqlite.js - new SQLite implementation using better-sqlite3
  2. SQL syntax differences to handle:

    • CREATE COLUMN TABLECREATE TABLE
    • NVARCHAR(n)TEXT
    • INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEYINTEGER PRIMARY KEY AUTOINCREMENT
    • HANA uses uppercase table/column names, SQLite is case-insensitive
    • Last insert ID: HANA uses SELECT MAX(ID), SQLite uses last_insert_rowid()
  3. Files that contain direct SQL queries (need to be refactored):

    • lib/db.js - database connection and table creation
    • lib/players.js - player CRUD operations
    • lib/games.js - game CRUD operations
    • app/api/rate-game/[secret]/route.js - rating logic
    • app/api/tags/[tagId]/vote/route.js - tag voting
    • app/api/players/[id]/tags/route.js
    • app/api/players/[id]/comprehensive-rating/route.js
    • app/api/games/[id]/share/route.js
    • app/api/games/[id]/ratings/route.js
    • app/api/leaderboard-config/route.js
  4. Environment variable: Add DB_TYPE=hana|sqlite to switch between databases.

Project Structure

RBAStats/
├── app/
│   ├── api/           # API routes
│   ├── games/         # Games pages
│   ├── players/       # Players pages
│   ├── globals.css    # Global styles
│   ├── layout.js      # Root layout
│   └── page.js        # Home page
├── components/
│   └── ui/            # UI components
├── lib/
│   ├── db.js          # Database setup (HANA Cloud)
│   ├── players.js     # Player queries
│   ├── games.js       # Game queries
│   └── utils.js       # Utility functions
└── .env.local         # Environment variables (not in git)

Authentication

The app includes simple authentication to protect game recording operations.

  • Admin Credential: Set via ADMIN_SECRET environment variable in .env.local
  • Protected Operations: Recording and deleting games, managing leaderboard configuration
  • Public Access: Adding/editing players, viewing all data, rating players via shared links

Security Note: Make sure to use a strong, unique secret for ADMIN_SECRET in production environments.

License

GPL

About

A simple ball game stats for common players. Including adding players, recording games, rating players, leadership boards and AI grouping by ratings.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages