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
e68b9402
Commit
e68b9402
authored
Mar 30, 2015
by
Jonathan Piacenti
Committed by
Saqib
Aug 04, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Output the number of read threads by a user in social stats.
parent
7f7c8fd2
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 @
e68b9402
...
@@ -95,14 +95,14 @@ get "#{APIPREFIX}/users/:user_id/social_stats" do |user_id|
...
@@ -95,14 +95,14 @@ get "#{APIPREFIX}/users/:user_id/social_stats" do |user_id|
user_stats
=
{}
user_stats
=
{}
thread_ids
=
{}
thread_ids
=
{}
flat_thread_ids
=
[]
content_selector
=
{
course_id:
course_id
,
anonymous:
false
,
anonymous_to_peers:
false
}
content_selector
=
{
course_id:
course_id
,
anonymous:
false
,
anonymous_to_peers:
false
}
if
end_date
if
end_date
content_selector
[
:created_at
.
lte
]
=
end_date
content_selector
[
:created_at
.
lte
]
=
end_date
end
end
if
user_id
!=
'*'
def
set_template_result
(
user_id
,
user_stats
,
thread_ids
)
content_selector
[
"author_id"
]
=
user_id
user_stats
[
user_id
]
=
{
user_stats
[
user_id
]
=
{
"num_threads"
=>
0
,
"num_threads"
=>
0
,
"num_comments"
=>
0
,
"num_comments"
=>
0
,
...
@@ -110,11 +110,18 @@ get "#{APIPREFIX}/users/:user_id/social_stats" do |user_id|
...
@@ -110,11 +110,18 @@ get "#{APIPREFIX}/users/:user_id/social_stats" do |user_id|
"num_upvotes"
=>
0
,
"num_upvotes"
=>
0
,
"num_downvotes"
=>
0
,
"num_downvotes"
=>
0
,
"num_flagged"
=>
0
,
"num_flagged"
=>
0
,
"num_comments_generated"
=>
0
"num_comments_generated"
=>
0
,
"num_thread_followers"
=>
0
,
"num_threads_read"
=>
0
,
}
}
thread_ids
[
user_id
]
=
[]
thread_ids
[
user_id
]
=
[]
end
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
# 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
# as we don't need it and we shouldn't push all that data over the wire
content
=
Content
.
where
(
content_selector
).
without
(
:body
)
content
=
Content
.
where
(
content_selector
).
without
(
:body
)
...
@@ -138,21 +145,13 @@ get "#{APIPREFIX}/users/:user_id/social_stats" do |user_id|
...
@@ -138,21 +145,13 @@ get "#{APIPREFIX}/users/:user_id/social_stats" do |user_id|
user_id
=
item
.
author_id
user_id
=
item
.
author_id
if
user_stats
.
key?
(
user_id
)
==
false
then
if
user_stats
.
key?
(
user_id
)
==
false
then
user_stats
[
user_id
]
=
{
set_template_result
(
user_id
,
user_stats
,
thread_ids
)
"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
]
=
[]
end
end
if
item
.
_type
==
"CommentThread"
then
if
item
.
_type
==
"CommentThread"
then
user_stats
[
user_id
][
"num_threads"
]
+=
1
user_stats
[
user_id
][
"num_threads"
]
+=
1
thread_ids
[
user_id
].
push
(
item
.
_id
)
thread_ids
[
user_id
].
push
(
item
.
_id
)
flat_thread_ids
.
push
(
item
.
_id
)
user_stats
[
user_id
][
"num_comments_generated"
]
+=
item
.
comment_count
user_stats
[
user_id
][
"num_comments_generated"
]
+=
item
.
comment_count
elsif
item
.
_type
==
"Comment"
and
item
.
parent_ids
==
[]
then
elsif
item
.
_type
==
"Comment"
and
item
.
parent_ids
==
[]
then
user_stats
[
user_id
][
"num_comments"
]
+=
1
user_stats
[
user_id
][
"num_comments"
]
+=
1
...
@@ -168,6 +167,7 @@ get "#{APIPREFIX}/users/:user_id/social_stats" do |user_id|
...
@@ -168,6 +167,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_downvotes"
]
+=
item
.
votes
[
"down"
].
count
user_stats
[
user_id
][
"num_flagged"
]
+=
item
.
abuse_flaggers
.
count
user_stats
[
user_id
][
"num_flagged"
]
+=
item
.
abuse_flaggers
.
count
end
end
# with the array of objectId's for threads, get a count of number of other users who have a subscription on it
# with the array of objectId's for threads, get a count of number of other users who have a subscription on it
...
@@ -179,6 +179,15 @@ get "#{APIPREFIX}/users/:user_id/social_stats" do |user_id|
...
@@ -179,6 +179,15 @@ get "#{APIPREFIX}/users/:user_id/social_stats" do |user_id|
end
end
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
user_stats
.
to_json
end
end
end
end
...
...
spec/api/user_spec.rb
View file @
e68b9402
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