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

Mohe/stats of prof on course #164

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
48 changes: 45 additions & 3 deletions home/templates/course.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,42 @@
{% block description %}View professor reviews and grade data for {{ course.name }} at the University of Maryland — College Park{% endblock %}

{% block head %}

<script type="text/javascript" src="{% static 'js/chart.min.js' %}"></script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
Copy link

@gamesover gamesover Oct 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see base_main.html already contains
<script type="text/javascript" src="{% static 'js/jquery-3.5.1.min.js' %}"></script>

Not sure whether we want to introduce https://code.jquery.com/jquery-3.6.0.min.js here?

<script>
function professorGrades(professor, elementId) {

var lastSearch = "professor";
$.ajax({
url: "{% url 'grades' %}",
type: "POST",
dataType: 'json',
data: {
'professor': professor,
'elementId': elementId,
},
success: function(data) {
var grade_data = data.professor_data.data;
for (var [course_name, course_data] of Object.entries(grade_data)) {
if (course_name == "{{ course.name }}") {
var averageGpa = course_data.average_gpa;
break;
} else {
var averageGpa = "N/A";
}
}
averageGpa = averageGpa.toFixed(2);
$("#gpa-information-"+ elementId).html(`${averageGpa}`);
},
error: function(xhr, status, error) {

console.error("Error occurred:", error);
}
});
}
</script>

{% endblock %}

{% block content %}
Expand Down Expand Up @@ -68,21 +103,26 @@ <h4><a href="{{ professor.get_absolute_url }}">{{ professor.name }}</a></h4>
<div class="card-body">
<p class="card-text">
{% if professor.num_reviews == 1 %}
{{ professor.num_reviews }} review
{{ professor.num_reviews }} review for {{course.name}}
{% else %}
{{ professor.num_reviews }} reviews
{{ professor.num_reviews }} reviews for {{course.name}}
{% endif %}
<br />
Average rating:
Average {{course.name}} rating:
{% if professor.average_rating_ %}
{{ professor.average_rating_|floatformat:2 }}
{% else %}
N/A
{% endif %}
<br />
Average {{course.name}} GPA: <span id="gpa-information-{{ professor.id }}">N/A</span>
</p>
</div>
</div>
</div>
<script>
professorGrades("{{ professor.name }}", "{{ professor.id }}");
</script>
{% endfor %}
</div>
{% endfor %}
Expand All @@ -92,4 +132,6 @@ <h4><a href="{{ professor.get_absolute_url }}">{{ professor.name }}</a></h4>
</div>
</div>
</div>


{% endblock %}
6 changes: 3 additions & 3 deletions home/views/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ def get(self, request, name):
.annotate(
# TODO consolidate this with the Professor#average_rating
# method, will likely require a new Professors queryset
average_rating_= (
average_rating_ = (
Sum(
"review__rating",
output_field=FloatField(),
filter=Q(review__status=Review.Status.VERIFIED)
filter=Q(review__status=Review.Status.VERIFIED, review__course__id=course.id)
)
/
Count(
"review",
filter=Q(review__status=Review.Status.VERIFIED)
filter=Q(review__status=Review.Status.VERIFIED, review__course__id=course.id)
)
)
)
Expand Down