Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
ease
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
ease
Commits
9a39aeb3
Commit
9a39aeb3
authored
Nov 07, 2012
by
Vik Paruchuri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add in error template. Return errors instead of feedback if errors exist.
parent
d6ddd2d7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
2 deletions
+21
-2
grade.py
+21
-2
No files found.
grade.py
View file @
9a39aeb3
...
...
@@ -42,17 +42,31 @@ feedback_template = u"""
</div>
"""
error_template
=
u"""
<div class="feedback">
<header>Feedback</header>
<section>
<div class="error">
{errors}
</div>
</section>
</div>
"""
def
grade
(
grader_path
,
submission
,
sandbox
=
None
):
log
.
debug
(
"Grader path: {0}
\n
Submission: {1}"
.
format
(
grader_path
,
submission
))
results
=
{
'errors'
:
[],
'tests'
:
[],
'correct'
:
False
,
'score'
:
0
,
'feedback'
:
""
}
has_error
=
False
#Try to find and load the model file
try
:
grader_data
=
pickle
.
load
(
file
(
grader_path
,
"r"
))
except
:
results
[
'errors'
]
.
append
(
"Could not find a valid model file."
)
has_error
=
True
grader_set
=
EssaySet
(
type
=
"test"
)
#Try to add essays to essay set object
...
...
@@ -61,14 +75,16 @@ def grade(grader_path,submission,sandbox=None):
grader_set
.
update_prompt
(
str
(
grader_data
[
'prompt'
]))
except
:
results
[
'errors'
]
.
append
(
"Essay could not be added to essay set:{0}"
.
format
(
submission
))
has_error
=
True
#Try to extract features from submission and assign score via the model
try
:
grader_feats
=
grader_data
[
'extractor'
]
.
gen_feats
(
grader_set
)
feedback
=
grader_data
[
'extractor'
]
.
gen_feedback
(
grader_set
)
feedback
=
grader_data
[
'extractor'
]
.
gen_feedback
(
grader_set
)
[
0
]
results
[
'score'
]
=
int
(
grader_data
[
'model'
]
.
predict
(
grader_feats
)[
0
])
except
:
results
[
'errors'
]
.
append
(
"Could not extract features and score essay."
)
has_error
=
True
#Determine maximum score and correctness of response
max_score
=
numpy
.
max
(
grader_data
[
'model'
]
.
classes_
)
...
...
@@ -78,8 +94,11 @@ def grade(grader_path,submission,sandbox=None):
results
[
'correct'
]
=
False
#Add feedback template to results
results
[
"feedback"
]
=
feedback_template
.
format
(
topicality
=
feedback
[
'topicality'
],
if
not
has_error
:
results
[
'feedback'
]
=
feedback_template
.
format
(
topicality
=
feedback
[
'topicality'
],
spelling
=
feedback
[
'spelling'
],
grammar
=
feedback
[
'grammar'
],
markup_text
=
feedback
[
'markup_text'
])
else
:
results
[
'feedback'
]
=
error_template
.
format
(
errors
=
' '
.
join
(
results
[
'errors'
]))
return
results
...
...
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