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
1d1800a5
Commit
1d1800a5
authored
Mar 30, 2015
by
Jonathan Piacenti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Output the number of read threads by a user in social stats.
parent
caa42cb4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
13 deletions
+22
-13
api/users.rb
+22
-13
spec/api/user_spec.rb
+0
-0
No files found.
api/users.rb
View file @
1d1800a5
...
...
@@ -90,14 +90,14 @@ get "#{APIPREFIX}/users/:user_id/social_stats" do |user_id|
user_stats
=
{}
thread_ids
=
{}
flat_thread_ids
=
[]
content_selector
=
{
course_id:
course_id
,
anonymous:
false
,
anonymous_to_peers:
false
}
if
end_date
content_selector
[
:created_at
.
lte
]
=
end_date
end
if
user_id
!=
'*'
content_selector
[
"author_id"
]
=
user_id
def
set_template_result
(
user_id
,
user_stats
,
thread_ids
)
user_stats
[
user_id
]
=
{
"num_threads"
=>
0
,
"num_comments"
=>
0
,
...
...
@@ -105,11 +105,18 @@ get "#{APIPREFIX}/users/:user_id/social_stats" do |user_id|
"num_upvotes"
=>
0
,
"num_downvotes"
=>
0
,
"num_flagged"
=>
0
,
"num_comments_generated"
=>
0
"num_comments_generated"
=>
0
,
"num_thread_followers"
=>
0
,
"num_threads_read"
=>
0
,
}
thread_ids
[
user_id
]
=
[]
end
if
user_id
!=
'*'
content_selector
[
"author_id"
]
=
user_id
set_template_result
(
user_id
,
user_stats
,
thread_ids
)
end
# get all metadata regarding forum content, but don't bother to fetch the body
# as we don't need it and we shouldn't push all that data over the wire
content
=
Content
.
where
(
content_selector
).
without
(
:body
)
...
...
@@ -133,21 +140,13 @@ get "#{APIPREFIX}/users/:user_id/social_stats" do |user_id|
user_id
=
item
.
author_id
if
user_stats
.
key?
(
user_id
)
==
false
then
user_stats
[
user_id
]
=
{
"num_threads"
=>
0
,
"num_comments"
=>
0
,
"num_replies"
=>
0
,
"num_upvotes"
=>
0
,
"num_downvotes"
=>
0
,
"num_flagged"
=>
0
,
"num_comments_generated"
=>
0
}
thread_ids
[
user_id
]
=
[]
set_template_result
(
user_id
,
user_stats
,
thread_ids
)
end
if
item
.
_type
==
"CommentThread"
then
user_stats
[
user_id
][
"num_threads"
]
+=
1
thread_ids
[
user_id
].
push
(
item
.
_id
)
flat_thread_ids
.
push
(
item
.
_id
)
user_stats
[
user_id
][
"num_comments_generated"
]
+=
item
.
comment_count
elsif
item
.
_type
==
"Comment"
and
item
.
parent_ids
==
[]
then
user_stats
[
user_id
][
"num_comments"
]
+=
1
...
...
@@ -163,6 +162,7 @@ get "#{APIPREFIX}/users/:user_id/social_stats" do |user_id|
user_stats
[
user_id
][
"num_downvotes"
]
+=
item
.
votes
[
"down"
].
count
user_stats
[
user_id
][
"num_flagged"
]
+=
item
.
abuse_flaggers
.
count
end
# with the array of objectId's for threads, get a count of number of other users who have a subscription on it
...
...
@@ -174,6 +174,15 @@ get "#{APIPREFIX}/users/:user_id/social_stats" do |user_id|
end
end
# Get the number of threads read by each user.
users
=
User
.
only
([
:_id
,
:read_states
]).
where
(
"read_states.course_id"
=>
course_id
)
users
.
each
do
|
user
|
if
user_stats
.
key?
(
user
.
_id
)
==
false
then
set_template_result
(
user
.
_id
,
user_stats
,
thread_ids
)
end
user_stats
[
user
.
_id
][
"num_threads_read"
]
=
user
.
read_states
.
find_by
(
:course_id
=>
course_id
).
last_read_times
.
length
end
user_stats
.
to_json
end
end
...
...
spec/api/user_spec.rb
View file @
1d1800a5
This diff is collapsed.
Click to expand it.
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