{"id":29878152,"url":"https://github.com/mohammadrezajavid-lab/contributors-leaderboard","last_synced_at":"2026-05-19T10:32:39.099Z","repository":{"id":307084391,"uuid":"1028234423","full_name":"mohammadrezajavid-lab/contributors-leaderboard","owner":"mohammadrezajavid-lab","description":"A real-time, interactive terminal-based leaderboard built with Go, Redis, and RediSearch, designed to track and rank team member contributions across multiple projects and timeframes","archived":false,"fork":false,"pushed_at":"2025-07-29T09:23:42.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-07-29T11:45:02.775Z","etag":null,"topics":["golang","hash","leaderboard","redis","redisearch","redisearch-go","zset"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mohammadrezajavid-lab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-29T08:20:20.000Z","updated_at":"2025-07-29T10:02:21.000Z","dependencies_parsed_at":"2025-07-29T11:45:06.939Z","dependency_job_id":"af6cdd6d-49c2-461d-8eee-c9caeafe93ba","html_url":"https://github.com/mohammadrezajavid-lab/contributors-leaderboard","commit_stats":null,"previous_names":["mohammadrezajavid-lab/contributors-leaderboard"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/mohammadrezajavid-lab/contributors-leaderboard","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohammadrezajavid-lab%2Fcontributors-leaderboard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohammadrezajavid-lab%2Fcontributors-leaderboard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohammadrezajavid-lab%2Fcontributors-leaderboard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohammadrezajavid-lab%2Fcontributors-leaderboard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mohammadrezajavid-lab","download_url":"https://codeload.github.com/mohammadrezajavid-lab/contributors-leaderboard/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohammadrezajavid-lab%2Fcontributors-leaderboard/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268003444,"owners_count":24179290,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-31T02:00:08.723Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","hash","leaderboard","redis","redisearch","redisearch-go","zset"],"created_at":"2025-07-31T07:01:20.064Z","updated_at":"2026-05-19T10:32:39.070Z","avatar_url":"https://github.com/mohammadrezajavid-lab.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Real-Time Leaderboard with Redis \u0026 RediSearch\n\nThis guide demonstrates how to build a **real-time, filterable leaderboard** using:\n\n- **Redis** with `ZSET` and `HASH` data structures\n- **RediSearch** for advanced queries and filtering\n\n---\n\n## Redis Stack Setup (with RediSearch)\n\nRediSearch is not included in the default Redis image. You must use:\n\n- [`redis/redis-stack`](https://hub.docker.com/r/redis/redis-stack) (**Recommended**)\n- [`redislabs/redisearch`](https://hub.docker.com/r/redislabs/redisearch) (Deprecated)\n\n### ➔ Start Redis with Docker Compose\n\n```bash\n  docker compose up -d\n```\n\nAccess Redis UI at: [http://127.0.0.1:8001](http://127.0.0.1:8001)\n\n- Username: _(leave blank)_\n- Password: `password1999`\n\n---\n\n## Running the Project\n\n### 1. Start the TUI (Leaderboard UI)\n\nThis should be launched **before inserting data** to observe leaderboard changes in real time.\n\n```bash\n  go run startLeaderboard.go\n```\n\nYou will see the leaderboard interface in your terminal. Use the following keys:\n\n- `←` / `→` to switch between projects\n- `↑` / `↓` to change timeframes (`week`, `month`, `year`)\n- `PgUp` / `PgDn` to scroll leaderboard vertically\n- `q` to quit\n\n### 2. Insert Sample Data into Redis\n\nOnce the leaderboard UI is running, insert the simulated data:\n\n```bash\n  go run insert.go\n```\n\nThis generates:\n\n- 100 users\n- 5 projects\n- 100,000 contributions across the last year\n\n---\n\n## System Design Overview\n\n### Why use ZSET, HASH, and RediSearch?\n\nFor displaying the necessary leaderboard data, including global rankings over the last week, month, and year, **ZSET**\nis preferred for real-time ranking. This allows us to efficiently maintain a leaderboard across different timeframes.\n\nFor more complex queries and detailed reporting or analytics, **HASH** and **RediSearch** are used. RediSearch allows us\nto:\n\n- Query specific data (e.g., which user contributed on a particular date)\n- Calculate total scores for users within specific timeframes\n- Filter contributions by time period\n- Aggregate and sort data more efficiently\n\nFor example, using RediSearch, we can answer questions like:\n\n1. Which user contributed on a specific date?\n2. What is the total score for a user on a project within a specific date range?\n3. How many contributions were made in the past week?\n4. What is the average score for users on project3?\n\nIn summary:\n\n- **ZSET** is used to display global and per-project leaderboard rankings.\n- **RediSearch** is used for detailed user activity insights, project analysis, and team management.\n\n---\n\n## ZSET Key Structure\n\nEach contribution updates **6 leaderboard keys**:\n\n### Global Leaderboard Keys\n\n```\nleaderboard:global:{timeframe}:{period}\n```\n\nExample:\n\n```\nleaderboard:global:week:2025-W31\n```\n\n### Per-Project Leaderboard Keys\n\n```\nleaderboard:{project}:{timeframe}:{period}\n```\n\nExample:\n\n```\nleaderboard:project2:month:2025-07\n```\n\n---\n\n## HASH Key Structure for Contributions\n\nEach contribution is stored in 3 `HASH` records (week/month/year):\n\n```\nuser:{project}:{timeframe}:{period}:{user_id}:{contrib_id}\n```\n\nExample:\n\n```\nuser:project1:year:2025:user9:contrib000001\n```\n\nEach hash contains:\n\n- `user_id`\n- `project`\n- `score`\n- `timeframe`, `period`\n- `contribute_id`\n\n---\n\n## Create RediSearch Index\n\n```bash\n  FT.CREATE contrib_idx ON HASH PREFIX 1 \"user:\" SCHEMA \\\n    project TAG SEPARATOR , \\\n    user_id TAG SEPARATOR , \\\n    timeframe TAG \\\n    period TEXT \\\n    score NUMERIC SORTABLE\n```\n\n---\n\n## Query Examples\n\n### 1. Get Global Rankings (ZSET)\n\n```bash\n  ZREVRANGE leaderboard:global:month:2025-07 0 -1 WITHSCORES\n```\n\n### 2. Get Project Rankings\n\n```bash\n  ZREVRANGE leaderboard:project2:year:2025 0 -1 WITHSCORES\n```\n\n### 3. Get Rank or Score of a User\n\n```bash\n  ZREVRANK leaderboard:global:week:2025-W31 user23\n  ZSCORE leaderboard:project3:month:2025-07 user23\n```\n\n---\n\n## RediSearch Aggregations\n\n### 1. Total Contributions Last Week\n\n```bash\n  FT.AGGREGATE contrib_idx \"@timeframe:{week}\" GROUPBY 0 REDUCE COUNT 0 AS total_contributions\n```\n\n### 2. Average Score in Project3\n\n```bash\n  FT.AGGREGATE contrib_idx \"@project:{project3}\" GROUPBY 0 REDUCE AVG 1 @score AS avg_score\n```\n\n### 3. Top Projects by Total Score\n\n```bash\n  FT.AGGREGATE contrib_idx \"*\" \\\n    GROUPBY 1 @project \\\n    REDUCE SUM 1 @score AS total_score \\\n    SORTBY 2 @total_score DESC\n```\n\n---\n\nThis design ensures your leaderboard system is **real-time**, **filterable**, and **scalable** across teams and\ntimeframes.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohammadrezajavid-lab%2Fcontributors-leaderboard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmohammadrezajavid-lab%2Fcontributors-leaderboard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohammadrezajavid-lab%2Fcontributors-leaderboard/lists"}