Skip to content

Commit

Permalink
Merge pull request #5435 from benjaoming/fix-coachreports
Browse files Browse the repository at this point in the history
Coach reports date filtering and exercise summaries
  • Loading branch information
benjaoming committed Apr 7, 2017
2 parents 8da5fa5 + dd2bd91 commit 9f7175c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
3 changes: 2 additions & 1 deletion docs/installguide/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Bug fixes
^^^^^^^^^

* Touch devices: Scroll events drop through to underlying page rather than scrolling long sidebar lists :url-issue:`5407` :url-issue:`5410`

* Respect selected date range on tabular coach report :url-issue:`5022`
* Correct summary of total exercise attempts on coach reports :url-issue:`5020`

Known issues
^^^^^^^^^^^^
Expand Down
23 changes: 16 additions & 7 deletions kalite/coachreports/api_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def get_learners_from_GET(request):
return FacilityUser.objects.filter(learner_filter & Q(is_teacher=False)).order_by("last_name")

def return_log_type_details(log_type, topic_ids=None):
fields = ["user", "points", "complete", "completion_timestamp", "completion_counter"]
fields = ["user", "points", "complete", "completion_timestamp", "completion_counter", "latest_activity_timestamp"]
if log_type == "exercise":
LogModel = ExerciseLog
fields.extend(["exercise_id", "attempts", "struggling", "streak_progress", "attempts_before_completion"])
Expand Down Expand Up @@ -164,7 +164,10 @@ def aggregate_learner_logs(request):

topic_ids = json.loads(request.GET.get("topic_ids", "[]"))

log_types = request.GET.getlist("log_type", ["exercise", "video", "content"])
# Previously, we defaulted to all types of logs, but views on coach reports
# seem to assume only exercises
# log_types = request.GET.getlist("log_type", ["exercise", "video", "content"])
log_types = request.GET.getlist("log_type", ["exercise"])

output_logs = []

Expand Down Expand Up @@ -198,22 +201,28 @@ def aggregate_learner_logs(request):

number_content += len(set(log_objects.values_list(id_field, flat=True)))

output_dict["total_complete"] += log_objects.filter(complete=True).count()
if log_type == "video":
output_dict["total_in_progress"] += log_objects.filter(complete=False).count()
output_dict["content_time_spent"] += log_objects.aggregate(Sum("total_seconds_watched"))["total_seconds_watched__sum"] or 0
elif log_type == "content":
output_dict["total_in_progress"] += log_objects.filter(complete=False).count()
output_dict["content_time_spent"] += log_objects.aggregate(Sum("time_spent"))["time_spent__sum"] or 0
elif log_type == "exercise":
output_dict["total_struggling"] = log_objects.filter(struggling=True).count()
output_dict["total_struggling"] += log_objects.filter(struggling=True).count()
output_dict["total_in_progress"] += log_objects.filter(complete=False, struggling=False).count()
output_dict["exercise_attempts"] = AttemptLog.objects.filter(user__in=learners,
timestamp__gte=start_date,
timestamp__lte=end_date, **obj_ids).count()

# Summarize struggling, in progress, and completed
output_dict["exercise_attempts"] += output_dict["total_struggling"] + output_dict["total_complete"] + output_dict["total_in_progress"]
# The below doesn't filter correctly, suspecting either bad
# AttemptLog generated in generaterealdata or because timestamp
# isn't correctly updated
# output_dict["exercise_attempts"] = AttemptLog.objects.filter(user__in=learners,
# timestamp__gte=start_date,
# timestamp__lte=end_date, **obj_ids).count()
if log_objects.aggregate(Avg("streak_progress"))["streak_progress__avg"] is not None:
output_dict["exercise_mastery"] = round(log_objects.aggregate(Avg("streak_progress"))["streak_progress__avg"])
output_logs.extend(log_objects)
output_dict["total_complete"] += log_objects.filter(complete=True).count()

object_buffer = LogModel.objects.filter(
user__in=learners,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ var TimeSetView = BaseView.extend({
"start_date": default_start_date,
"end_date": server_date_now
});

// Bad architecture:
// Store a single instance of this.model to be accessed by tabular_reports.views
$("html").data("main_coachreport_model", this.model);
this.render();
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,15 @@ var TabularReportView = BaseView.extend({
},

set_data_model: function (){
// Bad architecture:
// Retrieve a single instance of this.model to be accessed by tabular_reports.views
var main_coachreport_model = $("html").data("main_coachreport_model");
var self = this;
this.data_model = new Models.CoachReportModel({
facility: this.model.get("facility"),
group: this.model.get("group"),
start_date: date_string(this.model.get("start_date")),
end_date: date_string(this.model.get("end_date")),
start_date: date_string(main_coachreport_model.get("start_date")),
end_date: date_string(main_coachreport_model.get("end_date")),
topic_ids: this.model.get("topic_ids")
});
if (this.model.get("facility")) {
Expand All @@ -386,7 +389,7 @@ var TabularReportView = BaseView.extend({
self.learners.each(function(model){
model.set("logs", _.object(
_.map(_.filter(self.data_model.get("logs"), function(log) {
return log.user === model.get("pk");
return log.user === model.get("pk") && new Date(log.latest_activity_timestamp) >= main_coachreport_model.get("start_date") && new Date(log.latest_activity_timestamp) <= main_coachreport_model.get("end_date");
}), function(item) {
return [item.exercise_id || item.video_id || item.content_id, item];
})));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ var date_string = function(date) {

module.exports = {
date_string: date_string
};
};

0 comments on commit 9f7175c

Please sign in to comment.