<commit_before>import json
import logging

from lxml import etree

from datetime import datetime
from pkg_resources import resource_string
from .capa_module import ComplexEncoder
from .stringify import stringify_children
from .x_module import XModule
from xmodule.raw_module import RawDescriptor
from xmodule.modulestore import Location
from xmodule.modulestore.django import modulestore
from timeinfo import TimeInfo
from xblock.core import Object, Integer, Boolean, String, Scope

from xmodule.open_ended_grading_classes.peer_grading_service import PeerGradingService, GradingServiceError, MockPeerGradingService

log = logging.getLogger(__name__)

USE_FOR_SINGLE_LOCATION = False
LINK_TO_LOCATION = ""
TRUE_DICT = [True, "True", "true", "TRUE"]
MAX_SCORE = 1
IS_GRADED = True

EXTERNAL_GRADER_NO_CONTACT_ERROR = "Failed to contact external graders.  Please notify course staff."


class PeerGradingModule(XModule):
    _VERSION = 1

    js = {'coffee': [resource_string(__name__, 'js/src/peergrading/peer_grading.coffee'),
                     resource_string(__name__, 'js/src/peergrading/peer_grading_problem.coffee'),
                     resource_string(__name__, 'js/src/collapsible.coffee'),
                     resource_string(__name__, 'js/src/javascript_loader.coffee'),
                     ]}
    js_module_name = "PeerGrading"

    css = {'scss': [resource_string(__name__, 'css/combinedopenended/display.scss')]}

    use_for_single_location = Boolean(help="Whether to use this for a single location or as a panel.", default=USE_FOR_SINGLE_LOCATION, scope=Scope.settings)
    link_to_location = String(help="The location this problem is linked to.", default=LINK_TO_LOCATION, scope=Scope.settings)
    is_graded = Boolean(help="Whether or not this module is scored.",default=IS_GRADED, scope=Scope.settings)
    display_due_date_string = String(help="Due date that should be displayed.", default=None, scope=Scope.settings)
    grace_period_string = String(help="Amount of grace to give on the due date.", default=None, scope=Scope.settings)
    max_grade = Integer(help="The maximum grade that a student can receieve for this problem.", default=MAX_SCORE, scope=Scope.settings)
    student_data_for_location = Object(help="Student data for a given peer grading problem.", default=json.dumps({}),scope=Scope.student_state)

    def __init__(self, system, location, descriptor, model_data):
        XModule.__init__(self, system, location, descriptor, model_data)

        #We need to set the location here so the child modules can use it
        system.set('location', location)
        self.system = system
        if(self.system.open_ended_grading_interface):
            self.peer_gs = PeerGradingService(self.system.open_ended_grading_interface, self.system)
        else:
            self.peer_gs = MockPeerGradingService()

        log.debug(self.use_for_single_location)
        log.debug(type(self.use_for_single_location))
        log.debug(self.use_for_single_location==True)
        if self.use_for_single_location in TRUE_DICT:
            try:
                self.linked_problem = modulestore().get_instance(self.system.course_id, self.link_to_location)
            except:
                log.error("Linked location {0} for peer grading module {1} does not exist".format(
                    self.link_to_location, self.location))
                raise
            due_date = self.linked_problem._model_data.get('peer_grading_due', None)
            if due_date:
                self._model_data['due'] = due_date

        try:
            self.timeinfo = TimeInfo(self.display_due_date_string, self.grace_period_string)
        except:
            log.error("Error parsing due date information in location {0}".format(location))
            raise

        self.display_due_date = self.timeinfo.display_due_date

        try:
            self.student_data_for_location = json.loads(self.student_data_for_location)
        except:
            pass

        self.ajax_url = self.system.ajax_url
        if not self.ajax_url.endswith("/"):
            self.ajax_url = self.ajax_url + "/"

        if not isinstance(self.max_grade, (int, long)):
            #This could result in an exception, but not wrapping in a try catch block so it moves up the stack
            self.max_grade = int(self.max_grade)<commit_msg>Remove debug statements<commit_after>import json
import logging

from lxml import etree

from datetime import datetime
from pkg_resources import resource_string
from .capa_module import ComplexEncoder
from .stringify import stringify_children
from .x_module import XModule
from xmodule.raw_module import RawDescriptor
from xmodule.modulestore import Location
from xmodule.modulestore.django import modulestore
from timeinfo import TimeInfo
from xblock.core import Object, Integer, Boolean, String, Scope

from xmodule.open_ended_grading_classes.peer_grading_service import PeerGradingService, GradingServiceError, MockPeerGradingService

log = logging.getLogger(__name__)

USE_FOR_SINGLE_LOCATION = False
LINK_TO_LOCATION = ""
TRUE_DICT = [True, "True", "true", "TRUE"]
MAX_SCORE = 1
IS_GRADED = True

EXTERNAL_GRADER_NO_CONTACT_ERROR = "Failed to contact external graders.  Please notify course staff."


class PeerGradingModule(XModule):
    _VERSION = 1

    js = {'coffee': [resource_string(__name__, 'js/src/peergrading/peer_grading.coffee'),
                     resource_string(__name__, 'js/src/peergrading/peer_grading_problem.coffee'),
                     resource_string(__name__, 'js/src/collapsible.coffee'),
                     resource_string(__name__, 'js/src/javascript_loader.coffee'),
                     ]}
    js_module_name = "PeerGrading"

    css = {'scss': [resource_string(__name__, 'css/combinedopenended/display.scss')]}

    use_for_single_location = Boolean(help="Whether to use this for a single location or as a panel.", default=USE_FOR_SINGLE_LOCATION, scope=Scope.settings)
    link_to_location = String(help="The location this problem is linked to.", default=LINK_TO_LOCATION, scope=Scope.settings)
    is_graded = Boolean(help="Whether or not this module is scored.",default=IS_GRADED, scope=Scope.settings)
    display_due_date_string = String(help="Due date that should be displayed.", default=None, scope=Scope.settings)
    grace_period_string = String(help="Amount of grace to give on the due date.", default=None, scope=Scope.settings)
    max_grade = Integer(help="The maximum grade that a student can receieve for this problem.", default=MAX_SCORE, scope=Scope.settings)
    student_data_for_location = Object(help="Student data for a given peer grading problem.", default=json.dumps({}),scope=Scope.student_state)

    def __init__(self, system, location, descriptor, model_data):
        XModule.__init__(self, system, location, descriptor, model_data)

        #We need to set the location here so the child modules can use it
        system.set('location', location)
        self.system = system
        if(self.system.open_ended_grading_interface):
            self.peer_gs = PeerGradingService(self.system.open_ended_grading_interface, self.system)
        else:
            self.peer_gs = MockPeerGradingService()
            
        if self.use_for_single_location in TRUE_DICT:
            try:
                self.linked_problem = modulestore().get_instance(self.system.course_id, self.link_to_location)
            except:
                log.error("Linked location {0} for peer grading module {1} does not exist".format(
                    self.link_to_location, self.location))
                raise
            due_date = self.linked_problem._model_data.get('peer_grading_due', None)
            if due_date:
                self._model_data['due'] = due_date

        try:
            self.timeinfo = TimeInfo(self.display_due_date_string, self.grace_period_string)
        except:
            log.error("Error parsing due date information in location {0}".format(location))
            raise

        self.display_due_date = self.timeinfo.display_due_date

        try:
            self.student_data_for_location = json.loads(self.student_data_for_location)
        except:
            pass

        self.ajax_url = self.system.ajax_url
        if not self.ajax_url.endswith("/"):
            self.ajax_url = self.ajax_url + "/"

        if not isinstance(self.max_grade, (int, long)):
            #This could result in an exception, but not wrapping in a try catch block so it moves up the stack
            self.max_grade = int(self.max_grade)
{'fraction_non_alphanumeric': 0.08508648901355774, 'fraction_numerical': 0.0011687704534829358, 'mean_word_length': 3.3882051282051284, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3826837', 'n_tokens_mistral': 2488, 'n_tokens_neox': 2409, 'n_words': 608}