INCR-440 python3 compatibility

This commit is contained in:
Ayub khan
2019-07-12 15:23:17 +05:00
committed by Feanil Patel
parent 99060623ac
commit 3a04fbd37a
7 changed files with 70 additions and 54 deletions

View File

@@ -1,6 +1,8 @@
"""
Grading Context
"""
from __future__ import absolute_import
from collections import OrderedDict
from openedx.core.djangoapps.content.block_structure.api import get_course_in_cache

View File

@@ -1,5 +1,12 @@
"""
Emits course grade events.
"""
from __future__ import absolute_import
import six
from crum import get_current_user
from eventtracking import tracker
from track import contexts
from track.event_transaction_utils import (
create_new_event_transaction_id,
@@ -8,7 +15,6 @@ from track.event_transaction_utils import (
set_event_transaction_type
)
COURSE_GRADE_CALCULATED = u'edx.grades.course.grade_calculated'
GRADES_OVERRIDE_EVENT_TYPE = u'edx.grades.problem.score_overridden'
GRADES_RESCORE_EVENT_TYPE = u'edx.grades.problem.rescored'
@@ -35,13 +41,13 @@ def grade_updated(**kwargs):
root_id = create_new_event_transaction_id()
set_event_transaction_type(PROBLEM_SUBMITTED_EVENT_TYPE)
tracker.emit(
unicode(PROBLEM_SUBMITTED_EVENT_TYPE),
six.text_type(PROBLEM_SUBMITTED_EVENT_TYPE),
{
'user_id': unicode(kwargs['user_id']),
'course_id': unicode(kwargs['course_id']),
'problem_id': unicode(kwargs['usage_id']),
'event_transaction_id': unicode(root_id),
'event_transaction_type': unicode(PROBLEM_SUBMITTED_EVENT_TYPE),
'user_id': six.text_type(kwargs['user_id']),
'course_id': six.text_type(kwargs['course_id']),
'problem_id': six.text_type(kwargs['usage_id']),
'event_transaction_id': six.text_type(root_id),
'event_transaction_type': six.text_type(PROBLEM_SUBMITTED_EVENT_TYPE),
'weighted_earned': kwargs.get('weighted_earned'),
'weighted_possible': kwargs.get('weighted_possible'),
}
@@ -51,31 +57,31 @@ def grade_updated(**kwargs):
current_user = get_current_user()
instructor_id = getattr(current_user, 'id', None)
tracker.emit(
unicode(root_type),
six.text_type(root_type),
{
'course_id': unicode(kwargs['course_id']),
'user_id': unicode(kwargs['user_id']),
'problem_id': unicode(kwargs['usage_id']),
'course_id': six.text_type(kwargs['course_id']),
'user_id': six.text_type(kwargs['user_id']),
'problem_id': six.text_type(kwargs['usage_id']),
'new_weighted_earned': kwargs.get('weighted_earned'),
'new_weighted_possible': kwargs.get('weighted_possible'),
'only_if_higher': kwargs.get('only_if_higher'),
'instructor_id': unicode(instructor_id),
'event_transaction_id': unicode(get_event_transaction_id()),
'event_transaction_type': unicode(root_type),
'instructor_id': six.text_type(instructor_id),
'event_transaction_id': six.text_type(get_event_transaction_id()),
'event_transaction_type': six.text_type(root_type),
}
)
elif root_type in [SUBSECTION_OVERRIDE_EVENT_TYPE]:
tracker.emit(
unicode(root_type),
six.text_type(root_type),
{
'course_id': unicode(kwargs['course_id']),
'user_id': unicode(kwargs['user_id']),
'problem_id': unicode(kwargs['usage_id']),
'course_id': six.text_type(kwargs['course_id']),
'user_id': six.text_type(kwargs['user_id']),
'problem_id': six.text_type(kwargs['usage_id']),
'only_if_higher': kwargs.get('only_if_higher'),
'override_deleted': kwargs.get('score_deleted', False),
'event_transaction_id': unicode(get_event_transaction_id()),
'event_transaction_type': unicode(root_type),
'event_transaction_id': six.text_type(get_event_transaction_id()),
'event_transaction_type': six.text_type(root_type),
}
)
@@ -92,19 +98,19 @@ def subsection_grade_calculated(subsection_grade):
tracker.emit(
event_name,
{
'user_id': unicode(subsection_grade.user_id),
'course_id': unicode(subsection_grade.course_id),
'block_id': unicode(subsection_grade.usage_key),
'course_version': unicode(subsection_grade.course_version),
'user_id': six.text_type(subsection_grade.user_id),
'course_id': six.text_type(subsection_grade.course_id),
'block_id': six.text_type(subsection_grade.usage_key),
'course_version': six.text_type(subsection_grade.course_version),
'weighted_total_earned': subsection_grade.earned_all,
'weighted_total_possible': subsection_grade.possible_all,
'weighted_graded_earned': subsection_grade.earned_graded,
'weighted_graded_possible': subsection_grade.possible_graded,
'first_attempted': unicode(subsection_grade.first_attempted),
'subtree_edited_timestamp': unicode(subsection_grade.subtree_edited_timestamp),
'event_transaction_id': unicode(get_event_transaction_id()),
'event_transaction_type': unicode(get_event_transaction_type()),
'visible_blocks_hash': unicode(subsection_grade.visible_blocks_id),
'first_attempted': six.text_type(subsection_grade.first_attempted),
'subtree_edited_timestamp': six.text_type(subsection_grade.subtree_edited_timestamp),
'event_transaction_id': six.text_type(get_event_transaction_id()),
'event_transaction_type': six.text_type(get_event_transaction_type()),
'visible_blocks_hash': six.text_type(subsection_grade.visible_blocks_id),
}
)
@@ -121,14 +127,14 @@ def course_grade_calculated(course_grade):
tracker.emit(
event_name,
{
'user_id': unicode(course_grade.user_id),
'course_id': unicode(course_grade.course_id),
'course_version': unicode(course_grade.course_version),
'user_id': six.text_type(course_grade.user_id),
'course_id': six.text_type(course_grade.course_id),
'course_version': six.text_type(course_grade.course_version),
'percent_grade': course_grade.percent_grade,
'letter_grade': unicode(course_grade.letter_grade),
'course_edited_timestamp': unicode(course_grade.course_edited_timestamp),
'event_transaction_id': unicode(get_event_transaction_id()),
'event_transaction_type': unicode(get_event_transaction_type()),
'grading_policy_hash': unicode(course_grade.grading_policy_hash),
'letter_grade': six.text_type(course_grade.letter_grade),
'course_edited_timestamp': six.text_type(course_grade.course_edited_timestamp),
'event_transaction_id': six.text_type(get_event_transaction_id()),
'event_transaction_type': six.text_type(get_event_transaction_type()),
'grading_policy_hash': six.text_type(course_grade.grading_policy_hash),
}
)

View File

@@ -1,16 +1,16 @@
"""
Provides Python APIs exposed from Grades models.
"""
from lms.djangoapps.grades.models import (
PersistentCourseGrade as _PersistentCourseGrade,
PersistentSubsectionGrade as _PersistentSubsectionGrade,
PersistentSubsectionGradeOverride as _PersistentSubsectionGradeOverride,
VisibleBlocks as _VisibleBlocks,
)
from lms.djangoapps.utils import _get_key
from __future__ import absolute_import
from opaque_keys.edx.keys import CourseKey, UsageKey
from lms.djangoapps.grades.models import PersistentCourseGrade as _PersistentCourseGrade
from lms.djangoapps.grades.models import PersistentSubsectionGrade as _PersistentSubsectionGrade
from lms.djangoapps.grades.models import PersistentSubsectionGradeOverride as _PersistentSubsectionGradeOverride
from lms.djangoapps.grades.models import VisibleBlocks as _VisibleBlocks
from lms.djangoapps.utils import _get_key
def prefetch_grade_overrides_and_visible_blocks(user, course_key):
_PersistentSubsectionGradeOverride.prefetch(user.id, course_key)

View File

@@ -1,13 +1,16 @@
"""
Functionality for problem scores.
"""
from __future__ import absolute_import
from logging import getLogger
import six
from numpy import around
from xblock.core import XBlock
from openedx.core.lib.cache_utils import process_cached
from xmodule.graders import ProblemScore
from numpy import around
from .transformer import GradesTransformer
@@ -160,7 +163,7 @@ def _get_score_from_submissions(submissions_scores, block):
Returns the score values from the submissions API if found.
"""
if submissions_scores:
submission_value = submissions_scores.get(unicode(block.location))
submission_value = submissions_scores.get(six.text_type(block.location))
if submission_value:
first_attempted = submission_value['created_at']
weighted_earned = submission_value['points_earned']

View File

@@ -1,26 +1,28 @@
"""
SubsectionGrade Class
"""
from __future__ import absolute_import
from abc import ABCMeta
from collections import OrderedDict
from logging import getLogger
import six
from django.utils.html import escape
from lazy import lazy
from lms.djangoapps.grades.models import BlockRecord, PersistentSubsectionGrade
from lms.djangoapps.grades.scores import get_score, possibly_scored, compute_percent
from lms.djangoapps.grades.scores import compute_percent, get_score, possibly_scored
from xmodule import block_metadata_utils, graders
from xmodule.graders import AggregatedScore, ShowCorrectness
log = getLogger(__name__)
class SubsectionGradeBase(object):
class SubsectionGradeBase(six.with_metaclass(ABCMeta, object)):
"""
Abstract base class for Subsection Grades.
"""
__metaclass__ = ABCMeta
def __init__(self, subsection):
self.location = subsection.location
@@ -110,7 +112,7 @@ class ZeroSubsectionGrade(SubsectionGradeBase):
@lazy
def _aggregate_scores(self):
return graders.aggregate_scores(self.problem_scores.values())
return graders.aggregate_scores(list(self.problem_scores.values()))
@lazy
def problem_scores(self):
@@ -137,12 +139,11 @@ class ZeroSubsectionGrade(SubsectionGradeBase):
return locations
class NonZeroSubsectionGrade(SubsectionGradeBase):
class NonZeroSubsectionGrade(six.with_metaclass(ABCMeta, SubsectionGradeBase)):
"""
Abstract base class for Subsection Grades with
possibly NonZero values.
"""
__metaclass__ = ABCMeta
def __init__(self, subsection, all_total, graded_total, override=None):
super(NonZeroSubsectionGrade, self).__init__(subsection)
@@ -264,7 +265,7 @@ class CreateSubsectionGrade(NonZeroSubsectionGrade):
if problem_score:
self.problem_scores[block_key] = problem_score
all_total, graded_total = graders.aggregate_scores(self.problem_scores.values())
all_total, graded_total = graders.aggregate_scores(list(self.problem_scores.values()))
super(CreateSubsectionGrade, self).__init__(subsection, all_total, graded_total)
@@ -343,5 +344,5 @@ class CreateSubsectionGrade(NonZeroSubsectionGrade):
return [
BlockRecord(location, score.weight, score.raw_possible, score.graded)
for location, score in
self.problem_scores.iteritems()
six.iteritems(self.problem_scores)
]

View File

@@ -1,6 +1,8 @@
"""
Grades Transformer
"""
from __future__ import absolute_import
import json
from base64 import b64encode
from functools import reduce as functools_reduce

View File

@@ -1,4 +1,6 @@
"A light weight interface to grading helper functions"
from __future__ import absolute_import
from . import grade_utils