cardy 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
cardy-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,16 @@
1
+ Metadata-Version: 2.1
2
+ Name: cardy
3
+ Version: 0.0.1
4
+ Summary: Card Sorting Utilities
5
+ Project-URL: repository, https://github.com/Programming-Education-Research/cardy
6
+ Classifier: Development Status :: 1 - Planning
7
+ Classifier: Topic :: Utilities
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Requires-Python: >=3.12
11
+ Description-Content-Type: text/markdown
12
+ Requires-Dist: munkres~=1.1.4
13
+
14
+ # Cardy
15
+
16
+ Various card sorting utilities.
cardy-0.0.1/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Cardy
2
+
3
+ Various card sorting utilities.
@@ -0,0 +1,28 @@
1
+ [build-system]
2
+ requires = ["setuptools>=65.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "cardy"
7
+ version = "0.0.1"
8
+ description = "Card Sorting Utilities"
9
+
10
+ readme = "README.md"
11
+ requires-python = ">=3.12"
12
+ license = { file = "LICENSE" }
13
+ classifiers = [
14
+ "Development Status :: 1 - Planning",
15
+ "Topic :: Utilities",
16
+ "Programming Language :: Python :: 3",
17
+ "License :: OSI Approved :: MIT License",
18
+ ]
19
+ dynamic = ["dependencies"]
20
+
21
+ [project.urls]
22
+ repository = "https://github.com/Programming-Education-Research/cardy"
23
+
24
+ [tool.setuptools.dynamic]
25
+ dependencies = { file = ["requirements.txt"] }
26
+
27
+ [tool.setuptools.packages.find]
28
+ where = ["src"]
@@ -0,0 +1 @@
1
+ munkres~=1.1.4
cardy-0.0.1/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1 @@
1
+ from .distance import *
@@ -0,0 +1,28 @@
1
+ from collections.abc import Set
2
+
3
+ from munkres import Munkres, make_cost_matrix
4
+
5
+
6
+ __all__ = ("CardSort", "edit_distance")
7
+
8
+
9
+ type CardSort = tuple[Set[int], ...]
10
+
11
+
12
+ def edit_distance(sort1: CardSort, sort2: CardSort) -> int:
13
+ if not sort1 and not sort2:
14
+ return 0
15
+
16
+ matching_weights = [[] for _ in range(len(sort1))]
17
+ for i, group1 in enumerate(sort1):
18
+ for group2 in sort2:
19
+ intersection = len(group1 & group2)
20
+ matching_weights[i].append(intersection)
21
+
22
+ cost_matrix = make_cost_matrix(matching_weights)
23
+
24
+ running_sum = 0
25
+ for row, col in Munkres().compute(cost_matrix):
26
+ running_sum += matching_weights[row][col]
27
+
28
+ return sum(len(g) for g in sort1) - running_sum
@@ -0,0 +1,16 @@
1
+ Metadata-Version: 2.1
2
+ Name: cardy
3
+ Version: 0.0.1
4
+ Summary: Card Sorting Utilities
5
+ Project-URL: repository, https://github.com/Programming-Education-Research/cardy
6
+ Classifier: Development Status :: 1 - Planning
7
+ Classifier: Topic :: Utilities
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Requires-Python: >=3.12
11
+ Description-Content-Type: text/markdown
12
+ Requires-Dist: munkres~=1.1.4
13
+
14
+ # Cardy
15
+
16
+ Various card sorting utilities.
@@ -0,0 +1,11 @@
1
+ README.md
2
+ pyproject.toml
3
+ requirements.txt
4
+ src/cardy/__init__.py
5
+ src/cardy/distance.py
6
+ src/cardy.egg-info/PKG-INFO
7
+ src/cardy.egg-info/SOURCES.txt
8
+ src/cardy.egg-info/dependency_links.txt
9
+ src/cardy.egg-info/requires.txt
10
+ src/cardy.egg-info/top_level.txt
11
+ tests/test_edit_distance.py
@@ -0,0 +1 @@
1
+ munkres~=1.1.4
@@ -0,0 +1 @@
1
+ cardy
@@ -0,0 +1,39 @@
1
+ from cardy import edit_distance
2
+ from utils import test
3
+
4
+
5
+ @test
6
+ def empty_card_sorts_have_a_distance_of_zero():
7
+ assert edit_distance((), ()) == 0
8
+
9
+
10
+ @test
11
+ def equivalent_card_sorts_have_an_edit_distance_of_zero():
12
+ assert edit_distance(({1},), ({1},)) == 0
13
+ assert edit_distance(({1}, {2}), ({1}, {2})) == 0
14
+ assert edit_distance(({2}, {1}), ({1}, {2})) == 0
15
+ assert edit_distance(
16
+ ({1, 2, 3}, {4}, {5, 6}),
17
+ ({4}, {1, 2, 3}, {5, 6}),
18
+ ) == 0
19
+
20
+
21
+ @test
22
+ def empty_groups_are_ignored_when_computing_distances():
23
+ assert edit_distance(({1}, {2}, set()), ({1}, {2})) == 0
24
+ assert edit_distance(({1}, {2}), ({1}, set(), {2})) == 0
25
+
26
+
27
+ @test
28
+ def single_card_displacements_have_an_edit_distance_of_one():
29
+ assert edit_distance(({1, 2}, {3}), ({1}, {2, 3})) == 1
30
+ assert edit_distance(({1}, {2}, {3}), ({1}, {2, 3})) == 1
31
+ assert edit_distance(({1}, {2, 3}), ({1, 2, 3},)) == 1
32
+
33
+
34
+ @test
35
+ def distance_between_card_sorts():
36
+ assert edit_distance(
37
+ ({1, 2, 3}, {4, 5, 6}, {7, 8, 9}),
38
+ ({1, 2}, {3, 4}, {5, 6, 7}, {8, 9}),
39
+ ) == 3