Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-ora2
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
edx-ora2
Commits
f467ab54
Commit
f467ab54
authored
Feb 04, 2014
by
Stephen Sanchez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updating the API and tests.
parent
5d73dc4b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
73 additions
and
32 deletions
+73
-32
apps/openassessment/peer/api.py
+40
-21
apps/openassessment/peer/models.py
+3
-1
apps/openassessment/peer/serializers.py
+1
-0
apps/openassessment/peer/test/test_api.py
+27
-3
apps/submissions/api.py
+2
-7
No files found.
apps/openassessment/peer/api.py
View file @
f467ab54
...
...
@@ -11,10 +11,11 @@ from django.db import DatabaseError
from
openassessment.peer.models
import
PeerEvaluation
from
openassessment.peer.serializers
import
PeerEvaluationSerializer
from
submissions.models
import
Submission
,
StudentItem
logger
=
logging
.
getLogger
(
__name__
)
PEER_TYPE
=
"P
eer
"
PEER_TYPE
=
"P
E
"
class
PeerEvaluationError
(
Exception
):
...
...
@@ -97,7 +98,7 @@ def create_evaluation(submission_id, scorer_id, assessment_dict,
>>> points_possible=12,
>>> feedback="Your submission was thrilling.",
>>> )
>>> create_evaluation("
submission_one
", "Tim", assessment_dict)
>>> create_evaluation("
1
", "Tim", assessment_dict)
{
'points_earned': 6,
'points_possible': 12,
...
...
@@ -107,18 +108,19 @@ def create_evaluation(submission_id, scorer_id, assessment_dict,
}
"""
peer_evaluation
=
{
"scorer_id"
:
scorer_id
,
"submission_id"
:
submission_id
,
"points_earned"
:
sum
(
assessment_dict
[
"points_earned"
]),
"points_possible"
:
assessment_dict
[
"points_possible"
],
"score_type"
:
PEER_TYPE
,
"feedback"
:
assessment_dict
[
"feedback"
],
}
if
scored_at
:
peer_evaluation
[
"scored_at"
]
=
scored_at
try
:
submission
=
Submission
.
objects
.
get
(
pk
=
submission_id
)
peer_evaluation
=
{
"scorer_id"
:
scorer_id
,
"submission"
:
submission
.
pk
,
"points_earned"
:
sum
(
assessment_dict
[
"points_earned"
]),
"points_possible"
:
assessment_dict
[
"points_possible"
],
"score_type"
:
PEER_TYPE
,
"feedback"
:
assessment_dict
[
"feedback"
],
}
if
scored_at
:
peer_evaluation
[
"scored_at"
]
=
scored_at
peer_serializer
=
PeerEvaluationSerializer
(
data
=
peer_evaluation
)
if
not
peer_serializer
.
is_valid
():
raise
PeerEvaluationRequestError
(
peer_serializer
.
errors
)
...
...
@@ -126,7 +128,7 @@ def create_evaluation(submission_id, scorer_id, assessment_dict,
return
peer_serializer
.
data
except
DatabaseError
:
error_message
=
u"An error occurred while creating evaluation {} for submission: {} by: {}"
.
format
(
peer_evaluation
,
assessment_dict
,
submission_id
,
scorer_id
)
...
...
@@ -192,7 +194,7 @@ def get_evaluations(submission_id):
while retrieving the evaluations associated with this submission.
Examples:
>>> get_evaluations("
submission_one
")
>>> get_evaluations("
1
")
[
{
'points_earned': 6,
...
...
@@ -211,10 +213,20 @@ def get_evaluations(submission_id):
]
"""
pass
try
:
submission
=
Submission
.
objects
.
get
(
pk
=
submission_id
)
evaluations
=
PeerEvaluation
.
objects
.
filter
(
submission
=
submission
)
serializer
=
PeerEvaluationSerializer
(
evaluations
,
many
=
True
)
return
serializer
.
data
except
DatabaseError
:
error_message
=
(
u"Error getting evaluations for submission {}"
.
format
(
submission_id
)
)
logger
.
exception
(
error_message
)
raise
PeerEvaluationInternalError
(
error_message
)
def
get_submission_to_evaluate
(
student_item
,
scorer_id
):
def
get_submission_to_evaluate
(
student_item
_dict
):
"""Get a submission to peer evaluate.
Retrieves a submission for evaluation for the given student_item. This will
...
...
@@ -224,7 +236,7 @@ def get_submission_to_evaluate(student_item, scorer_id):
submissions from students who are not as active in the evaluation process.
Args:
student_item (dict):
student_item
_dict
(dict):
scorer_id (str):
Returns:
...
...
@@ -239,9 +251,10 @@ def get_submission_to_evaluate(student_item, scorer_id):
>>> student_item_dict = dict(
>>> item_id="item_1",
>>> course_id="course_1",
>>> item_type="type_one"
>>> item_type="type_one",
>>> student_id="Bob",
>>> )
>>> get_submission_to_evaluate(student_item_dict
, "Bob"
)
>>> get_submission_to_evaluate(student_item_dict)
{
'student_item': 2,
'attempt_number': 1,
...
...
@@ -253,4 +266,10 @@ def get_submission_to_evaluate(student_item, scorer_id):
"""
pass
student_items
=
StudentItem
.
objects
.
filter
(
course_id
=
student_item_dict
[
"course_id"
],
item_id
=
student_item_dict
[
"item_id"
],
)
.
exclude
(
student_id
=
student_item_dict
[
"student_id"
])
# TODO: We need a priority queue.
return
Submission
.
objects
.
filter
(
student_item__in
=
student_items
)[:
1
]
apps/openassessment/peer/models.py
View file @
f467ab54
...
...
@@ -6,9 +6,11 @@ be a lot here, like rubrics and such.
from
django.db
import
models
from
django.utils.timezone
import
now
from
submissions.models
import
Submission
class
PeerEvaluation
(
models
.
Model
):
#
submission = models.ForeignKey(Submission)
submission
=
models
.
ForeignKey
(
Submission
)
points_earned
=
models
.
PositiveIntegerField
(
default
=
0
)
points_possible
=
models
.
PositiveIntegerField
(
default
=
0
)
scored_at
=
models
.
DateTimeField
(
default
=
now
,
db_index
=
True
)
...
...
apps/openassessment/peer/serializers.py
View file @
f467ab54
...
...
@@ -10,6 +10,7 @@ class PeerEvaluationSerializer(serializers.ModelSerializer):
class
Meta
:
model
=
PeerEvaluation
fields
=
(
'submission'
,
'points_earned'
,
'points_possible'
,
'scored_at'
,
...
...
apps/openassessment/peer/test/test_api.py
View file @
f467ab54
from
ddt
import
ddt
from
django.test
import
TestCase
from
openassessment.peer.api
import
create_evaluation
,
get_evaluations
from
submissions.api
import
create_submission
from
submissions.tests.test_api
import
STUDENT_ITEM
,
ANSWER_ONE
ASSESSMENT_DICT
=
dict
(
points_earned
=
[
1
,
0
,
3
,
2
],
points_possible
=
12
,
feedback
=
"Your submission was thrilling."
,
)
@ddt
class
TestApi
(
TestCase
):
def
test_create_evaluation
(
self
):
pass
create_submission
(
STUDENT_ITEM
,
ANSWER_ONE
)
evaluation
=
create_evaluation
(
"1"
,
STUDENT_ITEM
[
"student_id"
],
ASSESSMENT_DICT
)
self
.
_assert_evaluation
(
evaluation
,
**
ASSESSMENT_DICT
)
def
test_get_evaluations
(
self
):
pass
create_submission
(
STUDENT_ITEM
,
ANSWER_ONE
)
create_evaluation
(
"1"
,
STUDENT_ITEM
[
"student_id"
],
ASSESSMENT_DICT
)
evaluations
=
get_evaluations
(
"1"
)
self
.
assertEqual
(
1
,
len
(
evaluations
))
self
.
_assert_evaluation
(
evaluations
[
0
],
**
ASSESSMENT_DICT
)
def
test_get_submission_to_evaluate
(
self
):
pass
def
test_concurrent_evaluators
(
self
):
pass
def
_assert_evaluation
(
self
,
evaluation
,
points_earned
,
points_possible
,
feedback
):
self
.
assertIsNotNone
(
evaluation
)
self
.
assertEqual
(
evaluation
[
"points_earned"
],
sum
(
points_earned
))
self
.
assertEqual
(
evaluation
[
"points_possible"
],
points_possible
)
self
.
assertEqual
(
evaluation
[
"feedback"
],
feedback
)
\ No newline at end of file
apps/submissions/api.py
View file @
f467ab54
...
...
@@ -129,7 +129,7 @@ def create_submission(student_item_dict, answer, submitted_at=None,
u"Submission answer could not be properly decoded to unicode."
)
model_kwargs
=
{
"student_item"
:
student_item_model
,
"student_item"
:
student_item_model
.
pk
,
"answer"
:
answer
,
"attempt_number"
:
attempt_number
,
}
...
...
@@ -137,12 +137,7 @@ def create_submission(student_item_dict, answer, submitted_at=None,
model_kwargs
[
"submitted_at"
]
=
submitted_at
try
:
# Serializer validation requires the student item primary key, rather
# than the student item model itself. Create a copy of the submission
# kwargs and replace the student item model with it's primary key.
validation_data
=
model_kwargs
.
copy
()
validation_data
[
"student_item"
]
=
student_item_model
.
pk
submission_serializer
=
SubmissionSerializer
(
data
=
validation_data
)
submission_serializer
=
SubmissionSerializer
(
data
=
model_kwargs
)
if
not
submission_serializer
.
is_valid
():
raise
SubmissionRequestError
(
submission_serializer
.
errors
)
submission_serializer
.
save
()
...
...
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