|
| 1 | +<!-- markdownlint-disable MD033 --> |
| 2 | + |
| 3 | +<h1 align="center"> |
| 4 | + <a href="https://github.com/SysSn13/leetcode-rating-predictor"> |
| 5 | + <img src="./data/screenshots/icon.png" alt="Logo" width="125" height="125" style="background:white"> |
| 6 | + </a> |
| 7 | +</h1> |
| 8 | + |
| 9 | +<div align="center"> |
| 10 | + <h3>LC Predictor</h3> |
| 11 | + Want to see your leetcode rating change right after the contest? Well, you are in the right place! |
| 12 | + <br /> |
| 13 | + <br /> |
| 14 | +</div> |
| 15 | + |
| 16 | +<br /> |
| 17 | +<div align="center"> |
| 18 | + <a href="https://chrome.google.com/webstore/detail/lc-predictor/jfhgaegpgiepniiebglgjhhfnjcibphh"><img |
| 19 | + src="https://i.imgur.com/iswHnpJ.png" alt="Chrome Web Store" height="50"> |
| 20 | + </img> |
| 21 | + </a> |
| 22 | +</div> |
| 23 | + |
| 24 | +<div align="center"> |
| 25 | + <a href="https://github.com/SysSn13/leetcode-rating-predictor/blob/main/LICENSE"><img |
| 26 | + src="https://img.shields.io/badge/license-MIT-blue.svg" alt="license" /></a> |
| 27 | + <a href="https://github.com/SysSn13/leetcode-rating-predictor/graphs/contributors" alt="Contributors"> |
| 28 | + <img src="https://img.shields.io/github/contributors/SysSn13/leetcode-rating-predictor" /> |
| 29 | + </a> |
| 30 | + <a href="https://chrome.google.com/webstore/detail/leethub/aciombdipochlnkbpcbgdpjffcfdbggi"><img |
| 31 | + src="https://img.shields.io/chrome-web-store/v/jfhgaegpgiepniiebglgjhhfnjcibphh.svg" alt="chrome-webstore" /></a> |
| 32 | + |
| 33 | +</div> |
| 34 | +<br /> |
| 35 | + |
| 36 | +# About |
| 37 | + |
| 38 | +It takes about 4-5 days for leetcode to update the contest ratings of participants. So you have to wait for a long time to know your rating changes. This application predicts accurate leetcode rating changes for all the contestants within a few minutes of completion of the contest. |
| 39 | + |
| 40 | +# Getting started |
| 41 | + |
| 42 | +This project consists of two types of user interfaces. You can either use browser extension or the website to get your rating changes. |
| 43 | + |
| 44 | +## Chrome extension |
| 45 | + |
| 46 | +You can install the extension from [Chrome Web Store](https://chrome.google.com/webstore/detail/lc-predictor/jfhgaegpgiepniiebglgjhhfnjcibphh). It adds the rating changes on leetcode ranking pages itself. |
| 47 | + |
| 48 | +<div align="center"> |
| 49 | + <img src="./data/screenshots/extension_demo.gif" alt="extension preview"> |
| 50 | +</div> |
| 51 | + |
| 52 | +## Website |
| 53 | + |
| 54 | +You can also visit [lcpredictor.herokuapp.com](https://lcpredictor.herokuapp.com/) to get your rating changes. |
| 55 | + |
| 56 | +<div align="center"> |
| 57 | + <img src="./data/screenshots/web_demo.gif" alt="website preview"> |
| 58 | +</div> |
| 59 | + |
| 60 | +# How It Works |
| 61 | + |
| 62 | +This project is written in Node + MongoDB + Redis tech stack. We can divide it into three microservices. |
| 63 | + |
| 64 | +| # | Name | Languages | |
| 65 | +| :-: | :--------: | :-------: | |
| 66 | +| 1. | Background | Js, Cpp | |
| 67 | +| 2. | Website | Js, Ejs | |
| 68 | +| 3. | API | Js | |
| 69 | + |
| 70 | +## Backgound |
| 71 | + |
| 72 | +It is the most important part of the project. It's job is to fetch the data from leetcode and predict the contest ratings periodically. |
| 73 | + |
| 74 | +### Rating prediction |
| 75 | + |
| 76 | +Rating prediction is a cpu intensive task. Therefore a [**nodejs C++ addon**](https://nodejs.org/api/addons.html) is implemented for this task so that we can utilize threading with better performance using **C++**. For performance measurement we got these results : |
| 77 | + |
| 78 | +| | No. of Threads | Contest | Time taken to make predictions(s) | |
| 79 | +| :-------: | :------------: | :----------------: | :-------------------------------: | |
| 80 | +| Js | 1 | Weekly contest 242 | 186.589 | |
| 81 | +| C++ addon | 1 | Weekly contest 242 | 39.607 | |
| 82 | +| C++ addon | 2 | Weekly contest 242 | 19.963 | |
| 83 | +| C++ addon | 4 | Weekly contest 242 | 11.401 | |
| 84 | +| C++ addon | 8 | Weekly contest 242 | 20.304 | |
| 85 | + |
| 86 | +#### Machine configuration : |
| 87 | + |
| 88 | +| Property | Value | |
| 89 | +| :-------- | :-------------------------------------- | |
| 90 | +| Processor | Intel® Core™ i5-8250U CPU @ 1.60GHz × 8 | |
| 91 | +| Memory | 7.7 GB | |
| 92 | +| OS | Ubuntu 21.04 | |
| 93 | + |
| 94 | +It implements leetcode's latest rating prediction algorithm. Rating predictions are very close to the original rating but the accuracy may not be 100% due to changes in contest rankings after the completion of contest (leetcode rejudges some submissons). |
| 95 | + |
| 96 | +These are the results for the predictions of weekly-contest-242: |
| 97 | + |
| 98 | +| Measure | Value | |
| 99 | +| :-------: | :----------------: | |
| 100 | +| MSE | 167.7947072739485 | |
| 101 | +| R-squared | 0.9988091420057561 | |
| 102 | + |
| 103 | +### Job scheduling |
| 104 | + |
| 105 | +Job scheduling is required for processing jobs on desired time. Leetcode contests are weekly and biweekly. We can schedule them by scheduling a repeated job. But for making it more generic, job schedulers are implemented who schedules prediction and data update jobs. These job schedulers are scheduled as a repeated job. It is accomplished by using [bull](https://github.com/OptimalBits/bull), a redis based queue for Node. A bull dashboard is also integrated using [bull-board](https://github.com/felixmosh/bull-board). |
| 106 | + |
| 107 | +<div align="center"> |
| 108 | + <img src="./data/screenshots/bull-dashboard1.png" alt="bull dashboard"> |
| 109 | + <img src="./data/screenshots/bull-dashboard2.png" alt="bull dashboard"> |
| 110 | +</div> |
| 111 | + |
| 112 | +## Website |
| 113 | + |
| 114 | +It is built using [express](https://expressjs.com/) framework. Ejs is used for writing templates. It contains a table for contests and ranking pages with predicted rating changes for all the contests. Pagination is added to ranking pages for better user experience and performace. |
| 115 | + |
| 116 | +## API |
| 117 | + |
| 118 | +It is also implemented using [express](https://expressjs.com/) framework. It contains an endpoint for fetching users' |
| 119 | +predicted rating changes which is used in the browser extension. |
| 120 | + |
| 121 | +IP based rate limit is enforced for both the API and the website using [express-rate-limit](https://github.com/nfriedly/express-rate-limit). |
| 122 | + |
| 123 | +# Development |
| 124 | + |
| 125 | +## Setup |
| 126 | + |
| 127 | +- Clone the repository |
| 128 | + ```bash |
| 129 | + git clone https://github.com/SysSn13/leetcode-rating-predictor |
| 130 | + ``` |
| 131 | +- Install the dependencies |
| 132 | + ```bash |
| 133 | + npm install |
| 134 | + ``` |
| 135 | +- Setup environment variables |
| 136 | + |
| 137 | + ```bash |
| 138 | + cp .env.example .env |
| 139 | + ``` |
| 140 | + |
| 141 | + Fill in the required values in the `.env` file. |
| 142 | + |
| 143 | +- Build the predict-addon (if you are using different node version) |
| 144 | + ```bash |
| 145 | + npm run buildAddon |
| 146 | + ``` |
| 147 | +- Start the project |
| 148 | + ```bash |
| 149 | + npm start |
| 150 | + ``` |
| 151 | +- Or start the development server by: |
| 152 | + ```bash |
| 153 | + npm run dev |
| 154 | + ``` |
| 155 | + |
| 156 | +## Environment variables |
| 157 | + |
| 158 | +``` |
| 159 | +DATABASE_URL: Connection string for mongodb. |
| 160 | + |
| 161 | +# for web |
| 162 | +WEB: Whether to run the website or not. (0 or 1) |
| 163 | + |
| 164 | +RATE_LIMIT_WINDOW: Window size for rate limit in milliseconds (default: 10000). |
| 165 | + |
| 166 | +RATE_LIMIT: Number of requests allowed in the window (default: 50). |
| 167 | + |
| 168 | + |
| 169 | +# for api |
| 170 | +API_DISABLED: Whether to disable the API or not. (0 or 1) |
| 171 | + |
| 172 | +API_RATE_LIMIT_WINDOW: Window size for API rate limit in milliseconds (default: 10000). |
| 173 | + |
| 174 | +API_RATE_LIMIT: Number of API requests allowed in the window (default: 20). |
| 175 | + |
| 176 | + |
| 177 | +# for background |
| 178 | +BACKGROUND: Whether to run the background or not. (0 or 1) |
| 179 | + |
| 180 | +REDIS_URL: Connection string for redis. |
| 181 | + |
| 182 | +THREAD_CNT: Number of threads for prediction.(default: 4) |
| 183 | +``` |
| 184 | +
|
| 185 | +## Browser extension |
| 186 | +
|
| 187 | +Current only chrome browser is suported. It uses manifest V3. See [this](https://developer.chrome.com/docs/extensions/mv3/getstarted/) for getting started with extension development. Source code for the extension is in `./chrome-extension`. |
| 188 | +
|
| 189 | +## Contributing |
| 190 | +
|
| 191 | +You can contribute by creating issues, feature/ pull requests. Any meaningful contributions you make are greatly appreciated. |
| 192 | +
|
| 193 | +For contributing in the source code, please follow these steps: |
| 194 | +
|
| 195 | +- Fork the Project |
| 196 | +- Create your new Branch |
| 197 | + ```bash |
| 198 | + git checkout -b feature/AmazingFeature |
| 199 | + ``` |
| 200 | +- Commit your Changes |
| 201 | + ``` |
| 202 | + git commit -m 'Add some AmazingFeature' |
| 203 | + ``` |
| 204 | +- Push to the Branch |
| 205 | + ``` |
| 206 | + git push origin feature/AmazingFeature |
| 207 | + ``` |
| 208 | +- Open a Pull Request |
| 209 | +
|
| 210 | +# License |
| 211 | +
|
| 212 | +Distributed under the MIT License. See [LICENSE](/LICENSE) for more information. |
0 commit comments