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
cc221a11
Commit
cc221a11
authored
Jul 23, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add task for generating seed for a single commentable
parent
58015e80
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
58 deletions
+72
-58
Rakefile
+72
-58
No files found.
Rakefile
View file @
cc221a11
...
@@ -84,25 +84,10 @@ namespace :db do
...
@@ -84,25 +84,10 @@ namespace :db do
Subscription
.
delete_all
Subscription
.
delete_all
end
end
task
:seed
=>
:environment
do
def
generate_comments_for
(
commentable_id
)
Comment
.
delete_all
CommentThread
.
delete_all
User
.
delete_all
Notification
.
delete_all
Subscription
.
delete_all
beginning_time
=
Time
.
now
level_limit
=
YAML
.
load_file
(
"config/application.yml"
)[
"level_limit"
]
level_limit
=
YAML
.
load_file
(
"config/application.yml"
)[
"level_limit"
]
users
=
(
1
..
10
).
map
{
|
id
|
User
.
find_or_create_by
(
external_id:
id
.
to_s
)}
thread_seeds
=
[
10
.
times
do
users
.
sample
.
subscribe
(
users
.
sample
)
end
THREAD_SEEDS
=
[
{
title:
"This is really interesting"
,
body:
"best I've ever seen!"
},
{
title:
"This is really interesting"
,
body:
"best I've ever seen!"
},
{
title:
"We can probably make this better"
,
body:
"Let's do it"
},
{
title:
"We can probably make this better"
,
body:
"Let's do it"
},
{
title:
"I don't know where to start"
,
body:
"Can anyone help me?"
},
{
title:
"I don't know where to start"
,
body:
"Can anyone help me?"
},
...
@@ -110,7 +95,7 @@ namespace :db do
...
@@ -110,7 +95,7 @@ namespace :db do
{
title:
"I need five threads but I don't know what to put here"
,
body:
"So I'll just leave it this way"
},
{
title:
"I need five threads but I don't know what to put here"
,
body:
"So I'll just leave it this way"
},
]
]
COMMENT_BODY_SEEDS
=
[
comment_body_seeds
=
[
"dude I don't know what you're talking about"
,
"dude I don't know what you're talking about"
,
"hi I'm Jack"
,
"hi I'm Jack"
,
"hi just sent you a message"
,
"hi just sent you a message"
,
...
@@ -119,56 +104,85 @@ namespace :db do
...
@@ -119,56 +104,85 @@ namespace :db do
"haha"
,
"haha"
,
"lol"
,
"lol"
,
]
]
def
generate_comments
(
commentable_id
,
level_limit
,
users
)
users
=
User
.
all
.
to_a
THREAD_SEEDS
.
each
do
|
thread_seed
|
comment_thread
=
CommentThread
.
new
(
commentable_id:
commentable_id
,
body:
thread_seed
[
:body
],
title:
thread_seed
[
:title
],
course_id:
"1"
)
puts
"Generating threads and comments for
#{
commentable_id
}
..."
comment_thread
.
author
=
users
.
sample
comment_thread
.
save!
threads
=
[]
3
.
times
do
comments
=
[]
comment
=
comment_thread
.
comments
.
new
(
body:
COMMENT_BODY_SEEDS
.
sample
,
course_id:
"1"
)
comment
.
author
=
users
.
sample
thread_seeds
.
each
do
|
thread_seed
|
comment
.
endorsed
=
[
true
,
false
].
sample
comment_thread
=
CommentThread
.
new
(
commentable_id:
commentable_id
,
body:
thread_seed
[
:body
],
title:
thread_seed
[
:title
],
course_id:
"1"
)
comment
.
save!
comment_thread
.
author
=
users
.
sample
end
comment_thread
.
save!
10
.
times
do
threads
<<
comment_thread
comment
=
Comment
.
where
(
comment_thread_id:
comment_thread
.
id
).
reject
{
|
c
|
c
.
depth
>=
level_limit
}.
sample
3
.
times
do
sub_comment
=
comment
.
children
.
new
(
body:
COMMENT_BODY_SEEDS
.
sample
,
course_id:
"1"
)
comment
=
comment_thread
.
comments
.
new
(
body:
comment_body_seeds
.
sample
,
course_id:
"1"
)
sub_comment
.
author
=
users
.
sample
comment
.
author
=
users
.
sample
sub_comment
.
endorsed
=
[
true
,
false
].
sample
comment
.
endorsed
=
[
true
,
false
].
sample
sub_comment
.
save!
comment
.
save!
end
comments
<<
comment
puts
"Generating a comment thread for
#{
commentable_id
}
"
end
10
.
times
do
comment
=
Comment
.
where
(
comment_thread_id:
comment_thread
.
id
).
reject
{
|
c
|
c
.
depth
>=
level_limit
}.
sample
sub_comment
=
comment
.
children
.
new
(
body:
comment_body_seeds
.
sample
,
course_id:
"1"
)
sub_comment
.
author
=
users
.
sample
sub_comment
.
endorsed
=
[
true
,
false
].
sample
sub_comment
.
save!
comments
<<
sub_comment
end
end
end
end
generate_comments
(
"question_1"
,
level_limit
,
users
)
puts
"voting for these threads & comments.."
generate_comments
(
"question_2"
,
level_limit
,
users
)
generate_comments
(
"course_1"
,
level_limit
,
users
)
generate_comments
(
"lecture_1"
,
level_limit
,
users
)
generate_comments
(
"video_1"
,
level_limit
,
users
)
generate_comments
(
"video_2"
,
level_limit
,
users
)
generate_comments
(
"lab_1"
,
level_limit
,
users
)
generate_comments
(
"lab_2"
,
level_limit
,
users
)
puts
"voting"
users
=
[]
(
1
..
10
).
each
do
|
id
|
users
<<
User
.
find_or_create_by
(
external_id:
id
.
to_s
)
end
CommentThread
.
all
.
each
do
|
c
|
threads
.
each
do
|
c
|
(
0
...
10
).
each
do
|
i
|
users
.
each
do
|
user
|
user
s
[
i
]
.
vote
(
c
,
[
:up
,
:down
].
sample
)
user
.
vote
(
c
,
[
:up
,
:down
].
sample
)
end
end
end
end
Comment
.
all
.
each
do
|
c
|
comments
.
each
do
|
c
|
(
0
...
10
).
each
do
|
i
|
users
.
each
do
|
user
|
user
s
[
i
]
.
vote
(
c
,
[
:up
,
:down
].
sample
)
user
.
vote
(
c
,
[
:up
,
:down
].
sample
)
end
end
end
end
puts
"finished"
end
task
:generate_comments
,
[
:commentable_id
]
=>
:environment
do
|
t
,
args
|
generate_comments_for
(
args
[
:commentable_id
])
end
task
:seed
=>
:environment
do
Comment
.
delete_all
CommentThread
.
delete_all
User
.
delete_all
Notification
.
delete_all
Subscription
.
delete_all
beginning_time
=
Time
.
now
users
=
(
1
..
10
).
map
{
|
id
|
User
.
find_or_create_by
(
external_id:
id
.
to_s
)}
10
.
times
do
users
.
sample
.
subscribe
(
users
.
sample
)
end
generate_comments_for
(
"question_1"
)
generate_comments_for
(
"question_2"
)
generate_comments_for
(
"course_1"
)
generate_comments_for
(
"lecture_1"
)
generate_comments_for
(
"video_1"
)
generate_comments_for
(
"video_2"
)
generate_comments_for
(
"lab_1"
)
generate_comments_for
(
"lab_2"
)
end_time
=
Time
.
now
end_time
=
Time
.
now
puts
"Number of comments generated:
#{
Comment
.
count
}
"
puts
"Number of comments generated:
#{
Comment
.
count
}
"
...
...
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