Giter Site home page Giter Site logo

pyjudge's Introduction

PyJaipur

Please follow the Code of Conduct at all times.

This repo is used to:

Local setup for repo

git clone https://github.com/<your own fork>/PyJaipur
git remote add pyj https://github.com/PyJaipur/PyJaipur

# if you want to use python-poetry
poetry install
poetry shell

# if you want to use vanilla virtualenv
virtualenv -p python3 .venv
source .venv/bin/activate
python -m pip install -r requirements.txt

# To submit changes
# make your changes. Then
git add <files you changed>
git commit -m 'small description of your change'
git push origin master
# now open a Pull request to pyjaipur/master

# To sync your master with pyjaipur
git fetch pyj
git checkout master
git reset --hard pyj/master
git push origin master -f

Changes to this repo are done as follows: - Fork this repo. - Make your changes in your copy of the fork. - Submit a PR to the master branch. - Await discussion / review and then merge. - Sync your repo's master to pyjaipur master

If you want to

Offline backups

  • In case github goes offline, we maintain a backup of all our issues in this repo
  • github-backup -o .backup --issues --issue-comments --issue-events --pulls --pull-comments --pull-details --labels --milestones -R PyJaipur PyJaipur -t <PERSONAL_ACCESS_TOKEN>

Community calls

  • Community calls are every sunday 9 PM
  • Github actions creates calendar events/ updates the website/ creates github issues etc automatically.
  • To trigger manually:
 curl
 -H "Accept: application/vnd.github.everest-preview+json"
 -H "Authorization: token <token>"
 --request POST
 --data '{"event_type": "manual-trigger"}'
 https://api.github.com/repos/PyJaipur/PyJaipur/dispatches

pyjudge's People

Contributors

arnabsinha99 avatar cquark7 avatar dependabot[bot] avatar gauravrock avatar heroichitesh avatar kirtibajaj avatar rishabhkalakoti avatar rohitjain00 avatar rsvarma95 avatar rustagishubhi avatar shivankgtm avatar soumilk avatar ssmita98 avatar surya1231 avatar thesage21 avatar yashj13 avatar

Stargazers

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

Watchers

 avatar

pyjudge's Issues

Interface to add questions via website

Questions are added via the file system right now. We need a mechanism to be able to add them via the web interface.

roadmap for this:

  • finish #117
  • finish #118
  • let anyone add questions. Each question has a "added by" field
  • let anyone create contests by selecting questions. Each contest has a "host"
  • Host has full control over contest settings like start/end time, title, questions to be included.

Avoid file write in user output checking

In the file upload code, the uploaded file is written to filesystem. We can avoid that by simply accessing the string directly using request.files.get('upload').file.read() and comparing that to the expected output.

The expected file is read every time the URL is called. We can read the file once and store the expected string globally and simply use that in the API. Thus the api will have no File read write inside it. Only string comparison.

How to Solve

  • According to bottle docs the FileUpload object has an open file object. Simply read that and obtain a string.
  • Move the expected file reading code outside the URL function code. Maybe somewhere just after the app = Bottle() code. Store the expected string in a variable.
  • In the API, simply read the user string and compare to expected string.

Understanding working with bottle

Bottle is a fast, simple and lightweight WSGI micro web-framework for Python. It is distributed as a single file module and has no dependencies other than the Python Standard Library.

  • Routing: Requests to function-call mapping with support for clean and dynamic URLs.
  • Templates: Fast and pythonic built-in template engine and support for mako, jinja2 and cheetah templates.
  • Utilities: Convenient access to form data, file uploads, cookies, headers and other HTTP-related metadata.
  • Server: Built-in HTTP development server and support for paste, fapws3, bjoern, gae, cherrypy or any other WSGI capable HTTP server.

Issue to fix #17

ISSUE Template

  • This is
    • Feature request
      I am trying to show code to serve css file
  • Description
  • I have applied the appropriate labels for this issue
  • I have provided steps to reproduce the bug (If a bug report)

What all should I solve in a Pull Request?

Sometimes it can be difficult to know what all to solve. Multiple issues can be related to each other and sometimes solving one thing can cause other issues and so on. Here are a few guiding principles. They can be broken, but only if a very good reason is there.

A good reason can be "This PR will fix 100 issues together with 1 line of code".

  • fix only one issue in a PR
  • If many issues are related, submit multiple PRs
  • Try to fill out the PR template to the best of your ability
  • If you know this is a work in progress and are not ready for review yet, use WIP: in the title.

There are other guidelines but they only come into picture once the project is large enough. For now this should be ok.

Record which user uploaded an output

Right now people can upload output and know if it was correct or not. We now need to record who uploaded the output. So, the following changes need to be made:

  • add a username field in the HTML upload form
  • receive the username in the upload API

Install pytest in pipenv

Dependency of pytest module is not present in the Pipfile in branch test. It has to be installed in pipenv if we are using it.

Use template inheritance to reuse code between ranking and question html

The question and ranking HTML both define some common things (like HTML, HEAD, BODY).
We can move the common things into a base.html file and use that in both question.html and rankings.html. See bottle template functions to understand how to do this.

Final folder structure can look like:

.
โ”œโ”€โ”€ css
โ”‚ย ย  โ””โ”€โ”€ styles.css
โ”œโ”€โ”€ files
โ”‚ย ย  โ””โ”€โ”€ questions
โ”‚ย ย      โ”œโ”€โ”€ 1
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ inputs.txt
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ output.txt
โ”‚ย ย      โ”‚ย ย  โ””โ”€โ”€ statement.txt
โ”‚ย ย      โ””โ”€โ”€ 2
โ”‚ย ย          โ”œโ”€โ”€ inputs.txt
โ”‚ย ย          โ”œโ”€โ”€ output.txt
โ”‚ย ย          โ””โ”€โ”€ statement.txt
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ server.py
โ””โ”€โ”€ templates
    โ”œโ”€โ”€ base.html
    โ”œโ”€โ”€ question.html
    โ””โ”€โ”€ ranking.html

Providing the input file for download

A participant must be able to download an input file related to the question. She will then run her program on this input file and produce an output file according to the question's instructions.

The web server must be able to supply this file when the participant asks for it by clicking on the link mentioned in #2

How to solve

  • Fork this project. You can see a Fork button on the top right of this project page.
  • Use the Bottle framework to do this since it's very simple to use. Put your code in a file called server.py
  • Commit your changes and submit a pull request to this project.

Contest timings

There is no concept of contest timings right now.

  • Keep record of when the contest is supposed to start and end (maybe store datetime in the database / question set).
  • make sure that APIs always follow the timings. For example, if time is up then the check api should no longer work.

Multiple contests

Right now our system provides the ability to host a single contest at a time. We need to include the ability to host multiple contests at the same time.

For example, one contest can be a simple practice contest so that people can see how the system works. Then the real contest can start based on the time setting implementation for #103

404 handler

Make a template and handler for requests with invalid urls and return that template whenever FileNotFound is invoked.

A sample question must be written along with sample input and expected output files

We need a sample question. The question statement must be included either in the HTML in #2 or in another file (maybe named statement.txt) and combined with the template feature in the Bottle framework.

A nice question I like is "Given a file which has numbers on every line, generate a file which has the squares of those numbers on corresponding lines"

How to solve

  • Fork this project. You can see a Fork button on the top right of this project page.
  • Use the Bottle framework to do this since it's very simple to use. Put your code in a file called server.py
  • Commit your changes and submit a pull request to this project.

Add tests for the code

As found out in another discussion the project is now big enough that simply reading the code during review does not ensure that it will run.

For starters a simple test file is needed which can run the server and make sure it does not crash. Later on we can add more tests.

Home page

The system needs a home page which describes the judge system and provides answers to common questions.

You'll need to add a new html file in the template system and change the / function in the server.py

User stats/ profile

Statistics based on the submissions done by user.
Features:

  • Submission History
  • Accuracy (Correct Attempts/ Total submissions)
  • Use calendar/ graph to show the frequency of submissions
    Anything else that comes to mind, please add in comments

reading a file when required. discussion needed.

  • **I am submitting this regarding **

    • Bug report
    • Feature request
    • Support request
    • Help request
    • Discussion or tutorial wanted
  • Description of the ISSUE:
    currently, the file is read everytime server is run.
    I want the file to be read only when it's required and someone is uploading his file to be checked.

Ranking / Leaderboard HTML page

An HTML page needs to be written to show the ranking generated in #30

The following information is available

  1. User name
  2. Score of user
  3. Rank of user

Session support

There are two problems with the system right now.

  1. A person should not have to insert their username again and again
  2. If someone solves a question, they have no way of automatically proving that they solved it (someone else could have submitted on their name)

A simple/bare bones solution for this is to have something called a session:

  • ask a person to register/ provide two pieces of information
    • public information = username
    • private information = password
  • then whenever needed, ask them to prove their identity by providing both pieces of info
  • on any api which needs to verify / access user details ask for these pairs

Asking for these pairs again and again becomes irritating very quickly. Instead what we do is:

  • ask them once
  • send them a random number
  • later on they can supply this random number instead of their details and we will know that it's them by looking up in some data structure internally.
  • this number/token exchange thing is carried out using cookies. Thus, the browser handles everything for us

Implementation

  1. login/registration/logout api
  2. login sets a cookie with a random number in the cookie
  3. everyone uses cookies to verify identity by looking up in some data structure (dict maybe?)
  4. logout un-sets the cookie

Multiple questions ability

The system must be able to show multiple questions. Thus the HTML must have a variable part which has the question in it. Refer to Bottle's documentation on the template system. We will be using that.

During attempts also, there must be a field which mentions which question the person is attempting so that the given output can be checked against the correct "expected.txt" file.

Pull request template

Since people are opening pull requests now, it's becoming irritating to manually close issues which the PR solves. A Pull request template will solve this.

Refer to github docs on PR templates and add a template. The template should ask the person to mention the issue that they are trying to solve. Then when the PR is merged, the issue is closed automatically.

Serve the css file for the statement page

The question statement page requires css files. Those files are not served by the server at the moment. We need to provide the css files just like we are providing the inputs for the questions. Maybe we can move both static files like css and input files to a single folder and serve that folder location?

Multiple Ranking Systems

Instead of just one ranking system it would be nice to be able to rank competitors using multiple ranking systems as mentioned in #30

PRs for this issue must include:

  • HTML template to show the rankings
  • python code to generate multiple rankings based on user attempt history

Accepting a participant's output file

We need a place for the participant to upload her program's output. We should be able to accept a plain text file from the form mentioned in #2

On accepting the file, we have to compare it to a known output file and tell the user if the output was correct or not.

How to solve

  • Fork this project. You can see a Fork button on the top right of this project page.
  • Use the Bottle framework to do this since it's very simple to use. Put your code in a file called server.py
  • The expected output file can be saved separately with the name expected_output.txt
  • Commit your changes and submit a pull request to this project.

test

ISSUE Template

  • I am submitting this regarding a :

    • Bug report
    • Feature request
    • Support request
    • Help request
    • Discussion or tutorial wanted
  • Description of the ISSUE :

  • Appropriate Label for this ISSUE would be :

  • If a bug report, then description of the expected and present behaviour :

Database

Our system needs a database system since if we restart the server right now, all attempt information is lost. The simplest system is to use the shelve system provided by python. This would store the data you update on the disk so that the server can be restarted and no information is lost.

You would need to store whatever gets lost whenever the server is restarted, for example the attempt history.

Integrate black into our project

Our project now has some logic code (like the ranking function). Since these functions/computations can be written over multiple lines, code formatting becomes an issue. Different people have different styles of writing the same code.

To make collaboration easier, we don't leave it up to the programmer to select a style. We enforce a style using Black.

To solve this issue, go through the README of the Black project and set it up with the git pre commit hook method as mentioned in this part of the README

Record history of all user's attempts

As users attempt questions, we need to record their attempts somehow. For now, we must store the attempts in a list. The information to store can be username, correct_or_not, question_number

test issue

ISSUE Template

  • I am submitting this regarding a :

    • Bug report
    • Feature request
    • Support request
    • Help request
    • Discussion or tutorial wanted
  • Description of the ISSUE :

  • Appropriate Label for this ISSUE would be :

  • If a bug report, then description of the expected and present behaviour :

Use sqlite as a database

After completing #117 we will have enough amount of data that we need a system to take care of it.

We can use peewee to handle out database.

Things to put in the database:

  • questions
  • contests
  • users
  • scores
  • session information

only static html file no css

ISSUE Template

  • This is a
    • Help request
    • Discussion or tutorial wanted
  • my issue is why running the command python server.py and then http://localhost:8080/question/1 only shows the static HTML page & not CSS because yesterday it was working fine by doing the same.
  • however, I am able to see all the embed CSS in HTML file:///Users/apple/Desktop/project/PyJudge/index.html. but the thing that is not running the project.
    #74

Multiple contest UI design

The UI will need to account for the fact that multiple contests can be hosted at the same time.

Thus #104 will need to change to show multiple contests somehow.

Clean up HTML and CSS

The html in index.html has some CSS classes which are note being used. We need to clean it up. that file also has lots of inline style code. That has to be removed.

Showing the submission page

The web server must show a HTML page which has the following:

  • place to show a question statement
  • link to download the test input data
  • a form to upload their output file

How to solve

  • Fork this project. You can see a Fork button on the top right of this project page.
  • Use the Bottle framework to do this since it's very simple to use. Put your code in a file called server.py
  • Commit your changes and submit a pull request to this project.

Ranking / Leaderboard

A new URL must be written along with corresponding HTML page to display the user's ranking. The ranking must be calculated on some scoring system (for example how many questions have you correctly attempted?).

this ranking must display the user's names and their rank.

Our product is not giving correct output.

  • I am submitting this regarding a:

    • Bug report
  • Description of the ISSUE:
    it's not telling the output correctly. though following part of the code looks good when we see it.

expected = expected.strip()
    uploaded = uploaded.strip()
    ans = (uploaded==expected)
    
    if not ans:
        return "Wrong Answer!!"
    else:
        
        return "Solved! Great Job! "

expected and present behavior

  • I solved the question1 of adding two numbers and submitted on our platform but it's not showing the "Wrong Answer".
  • I should have got "Solved! Great Job".

someone need to look into it and see what's going on.

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.