From e9f1f71cc67bc832c1f421f7189ac681ef813e79 Mon Sep 17 00:00:00 2001 From: Jonas Engicht Date: Tue, 19 Nov 2024 11:56:25 +0100 Subject: [PATCH 1/2] update item format --- README.md | 12 +++ adaptivetesting/models/__init__.py | 2 +- adaptivetesting/models/__test_item.py | 73 ++++++++++++++++++- adaptivetesting/tests/test_load_test_items.py | 48 ++++++++++++ 4 files changed, 131 insertions(+), 4 deletions(-) create mode 100644 adaptivetesting/tests/test_load_test_items.py diff --git a/README.md b/README.md index 0777c5a..7037bae 100644 --- a/README.md +++ b/README.md @@ -51,3 +51,15 @@ For more information, please consult the documentation for the ``AdaptiveTest`` ## Documentation Extensive documentation of all programm code is available at [`/documentation`](/documentation). + + +# ToDo: + +- 4PL Model + - ML + - Item Bank + - Test Information + - Implementations + +- Bayes Modal + - Change AdaptiveTesting stucture \ No newline at end of file diff --git a/adaptivetesting/models/__init__.py b/adaptivetesting/models/__init__.py index cb8e59f..0fc9a1a 100644 --- a/adaptivetesting/models/__init__.py +++ b/adaptivetesting/models/__init__.py @@ -2,6 +2,6 @@ from .__algorithm_exception import AlgorithmException from .__item_pool import ItemPool from .__item_selection_exception import ItemSelectionException -from .__test_item import TestItem, load_test_items_from_list +from .__test_item import TestItem, load_test_items_from_list, load_test_items_from_dict from .__test_result import TestResult diff --git a/adaptivetesting/models/__test_item.py b/adaptivetesting/models/__test_item.py index a4c7b1f..c0ac82e 100644 --- a/adaptivetesting/models/__test_item.py +++ b/adaptivetesting/models/__test_item.py @@ -3,15 +3,30 @@ class TestItem: - """Representation of a test item in the item pool. - The format is equal to the implementation in catR. - """ def __init__(self): + """Representation of a test item in the item pool. + The format is equal to the implementation in catR. + + ## Properties: + - a (float): + - b (float): difficulty + - c (float): + - d (float): + + """ self.id: int | None = None self.a: float = 1 self.b: float = float("nan") self.c: float = 0 self.d: float = 1 + + def __dict__(self): + return { + "a": self.a, + "b": self.b, + "c": self.c, + "d": self.d + } def load_test_items_from_list(source: List[float]) -> List[TestItem]: @@ -31,3 +46,55 @@ def load_test_items_from_list(source: List[float]) -> List[TestItem]: items.append(item) return items + +def load_test_items_from_dict(source: dict[str, List[float]]) -> List[TestItem]: + """Creates test items from a dictionary. + The dictionary has to have the following keys: + + - a + - b + - c + - d + each containing a list of float. + + Args: + source (dict[str, List[float]]): item pool dictionary + + Returns: + List[TestItem]: item pool + """ + a = source.get("a") + b = source.get("b") + c = source.get("c") + d = source.get("d") + + # check none + if a is None: + raise ValueError("a cannot be None") + + if b is None: + raise ValueError("b cannot be None") + + if c is None: + raise ValueError("c cannot be None") + + if d is None: + raise ValueError("d cannot be None") + + # check if a, b, c, and d have the same length + if not (len(a) == len(b) == len(c) == len(d)): + raise ValueError("All lists in the source dictionary must have the same length") + + n_items = len(b) + items: List[TestItem] = [] + for i in range(n_items): + item = TestItem() + item.a = a[i] + item.b = b[i] + item.c = c[i] + item.d = d[i] + + items.append(item) + + return items + diff --git a/adaptivetesting/tests/test_load_test_items.py b/adaptivetesting/tests/test_load_test_items.py new file mode 100644 index 0000000..672d600 --- /dev/null +++ b/adaptivetesting/tests/test_load_test_items.py @@ -0,0 +1,48 @@ +from unittest import TestCase +from ..models import TestItem, load_test_items_from_dict + +class TestLoadTestItems(TestCase): + def __init__(self, methodName = "runTest"): + super().__init__(methodName) + self.item1 = TestItem() + self.item1.a = 0.9 + self.item1.b = 5 + self.item1.c = 0.9 + + self.item2 = TestItem() + self.item2.a = 1.9 + self.item2.b = 3 + self.item2.c = 1.9 + + def test_load_test_items_from_dict_success(self): + source_dictionary = { + "a": [0.9, 1.9], + "b": [5, 3], + "c": [0.9, 1.9], + "d": [1, 1] + } + + generated = load_test_items_from_dict(source_dictionary) + + self.assertEqual([self.item1.__dict__(), self.item2.__dict__()], [i.__dict__() for i in generated]) + + def test_load_test_items_from_dict_error_none(self): + source_dictionary = { + "a": [0.9, 1.9], + "b": [5, 3], + "c": [0.9, 1.9], + } + + with self.assertRaises(ValueError): + load_test_items_from_dict(source_dictionary) + + def test_load_test_items_from_dict_error_length(self): + source_dictionary = { + "a": [0.9, 1.9], + "b": [5, 3], + "c": [0.9, 1.9], + "d": [1] + } + + with self.assertRaises(ValueError): + load_test_items_from_dict(source_dictionary) \ No newline at end of file From 1969d8ffd85f8a1d63f44f31912944334665ffc0 Mon Sep 17 00:00:00 2001 From: Jonas Engicht Date: Tue, 19 Nov 2024 12:02:47 +0100 Subject: [PATCH 2/2] fix type error --- adaptivetesting/models/__test_item.py | 2 +- adaptivetesting/tests/test_load_test_items.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/adaptivetesting/models/__test_item.py b/adaptivetesting/models/__test_item.py index c0ac82e..3242c67 100644 --- a/adaptivetesting/models/__test_item.py +++ b/adaptivetesting/models/__test_item.py @@ -20,7 +20,7 @@ def __init__(self): self.c: float = 0 self.d: float = 1 - def __dict__(self): + def as_dict(self) -> dict[str, float]: return { "a": self.a, "b": self.b, diff --git a/adaptivetesting/tests/test_load_test_items.py b/adaptivetesting/tests/test_load_test_items.py index 672d600..c479a22 100644 --- a/adaptivetesting/tests/test_load_test_items.py +++ b/adaptivetesting/tests/test_load_test_items.py @@ -15,7 +15,7 @@ def __init__(self, methodName = "runTest"): self.item2.c = 1.9 def test_load_test_items_from_dict_success(self): - source_dictionary = { + source_dictionary: dict[str, list[float]] = { "a": [0.9, 1.9], "b": [5, 3], "c": [0.9, 1.9], @@ -24,10 +24,10 @@ def test_load_test_items_from_dict_success(self): generated = load_test_items_from_dict(source_dictionary) - self.assertEqual([self.item1.__dict__(), self.item2.__dict__()], [i.__dict__() for i in generated]) + self.assertEqual([self.item1.as_dict(), self.item2.as_dict()], [i.as_dict() for i in generated]) def test_load_test_items_from_dict_error_none(self): - source_dictionary = { + source_dictionary: dict[str, list[float]] = { "a": [0.9, 1.9], "b": [5, 3], "c": [0.9, 1.9], @@ -37,7 +37,7 @@ def test_load_test_items_from_dict_error_none(self): load_test_items_from_dict(source_dictionary) def test_load_test_items_from_dict_error_length(self): - source_dictionary = { + source_dictionary: dict[str, list[float]] = { "a": [0.9, 1.9], "b": [5, 3], "c": [0.9, 1.9],