Skip to content

Commit

Permalink
add notification on last problem:
Browse files Browse the repository at this point in the history
  • Loading branch information
phattd15 committed Nov 26, 2021
1 parent bd038dc commit 71692d1
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 14 deletions.
18 changes: 18 additions & 0 deletions base/migrations/0008_profile_msg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.9 on 2021-11-26 16:57

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('base', '0007_fetchdata'),
]

operations = [
migrations.AddField(
model_name='profile',
name='msg',
field=models.IntegerField(default=0),
),
]
Binary file not shown.
1 change: 1 addition & 0 deletions base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Profile(models.Model):
current_problem = models.CharField(max_length=20, default="Unselected")
deadline = models.DateTimeField(auto_now_add=True)
history = models.CharField(max_length=1000, default="[]")
msg = models.IntegerField(default=0)

def __str__(self):
return self.handle + "|" + self.rating_progress
Expand Down
13 changes: 1 addition & 12 deletions base/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,18 +227,6 @@ def safe_submission(submission):
return True


def validate_registration(handle):
latest_data = get_latest_submissions(handle, 1)

if len(latest_data) > 0 and safe_submission(latest_data[0]):
return (
len(latest_data) > 0
and latest_data[0]["verdict"] == "COMPILATION_ERROR"
and latest_data[0]["problem"]["contestId"] == 1302
and latest_data[0]["problem"]["index"] == "I"
)


def validate_solution(handle, problem_id, deadline):
latest_data = get_latest_submissions(handle, 20)
for submission in latest_data:
Expand Down Expand Up @@ -274,6 +262,7 @@ def parse_problem_id(problem_id):


def apply_rating_change(profile, delta, problem, direct_apply=False):
profile.msg = 1 if delta > 0 else 2
profile.virtual_rating += delta

if direct_apply:
Expand Down
12 changes: 10 additions & 2 deletions base/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def index(request):
context["profile"] = profile
context["graph"] = make_graph(profile.handle, eval(profile.rating_progress))
context["xcolor"] = color_rating_2(profile.virtual_rating)

context["state"] = profile.msg
profile.msg = 0
profile.save()
history = eval(profile.history)

context["history_data"] = []
Expand Down Expand Up @@ -75,6 +77,9 @@ def challenge_list(request):
context = {}
context["user"] = user
context["profile"] = profile
context["state"] = profile.msg
profile.msg = 0
profile.save()
context["challenges"] = get_challenge(
handle,
profile.virtual_rating,
Expand Down Expand Up @@ -229,6 +234,9 @@ def challenge_site(request):
if validate_challenge(profile):
return redirect("list")

profile.msg = 0
profile.save()

contest_id, index = parse_problem_id(profile.current_problem)
problem = Problem.objects.get(contest_id=contest_id, index=index)
color, bg_color = rating_color(problem.rating)
Expand Down Expand Up @@ -311,4 +319,4 @@ def discard(request):

discard_challenge(profile)

return redirect("list")
return redirect("list")
11 changes: 11 additions & 0 deletions templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ <h1 class="display-1">
<p class="h4">Registered users count: {{user_count}}.</p>
</div>
{% else %}
<div class="container">
{% if state == 1 %}
<div class="alert alert-success" role="alert">
Congratulate on solving the last problem!
</div>
{% elif state == 2 %}
<div class="alert alert-warning" role="alert">
You failed the last challenge :( Try harder ?
</div>
{% endif %}
</div>
<div class="container">
<h1 class="display-2">Hello, <a href="https://codeforces.com/profile/{{profile.handle}}" style="text-decoration: none"><span style="color:{{xcolor}}">{{profile.handle}}</span></a>!</h1>
<p> Your rating: <span style="color:{{xcolor}}">{{profile.virtual_rating}}</span></p>
Expand Down
11 changes: 11 additions & 0 deletions templates/list.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
{% extends 'main.html' %}

{% block content %}
<div class="container">
{% if state == 1 %}
<div class="alert alert-success" role="alert">
Congratulate on solving the last problem!
</div>
{% elif state == 2 %}
<div class="alert alert-warning" role="alert">
You failed the last challenge :( Try harder ?
</div>
{% endif %}
</div>
<div class="container">
<h1 class="display-1">
Challenge List
Expand Down

0 comments on commit 71692d1

Please sign in to comment.