mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 23:58:02 -05:00
Add top school counts to analytics dashboard
This commit is contained in:
parent
e8c22679d9
commit
5d2ad62fb9
3 changed files with 52 additions and 1 deletions
|
@ -57,6 +57,22 @@ block content
|
|||
else
|
||||
div Loading ...
|
||||
|
||||
h3 School Counts
|
||||
.small Only including schools with #{view.minSchoolCount}+ counts
|
||||
if view.schoolCounts
|
||||
table.table.table-striped.table-condensed
|
||||
tr
|
||||
th
|
||||
th School Name
|
||||
th User Count
|
||||
each val, i in view.schoolCounts
|
||||
tr
|
||||
td= i + 1
|
||||
td= val.schoolName
|
||||
td= val.count
|
||||
else
|
||||
div Loading ...
|
||||
|
||||
h1 Active Classes
|
||||
table.table.table-striped.table-condensed
|
||||
tr
|
||||
|
|
|
@ -12,6 +12,7 @@ module.exports = class AnalyticsView extends RootView
|
|||
template: template
|
||||
furthestCourseDayRange: 30
|
||||
lineColors: ['red', 'blue', 'green', 'purple', 'goldenrod', 'brown', 'darkcyan']
|
||||
minSchoolCount: 20
|
||||
|
||||
constructor: (options) ->
|
||||
super options
|
||||
|
@ -118,7 +119,19 @@ module.exports = class AnalyticsView extends RootView
|
|||
@updateRevenueChartData()
|
||||
@render?()
|
||||
}, 0).load()
|
||||
|
||||
|
||||
@supermodel.addRequestResource('school_counts', {
|
||||
url: '/db/user/-/school_counts'
|
||||
method: 'POST'
|
||||
data: {minCount: @minSchoolCount}
|
||||
success: (@schoolCounts) =>
|
||||
@schoolCounts?.sort (a, b) ->
|
||||
return -1 if a.count > b.count
|
||||
return 0 if a.count is b.count
|
||||
1
|
||||
@render?()
|
||||
}, 0).load()
|
||||
|
||||
@courses = new CocoCollection([], { url: "/db/course", model: Course})
|
||||
@courses.comparator = "_id"
|
||||
@listenToOnce @courses, 'sync', @onCoursesSync
|
||||
|
|
|
@ -309,6 +309,7 @@ UserHandler = class UserHandler extends Handler
|
|||
return @getByIDs(req, res) if args[1] is 'users'
|
||||
return @getNamesByIDs(req, res) if args[1] is 'names'
|
||||
return @getPrepaidCodes(req, res) if args[1] is 'prepaid_codes'
|
||||
return @getSchoolCounts(req, res) if args[1] is 'school_counts'
|
||||
return @nameToID(req, res, args[0]) if args[1] is 'nameToID'
|
||||
return @getLevelSessionsForEmployer(req, res, args[0]) if args[1] is 'level.sessions' and args[2] is 'employer'
|
||||
return @getLevelSessions(req, res, args[0]) if args[1] is 'level.sessions'
|
||||
|
@ -464,6 +465,27 @@ UserHandler = class UserHandler extends Handler
|
|||
Prepaid.find({}).or(orQuery).exec (err, documents) =>
|
||||
@sendSuccess(res, documents)
|
||||
|
||||
getSchoolCounts: (req, res) ->
|
||||
return @sendSuccess(res, []) unless req.user?.isAdmin()
|
||||
minCount = req.body.minCount ? 20
|
||||
query = {$and: [
|
||||
{anonymous: false},
|
||||
{schoolName: {$exists: true}},
|
||||
{schoolName: {$ne: ''}}
|
||||
]}
|
||||
User.find(query, {schoolName: 1}).exec (err, documents) =>
|
||||
return @sendDatabaseError(res, err) if err
|
||||
schoolCountMap = {}
|
||||
for doc in documents
|
||||
schoolName = doc.get('schoolName')
|
||||
schoolCountMap[schoolName] ?= 0;
|
||||
schoolCountMap[schoolName]++;
|
||||
schoolCounts = []
|
||||
for schoolName, count of schoolCountMap
|
||||
continue unless count >= minCount
|
||||
schoolCounts.push schoolName: schoolName, count: count
|
||||
@sendSuccess(res, schoolCounts)
|
||||
|
||||
agreeToCLA: (req, res) ->
|
||||
return @sendForbiddenError(res) unless req.user
|
||||
doc =
|
||||
|
|
Loading…
Reference in a new issue