Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cs_comments_service
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
cs_comments_service
Commits
b543f88f
Commit
b543f88f
authored
Dec 20, 2012
by
Calen Pennington
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #17 from rll/feature/kevin/kpis_4
Feature/kevin/kpis 4
parents
9f0bbe59
361e9ed0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
225 additions
and
1 deletions
+225
-1
.gitignore
+3
-0
lib/tasks/kpis.rake
+157
-0
models/content.rb
+65
-1
No files found.
.gitignore
View file @
b543f88f
...
@@ -30,3 +30,6 @@ benchmark_log
...
@@ -30,3 +30,6 @@ benchmark_log
bin/
bin/
log/
log/
#redcar
.redcar/
lib/tasks/kpis.rake
0 → 100644
View file @
b543f88f
require
'rest_client'
roots
=
{}
roots
[
'development'
]
=
"http://localhost:8000"
roots
[
'test'
]
=
"http://localhost:8000"
roots
[
'production'
]
=
"http://edx.org"
ROOT
=
roots
[
ENV
[
'SINATRA_ENV'
]]
namespace
:kpis
do
task
:prolific
=>
:environment
do
#USAGE
#SINATRA_ENV=development rake kpis:prolific
#or
#SINATRA_ENV=development bundle exec rake kpis:prolific
courses
=
Content
.
all
.
distinct
(
"course_id"
)
puts
"
\n\n
*********************************************************************"
puts
" Users who have created the most forum content on edX (
#{
Date
.
today
}
) "
puts
"*********************************************************************
\n\n
"
courses
.
each
do
|
c
|
contributors
=
Content
.
prolific_metric
({
"course_id"
=>
c
},
10
)
#now output
puts
c
puts
"*********************"
contributors
.
each
do
|
p
|
url
=
ROOT
+
"/courses/
#{
c
}
/discussion/forum/users/
#{
p
[
'_id'
]
}
"
count_string
=
"
#{
p
[
'value'
].
to_i
}
contributions:"
.
rjust
(
25
)
puts
"
#{
count_string
}
#{
url
}
"
end
puts
"
\n
"
end
end
task
:starters
=>
:environment
do
#USAGE
#SINATRA_ENV=development rake kpis:starters
#or
#SINATRA_ENV=development bundle exec rake kpis:starters
courses
=
Content
.
all
.
distinct
(
"course_id"
)
puts
"
\n\n
*********************************************************************"
puts
" Users who have started the most threads on edX (
#{
Date
.
today
}
) "
puts
"*********************************************************************
\n\n
"
courses
.
each
do
|
c
|
contributors
=
Content
.
prolific_metric
({
"course_id"
=>
c
,
"_type"
=>
"CommentThread"
},
10
)
#now output
puts
c
puts
"*********************"
contributors
.
each
do
|
p
|
url
=
ROOT
+
"/courses/
#{
c
}
/discussion/forum/users/
#{
p
[
'_id'
]
}
"
count_string
=
"
#{
p
[
'value'
].
to_i
}
contributions:"
.
rjust
(
25
)
puts
"
#{
count_string
}
#{
url
}
"
end
puts
"
\n
"
end
end
task
:ppu
=>
:environment
do
#USAGE
#SINATRA_ENV=development rake kpis:ppu
#or
#SINATRA_ENV=development bundle exec rake kpis:ppu
courses
=
Content
.
all
.
distinct
(
"course_id"
)
puts
"
\n\n
*********************************************************************"
puts
"Average threads per contributing user per course on edX (
#{
Date
.
today
}
) "
puts
"*********************************************************************
\n\n
"
courses
.
each
do
|
c
|
#first, get all the users who have contributed
contributors
=
Content
.
prolific_metric
({
"course_id"
=>
c
},
10
)
total_users
=
contributors
.
count
#now, get the threads
total_threads
=
Content
.
where
(
"_type"
=>
"CommentThread"
,
"course_id"
=>
c
).
count
ratio
=
total_threads
.
to_f
/
total_users
.
to_f
#now output
puts
c
puts
"*********************"
puts
"Total Threads:
#{
total_threads
}
"
puts
"Total Users:
#{
total_users
}
"
puts
"Average Thread/User:
#{
ratio
}
"
puts
"
\n
"
end
end
task
:epu
=>
:environment
do
#USAGE
#SINATRA_ENV=development rake kpis:epu
#or
#SINATRA_ENV=development bundle exec rake kpis:epu
courses
=
Content
.
all
.
distinct
(
"course_id"
)
puts
"
\n\n
*****************************************************************************************************************"
puts
"Average contributions (votes, threads, or comments) per contributing user per course on edX (
#{
Date
.
today
}
) "
puts
"*********************************************************************************************************************
\n\n
"
courses
.
each
do
|
c
|
#first, get all the users who have contributed
summary
=
Content
.
summary
({
"course_id"
=>
c
})
total_users
=
summary
[
"contributor_count"
]
total_activity
=
summary
[
'thread_count'
]
total_activity
+=
summary
[
'comment_count'
]
total_activity
+=
summary
[
'vote_count'
]
ratio
=
total_activity
.
to_f
/
total_users
.
to_f
puts
c
puts
"*********************"
puts
"Total Threads:
#{
summary
[
'thread_count'
]
}
"
puts
"Total Comments:
#{
summary
[
'comment_count'
]
}
"
puts
"Total Votes:
#{
summary
[
'vote_count'
]
}
\n\n
"
puts
"Total Users:
#{
summary
[
'contributor_count'
]
}
"
puts
"Total Engagements:
#{
total_activity
}
\n\n
"
puts
"Average Engagement Per Engaging User:
#{
ratio
}
\n\n\n
"
end
end
task
:orphans
=>
:environment
do
#USAGE
#SINATRA_ENV=development rake kpis:orphans
#or
#SINATRA_ENV=development bundle exec rake kpis:orphans
courses
=
Content
.
all
.
distinct
(
"course_id"
)
puts
"
\n\n
****************************************************"
puts
"thread reply rate per course on edX (
#{
Date
.
today
}
) "
puts
"****************************************************
\n\n
"
courses
.
each
do
|
c
|
#first, get all the users who have contributed
threads
=
Content
.
where
({
"course_id"
=>
c
,
"_type"
=>
"CommentThread"
})
orphans
=
Content
.
where
({
"course_id"
=>
c
,
"_type"
=>
"CommentThread"
,
"comment_count"
=>
0
})
ratio
=
orphans
.
count
.
to_f
/
threads
.
count
.
to_f
puts
c
puts
"*********************"
puts
"Total Threads:
#{
threads
.
count
}
"
puts
"Total Orphaned Threads:
#{
orphans
.
count
}
"
if
threads
.
count
>
0
puts
"Orphan Ratio:
#{
(
ratio
*
1000
).
round
.
to_f
/
10.0
}
%"
end
puts
"
\n\n\n
"
end
end
end
models/content.rb
View file @
b543f88f
class
Content
class
Content
include
Mongoid
::
Document
include
Mongoid
::
Document
def
author_with_anonymity
(
attr
=
nil
,
attr_when_anonymous
=
nil
)
def
author_with_anonymity
(
attr
=
nil
,
attr_when_anonymous
=
nil
)
if
not
attr
if
not
attr
(
anonymous
||
anonymous_to_peers
)
?
nil
:
author
(
anonymous
||
anonymous_to_peers
)
?
nil
:
author
...
@@ -9,4 +9,68 @@ class Content
...
@@ -9,4 +9,68 @@ class Content
(
anonymous
||
anonymous_to_peers
)
?
attr_when_anonymous
:
author
.
send
(
attr
)
(
anonymous
||
anonymous_to_peers
)
?
attr_when_anonymous
:
author
.
send
(
attr
)
end
end
end
end
def
self
.
prolific_metric
what
,
count
#take a hash of criteria (what) and return a hash of hashes
#course => user => count
contributors
=
{}
map
=
"function(){emit(this.author_id,1)}"
reduce
=
"function(k, vals) { var sum = 0; for(var i in vals) sum += vals[i]; return sum; }"
contributors
=
[]
self
.
where
(
what
).
map_reduce
(
map
,
reduce
).
out
(
replace:
"results"
).
each
do
|
d
|
contributors
<<
d
end
#now sort and limit them
#first sort destructively
contributors
.
sort!
{
|
a
,
b
|
-
a
[
"value"
]
<=>
-
b
[
"value"
]}
#then trim it
contributors
=
contributors
[
0
..
(
count
-
1
)]
contributors
end
def
self
.
summary
what
#take a hash of criteria (what) and return a hash of hashes
#of total users, votes, comments, endorsements,
answer
=
{}
vote_count
=
0
thread_count
=
0
comment_count
=
0
contributors
=
[]
content
=
self
.
where
(
what
)
content
.
each
do
|
c
|
contributors
<<
c
.
author_id
contributors
<<
c
[
"votes"
][
"up"
]
contributors
<<
c
[
"votes"
][
"down"
]
vote_count
+=
c
[
"votes"
][
"count"
]
if
c
.
_type
==
"CommentThread"
thread_count
+=
1
elsif
c
.
_type
==
"Comment"
comment_count
+=
1
end
end
#uniquify contributors
contributors
=
contributors
.
uniq
#assemble the answer and ship
answer
[
"vote_count"
]
=
vote_count
answer
[
"thread_count"
]
=
thread_count
answer
[
"comment_count"
]
=
comment_count
answer
[
"contributor_count"
]
=
contributors
.
count
answer
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment