Giter Club home page Giter Club logo

lccn_predictor's Introduction

Introduction

This is a LeetCode weekly and biweekly contest rating predictor. The APP is available online at 🔗 lccn.lbao.site

Hopefully, you can get the predicted result within 15-30 minutes after the contest has finished.

Features

  • ⚡️ Fast
    • The core Elo rating algorithm is significantly enhanced by a Just-In-Time (JIT) compiler through Numba, reducing execution time to approximately 20 seconds on a dual-core Intel(R) Xeon(R) Platinum 8255C CPU (@ 2.50GHz).
    • In addition to the JIT implementation, this project incorporates a Fast Fourier Transform (FFT) implementation. The Elo rating system employed by LeetCode benefits significantly from the FFT algorithm, achieving speedups ranging from 65 to 1,000 times for individual contest predictions. The most efficient FFT implementation (EXPAND_SIZE=1) completes predictions in under 0.25 seconds, maintaining an impressively low Mean Squared Error (MSE) of approximately 0.027.
    • Caching the user's latest rating before initiating the prediction process leads to a substantial reduction in the time required for data retrieval.
  • 🎯 Accurate
    • If there were no significant rejudges (assuming everyone's global ranking remains unchanged), it is ensured that the prediction error for rating deltas for EACH participant is within the precision limit of 0.05. As a result, the rating difference should be negligible.
    • Please note that a normal case is that there would be some misconduct detection, so your global ranking will be slightly higher even if your submissions are not rejudged, which results in a slightly higher rating :)
  • 📱 Responsive web page
    • Tested on phones and tablets.

More Information

Underlying Mechanism

Algorithm

Database

Backend

  • APScheduler: background tasks
  • Numpy and Numba: core prediction algorithm implementation and acceleration
  • FastAPI: restful API
  • 🚮 Jinja: HTML templates for server-side rendering

Frontend

Development

Backend Deployment

virtualenv

git clone [email protected]:baoliay2008/lccn_predictor.git
cd lccn_predictor

# write your mongodb environment config
cp config.yaml.template config.yaml
vi config.yaml

python3.10 -m virtualenv venv/
source venv/bin/activate

pip3 install -r requirements.txt

python main.py
uvicorn api.entry:app --host 0.0.0.0 --port 55555

Docker

git clone [email protected]:baoliay2008/lccn_predictor.git
cd lccn_predictor

# write production environment mongodb config
cp config.yaml.template config.yaml
vi config.yaml

# build docker image
docker image build -t lccn_predictor:0.1.2 .

# create docker volume
docker volume create lccn_predictor

# run container
docker run -d -v lccn_predictor:/lccn_predictor -p 55555:55555 --name lp lccn_predictor:0.1.2

docker exec -it lp bash

docker container stop lp

docker container start lp

Frontend Deployment

cd client

# install dependencies
npm install

# change `baseUrl` to your local backend process
vi src/data/constants.js
# if you followed instruction above
# it should be "http://localhost:55555/api/v1"

# local test
npm start

# publish
npm run build

License

MIT License

Changelog

  • v0.0.1(2022/11/14)

    make this repo public, first release.

  • v0.0.2(2022/11/25)

    first version in production

  • v0.1.1(2023/02/14)

    change frontend from server-side rendering(Jinja + Materialize) to client-side rendering(React).

  • v0.1.2(2023/10/04)

    refine backend logic to enhance robustness and clean up deprecated static site rendering code


Supported by

JetBrains Logo (Main) logo

lccn_predictor's People

Contributors

baoliay2008 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

lccn_predictor's Issues

Premature Rating Predictions on lccn.lbao.site

The results of leetcode contests typically require over 15 minutes to account for every participant. However, https://lccn.lbao.site/ consistently predicts ratings before all participants' results are collected. For instance, during today's bi-weekly contest (4/29/2023), the prediction occurred at 11:11:43 AM CDT, but the final participant count was only completed around 11:20 AM. Consequently, the last page of https://lccn.lbao.site/predicted/biweekly-contest-103 displays 12,498 participants, while the actual total was 17,137. This incomplete data leads to inaccurate rating predictions.

Navigating to different page numbers is difficult

On the leetcode contests website, the URL is formatted like weekly-contest-367/ranking/<page_number>. This allows users to skip to a page number they want. On the prediction page, the URL is formatted like /weekly-contest-367/, which gives no page number skipping capabilities.

The only way to navigate through pages on the current site is with the buttons below the ratings, which only allows you to move two pages back or forward (Shown below).
image

This is very inconvenient, as there are hundreds of pages per contest. Could we change the URL routing system or add a button on the page navigator that allows the user to specify which page they would like to navigate to? I would be happy to work on this issue.

Username history is lost

When I click the username textbox
I used to get a popup of previous searched usernames

Today it didn't come up
image

Even after I searched for a username, it does not show up popup of recently searched usernames
image

It is good to show last 50 or so searched usernames, in a drop down with a scroll bar ( previously it used to show only 5 or so )
thank you for your efforts & time.

Plag checker

Every code that has been written by a user, together with the submission time, is stored in our database.
If this website provides a feature that allows us to determine how many times a specific code has been sent, or if that number surpasses a predetermined threshold, we may label it red to indicate that the code has been copied.

We can simply use Plagiarism detection techniques-

  1. Text-Based Plagiarism Detection - Some popular tools include Turnitin, Copyscape, and MOSS (Measure Of Software Similarity).
  2. Code Similarity Algorithms - Libraries like Simian and JPlag are examples.

ML Integration : Train machine learning models to identify code plagiarism. You can use techniques like natural language processing (NLP) and deep learning to analyze and compare code submissions.

Q3 and Q4 of "biweekly contest 97" are on backwards

Problem Description

Currently, Q1-Q4 are sorted by credit at first and then by question_id.

But for "biweekly contest 97", Q3's question_id is bigger than Q4's question_id

db.getCollection('Question').find(
    {"contest_name" : "biweekly-contest-97"}, 
    {title:1, title_slug:1, credit:1, question_id:1, _id:0}
).sort({credit:1, question_id:1})

↩️

/* 1 */
{
    "question_id" : 2639,
    "credit" : 3,
    "title" : "Separate the Digits in an Array",
    "title_slug" : "separate-the-digits-in-an-array"
}

/* 2 */
{
    "question_id" : 2640,
    "credit" : 4,
    "title" : "Maximum Number of Integers to Choose From a Range I",
    "title_slug" : "maximum-number-of-integers-to-choose-from-a-range-i"
}

/* 3 */
{
    "question_id" : 2641,
    "credit" : 5,
    "title" : "Disconnect Path in a Binary Matrix by at Most One Flip",
    "title_slug" : "disconnect-path-in-a-binary-matrix-by-at-most-one-flip"
}

/* 4 */
{
    "question_id" : 2673,
    "credit" : 5,
    "title" : "Maximize Win From Two Segments",
    "title_slug" : "maximize-win-from-two-segments"
}

So, Q3 and Q4 are misplaced.

Screen Shot 2023-02-05 at 00.53.13.png

Observed Time

Sun Feb 5 00:51:31 UTC+8, 2023

Possible Solution

  • 🤔️

Site is Still down.

The Site has been down again. When i try to open it, it gets stuck on loading the page

api 提供的时间问题?

https://lccn.lbao.site/api/v1/contest-records/user?contest_name=weekly-contest-338&username=tian-tang-6 为例

其中 finish_time, insert_time, predict_time 分别代表什么及对应时区是什么?

我大概试了一下时区没对的上

我是需要该竞赛对应的用户开始时间,用户结束时间的数据

[
    {
        "_id": "641fcb550455ebb2feb3c666",
        "contest_name": "weekly-contest-338",
        "contest_id": 843,
        "username": "tian-tang-6",
        "user_slug": "tian-tang-6",
        "country_code": "CN",
        "country_name": "**",
        "rank": 1,
        "score": 18,
        "finish_time": "2023-03-26T02:59:06",
        "data_region": "CN",
        "insert_time": "2023-03-26T04:34:28.298000",
        "attendedContestsCount": 116,
        "old_rating": 3065.1544669116574,
        "new_rating": 3174.170162632678,
        "delta_rating": 109.01569572102062,
        "predict_time": "2023-03-26T04:38:28.557000"
    }
]

Use Cooley-Tukey FFT to accelerate prediction.

During the Elo rating system, calculating $f(x) = \sum \dfrac{1}{1 + 10^{x - R_i}}$ each time in linear complexity is actually a waste of time. By using FFT, we can calculate $f(x)$ for all $x \in \mathbb{Z}$ and $x \in [0, 8000]$.

You can check out here to learn how python make it done. In short, set $g(x)$ as the count of people with a rating $x$, and $h(x) = \dfrac{1}{1 + 10^{x}}$. By computing $g(x)$ and $h(x)\ \ (x \in [-8000,8000])$, we can use a FFT to convolve these two functions, thus calculates $f(x)$.

In Leetcode, I think we can multiply each rating by 10 and round them to integers. The lengths of arrays will be bigger than usual, but the complexity of this algorithm is still perfect. $O(10M \log (10M) + n \log M)$ is way smaller than $O(N^2 \log M)$.

Color in Rank Change (Delta) should be reversed

On the main website change of each rating (delta) has red color shade for positive rating and Green color for negative rating change.
This seems so off , an Improvement should be represented by Green color and decrement in rating with Red.

image

If this seems to be an Issue. Kindly assign this to me.

biweekly-contest-116 ratings not up yet

biweekly-contest-116 ratings not up yet at https://lccn.lbao.site/predicted/biweekly-contest-116
it's been about 2 & 1/2 hours post contest

===

ideally,

1 https://lccn.lbao.site/ should show Biweekly Contest 116 after contest is completed

Currently shows below:
image

2 https://lccn.lbao.site/predicted/biweekly-contest-116
should show proper message of why there is delay
For example: "US Data not present. Check back after few hours", etc.

Currently shows below:
image

===

thanks for your hard work @baoliay2008

not able to start the front end by following read me instructions

I am not able to run the front end of the application. On running the command npm start, I get below error:

  Line 22:   'React' must be in scope when using JSX  react/react-in-jsx-scope
  Line 23:   'React' must be in scope when using JSX  react/react-in-jsx-scope
  Line 24:   'React' must be in scope when using JSX  react/react-in-jsx-scope
  Line 25:   'React' must be in scope when using JSX  react/react-in-jsx-scope
  Line 26:  'React' must be in scope when using JSX  react/react-in-jsx-scope
  Line 27:  'React' must be in scope when using JSX  react/react-in-jsx-scope
  Line 28:  'React' must be in scope when using JSX  react/react-in-jsx-scope
  Line 34:  'React' must be in scope when using JSX  react/react-in-jsx-scope
  Line 40:  'React' must be in scope when using JSX  react/react-in-jsx-scope
  Line 41:  'React' must be in scope when using JSX  react/react-in-jsx-scope
  Line 42:  'React' must be in scope when using JSX  react/react-in-jsx-scope
  Line 42:  'React' must be in scope when using JSX  react/react-in-jsx-scope
  Line 43:  'React' must be in scope when using JSX  react/react-in-jsx-scope
  Line 45:  'React' must be in scope when using JSX  react/react-in-jsx-scope
  Line 49:   'React' must be in scope when using JSX  react/react-in-jsx-scope
  Line 50:   'React' must be in scope when using JSX  react/react-in-jsx-scope

failed to start mongodb

getting this error while executing step number 8 from this..
| ERROR | app.db.mongodb:start_async_mongodb:100 - Failed to start mongodb. error=Authentication failed., full error: {'ok': 0.0, 'errmsg': 'Authentication failed.', 'code': 18, 'codeName': 'AuthenticationFailed'}
pls help
`1-git clone [email protected]:baoliay2008/lccn_predictor.git
2-cd lccn_predictor

write your mongodb environment config

3-cp config.yaml.template config.yaml
4-vi config.yaml

5-python3.10 -m virtualenv venv/
6-source venv/bin/activate

7-pip3 install -r requirements.txt

8-python main.py
9-uvicorn api.entry:app --host 0.0.0.0 --port 55555`

Edge case in prediction algorithm

Today I gave LeetCode biweekly contest, I submitted the last question 30 seconds prior to the end, and the algorithm is most probably not considering my submission for the last question while predicting the delta and the combined rank.

image
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.