Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dtu-quiz
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
enote
dtu-quiz
Commits
df6c1c1b
Commit
df6c1c1b
authored
9 years ago
by
Iain Bryson
Browse files
Options
Downloads
Patches
Plain Diff
Extract review stats query as a service.
parent
b67ac9ea
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/controllers/quiz_templates_controller.rb
+3
-62
3 additions, 62 deletions
app/controllers/quiz_templates_controller.rb
app/services/review_stats_service.rb
+76
-0
76 additions, 0 deletions
app/services/review_stats_service.rb
with
79 additions
and
62 deletions
app/controllers/quiz_templates_controller.rb
+
3
−
62
View file @
df6c1c1b
...
@@ -72,7 +72,7 @@ class QuizTemplatesController < ApplicationController
...
@@ -72,7 +72,7 @@ class QuizTemplatesController < ApplicationController
unless
@quiz_template
.
editable?
unless
@quiz_template
.
editable?
@editable
=
false
@editable
=
false
term
=
@quiz_template
.
was_visible_to_students
?
"was previosly"
:
"is"
term
=
@quiz_template
.
was_visible_to_students
?
"was previo
u
sly"
:
"is"
@form_modal_body
=
"Quiz cannot be edited; it
#{
term
}
visible to students"
@form_modal_body
=
"Quiz cannot be edited; it
#{
term
}
visible to students"
else
else
@editable
=
true
@editable
=
true
...
@@ -118,40 +118,9 @@ class QuizTemplatesController < ApplicationController
...
@@ -118,40 +118,9 @@ class QuizTemplatesController < ApplicationController
def
review_stats
def
review_stats
get_quiz_level_params
get_quiz_level_params
@
form_modal_title
=
"
Review
Stat
istics Q
#{
@quiz_id
}
"
@
review_stats_data
=
ReviewStat
sService
.
new
(
@quiz_template
,
@course
,
current_user
).
generate_stats
@review_stats_query
=
QuizInstance
.
where
({
:course_id
=>
@course_id
,
:quiz_number
=>
@quiz_id
}).
map_reduce
(
map_stats_js
,
reduce_stats_js
).
out
(
inline:
true
).
entries
respond_with_dialog
"Review Statistics Q
#{
@quiz_id
}
"
ap
@review_stats_query
@review_stats_data
=
[
"FreeTextQuestion"
,
"FillInTheBlankQuestion"
,
"DrawQuestion"
].
map
do
|
type
|
stats
=
@review_stats_query
.
select
{
|
s
|
s
[
"_id"
][
"type"
]
==
type
&&
!
s
[
"_id"
][
"scored"
]
}
groups
=
stats
.
map
{
|
s
|
s
[
"_id"
][
"group_name"
]
}.
uniq
questions
=
stats
.
map
{
|
s
|
s
[
"_id"
][
"question_number"
]
}.
uniq
.
sort
question_number_to_column
=
{}
questions
.
each_with_index
{
|
e
,
i
|
question_number_to_column
[
e
]
=
i
}
rows
=
groups
.
map
do
|
group
|
question_columns
=
Array
.
new
(
questions
.
length
,
0
)
stats
.
select
{
|
s
|
s
[
"_id"
][
"group_name"
]
==
group
}.
map
do
|
s
|
question_columns
[
question_number_to_column
[
s
[
"_id"
][
"question_number"
]]]
+=
s
[
"value"
].
to_i
end
[
group
].
concat
question_columns
end
{
:type
=>
type
.
gsub
(
"Question"
,
""
),
:questions
=>
questions
,
:rows
=>
rows
}
end
ap
@review_stats_data
respond_to
do
|
format
|
format
.
html
format
.
js
end
end
end
def
review_questions
def
review_questions
...
@@ -309,34 +278,6 @@ class QuizTemplatesController < ApplicationController
...
@@ -309,34 +278,6 @@ class QuizTemplatesController < ApplicationController
end
end
end
end
def
map_stats_js
%Q{
function map_stats() {
for (var q_no in this.sections) {
var q = this.sections[q_no]
print(q)
if (q._type && (q._type == 'FreeTextQuestion' || q._type == 'FillInTheBlankQuestion' || q._type == 'DrawQuestion')) {
emit({
type: q._type,
question_number: q_no,
group_name: this.group_name,
scored: q.answers[0].answer_kind !== undefined,
},
1);
}
}
}
}
end
def
reduce_stats_js
%Q{
function reduce_stats(id, docs) {
return Array.sum(docs);
}
}
end
def
exec_quiz_service
(
&
block
)
def
exec_quiz_service
(
&
block
)
return
unless
get_quiz_level_params
return
unless
get_quiz_level_params
...
...
This diff is collapsed.
Click to expand it.
app/services/review_stats_service.rb
0 → 100644
+
76
−
0
View file @
df6c1c1b
class
ReviewStatsService
attr_accessor
(
:course
,
:quiz_template
,
:user
)
def
initialize
(
quiz_template
,
course
,
user
)
@quiz_template
=
quiz_template
@course
=
course
@user
=
user
end
def
generate_stats
@review_stats_query
=
QuizInstance
.
where
({
:course_id
=>
@course
.
_id
,
:quiz_number
=>
@quiz_template
.
quiz_number
}).
map_reduce
(
map_stats_js
,
reduce_stats_js
).
out
(
inline:
true
).
entries
Rails
.
logger
.
info
"Review stats query:
#{
ap
@review_stats_query
}
"
review_stats_data
=
[
"FreeTextQuestion"
,
"FillInTheBlankQuestion"
,
"DrawQuestion"
].
map
do
|
type
|
stats
=
@review_stats_query
.
select
{
|
s
|
s
[
"_id"
][
"type"
]
==
type
&&
!
s
[
"_id"
][
"scored"
]
}
groups
=
stats
.
map
{
|
s
|
s
[
"_id"
][
"group_name"
]
}.
uniq
questions
=
stats
.
map
{
|
s
|
s
[
"_id"
][
"question_number"
]
}.
uniq
.
sort
question_number_to_column
=
{}
questions
.
each_with_index
{
|
e
,
i
|
question_number_to_column
[
e
]
=
i
}
rows
=
groups
.
map
do
|
group
|
question_columns
=
Array
.
new
(
questions
.
length
,
0
)
stats
.
select
{
|
s
|
s
[
"_id"
][
"group_name"
]
==
group
}.
map
do
|
s
|
question_columns
[
question_number_to_column
[
s
[
"_id"
][
"question_number"
]]]
+=
s
[
"value"
].
to_i
end
[
group
].
concat
question_columns
end
next
if
rows
.
count
==
0
{
:type
=>
type
.
gsub
(
"Question"
,
""
),
:questions
=>
questions
,
:rows
=>
rows
}
end
.
reject
(
&
:nil?
)
Rails
.
logger
.
info
"Review stats data:
#{
ap
review_stats_data
}
"
review_stats_data
end
private
def
map_stats_js
%Q{
function map_stats() {
for (var q_no in this.sections) {
var q = this.sections[q_no]
print(q)
if (q._type && (q._type == 'FreeTextQuestion' || q._type == 'FillInTheBlankQuestion' || q._type == 'DrawQuestion')) {
emit({
type: q._type,
question_number: q_no,
group_name: this.group_name,
scored: q.answers[0].answer_kind !== undefined,
},
1);
}
}
}
}
end
def
reduce_stats_js
%Q{
function reduce_stats(id, docs) {
return Array.sum(docs);
}
}
end
end
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment