Skip to content

Commit

Permalink
renamed parsers package
Browse files Browse the repository at this point in the history
Started additing iteractions
  • Loading branch information
LucasWolfgang committed Oct 6, 2023
1 parent 395eace commit 8cb8cf4
Show file tree
Hide file tree
Showing 26 changed files with 116 additions and 206 deletions.
77 changes: 33 additions & 44 deletions qas_editor/answer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,19 @@
import logging
from typing import TYPE_CHECKING, Dict, List, Callable
from .enums import TolFormat, TextFormat, ShapeType, EmbeddedFormat, Direction,\
TolType, Logic
TolType
from .utils import Serializable, File, FText, TList, attribute_setup
_LOG = logging.getLogger(__name__)


class Processor:
"""Logic expression used to define the result of the question.
"""

def __init__(self, key: str|Callable, value: str) -> None:
self.children: Dict[Logic, Processor] = None
self.key = key
self.val = value

def any_n(self, *args):
pass

def run(self):
for key, value in self.children.items():
pass


class Item:
"""This is an abstract class Question used as a parent for specific
types of Questions.
"""
ANS_TYPE = None

def __init__(self, default_grade=1.0, feedbacks: Dict[float, FText] = None,
time_lim: int = 0, free_hints: list = None):
def __init__(self, feedbacks: Dict[str, FText] = None,
hints: Dict[str, FText] = None):
"""[summary]
Args:
name (str): name of the question
Expand All @@ -58,33 +41,39 @@ def __init__(self, default_grade=1.0, feedbacks: Dict[float, FText] = None,
general_feedback (str, optional): general feedback.
dbid (int, optional): id number.
"""
self.units = None
self._grade = float(default_grade)
self._time_lim = int(time_lim)
self._feedbacks = None
self._free_hints = TList(FText, free_hints)
self._options = []
self._procs: Processor = None

grade = attribute_setup(float, "_grade")
time_lim = attribute_setup(int, "_time_lim")
self._grading = None
self._feedbacks = feedbacks
self._hints = hints
self._options = None

grading = attribute_setup(float, "_grading")
feedbacks = attribute_setup(dict, "_feedbacks")
free_hints = attribute_setup(TList, "_free_hints")
procs = attribute_setup(TList, "_procs")
hints = attribute_setup(dict, "_free_hints")
options = attribute_setup(TList, "_options")


class ChoicesItem(Item):
"""
This is the basic class used to hold possible answers
"""

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._options = TList(Choice)


class Choice(Item):
"""
This is the basic class used to hold possible answers
"""

def __init__(self, fraction=0.0, text="", feedback: FText = None,
formatting: TextFormat = None):
self.fraction = fraction

options = attribute_setup(dict, "_options")

def check(self):
"""Check if the instance parameters have valid values. Call this method
before exporting the instance, or right after modifying many valid of
a instance.
"""
if (not isinstance(self.name, str) or self._time_lim < 0
or (self.dbid is not None and not isinstance(self.dbid, int))
or self.default_grade < 0):
raise ValueError("Invalid value(s).")
for key, value in self._feedbacks.items():
if not isinstance(key, float) or not isinstance(value, FText):
raise TypeError()



class Answer(Serializable):
Expand Down
2 changes: 1 addition & 1 deletion qas_editor/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from .utils import Serializable, File, FText
from .question import _Question
from .enums import Status
from ._parsers import aiken, csv_card, cloze, gift, json, kahoot, latex, \
from .parsers import aiken, csv_card, cloze, gift, json, kahoot, latex, \
markdown, moodle, olx, ims
if TYPE_CHECKING:
from .utils import Dataset
Expand Down
7 changes: 0 additions & 7 deletions qas_editor/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,6 @@ class Numbering(EnhancedEnum):
ROM_UR = "IIII", "IIII"


class Logic(Enum):
AND = auto()
OR = auto()
NOT = auto()
ELSE = auto()


class OutFormat(Enum):
"""_summary_
"""
Expand Down
9 changes: 5 additions & 4 deletions qas_editor/_parsers/aiken.py → qas_editor/parsers/aiken.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
from __future__ import annotations
import re
import logging
import glob
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Type
from ..question import QMultichoice
from ..utils import FText
from ..enums import TextFormat
Expand Down Expand Up @@ -46,14 +47,14 @@ def _from_question(buffer, line: str, name: str):
answers[ord(_line[8].upper())-65].fraction = 100.0
break
answers.append(Answer(0.0, match[1], None, TextFormat.PLAIN))
question = FText(header.strip(), TextFormat.PLAIN)
question = FText([header.strip()]).from_string
return QMultichoice(name=name, options=answers, question=question)


# -----------------------------------------------------------------------------


def read_aiken(cls: "Category", file_path: str, category: str = "$course$") -> "Category":
def read_aiken(cls: Type[Category], file_path: str, category: str = "$course$") -> Category:
"""_summary_
Args:
Expand All @@ -75,7 +76,7 @@ def read_aiken(cls: "Category", file_path: str, category: str = "$course$") -> "
return quiz


def write_aiken(category: "Category", file_path: str) -> None:
def write_aiken(category: Type[Category], file_path: str) -> None:
"""_summary_
Args:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 7 additions & 6 deletions qas_editor/question.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from .enums import EmbeddedFormat, Grading, RespFormat, ShowUnits, ShowAnswer, ShuffleType,\
Distribution, Numbering, Synchronise, TextFormat, Status
from .utils import Serializable, MarkerError, AnswerError, File, Dataset, \
FText, Hint, Unit, TList
FText, Hint, Unit, TList, attribute_setup
from .answer import ACalculated, ACrossWord, Answer, EmbeddedItem, ANumerical,\
DragGroup, DragImage, SelectOption, Subquestion,\
DropZone, DragItem
Expand Down Expand Up @@ -611,18 +611,18 @@ def __init__(self, name="qstn", dbid: int = None, tags: TList = None,
self.name = str(name)
self.dbid = int(dbid) if dbid else None
self.notes = str(notes)
self.points = 0
self._time_lim = 0
self._body = None
self._remarks = None
self._notes = None
self._tags = TList(str, tags)
self.__parent: Category = None
_LOG.debug("New question (%s) created.", self)

def __str__(self) -> str:
return f"{self.QNAME}: '{self.name}' @{hex(id(self))}"

body = FText.prop("_body", "Question body")
remarks = FText.prop("_remarks", "Solution or global feedback")
body = attribute_setup(FText, "_body", "Question body")
time_lim = attribute_setup(int, "_time_lim")

@property
def parent(self) -> Category:
Expand Down Expand Up @@ -655,4 +655,5 @@ def check(self):
raise ValueError("Invalid value(s).")
for key, value in self._feedbacks.items():
if not isinstance(key, float) or not isinstance(value, FText):
raise TypeError()
raise TypeError()

Loading

0 comments on commit 8cb8cf4

Please sign in to comment.