Skip to content

Commit

Permalink
ReportDetails: Completed course steps (fixes #7002) (#7003)
Browse files Browse the repository at this point in the history
  • Loading branch information
lmmrssa authored Sep 1, 2020
1 parent 569940f commit 2ea9f4c
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 11 deletions.
9 changes: 9 additions & 0 deletions design/courses_progress/courses_progress-design.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ module.exports = {
}
},
"reduce": "_stats"
},
"steps": {
"map": function (doc) {
// Found sometimes course progress record stepNum 0
if (doc.passed && doc.stepNum > 0) {
emit({ userId: doc.userId, courseId: doc.courseId, stepNum: doc.stepNum } , doc.updatedDate);
}
},
"reduce": "_stats"
}
}
}
2 changes: 1 addition & 1 deletion design/courses_progress/courses_progress-design.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"views":{"enrollment":{"map":"function (doc) {\n emit({ userId: doc.userId, courseId: doc.courseId } , doc.createdDate);\n }","reduce":"_stats"},"completion":{"map":"function (doc) {\n if (doc.passed) {\n emit({ userId: doc.userId, courseId: doc.courseId } , doc.updatedDate);\n }\n }","reduce":"_stats"}}}
{"views":{"enrollment":{"map":"function (doc) {\n emit({ userId: doc.userId, courseId: doc.courseId } , doc.createdDate);\n }","reduce":"_stats"},"completion":{"map":"function (doc) {\n if (doc.passed) {\n emit({ userId: doc.userId, courseId: doc.courseId } , doc.updatedDate);\n }\n }","reduce":"_stats"},"steps":{"map":"function (doc) {\n // Found sometimes course progress record stepNum 0\n if (doc.passed && doc.stepNum > 0) {\n emit({ userId: doc.userId, courseId: doc.courseId, stepNum: doc.stepNum } , doc.updatedDate);\n }\n }","reduce":"_stats"}}}
2 changes: 1 addition & 1 deletion e2e/login.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('Login', () => {
passInput.sendKeys('e2e');
page.clickSignin();
browser.getCurrentUrl().then((url) => {
expect(url).toEqual('http://localhost:3000/');
expect(url).toEqual('http://localhost:3000/login');
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@
</ng-container>
<ng-container matColumnDef="steps">
<mat-header-cell *matHeaderCellDef mat-sort-header i18n>Steps</mat-header-cell>
<mat-cell *matCellDef="let element">{{element?.steps}}</mat-cell>
<mat-cell *matCellDef="let element">{{element?.max?.steps}}</mat-cell>
</ng-container>
<ng-container matColumnDef="exams">
<mat-header-cell *matHeaderCellDef mat-sort-header i18n>Tests</mat-header-cell>
<mat-cell *matCellDef="let element">{{element?.exams}}</mat-cell>
<mat-cell *matCellDef="let element">{{element?.max?.exams}}</mat-cell>
</ng-container>
<ng-container matColumnDef="stepsCompleted">
<mat-header-cell *matHeaderCellDef mat-sort-header i18n>Steps Completed</mat-header-cell>
<mat-cell *matCellDef="let element">{{element?.stepsCompleted}}</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;" (click)="rowClick(row)" class="cursor-pointer"></mat-row>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ReportsDetailData } from './reports-detail-data';

const columns = {
resources: [ 'title', 'count', 'averageRating' ],
courses: [ 'title', 'count', 'averageRating', 'steps', 'exams', 'enrollments', 'completions' ],
courses: [ 'title', 'count', 'averageRating', 'steps', 'exams', 'enrollments', 'completions', 'stepsCompleted' ],
health: [ 'weekOf', 'count', 'unique' ]
};

Expand All @@ -17,7 +17,11 @@ export class ReportsDetailActivitiesComponent implements OnInit, OnChanges, Afte

@Input() activitiesByDoc = [];
@Input() ratings = [];
@Input() progress = { enrollments: new ReportsDetailData('time'), completions: new ReportsDetailData('time') };
@Input() progress = {
enrollments: new ReportsDetailData('time'),
completions: new ReportsDetailData('time'),
steps: new ReportsDetailData('time')
};
@Input() activityType: 'resources' | 'courses' | 'health' = 'resources';
@Output() itemClick = new EventEmitter<any>();
matSortActive = '';
Expand Down Expand Up @@ -46,6 +50,7 @@ export class ReportsDetailActivitiesComponent implements OnInit, OnChanges, Afte
averageRating: (this.ratings.find((rating: any) => rating.item === (activity.resourceId || activity.courseId)) || {}).value,
enrollments: this.progress.enrollments.filteredData.filter(filterCourse(activity)).length,
completions: this.progress.completions.filteredData.filter(filterCourse(activity)).length,
stepsCompleted: this.progress.steps.filteredData.filter(filterCourse(activity)).length,
...activity
}));
}
Expand Down
12 changes: 9 additions & 3 deletions src/app/manager-dashboard/reports/reports-detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ export class ReportsDetailComponent implements OnInit, OnDestroy {
loginActivities = new ReportsDetailData('loginTime');
resourceActivities = { byDoc: [], total: new ReportsDetailData('time') };
courseActivities = { byDoc: [], total: new ReportsDetailData('time') };
progress = { enrollments: new ReportsDetailData('time'), completions: new ReportsDetailData('time') };
progress = {
enrollments: new ReportsDetailData('time'),
completions: new ReportsDetailData('time'),
steps: new ReportsDetailData('time')
};
today: Date;
minDate: Date;
ratings = { total: new ReportsDetailData('time'), resources: [], courses: [] };
Expand Down Expand Up @@ -152,6 +156,7 @@ export class ReportsDetailComponent implements OnInit, OnDestroy {
this.setDocVisits('courseActivities');
this.progress.enrollments.filter(this.filter);
this.progress.completions.filter(this.filter);
this.progress.steps.filter(this.filter);
this.setUserCounts(this.activityService.groupUsers(
this.users.filter(
user => this.filter.members.length === 0 || this.filter.members.some(
Expand Down Expand Up @@ -204,10 +209,11 @@ export class ReportsDetailComponent implements OnInit, OnDestroy {
}

getCourseProgress() {
this.activityService.courseProgressReport().subscribe(({ enrollments, completions, courses }) => {
this.activityService.courseProgressReport().subscribe(({ enrollments, completions, steps, courses }) => {
this.progress.enrollments.data = enrollments;
this.progress.completions.data = completions;
this.courseActivities.byDoc = this.courseActivities.byDoc.map(courseActivity => {
this.progress.steps.data = steps;
this.courseActivities.total.data = this.courseActivities.total.data.map(courseActivity => {
const course = courses.find(c => c._id === courseActivity.courseId) || { steps: 0, exams: 0 };
return { ...course, ...courseActivity };
});
Expand Down
6 changes: 4 additions & 2 deletions src/app/manager-dashboard/reports/reports.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,9 @@ export class ReportsService {
return forkJoin([
this.couchService.get('courses_progress/_design/courses_progress/_view/enrollment?group=true'),
this.couchService.get('courses_progress/_design/courses_progress/_view/completion?group=true'),
this.couchService.get('courses_progress/_design/courses_progress/_view/steps?group=true'),
this.coursesService.coursesListener$().pipe(take(1))
]).pipe(map(([ { rows: enrollments }, { rows: completions }, courses ]) => {
]).pipe(map(([ { rows: enrollments }, { rows: completions }, { rows: steps }, courses ]) => {
return {
courses: courses.map(course => ({
steps: course.doc.steps.length,
Expand All @@ -243,7 +244,8 @@ export class ReportsService {
const course = courses.find(c => c._id === key.courseId);
return course && value.count === course.doc.steps.length;
})
.map(({ key, value }) => ({ ...key, time: value.max, stepCount: value.count }))
.map(({ key, value }) => ({ ...key, time: value.max, stepCount: value.count })),
steps: steps.map(({ key, value }) => ({ ...key, time: value.max }))
};
}));
}
Expand Down

0 comments on commit 2ea9f4c

Please sign in to comment.