<commit_before>from uuid import uuid4, UUID

from sqlalchemy import Column, Unicode, Boolean, ForeignKey, Integer
from sqlalchemy.orm import relationship
from sqlalchemy_utils import UUIDType


from unicore.ask.service import Base


class UUIDMixin(object):
    _uuid = Column(
        UUIDType(binary=False), name='uuid', default=uuid4,
        primary_key=True)

    @property
    def uuid(self):
        return self._uuid.hex

    @uuid.setter
    def uuid(self, value):
        if isinstance(value, UUID):
            self._uuid = value
        else:
            self._uuid = UUID(hex=value)


class QuestionResponses(Base, UUIDMixin):
    __tablename__ = 'question_responses'

    text = Column(Unicode(255), nullable=False)
    question_option_id = Column(
        UUIDType(binary=False), ForeignKey('question_options.uuid'),
        nullable=False)

    def to_dict(self):
        return {
            'uuid': self.uuid,
            'text': self.text,
        }


class QuestionOption(Base, UUIDMixin):
    __tablename__ = 'question_options'

    title = Column(Unicode(255), nullable=True)
    short_name = Column(Unicode(255), nullable=True)
    responses_count = Column(Integer())
    question_id = Column(
        UUIDType(binary=False), ForeignKey('questions.uuid'), nullable=False)
    responses = relationship(
        QuestionResponses, backref='questions', lazy="dynamic")

    def to_dict(self):
        return {
            'uuid': self.uuid,
            'title': self.title,
            'short_name': self.short_name,
            'responses_count': self.responses_count,
        }


class Question(Base, UUIDMixin):
    __tablename__ = 'questions'

    question_types = (
        'free_text',
        'multiple_choice',
    )

    title = Column(Unicode(255), nullable=False)
    short_name = Column(Unicode(255), nullable=True)
    multiple = Column(Boolean(255), default=True)
    question_type = Column(Unicode(255), nullable=False)
    options = relationship(QuestionOption, backref='questions', lazy="dynamic")

    def to_dict(self):
        return {
            'uuid': self.uuid,
            'title': self.title,
            'short_name': self.short_name,
            'multiple': self.multiple,
            'question_type': self.question_type,
            'options': [option.to_dict() for option in self.options]
        }
<commit_msg>fix question repsonse class definition<commit_after>from uuid import uuid4, UUID

from sqlalchemy import Column, Unicode, Boolean, ForeignKey, Integer
from sqlalchemy.orm import relationship
from sqlalchemy_utils import UUIDType


from unicore.ask.service import Base


class UUIDMixin(object):
    _uuid = Column(
        UUIDType(binary=False), name='uuid', default=uuid4,
        primary_key=True)

    @property
    def uuid(self):
        return self._uuid.hex

    @uuid.setter
    def uuid(self, value):
        if isinstance(value, UUID):
            self._uuid = value
        else:
            self._uuid = UUID(hex=value)


class QuestionResponse(Base, UUIDMixin):
    __tablename__ = 'question_responses'

    text = Column(Unicode(255), nullable=False)
    question_option_id = Column(
        UUIDType(binary=False), ForeignKey('question_options.uuid'),
        nullable=False)

    def to_dict(self):
        return {
            'uuid': self.uuid,
            'text': self.text,
        }


class QuestionOption(Base, UUIDMixin):
    __tablename__ = 'question_options'

    title = Column(Unicode(255), nullable=True)
    short_name = Column(Unicode(255), nullable=True)
    responses_count = Column(Integer())
    question_id = Column(
        UUIDType(binary=False), ForeignKey('questions.uuid'), nullable=False)
    responses = relationship(
        QuestionResponse, backref='question_options', lazy="dynamic")

    def to_dict(self):
        return {
            'uuid': self.uuid,
            'title': self.title,
            'short_name': self.short_name,
            'responses_count': self.responses_count,
        }


class Question(Base, UUIDMixin):
    __tablename__ = 'questions'

    question_types = (
        'free_text',
        'multiple_choice',
    )

    title = Column(Unicode(255), nullable=False)
    short_name = Column(Unicode(255), nullable=True)
    multiple = Column(Boolean(255), default=True)
    question_type = Column(Unicode(255), nullable=False)
    options = relationship(QuestionOption, backref='questions', lazy="dynamic")

    def to_dict(self):
        return {
            'uuid': self.uuid,
            'title': self.title,
            'short_name': self.short_name,
            'multiple': self.multiple,
            'question_type': self.question_type,
            'options': [option.to_dict() for option in self.options]
        }

{'fraction_non_alphanumeric': 0.11148506520824569, 'fraction_numerical': 0.009676062263357174, 'mean_word_length': 2.8131515637530073, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '218814', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1417, 'n_words': 298}