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
620dd38b
Commit
620dd38b
authored
Jul 10, 2014
by
Chris Dodge
Committed by
Jonathan Piacenti
Aug 12, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
All for aggregate queries on the social stats API endpoint
parent
6d159a29
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
30 deletions
+38
-30
api/users.rb
+38
-30
No files found.
api/users.rb
View file @
620dd38b
...
@@ -85,51 +85,59 @@ get "#{APIPREFIX}/users/:user_id/social_stats" do |user_id|
...
@@ -85,51 +85,59 @@ get "#{APIPREFIX}/users/:user_id/social_stats" do |user_id|
# 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
(
author_id:
user_id
,
course_id:
course_id
).
without
(
:body
)
if
user_id
==
"*"
then
content
=
Content
.
where
(
course_id:
course_id
).
without
(
:body
)
num_threads
=
0
else
num_comments
=
0
content
=
Content
.
where
(
author_id:
user_id
,
course_id:
course_id
).
without
(
:body
)
num_replies
=
0
end
num_upvotes
=
0
num_downvotes
=
0
num_flagged
=
0
num_comments_generated
=
0
thread_ids
=
[]
user_stats
=
{}
thread_ids
=
{}
content
.
each
do
|
item
|
content
.
each
do
|
item
|
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
]
=
[]
end
if
item
.
_type
==
"CommentThread"
then
if
item
.
_type
==
"CommentThread"
then
num_threads
+=
1
user_stats
[
user_id
][
"num_threads"
]
+=
1
thread_ids
.
push
(
item
.
_id
)
thread_ids
[
user_id
]
.
push
(
item
.
_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
num_comments
+=
1
user_stats
[
user_id
][
"num_comments"
]
+=
1
else
else
num_replies
+=
1
user_stats
[
user_id
][
"num_replies"
]
+=
1
end
end
# don't allow for self-voting
# don't allow for self-voting
item
.
votes
[
"up"
].
delete
(
user_id
)
item
.
votes
[
"up"
].
delete
(
user_id
)
item
.
votes
[
"down"
].
delete
(
user_id
)
item
.
votes
[
"down"
].
delete
(
user_id
)
num_upvotes
+=
item
.
votes
[
"up"
].
count
user_stats
[
user_id
][
"num_upvotes"
]
+=
item
.
votes
[
"up"
].
count
num_downvotes
+=
item
.
votes
[
"down"
].
count
user_stats
[
user_id
][
"num_downvotes"
]
+=
item
.
votes
[
"down"
].
count
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
num_thread_followers
=
Subscription
.
where
(
:subscriber_id
.
ne
=>
user_id
,
:source_id
.
in
=>
thread_ids
).
count
()
user_stats
.
keys
.
each
do
|
user_id
|
user_stats
[
user_id
][
"num_thread_followers"
]
=
Subscription
.
where
(
:subscriber_id
.
ne
=>
user_id
,
:source_id
.
in
=>
thread_ids
[
user_id
]).
count
()
{
end
num_threads:
num_threads
,
num_comments:
num_comments
,
user_stats
.
to_json
num_replies:
num_replies
,
num_upvotes:
num_upvotes
,
num_downvotes:
num_downvotes
,
num_flagged:
num_flagged
,
num_thread_followers:
num_thread_followers
,
num_comments_generated:
num_comments_generated
}.
to_json
end
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