Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add participant progress bar #2234

Merged
merged 33 commits into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4261e47
hack first version of participant progress bar
Kakadus Jun 28, 2024
721c8fc
PR review
richardebeling Jun 30, 2024
58a3ed0
Cleanup
richardebeling Jun 30, 2024
919ca05
Show correct last vote time
richardebeling Jun 30, 2024
c0c47f2
Tests, edge case handling
richardebeling Jun 30, 2024
24e5384
Fix test failure due to missing setting
richardebeling Jun 30, 2024
ca45744
More edge case handling
richardebeling Jun 30, 2024
9bfe80f
Apply suggestions from code review
richardebeling Jul 1, 2024
4595ff6
refactor GlobalRewards a bit
Kakadus Jul 1, 2024
5da3004
migrate to Fraction
Kakadus Jul 1, 2024
5893423
add test to test correct rounding of 0.07
Kakadus Jul 1, 2024
92c92cf
add test to test correct rounding of 0.07 v2
Kakadus Jul 1, 2024
a26abe9
test against float128
Kakadus Jul 1, 2024
f9fd312
fixup! add test to test correct rounding of 0.07 v2
Kakadus Jul 1, 2024
4a765c2
fixup! fixup! add test to test correct rounding of 0.07 v2
Kakadus Jul 1, 2024
b03517f
nice UI :)
janno42 Jul 1, 2024
d56dba6
removed unused code
janno42 Jul 1, 2024
1af51ee
Uniform naming
richardebeling Jul 1, 2024
7946709
extract student_global_reward.html page
Kakadus Jul 1, 2024
bb4e6a9
remove useless div
Kakadus Jul 2, 2024
e4f944c
replace inlinestyle with classes
Kakadus Jul 2, 2024
0be6bd5
introduce left-percent- and replace last inline style
Kakadus Jul 2, 2024
10b8ea3
Fix indentationl. Consistent long-line formatting (we ignore 120-char…
richardebeling Jul 3, 2024
6ce12d6
Remove unused variable
richardebeling Jul 3, 2024
404d2f3
Pluralization
richardebeling Jul 3, 2024
f81b1ef
Update tests
richardebeling Jul 3, 2024
06a65cb
Linting
richardebeling Jul 3, 2024
2562661
Update evap/static/scss/components/_progress.scss
janno42 Jul 6, 2024
e58d700
Update evap/student/tests/test_views.py
janno42 Jul 6, 2024
fa82909
Update evap/student/templates/student_global_reward.html
janno42 Jul 6, 2024
da420d2
use custom percentage filter
janno42 Jul 6, 2024
8581fac
linter
janno42 Jul 6, 2024
608ae30
Update evap/evaluation/templatetags/evaluation_filters.py
janno42 Jul 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions evap/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,17 @@ class ManifestStaticFilesStorageWithJsReplacement(ManifestStaticFilesStorage):
# Absolute filesystem path to the directory that will hold user-uploaded files.
MEDIA_ROOT = os.path.join(BASE_DIR, "upload")

### Evaluation progress rewards
GLOBAL_EVALUATION_PROGRESS_REWARDS: list[tuple[float, str]] = [
(0, "0€"),
(0.25, "1.000€"),
(0.6, "3.000€"),
(0.7, "7.000€"),
(0.9, "10.000€"),
]
EXCLUDED_COURSE_TYPE_IDS: list[int] = []
EXCLUDED_EVALUATION_IDS: list[int] = []
richardebeling marked this conversation as resolved.
Show resolved Hide resolved
PARTICIPANT_PROGRESS_TEXT = "Deine Teilnahme am Evaluationsprojekt wird helfen. Evaluiere also <b>jetzt</b>!"
richardebeling marked this conversation as resolved.
Show resolved Hide resolved

### Slogans
SLOGANS_DE = [
Expand Down
33 changes: 33 additions & 0 deletions evap/student/templates/student_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,40 @@
</div>
</div>
{% endif %}
{% if global_progress_rewards %}
<div class="card mb-3">
<div class="card-header">Nächstes Spendenziel: {{ next_reward }}</div>
richardebeling marked this conversation as resolved.
Show resolved Hide resolved
<div class="card-body">
<div>
noch {{ remaining_votes }} Evaluierungen benötigt
</div>

<div class="position-relative d-grid py-2 px-4">
<span class="progress-container d-flex" style="height: 25px; grid-column-start: 1; grid-row-start: 1">
<span class="progress m-0 bg-info">
<span class="progress-bar progress-bar-striped progress-bar-animated bg-success width-percent-{% widthratio num_total_votes final_goal 100 %}"></span>
richardebeling marked this conversation as resolved.
Show resolved Hide resolved
<span class="progress-bartext">
{{ num_total_votes }}/{{ final_goal }}
</span>
</span>
</span>
{% for ratio, global_ratio, tag in global_progress_rewards %}
<div class="position-relative "
style="left: {% widthratio ratio 1 100 %}%; transform: translateX(-50%); width: fit-content;grid-column-start: 1; grid-row-start: 2">
<div style="width: fit-content">
<div class="text-center">|</div>
<div class="text-lg-center fw-semibold">{{ tag }}</div>
<div class="text-center">bei {% widthratio global_ratio 1 100 %}%</div>
</div>
</div>
{% endfor %}
</div>
{{ progress_description | safe }}. This should be collapsed by default.
<br>
The last evaluation was submitted N minutes/hours/days ago.
richardebeling marked this conversation as resolved.
Show resolved Hide resolved
</div>
</div>
{% endif %}
{% if unfinished_evaluations %}
<div class="card card-outline-primary mb-3">
<div class="card-header">
Expand Down
45 changes: 42 additions & 3 deletions evap/student/views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from collections import OrderedDict
from collections import OrderedDict, defaultdict

from django.conf import settings
from django.contrib import messages
from django.core.exceptions import PermissionDenied
from django.db import transaction
from django.db.models import Exists, F, OuterRef, Q
from django.db.models import Exists, F, OuterRef, Q, Sum
from django.http import HttpResponse
from django.shortcuts import get_object_or_404, render
from django.urls import reverse
Expand All @@ -25,7 +25,7 @@


@participant_required
def index(request):
def index(request): # pylint: disable=too-many-locals
query = (
Evaluation.objects.annotate(
participates_in=Exists(Evaluation.objects.filter(id=OuterRef("id"), participants=request.user))
Expand Down Expand Up @@ -105,12 +105,51 @@ def sorter(evaluation):
)

unfinished_evaluations.sort(key=sorter)
info = Evaluation.annotate_with_participant_and_voter_counts(
Semester.active_semester()
richardebeling marked this conversation as resolved.
Show resolved Hide resolved
.evaluations.filter(is_single_result=False)
.exclude(state__lt=Evaluation.State.APPROVED)
.exclude(is_rewarded=False)
.exclude(id__in=settings.EXCLUDED_EVALUATION_IDS)
.exclude(course__type__id__in=settings.EXCLUDED_COURSE_TYPE_IDS)
.exclude(course__is_private=True)
).aggregate(
total_votes=Sum("num_voters"),
participants=Sum("num_participants"),
)
richardebeling marked this conversation as resolved.
Show resolved Hide resolved
if settings.GLOBAL_EVALUATION_PROGRESS_REWARDS:
max_reward = max(settings.GLOBAL_EVALUATION_PROGRESS_REWARDS)
final_goal = round(info["participants"] * max_reward[0])
richardebeling marked this conversation as resolved.
Show resolved Hide resolved
next_goal = final_goal
next_reward = max_reward[1]
for percentage, reward in settings.GLOBAL_EVALUATION_PROGRESS_REWARDS:
candidate = info["participants"] * percentage
if info["total_votes"] < candidate < next_goal:
next_goal = round(candidate)
next_reward = reward
positioned_labels = [
richardebeling marked this conversation as resolved.
Show resolved Hide resolved
(percentage / max_reward[0], percentage, label)
for percentage, label in settings.GLOBAL_EVALUATION_PROGRESS_REWARDS
]

else:
final_goal = None
positioned_labels = None
info = defaultdict(lambda: 0)
next_goal = 0
next_reward = 0

template_data = {
"semester_list": semester_list,
"can_download_grades": request.user.can_download_grades,
"unfinished_evaluations": unfinished_evaluations,
"evaluation_end_warning_period": settings.EVALUATION_END_WARNING_PERIOD,
"num_total_votes": info["total_votes"],
"final_goal": final_goal,
"global_progress_rewards": positioned_labels,
"remaining_votes": next_goal - info["total_votes"],
"next_reward": next_reward,
"progress_description": settings.PARTICIPANT_PROGRESS_TEXT,
}
richardebeling marked this conversation as resolved.
Show resolved Hide resolved

return render(request, "student_index.html", template_data)
Expand Down
Loading