mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 17:45:40 -05:00
Add stats to ClassroomView
This commit is contained in:
parent
b2ed489197
commit
d874569b27
2 changed files with 40 additions and 5 deletions
|
@ -17,7 +17,24 @@ block content
|
||||||
if view.classroom.get('description')
|
if view.classroom.get('description')
|
||||||
p= view.classroom.get('description')
|
p= view.classroom.get('description')
|
||||||
|
|
||||||
// TODO: Add classroom statistics (grab from CourseDetailsView)
|
h3(data-i18n="courses.stats")
|
||||||
|
table.progress-stats-container
|
||||||
|
- var stats = view.classStats()
|
||||||
|
tr
|
||||||
|
td(data-i18n="courses.total_students")
|
||||||
|
td= _.size(view.classroom.get('members'))
|
||||||
|
tr
|
||||||
|
td(data-i18n="courses.average_time")
|
||||||
|
td= stats.averagePlaytime
|
||||||
|
tr
|
||||||
|
td(data-i18n="courses.total_time")
|
||||||
|
td= stats.totalPlaytime
|
||||||
|
tr
|
||||||
|
td(data-i18n="courses.average_levels")
|
||||||
|
td= stats.averageLevelsComplete
|
||||||
|
tr
|
||||||
|
td(data-i18n="courses.total_levels")
|
||||||
|
td= stats.totalLevelsComplete
|
||||||
|
|
||||||
h1
|
h1
|
||||||
| Students
|
| Students
|
||||||
|
@ -36,8 +53,8 @@ block content
|
||||||
span.spl remove student
|
span.spl remove student
|
||||||
|
|
||||||
h2= user.broadName()
|
h2= user.broadName()
|
||||||
- var lastPlayedString = view.makeLastPlayedString(user);
|
- var lastPlayedString = view.userLastPlayedString(user);
|
||||||
- var playtime = view.makePlaytimeString(user);
|
- var playtime = view.userPlaytimeString(user);
|
||||||
if lastPlayedString || playtime
|
if lastPlayedString || playtime
|
||||||
#student-stats-row.row
|
#student-stats-row.row
|
||||||
if lastPlayedString
|
if lastPlayedString
|
||||||
|
|
|
@ -44,6 +44,7 @@ module.exports = class ClassroomView extends RootView
|
||||||
@users.comparator = (user) => user.broadName().toLowerCase()
|
@users.comparator = (user) => user.broadName().toLowerCase()
|
||||||
@supermodel.loadCollection(@users, 'users')
|
@supermodel.loadCollection(@users, 'users')
|
||||||
@listenToOnce @courseInstances, 'sync', @onCourseInstancesSync
|
@listenToOnce @courseInstances, 'sync', @onCourseInstancesSync
|
||||||
|
@sessions = new CocoCollection([], { model: LevelSession })
|
||||||
|
|
||||||
onCourseInstancesSync: ->
|
onCourseInstancesSync: ->
|
||||||
@sessions = new CocoCollection([], { model: LevelSession })
|
@sessions = new CocoCollection([], { model: LevelSession })
|
||||||
|
@ -115,7 +116,7 @@ module.exports = class ClassroomView extends RootView
|
||||||
@openModalView(modal)
|
@openModalView(modal)
|
||||||
@listenToOnce modal, 'hidden', @render
|
@listenToOnce modal, 'hidden', @render
|
||||||
|
|
||||||
makeLastPlayedString: (user) ->
|
userLastPlayedString: (user) ->
|
||||||
session = user.sessions.last()
|
session = user.sessions.last()
|
||||||
return '' if not session
|
return '' if not session
|
||||||
campaign = session.collection.campaign
|
campaign = session.collection.campaign
|
||||||
|
@ -123,11 +124,28 @@ module.exports = class ClassroomView extends RootView
|
||||||
campaignLevel = campaign.get('levels')[levelOriginal]
|
campaignLevel = campaign.get('levels')[levelOriginal]
|
||||||
return "#{campaign.get('fullName')}, #{campaignLevel.name}"
|
return "#{campaign.get('fullName')}, #{campaignLevel.name}"
|
||||||
|
|
||||||
makePlaytimeString: (user) ->
|
userPlaytimeString: (user) ->
|
||||||
playtime = _.reduce user.sessions.pluck('playtime'), (s1, s2) -> (s1 or 0) + (s2 or 0)
|
playtime = _.reduce user.sessions.pluck('playtime'), (s1, s2) -> (s1 or 0) + (s2 or 0)
|
||||||
return '' unless playtime
|
return '' unless playtime
|
||||||
return moment.duration(playtime, 'seconds').humanize()
|
return moment.duration(playtime, 'seconds').humanize()
|
||||||
|
|
||||||
|
classStats: ->
|
||||||
|
stats = {}
|
||||||
|
|
||||||
|
playtime = 0
|
||||||
|
total = 0
|
||||||
|
for session in @sessions.models
|
||||||
|
pt = session.get('playtime') or 0
|
||||||
|
playtime += pt
|
||||||
|
total += 1
|
||||||
|
stats.averagePlaytime = if playtime and total then moment.duration(playtime / total, "seconds").humanize() else 0
|
||||||
|
stats.totalPlaytime = if playtime then moment.duration(playtime, "seconds").humanize() else 0
|
||||||
|
|
||||||
|
completeSessions = @sessions.filter (s) -> s.get('state').complete
|
||||||
|
stats.averageLevelsComplete = if @users.size() then (_.size(completeSessions) / @users.size()).toFixed(1) else 'N/A'
|
||||||
|
stats.totalLevelsComplete = _.size(completeSessions)
|
||||||
|
return stats
|
||||||
|
|
||||||
onClickAddStudentsButton: (e) ->
|
onClickAddStudentsButton: (e) ->
|
||||||
modal = new InviteToClassroomModal({classroom: @classroom})
|
modal = new InviteToClassroomModal({classroom: @classroom})
|
||||||
@openModalView(modal)
|
@openModalView(modal)
|
||||||
|
|
Loading…
Reference in a new issue