Skip to content

Commit

Permalink
fix styling and add middle accept page
Browse files Browse the repository at this point in the history
  • Loading branch information
polarity-ac committed Dec 26, 2021
1 parent 6efc636 commit fdd4f33
Show file tree
Hide file tree
Showing 11 changed files with 437 additions and 211 deletions.
1 change: 1 addition & 0 deletions base/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
path("discard/", views.discard, name="discard"),
path("", views.index, name="home-page"),
path("test/", views.testing, name="test"),
path("confirm/<int:contest_id>/<str:index>/", views.confirm, name="confirm")
]
36 changes: 33 additions & 3 deletions base/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,15 @@ def challenge_list(request):

fd = FetchData.objects.using("problemset").all()

if fd[0].last_update + timedelta(hours=12) < timezone.now():
if fd[0].last_update + timedelta(hours=6) < timezone.now():
update_problemset()

if request.method == "POST":
contest_id = request.POST.get("contest_id")
index = request.POST.get("index")

if represents_int(contest_id):
accept_challenge(profile, int(contest_id), index)
return redirect("challenge")
return redirect("confirm", contest_id=contest_id, index=index)

handle = profile.handle
rating = profile.virtual_rating
Expand Down Expand Up @@ -340,3 +339,34 @@ def discard(request):

def testing(request):
return render(request, "test.html")

def confirm(request, contest_id, index):
if not request.user.is_authenticated:
return redirect("home-page")
contest = Problem.objects.using("problemset").filter(
contest_id=contest_id, index=index
)
if len(contest) == 0:
return redirect("list")
user = request.user
profile = Profile.objects.get(user=user)
if profile.in_progress:
return redirect("challenge")
problem = Problem.objects.using("problemset").get(
contest_id=contest_id, index=index
)
color, bg_color = rating_color(problem.rating)
context = {}
context["problem"] = problem
context["api_is_down"] = not validate_handle(profile.handle)
context["color"] = color
context["bg_color"] = bg_color
context["gain"] = rating_gain(profile.virtual_rating, problem.rating)
context["loss"] = rating_loss(profile.virtual_rating, problem.rating)
context["user"] = request.user
context["profile"] = profile
context["xcolor"] = color_rating_2(problem.rating)
if request.method == 'POST':
accept_challenge(profile, contest_id, index)
return redirect("challenge")
return render(request, "confirm.html", context)
36 changes: 22 additions & 14 deletions templates/challenge.html
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
{% extends 'main.html' %}

{% block content %}
{% extends 'main.html' %} {% block content %}
<div class="container">
<h1 class="display-1">
Current Challenge
</h1>
<div class="alert" style="border-width: 2px; border-color: {{color}}; background-color: {{bg_color}}">
<h1 class="display-1">Current Challenge</h1>
<div
class="alert"
style="border-width: 2px; border-color: {{color}}; background-color: {{bg_color}}"
>
<div class="container">
<a class="btn btn-success btn-lg left-text" style="background-color: {{xcolor}};"
href="https://codeforces.com/contest/{{problem.contest_id}}/problem/{{problem.index}}" target="_blank">
{{ problem }} </a>
<a
class="btn btn-success btn-lg left-text"
style="background-color: {{xcolor}};"
href="https://codeforces.com/contest/{{problem.contest_id}}/problem/{{problem.index}}"
target="_blank"
>
{{ problem }}
</a>
</div>
<div class="container">
<p id="time_left">
Total time left for the challenge: {{minutes}} minutes {{seconds}} seconds.
Total time left for the challenge: {{minutes}} minutes
{{seconds}} seconds.
</p>
<p>
Rating delta: <span class="text-success">{{gain}}</span> | <span class="text-danger">{{loss}}</span>
Rating delta: <span class="text-success">{{gain}}</span> |
<span class="text-danger">{{loss}}</span>
</p>
<p>
Please refresh the page or hit the validate right the moment you got the problem accepted. The page will also refresh the data every 2 minutes.
Please refresh the page or hit the validate right the moment you
got the problem accepted. The page will also refresh the data
every 2 minutes.
</p>
</div>
<div class="container">
Expand Down Expand Up @@ -57,4 +65,4 @@ <h1 class="display-1">
}, 1000);
</script>
</div>
{% endblock content %}
{% endblock content %}
34 changes: 34 additions & 0 deletions templates/confirm.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{% extends 'main.html' %} {% block content %}
<div class="container">
<h1 class="display-1">Choosing Challenge</h1>
<div
class="alert"
style="border-width: 2px; border-color: {{color}}; background-color: {{bg_color}}"
>
<div class="container">
<a
class="btn btn-success btn-lg left-text"
style="background-color: {{xcolor}};"
href="https://codeforces.com/contest/{{problem.contest_id}}/problem/{{problem.index}}"
target="_blank"
>
{{ problem }}
</a>
</div>
<div class="container">
<p>
Rating delta: <span class="text-success">{{gain}}</span> |
<span class="text-danger">{{loss}}</span>
</p>
<p>Please confirm if you are taking this challenge.</p>
</div>
<form method="POST">
{% csrf_token %}
<div class="container">
<input type="submit" class="btn btn-primary" value="Accept" />
<a class="btn btn-warning" href="{% url 'list' %}"> Decline </a>
</div>
</form>
</div>
</div>
{% endblock content %}
128 changes: 84 additions & 44 deletions templates/help.html
Original file line number Diff line number Diff line change
@@ -1,49 +1,89 @@
{% extends 'main.html' %}
{% block content %}
{% extends 'main.html' %} {% block content %}
<div class="container">
<h1 class="display-1">Help & About</h1>
</div>
<div style="text-align: justify; text-justify: inter-word;">
<div class="container">
<p class="h4">What is this site?
</p>
<p>This site helps users that want to do practice and can keep track of their progress through a virtual rating
system. You can assign yourself with an initial rating, do practice based on random suggested problems and
earn a virtual rating through it. This site is inspired by my past training days, which I always wanted to
have something like this to aid my training.</p><hr>
</div>
<div class="container">
<p class="h4">How do I register?</p>
<p> First, you must have a codeforces account. Then, to register for this site you need to show the ownership of
the account by submitting a compile error solution to a certain problem that was required. Please make sure that by the time you
submit the request, CE is the last submission. The process is very similar to the TLE discord bot. </p><hr>
</div>
<div class="container">
<p class="h4">How to submit a compile error?</p>
<p>You can submit a nonsense solution in c++ to that problem.</p><hr>
</div>
<div class="container">
<p class="h4">How to take a challenge?</p>
<p>First, go to the "list" section and pick up a problem of your preference. You can take a brief look at the
problem through the link and can decide whether to take it or not (though I recommend taking it without
peeking). After that, the problem list will be locked and you will have 80 minutes to finish the challenge
at the "challenge" site. If you have the problem accepted, please refresh or reaccess the challenge site to
validate your solution. Please make sure that the last submission is also the accepted one. Or else, when 80
minutes mark passes and you could not solve it or you gave up, your rating will get reduced.</p><hr>
</div>
<div class="container">
<p class="h4">What is my rating progress?</p>
<p>Your rating progress is the initial rating when you registered for this account. And by taking challenges,
your virtual rating will change and you can view the last 30 changes through the graph.</p><hr>
<h1 class="display-1">Help & About</h1>
</div>
<div class="container">
<p class="h4">What is the formula to my rating change?</p>
<p> Incase that you successfully solve the problem, your rating will increases by $$\min(magnitude*10, \lfloor \frac{0.5*magnitude}{\frac{1.15}{1 + 10^{\frac{problem\_rating - user\_rating}{500}}}} \rfloor)$$ Else decreases by $$\min(magnitude*10, \lfloor \frac{0.5*magnitude}{1 - \frac{1}{1 + 10^{\frac{problem\_rating - user\_rating}{500}}}} \rfloor)$$ Here, magnitude is 16, which means if you solve a problem of your own rating range, then solving 7 of it should take you 100 rating above.</p>
<hr>
</div>
<div class="container">
<p class="h4">I forgot my password or want to change the rating level?</p>
<p>Do the same as in the registration process. The site will update your new info.</p>
<div style="text-align: justify; text-justify: inter-word">
<div class="container">
<p class="h4">What is this site?</p>
<p>
This site helps users that want to do practice and can keep
track of their progress through a virtual rating system. You can
assign yourself with an initial rating, do practice based on
random suggested problems and earn a virtual rating through it.
This site is inspired by my past training days, which I always
wanted to have something like this to aid my training.
</p>
<hr />
</div>
<div class="container">
<p class="h4">How do I register?</p>
<p>
First, you must have a codeforces account. Then, to register for
this site you need to show the ownership of the account by
submitting a compile error solution to a certain problem that
was required. Please make sure that by the time you submit the
request, CE is the last submission. The process is very similar
to the TLE discord bot.
</p>
<hr />
</div>
<div class="container">
<p class="h4">How to submit a compile error?</p>
<p>You can submit a nonsense solution in c++ to that problem.</p>
<hr />
</div>
<div class="container">
<p class="h4">How to take a challenge?</p>
<p>
First, go to the "list" section and pick up a problem of your
preference. You can take a brief look at the problem through the
link and can decide whether to take it or not (though I
recommend taking it without peeking). After that, the problem
list will be locked and you will have 80 minutes to finish the
challenge at the "challenge" site. If you have the problem
accepted, please refresh or reaccess the challenge site to
validate your solution. Please make sure that the last
submission is also the accepted one. Or else, when 80 minutes
mark passes and you could not solve it or you gave up, your
rating will get reduced.
</p>
<hr />
</div>
<div class="container">
<p class="h4">What is my rating progress?</p>
<p>
Your rating progress is the initial rating when you registered
for this account. And by taking challenges, your virtual rating
will change and you can view the last 30 changes through the
graph.
</p>
<hr />
</div>
<div class="container">
<p class="h4">What is the formula to my rating change?</p>
<p>
Incase that you successfully solve the problem, your rating will
increases by $$\min(magnitude*10, \lfloor
\frac{0.5*magnitude}{\frac{1.15}{1 + 10^{\frac{problem\_rating -
user\_rating}{500}}}} \rfloor)$$ Else decreases by
$$\min(magnitude*10, \lfloor \frac{0.5*magnitude}{1 - \frac{1}{1
+ 10^{\frac{problem\_rating - user\_rating}{500}}}} \rfloor)$$
Here, magnitude is 16, which means if you solve a problem of
your own rating range, then solving 7 of it should take you 100
rating above.
</p>
<hr />
</div>
<div class="container">
<p class="h4">
I forgot my password or want to change the rating level?
</p>
<p>
Do the same as in the registration process. The site will update
your new info.
</p>
</div>
</div>
</div>
{% endblock content %}
{% endblock content %}
Loading

0 comments on commit fdd4f33

Please sign in to comment.