Skip to content

Commit

Permalink
changed underlying data structures
Browse files Browse the repository at this point in the history
  • Loading branch information
Giantpizzahead committed Aug 8, 2020
1 parent 16b5d85 commit 7985546
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 23 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion TODOs.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## TODOs (pre-V1)
- Make a logo for JudgeLite
- Update the wiki / add documentation
- Update the wiki / README / add documentation
- Continue getting feedback from people
- Make some stronger tests

Expand Down
26 changes: 16 additions & 10 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@ def favicon():
return send_from_directory('media', 'favicon.ico', mimetype='image/vnd.microsoft.icon')


@app.route('/media/particles.mp4', methods=['GET'])
def media_particles():
return send_from_directory('media', 'particles.mp4', mimetype='video/mp4')


@app.route('/', methods=['GET'])
def show_index():
timestamp = pytz.timezone('US/Pacific').localize(datetime.now())
timestamp = datetime.now(tz=pytz.utc).astimezone(pytz.timezone('US/Pacific'))
timestamp = timestamp.strftime("%m/%d/%Y %I:%M %p")
return render_template('index.html', num_problems=get_num_problems(), num_submissions=redis_get_num_submissions(),
curr_time=timestamp)
Expand All @@ -58,16 +63,17 @@ def show_submission_list():
num_pages=(redis_get_num_submissions() + PAGE_SIZE - 1) // PAGE_SIZE)


@app.route('/submission_details/<i>', methods=['GET'])
def show_submission_details(i):
@app.route('/submission_details', methods=['GET'])
def show_submission_details():
if 'job_id' not in request.args:
return json_error('No job id provided!')
try:
Job.fetch(request.args['job_id'], connection=REDIS_CONN)
except NoSuchJobError:
return json_error('Job not found!')
return render_template('submission_details.html', submission_source=_get_submission_source(i),
submission=redis_get_submission(i), job_id=request.args['job_id'])
job_id = request.args['job_id']
return render_template('submission_details.html', submission_source=_get_submission_source(job_id),
submission=redis_get_submission(job_id), job_id=job_id)


@app.route('/view_problem/<problem_id>', methods=['GET'])
Expand Down Expand Up @@ -172,18 +178,18 @@ def _get_submissions(page=1):
return redis_get_submissions(page)


@app.route('/api/get_submission_source/<i>', methods=['GET'])
@app.route('/api/get_submission_source/<job_id>', methods=['GET'])
@cross_origin()
def get_submission_source(i):
def get_submission_source(job_id):
if 'secret_key' not in request.args:
return 'Missing secret key in GET parameters!'
elif request.args['secret_key'] != SECRET_KEY:
return 'Invalid secret key!'
return _get_submission_source(i)
return _get_submission_source(job_id)


def _get_submission_source(i):
source_code = redis_get_submission_source(i)
def _get_submission_source(job_id):
source_code = redis_get_submission_source(job_id)
if source_code is None:
return 'Invalid submission index!'
else:
Expand Down
21 changes: 13 additions & 8 deletions manage_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,34 @@


def redis_add_submission(problem_id: str, username: str, score: float, job_id: str, source_code: str, verdict: str):
timestamp = pytz.timezone('US/Pacific').localize(datetime.now())
timestamp = datetime.now(tz=pytz.utc).astimezone(pytz.timezone('US/Pacific'))
timestamp = timestamp.strftime("%m/%d/%Y %I:%M:%S %p")
submission_json = json.dumps({'problem_id': problem_id, 'username': username, 'score': score, 'job_id': job_id,
'verdict': verdict, 'timestamp': timestamp})
REDIS_CONN.lpush('submissions', submission_json)
REDIS_CONN.lpush('submission_source', source_code)
REDIS_CONN.rpush('submissions', submission_json)
REDIS_CONN.rpush('submission_source', source_code)
REDIS_CONN.set('submission_index:{}'.format(job_id), redis_get_num_submissions() - 1)


def redis_get_submissions(page=1):
submissions = REDIS_CONN.lrange('submissions', (page-1) * PAGE_SIZE, page * PAGE_SIZE)
submissions = REDIS_CONN.lrange('submissions', -(page * PAGE_SIZE), -(page-1) * PAGE_SIZE - 1)[::-1]
for i in range(len(submissions)):
submissions[i] = json.loads(submissions[i])
return submissions


def redis_get_submission(i):
submission = REDIS_CONN.lindex('submissions', i)
def redis_get_submission(job_id):
submission = REDIS_CONN.lindex('submissions', redis_get_index_from_id(job_id))
submission = json.loads(submission)
return submission


def redis_get_submission_source(i):
return REDIS_CONN.lindex('submission_source', i)
def redis_get_submission_source(job_id):
return REDIS_CONN.lindex('submission_source', redis_get_index_from_id(job_id))


def redis_get_index_from_id(job_id):
return REDIS_CONN.get('submission_index:{}'.format(job_id))


def redis_get_num_submissions():
Expand Down
5 changes: 3 additions & 2 deletions static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ h2 {
font-weight: bold;
overflow-wrap: anywhere;
background-color: white;
z-index: -2;
}

.submission-result-compile-error {
Expand All @@ -210,7 +209,7 @@ h2 {
width: 0%;
height: 100%;
background-color: #f4f4f4;
z-index: -1;
z-index: 1;
transition: width 0.6s ease;
}

Expand All @@ -235,6 +234,7 @@ h2 {
#submission-result-box .status-text {
margin: 5px 7px 5px 5px;
text-align: center;
z-index: 2;
}

#submission-result-box .loader {
Expand All @@ -260,6 +260,7 @@ h2 {

#submission-result-box .tooltip-no-underline {
text-decoration: none;
z-index: 2;
}

#submission-result-box .test-result {
Expand Down
2 changes: 1 addition & 1 deletion templates/api_reference.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ <h3>No Key Required</h3>
<h3>Secret Key Required</h3>
<p><a href="/api/submit">Submit Code to JudgeLite</a></p>
<p><a href="/api/get_submissions/1">Get Evaluated Submissions (change 1 to desired page #)</a></p>
<p><a href="/api/get_submission_source/0">Get Evaluated Submission Source (change 0 to desired index)</a></p>
<p><a href="/api/get_submission_source/job_id">Get Evaluated Submission Source (change job_id to desired job ID)</a></p>
{% endblock %}
4 changes: 3 additions & 1 deletion templates/submission_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h1>Submission List</h1>
</thead>
<tbody>
{% for submission in submissions %}
<tr onclick="window.location='submission_details/{{ loop.index0 }}?job_id={{ submission["job_id"] }}';"
<tr onclick="window.location='submission_details?job_id={{ submission["job_id"] }}';"
{{ 'class=submission-pass' if submission["verdict"] == "AC" else
'class=submission-bonus' if submission["verdict"] == "AC*" else ''}}>
<td>{{ submission["username"] }}</td>
Expand All @@ -32,4 +32,6 @@ <h1>Submission List</h1>
<a href="/submission_list?page={{ [num_pages, page + 1] | min }}">&gt;</a>
<a href="/submission_list?page={{ num_pages }}">&gt;&gt;</a>
</div>

<br>
{% endblock %}

0 comments on commit 7985546

Please sign in to comment.