From 4b085b400955bb826a9651bbcfa93c73a0b843ab Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Sat, 9 Mar 2019 22:55:26 -0500 Subject: [PATCH 001/119] Added docstring to test/test_group_graph --- tests/test_group_graph.py | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 tests/test_group_graph.py diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py new file mode 100644 index 00000000..aa585d96 --- /dev/null +++ b/tests/test_group_graph.py @@ -0,0 +1,4 @@ +""" Test group graph algorithm""" +# from gatorgrouper.utils import group_graph +from networkx import Graph +from gatorgrouper.utils import group_graph From 92acae67b19aa6a5dae51751dd611a38e2c34107 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Sat, 9 Mar 2019 22:58:01 -0500 Subject: [PATCH 002/119] Started work on first test case of test/test_group_graph --- tests/test_group_graph.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index aa585d96..bc85a828 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -2,3 +2,9 @@ # from gatorgrouper.utils import group_graph from networkx import Graph from gatorgrouper.utils import group_graph + + +def test_recursive_kl(): + """ Test if groups made match recursion""" + group = [{0, 2}, {4, 7}, {3, 5}, {1, 6}] + weights = [[0, 0], [0, 0.5], [0.5, 0], [0.75, 0.75], [0.8, 0.1], [0, 1], [1, 0], [1, 1]] From a42ce2c0e2a6ee6336a10e35c54b7647f7de9f61 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Sat, 9 Mar 2019 23:01:38 -0500 Subject: [PATCH 003/119] Created assertion to compare a group to randomized groups --- tests/test_group_graph.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index bc85a828..08ee983b 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -8,3 +8,12 @@ def test_recursive_kl(): """ Test if groups made match recursion""" group = [{0, 2}, {4, 7}, {3, 5}, {1, 6}] weights = [[0, 0], [0, 0.5], [0.5, 0], [0.75, 0.75], [0.8, 0.1], [0, 1], [1, 0], [1, 1]] + vertex_weight_pairs = enumerate([{"weight": w} for w in weights]) + G = Graph() + G.add_nodes_from(vertex_weight_pairs) + output = group_graph.recursive_kl(G, 4) + alloutput =[] + for i in output: + if i = + alloutput.append(output[i]) + assert [item for item in alloutput] in group From 4b27420cbbae1575c5d5e0545444f48fcbe51afa Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Sun, 10 Mar 2019 13:02:42 -0400 Subject: [PATCH 004/119] Refactored main function to make it easier to test --- tests/test_group_graph.py | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 08ee983b..a31d1665 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -1,19 +1,32 @@ """ Test group graph algorithm""" -# from gatorgrouper.utils import group_graph -from networkx import Graph from gatorgrouper.utils import group_graph +from networkx import Graph def test_recursive_kl(): """ Test if groups made match recursion""" - group = [{0, 2}, {4, 7}, {3, 5}, {1, 6}] weights = [[0, 0], [0, 0.5], [0.5, 0], [0.75, 0.75], [0.8, 0.1], [0, 1], [1, 0], [1, 1]] vertex_weight_pairs = enumerate([{"weight": w} for w in weights]) G = Graph() G.add_nodes_from(vertex_weight_pairs) - output = group_graph.recursive_kl(G, 4) - alloutput =[] - for i in output: - if i = - alloutput.append(output[i]) - assert [item for item in alloutput] in group + groups = [] + for i in kernighan_lin_bisection(G): + subgraph = G.subgraph(subset) + groups.extend(recursive_kl(subgraph, numgrp=next_numgrp)) + assert i in groups is True + + +def test_main(): + students = [ + ["one", 0, 0], + ["two", 0, 0.5], + ["three", 0.5, 0], + ["four", 0.75, 0.75], + ["five", 0.8, 0.1], + ["six", 0, 1], + ["seven", 1, 0], + ["eight", 1, 1], + ] + weights = [[0, 0], [0, 0.5], [0.5, 0], [0.75, 0.75], [0.8, 0.1], [0, 1], [1, 0], [1, 1]] + groups = group_graph.group_graph_partition(students, 4) + assert weights in groups From 8572010611c1227e00e5a7372a98793c987f9523 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Sun, 10 Mar 2019 15:23:24 -0400 Subject: [PATCH 005/119] Changed main function --- gatorgrouper/utils/group_graph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gatorgrouper/utils/group_graph.py b/gatorgrouper/utils/group_graph.py index 2b61cf64..4f1ea6d1 100644 --- a/gatorgrouper/utils/group_graph.py +++ b/gatorgrouper/utils/group_graph.py @@ -118,7 +118,7 @@ def group_graph_partition( return groups -if __name__ == "__main__": +def main(): students = [ ["one", 0, 0], ["two", 0, 0.5], From e7877aa30aa886972944a5bcf88d99c64bb0ed3d Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Sun, 10 Mar 2019 15:23:43 -0400 Subject: [PATCH 006/119] Changed exit command to work in init --- gatorgrouper/utils/group_graph.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gatorgrouper/utils/group_graph.py b/gatorgrouper/utils/group_graph.py index 4f1ea6d1..c70d61a1 100644 --- a/gatorgrouper/utils/group_graph.py +++ b/gatorgrouper/utils/group_graph.py @@ -131,3 +131,10 @@ def main(): ] student_groups = group_graph_partition(students, 4) print(student_groups) + + +def init(): + if __name__ == "__main__": + exit(main()) + +init() From ccab327224c92a46281d1934c7cbc8137effa88b Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Sun, 10 Mar 2019 17:01:15 -0400 Subject: [PATCH 007/119] Changes made by pull from main branch --- gatorgrouper/utils/group_graph.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/gatorgrouper/utils/group_graph.py b/gatorgrouper/utils/group_graph.py index 980cd0b0..94f08ca1 100644 --- a/gatorgrouper/utils/group_graph.py +++ b/gatorgrouper/utils/group_graph.py @@ -135,13 +135,8 @@ def group_graph_partition( return groups -<<<<<<< HEAD def main(): students = [ -======= -if __name__ == "__main__": - student_data = [ ->>>>>>> 30d8848b1d0f6801ce744547fa2d2fbefc1dfc02 ["one", 0, 0], ["two", 0, 0.5], ["three", 0.5, 0], @@ -151,7 +146,6 @@ def main(): ["seven", 1, 0], ["eight", 1, 1], ] -<<<<<<< HEAD student_groups = group_graph_partition(students, 4) print(student_groups) @@ -161,6 +155,3 @@ def init(): exit(main()) init() -======= - student_groups = group_graph_partition(student_data, 4) ->>>>>>> 30d8848b1d0f6801ce744547fa2d2fbefc1dfc02 From 1b93db518d93195fdfceb168bc484ee54ac4e575 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Mon, 11 Mar 2019 10:47:27 -0400 Subject: [PATCH 008/119] Imported pytest to use test Exception --- tests/test_group_graph.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index a31d1665..10a0f13b 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -1,6 +1,7 @@ """ Test group graph algorithm""" from gatorgrouper.utils import group_graph from networkx import Graph +import pytest def test_recursive_kl(): From f64a7f4c9c681711da6177fd47e038dfe141989e Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Mon, 11 Mar 2019 13:41:50 -0400 Subject: [PATCH 009/119] Work on test_compatibility_raises, a test for compatibility --- tests/test_group_graph.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 10a0f13b..c0ea490c 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -17,6 +17,27 @@ def test_recursive_kl(): assert i in groups is True +def test_compatability_raises(): + """Raises exception for unequal tuples""" + # len(a) != len(b) + with pytest.raises(Exception) as excinfo: + a: ["one", 0, 0] + b: ["two", 0, 0.5] + group_graph .compatibility(a, b) + exception_msg = group_graph.compatibility.value.args[0] + assert exception_msg == "Tuples passed to compatibility() must have same size" + +def test_compatability_measure(): + """ Test whether scores measured return true or false""" + a = Tuple[int] + b = Tuple[int] + scores = [0.25, 0.25, 0.5, 0.75, 1.0, 1.0, 0.45, 0.7, 0.7000000000000001, + 1.2, 0.5, 0.75, 0.75, 1.25, 0.9500000000000001, 0.5, 0.75, 0.75, 1.25, + 0.9500000000000001, 1.0, 1.0, 1.25, 1.25, 1.75, 1.4500000000000002, 1.5, 1.5] + for i in a and b: + check = measure() + + def test_main(): students = [ ["one", 0, 0], From 6a9f68f569583e433d59605ec50403032bf1388e Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Mon, 11 Mar 2019 13:42:26 -0400 Subject: [PATCH 010/119] A initial test of main. Currently not a priority, but can be looked at --- tests/test_group_graph.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index c0ea490c..308d58e9 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -49,6 +49,16 @@ def test_main(): ["seven", 1, 0], ["eight", 1, 1], ] + group = [] weights = [[0, 0], [0, 0.5], [0.5, 0], [0.75, 0.75], [0.8, 0.1], [0, 1], [1, 0], [1, 1]] - groups = group_graph.group_graph_partition(students, 4) - assert weights in groups + output = group_graph.group_graph_partition(students[1:]) + # assert output == None + # set(group) == set(students) + # for item in output: + # group += item + # assert group == students + + if set(group) == set(students): + check = all(elem == group[0] for elem in group) + assert check == True + assert group == students From 085256cfb1f9707090e605b7395984088c30132f Mon Sep 17 00:00:00 2001 From: Benjamin Watto Date: Mon, 11 Mar 2019 13:50:54 -0400 Subject: [PATCH 011/119] Changed group_graph spacing according to pylint --- gatorgrouper/utils/group_graph.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gatorgrouper/utils/group_graph.py b/gatorgrouper/utils/group_graph.py index 94f08ca1..fce9c4f0 100644 --- a/gatorgrouper/utils/group_graph.py +++ b/gatorgrouper/utils/group_graph.py @@ -151,7 +151,7 @@ def main(): def init(): - if __name__ == "__main__": - exit(main()) + if __name__ == "__main__": + exit(main()) init() From f2b025f003f30b714e5e3ea5f44ecdfe52337f6d Mon Sep 17 00:00:00 2001 From: Benjamin Watto Date: Mon, 11 Mar 2019 13:57:05 -0400 Subject: [PATCH 012/119] Running Black for Formatting --- tests/test_group_graph.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index a31d1665..2fcb786b 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -5,7 +5,16 @@ def test_recursive_kl(): """ Test if groups made match recursion""" - weights = [[0, 0], [0, 0.5], [0.5, 0], [0.75, 0.75], [0.8, 0.1], [0, 1], [1, 0], [1, 1]] + weights = [ + [0, 0], + [0, 0.5], + [0.5, 0], + [0.75, 0.75], + [0.8, 0.1], + [0, 1], + [1, 0], + [1, 1], + ] vertex_weight_pairs = enumerate([{"weight": w} for w in weights]) G = Graph() G.add_nodes_from(vertex_weight_pairs) @@ -27,6 +36,15 @@ def test_main(): ["seven", 1, 0], ["eight", 1, 1], ] - weights = [[0, 0], [0, 0.5], [0.5, 0], [0.75, 0.75], [0.8, 0.1], [0, 1], [1, 0], [1, 1]] + weights = [ + [0, 0], + [0, 0.5], + [0.5, 0], + [0.75, 0.75], + [0.8, 0.1], + [0, 1], + [1, 0], + [1, 1], + ] groups = group_graph.group_graph_partition(students, 4) assert weights in groups From bcb57233fe8018a7a29b233613d58462c42f090d Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Mon, 11 Mar 2019 17:17:07 -0400 Subject: [PATCH 013/119] Added list of student weights to test for test_main --- tests/test_group_graph.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 308d58e9..60e13e6d 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -62,3 +62,4 @@ def test_main(): check = all(elem == group[0] for elem in group) assert check == True assert group == students +# ["four", 0.75, 0.75], From 8d2eda8fd380c9b732899e8f761b2d876c6720c8 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Mon, 11 Mar 2019 17:17:54 -0400 Subject: [PATCH 014/119] Created 4 different test cases that are not functional at the moment, but are under development --- tests/test_group_graph.py | 120 ++++++++++++++++++++++---------------- 1 file changed, 71 insertions(+), 49 deletions(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 60e13e6d..06220a64 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -6,60 +6,82 @@ def test_recursive_kl(): """ Test if groups made match recursion""" - weights = [[0, 0], [0, 0.5], [0.5, 0], [0.75, 0.75], [0.8, 0.1], [0, 1], [1, 0], [1, 1]] - vertex_weight_pairs = enumerate([{"weight": w} for w in weights]) + # weights = [[0, 0], [0, 0.5], [0.5, 0], [0.75, 0.75], [0.8, 0.1], [0, 1], [1, 0], [1, 1]] + # vertex_weight_pairs = enumerate([{"weight": w} for w in weights]) G = Graph() - G.add_nodes_from(vertex_weight_pairs) - groups = [] - for i in kernighan_lin_bisection(G): - subgraph = G.subgraph(subset) - groups.extend(recursive_kl(subgraph, numgrp=next_numgrp)) - assert i in groups is True + with pytest.raises(ValueError) as excinfo: + group_graph.recursive_kl(G,numgrp = 1) + exception_msg = excinfo.value.args[0] + assert exception_msg == "numgrp must be a power of 2 and at least 2." -def test_compatability_raises(): - """Raises exception for unequal tuples""" - # len(a) != len(b) - with pytest.raises(Exception) as excinfo: - a: ["one", 0, 0] - b: ["two", 0, 0.5] - group_graph .compatibility(a, b) - exception_msg = group_graph.compatibility.value.args[0] - assert exception_msg == "Tuples passed to compatibility() must have same size" -def test_compatability_measure(): - """ Test whether scores measured return true or false""" - a = Tuple[int] - b = Tuple[int] - scores = [0.25, 0.25, 0.5, 0.75, 1.0, 1.0, 0.45, 0.7, 0.7000000000000001, - 1.2, 0.5, 0.75, 0.75, 1.25, 0.9500000000000001, 0.5, 0.75, 0.75, 1.25, - 0.9500000000000001, 1.0, 1.0, 1.25, 1.25, 1.75, 1.4500000000000002, 1.5, 1.5] - for i in a and b: - check = measure() -def test_main(): - students = [ - ["one", 0, 0], - ["two", 0, 0.5], - ["three", 0.5, 0], - ["four", 0.75, 0.75], - ["five", 0.8, 0.1], - ["six", 0, 1], - ["seven", 1, 0], - ["eight", 1, 1], - ] - group = [] - weights = [[0, 0], [0, 0.5], [0.5, 0], [0.75, 0.75], [0.8, 0.1], [0, 1], [1, 0], [1, 1]] - output = group_graph.group_graph_partition(students[1:]) - # assert output == None - # set(group) == set(students) - # for item in output: - # group += item - # assert group == students - if set(group) == set(students): - check = all(elem == group[0] for elem in group) - assert check == True - assert group == students + # G = Graph() + # G.add_nodes_from(vertex_weight_pairs) + # groups = [] + # for i in kernighan_lin_bisection(G): + # subgraph = G.subgraph(subset) + # groups.extend(recursive_kl(subgraph, numgrp=next_numgrp)) + # assert i in groups is True + + +# def test_total_cut_size(): +# """ Test if sums computed match actual sum of weights of all edges between different subsets in the partition""" +# weights = [[0, 0], [0, 0.5], [0.5, 0], [0.75, 0.75], [0.8, 0.1], [0, 1], [1, 0], [1, 1]] +# cut = 0.0 +# G = Graph() +# G.add_nodes_from(vertex_weight_pairs) +# expected_output = [cut += cut_size(graph, subset1, T=subset2)] +# assert expected_output == sum(weights) +# +# +# +# def test_compatability_raises(): +# """Raises exception for unequal tuples""" +# # len(a) != len(b) +# with pytest.raises(Exception) as excinfo: +# a: ["one", 0, 0] +# b: ["two", 0, 0.5] +# group_graph .compatibility(a, b) + # exception_msg = group_graph.compatibility.value.args[0] + # assert exception_msg == "Tuples passed to compatibility() must have same size" +# +# +# def test_compatability_measure(): +# """ Test whether scores measured return true or false""" +# a = Tuple[int] +# b = Tuple[int] +# scores = [0.25, 0.25, 0.5, 0.75, 1.0, 1.0, 0.45, 0.7, 0.7000000000000001, +# 1.2, 0.5, 0.75, 0.75, 1.25, 0.9500000000000001, 0.5, 0.75, 0.75, 1.25, +# 0.9500000000000001, 1.0, 1.0, 1.25, 1.25, 1.75, 1.4500000000000002, 1.5, 1.5] +# for i in a and b: +# check = measure() +# +# +# def test_main(): +# students = [ +# ["one", 0, 0], +# ["two", 0, 0.5], +# ["three", 0.5, 0], # ["four", 0.75, 0.75], +# ["five", 0.8, 0.1], +# ["six", 0, 1], +# ["seven", 1, 0], +# ["eight", 1, 1], +# ] +# group = [] +# weights = [[0, 0], [0, 0.5], [0.5, 0], [0.75, 0.75], [0.8, 0.1], [0, 1], [1, 0], [1, 1]] +# output = group_graph.group_graph_partition(students[1:]) +# # assert output == None +# # set(group) == set(students) +# # for item in output: +# # group += item +# # assert group == students +# +# if set(group) == set(students): +# check = all(elem == group[0] for elem in group) +# assert check == True +# assert group == students From 24b01f3cd0895533e2b7af20db3845367debd0de Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Mon, 11 Mar 2019 19:43:55 -0400 Subject: [PATCH 015/119] Fixed pylint error in Travis from a test case --- tests/test_group_graph.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 06220a64..ca6025f9 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -10,15 +10,11 @@ def test_recursive_kl(): # vertex_weight_pairs = enumerate([{"weight": w} for w in weights]) G = Graph() with pytest.raises(ValueError) as excinfo: - group_graph.recursive_kl(G,numgrp = 1) + group_graph.recursive_kl(G,numgrp=1) exception_msg = excinfo.value.args[0] assert exception_msg == "numgrp must be a power of 2 and at least 2." - - - - # G = Graph() # G.add_nodes_from(vertex_weight_pairs) # groups = [] From 2e091094e94448f1b2fe48b685abdb1deda9eb1f Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Mon, 11 Mar 2019 19:45:01 -0400 Subject: [PATCH 016/119] Created test case for total_cut_size using parameterizing --- tests/test_group_graph.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index ca6025f9..972a4acb 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -24,16 +24,21 @@ def test_recursive_kl(): # assert i in groups is True -# def test_total_cut_size(): -# """ Test if sums computed match actual sum of weights of all edges between different subsets in the partition""" -# weights = [[0, 0], [0, 0.5], [0.5, 0], [0.75, 0.75], [0.8, 0.1], [0, 1], [1, 0], [1, 1]] -# cut = 0.0 -# G = Graph() -# G.add_nodes_from(vertex_weight_pairs) -# expected_output = [cut += cut_size(graph, subset1, T=subset2)] -# assert expected_output == sum(weights) -# -# +input = [(2, 2)] +@pytest.mark.parametrize("a,b", output) +# @pytest.mark.parametrize("input, expected_output", [(input, 4)]) +def test_total_cut_size(input): + """ Test if sums computed match actual sum of weights of all edges between different subsets in the partition""" + output = group_graph.total_cut_size(input) + assert output = expected_output + + + # partition: List[int] + # G = Graph() + # input = [G, partition] + # expected_output = cutsize(graph, subset1, T=subset2) + # assert + # # def test_compatability_raises(): # """Raises exception for unequal tuples""" From d0d43cf2f02b9347680ffe2587489d1165daa48d Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Mon, 11 Mar 2019 23:39:09 -0400 Subject: [PATCH 017/119] Use parameterize testing for total_cut_size from group_graph --- tests/test_group_graph.py | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 972a4acb..35ab3982 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -24,12 +24,12 @@ def test_recursive_kl(): # assert i in groups is True -input = [(2, 2)] -@pytest.mark.parametrize("a,b", output) +@pytest.mark.parametrize("2, 2") # @pytest.mark.parametrize("input, expected_output", [(input, 4)]) -def test_total_cut_size(input): +def test_total_cut_size(2, 2, expected_output): """ Test if sums computed match actual sum of weights of all edges between different subsets in the partition""" - output = group_graph.total_cut_size(input) + G = Graph() + expected_output = group_graph.total_cut_size(G, input[2,2]) assert output = expected_output @@ -86,3 +86,28 @@ def test_total_cut_size(input): # check = all(elem == group[0] for elem in group) # assert check == True # assert group == students +# +# +# def test_main(): +# students = [ +# ["one", 0, 0], +# ["two", 0, 0.5], +# ["three", 0.5, 0], +# ["four", 0.75, 0.75], +# ["five", 0.8, 0.1], +# ["six", 0, 1], +# ["seven", 1, 0], +# ["eight", 1, 1], +# ] +# weights = [ +# [0, 0], +# [0, 0.5], +# [0.5, 0], +# [0.75, 0.75], +# [0.8, 0.1], +# [0, 1], +# [1, 0], +# [1, 1], +# ] +# groups = group_graph.group_graph_partition(students, 4) +# assert weights in groups From 574dd677dc1116b210e09ffebd86e04456f72dd8 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Tue, 12 Mar 2019 00:17:00 -0400 Subject: [PATCH 018/119] Reformatted docstring --- gatorgrouper/utils/group_graph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gatorgrouper/utils/group_graph.py b/gatorgrouper/utils/group_graph.py index fce9c4f0..3b25e045 100644 --- a/gatorgrouper/utils/group_graph.py +++ b/gatorgrouper/utils/group_graph.py @@ -58,7 +58,7 @@ def compatibility( If no measures are specified, "avg" is used as a default. """ if not len(a) == len(b): - raise Exception("Tuples passed to compatibility() must have same size") + raise Exception("Tuples passed to compatibility() must have same size.") if objective_weights is None: objective_weights = [1] * len(a) if objective_measures is None: From 7e20ec91ddb9f9703d709b983d6f3ee339a46305 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Tue, 12 Mar 2019 00:17:36 -0400 Subject: [PATCH 019/119] Reformatted docstring in group_graph_partition --- gatorgrouper/utils/group_graph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gatorgrouper/utils/group_graph.py b/gatorgrouper/utils/group_graph.py index 3b25e045..af3c158e 100644 --- a/gatorgrouper/utils/group_graph.py +++ b/gatorgrouper/utils/group_graph.py @@ -96,7 +96,7 @@ def group_graph_partition( preferences_weight_match=1.3, ): """ - Form groups using recursive Kernighan-Lin algorithm + Form groups using recursive Kernighan-Lin algorithm. """ # Read in students list and the weight list students = [item[0] for item in inputlist] From 495fd6e7870990824c779feae415f5d884972162 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Tue, 12 Mar 2019 00:18:02 -0400 Subject: [PATCH 020/119] Reformatted main function and added docstring for documentation --- gatorgrouper/utils/group_graph.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gatorgrouper/utils/group_graph.py b/gatorgrouper/utils/group_graph.py index af3c158e..cf0724b0 100644 --- a/gatorgrouper/utils/group_graph.py +++ b/gatorgrouper/utils/group_graph.py @@ -135,7 +135,11 @@ def group_graph_partition( return groups -def main(): +def group_graph(): + """ + Create student groups using list of list containing student names + and their weights. + """ students = [ ["one", 0, 0], ["two", 0, 0.5], From 01081b96ccfb9b7922aa3abeaf5036fb8cce12bf Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Tue, 12 Mar 2019 00:18:48 -0400 Subject: [PATCH 021/119] Refactored main function and changed name for easier testing --- gatorgrouper/utils/group_graph.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/gatorgrouper/utils/group_graph.py b/gatorgrouper/utils/group_graph.py index cf0724b0..247203fe 100644 --- a/gatorgrouper/utils/group_graph.py +++ b/gatorgrouper/utils/group_graph.py @@ -153,9 +153,5 @@ def group_graph(): student_groups = group_graph_partition(students, 4) print(student_groups) - -def init(): - if __name__ == "__main__": - exit(main()) - -init() +if __name__ == "__main__": + group_graph() From 14f73e9ce43b06f275e40f37179d50ce5b0cd65e Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Tue, 12 Mar 2019 01:34:34 -0400 Subject: [PATCH 022/119] Removed parameterized testing for total_cut_size --- tests/test_group_graph.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 35ab3982..e0dc028d 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -24,13 +24,14 @@ def test_recursive_kl(): # assert i in groups is True -@pytest.mark.parametrize("2, 2") -# @pytest.mark.parametrize("input, expected_output", [(input, 4)]) -def test_total_cut_size(2, 2, expected_output): +def test_total_cut_size(): """ Test if sums computed match actual sum of weights of all edges between different subsets in the partition""" - G = Graph() - expected_output = group_graph.total_cut_size(G, input[2,2]) - assert output = expected_output + G = Graph() + G.add_edges_from([(1, 4), (2, 3)]) + partition = ([(1, 2), (3, 4)]) + output = group_graph.total_cut_size(G, partition) + expected_output = 2 + assert output == expected_output # partition: List[int] From a44c28c8251c266e6d1af6da9719bb8f08615d4f Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Tue, 12 Mar 2019 01:42:00 -0400 Subject: [PATCH 023/119] Rewrote docstring for test_total_cut_size() --- tests/test_group_graph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index e0dc028d..4d9f8e72 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -25,7 +25,7 @@ def test_recursive_kl(): def test_total_cut_size(): - """ Test if sums computed match actual sum of weights of all edges between different subsets in the partition""" + """ Test if cut size of subsets in partition match""" G = Graph() G.add_edges_from([(1, 4), (2, 3)]) partition = ([(1, 2), (3, 4)]) From 937905c37aa505cc4d9c97c15e47910ff58db2f9 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Tue, 12 Mar 2019 08:04:43 -0400 Subject: [PATCH 024/119] Reformated docstrings and began testing of compatibility --- tests/test_group_graph.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 4d9f8e72..75625a9d 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -5,7 +5,7 @@ def test_recursive_kl(): - """ Test if groups made match recursion""" + """ Test if groups made match recursion """ # weights = [[0, 0], [0, 0.5], [0.5, 0], [0.75, 0.75], [0.8, 0.1], [0, 1], [1, 0], [1, 1]] # vertex_weight_pairs = enumerate([{"weight": w} for w in weights]) G = Graph() @@ -25,7 +25,7 @@ def test_recursive_kl(): def test_total_cut_size(): - """ Test if cut size of subsets in partition match""" + """ Test if cut size of subsets in partition match """ G = Graph() G.add_edges_from([(1, 4), (2, 3)]) partition = ([(1, 2), (3, 4)]) @@ -34,13 +34,8 @@ def test_total_cut_size(): assert output == expected_output - # partition: List[int] - # G = Graph() - # input = [G, partition] - # expected_output = cutsize(graph, subset1, T=subset2) - # assert - -# +def test_compatibility(): + """ Test if compatibility score equates to summ of scaled scores """ # def test_compatability_raises(): # """Raises exception for unequal tuples""" # # len(a) != len(b) From 2c6aaa380e0bc32e6c1f2e946226b7362b70bebf Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Tue, 12 Mar 2019 08:35:46 -0400 Subject: [PATCH 025/119] Included comment to remind exception handling is needed for test --- tests/test_group_graph.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 75625a9d..35a2b312 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -23,6 +23,8 @@ def test_recursive_kl(): # groups.extend(recursive_kl(subgraph, numgrp=next_numgrp)) # assert i in groups is True +# Need to parametrize test_total_cut_size because it would, but should not, handle +# groups of 1 def test_total_cut_size(): """ Test if cut size of subsets in partition match """ From f4c41c931f83ec7ac8aef10f2493149ac27a7053 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Tue, 12 Mar 2019 08:37:02 -0400 Subject: [PATCH 026/119] Refactored test caes for compatibility length between students --- tests/test_group_graph.py | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 35a2b312..28633f4d 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -36,30 +36,16 @@ def test_total_cut_size(): assert output == expected_output -def test_compatibility(): +def test_compatibility_length(): """ Test if compatibility score equates to summ of scaled scores """ -# def test_compatability_raises(): -# """Raises exception for unequal tuples""" -# # len(a) != len(b) -# with pytest.raises(Exception) as excinfo: -# a: ["one", 0, 0] -# b: ["two", 0, 0.5] -# group_graph .compatibility(a, b) - # exception_msg = group_graph.compatibility.value.args[0] - # assert exception_msg == "Tuples passed to compatibility() must have same size" -# -# -# def test_compatability_measure(): -# """ Test whether scores measured return true or false""" -# a = Tuple[int] -# b = Tuple[int] -# scores = [0.25, 0.25, 0.5, 0.75, 1.0, 1.0, 0.45, 0.7, 0.7000000000000001, -# 1.2, 0.5, 0.75, 0.75, 1.25, 0.9500000000000001, 0.5, 0.75, 0.75, 1.25, -# 0.9500000000000001, 1.0, 1.0, 1.25, 1.25, 1.75, 1.4500000000000002, 1.5, 1.5] -# for i in a and b: -# check = measure() -# -# + a = (2) + b = (1) + with pytest.raises(Exception) as excinfo: + group_graph.compatibility(a, b) + exception_msg = excinfo.value.args[0] + assert exception_msg == "Tuples passed to compatibility() must have same size." + + # def test_main(): # students = [ # ["one", 0, 0], From d8fc19eadea64e0a6839c865c5a4f00eef47a9d3 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Tue, 12 Mar 2019 08:50:13 -0400 Subject: [PATCH 027/119] Deleted unused/extraneous code --- tests/test_group_graph.py | 67 ++++----------------------------------- 1 file changed, 6 insertions(+), 61 deletions(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 28633f4d..322d1535 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -6,8 +6,6 @@ def test_recursive_kl(): """ Test if groups made match recursion """ - # weights = [[0, 0], [0, 0.5], [0.5, 0], [0.75, 0.75], [0.8, 0.1], [0, 1], [1, 0], [1, 1]] - # vertex_weight_pairs = enumerate([{"weight": w} for w in weights]) G = Graph() with pytest.raises(ValueError) as excinfo: group_graph.recursive_kl(G,numgrp=1) @@ -15,17 +13,8 @@ def test_recursive_kl(): assert exception_msg == "numgrp must be a power of 2 and at least 2." - # G = Graph() - # G.add_nodes_from(vertex_weight_pairs) - # groups = [] - # for i in kernighan_lin_bisection(G): - # subgraph = G.subgraph(subset) - # groups.extend(recursive_kl(subgraph, numgrp=next_numgrp)) - # assert i in groups is True - # Need to parametrize test_total_cut_size because it would, but should not, handle # groups of 1 - def test_total_cut_size(): """ Test if cut size of subsets in partition match """ G = Graph() @@ -37,7 +26,7 @@ def test_total_cut_size(): def test_compatibility_length(): - """ Test if compatibility score equates to summ of scaled scores """ + """ Test if exception message is raised by unequal students scores """ a = (2) b = (1) with pytest.raises(Exception) as excinfo: @@ -46,52 +35,8 @@ def test_compatibility_length(): assert exception_msg == "Tuples passed to compatibility() must have same size." -# def test_main(): -# students = [ -# ["one", 0, 0], -# ["two", 0, 0.5], -# ["three", 0.5, 0], -# ["four", 0.75, 0.75], -# ["five", 0.8, 0.1], -# ["six", 0, 1], -# ["seven", 1, 0], -# ["eight", 1, 1], -# ] -# group = [] -# weights = [[0, 0], [0, 0.5], [0.5, 0], [0.75, 0.75], [0.8, 0.1], [0, 1], [1, 0], [1, 1]] -# output = group_graph.group_graph_partition(students[1:]) -# # assert output == None -# # set(group) == set(students) -# # for item in output: -# # group += item -# # assert group == students -# -# if set(group) == set(students): -# check = all(elem == group[0] for elem in group) -# assert check == True -# assert group == students -# -# -# def test_main(): -# students = [ -# ["one", 0, 0], -# ["two", 0, 0.5], -# ["three", 0.5, 0], -# ["four", 0.75, 0.75], -# ["five", 0.8, 0.1], -# ["six", 0, 1], -# ["seven", 1, 0], -# ["eight", 1, 1], -# ] -# weights = [ -# [0, 0], -# [0, 0.5], -# [0.5, 0], -# [0.75, 0.75], -# [0.8, 0.1], -# [0, 1], -# [1, 0], -# [1, 1], -# ] -# groups = group_graph.group_graph_partition(students, 4) -# assert weights in groups +def test_compatibility(): + """ Test compatibility between students """ + a = (2) + b = (2) + From 1d2d0990b59be1b2088fa572e336aac8a59e9a9b Mon Sep 17 00:00:00 2001 From: Benjamin Watto Date: Tue, 12 Mar 2019 09:33:02 -0400 Subject: [PATCH 028/119] Format Changes --- tests/test_group_graph.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 322d1535..6eea6bab 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -8,7 +8,7 @@ def test_recursive_kl(): """ Test if groups made match recursion """ G = Graph() with pytest.raises(ValueError) as excinfo: - group_graph.recursive_kl(G,numgrp=1) + group_graph.recursive_kl(G, numgrp=1) exception_msg = excinfo.value.args[0] assert exception_msg == "numgrp must be a power of 2 and at least 2." @@ -19,7 +19,7 @@ def test_total_cut_size(): """ Test if cut size of subsets in partition match """ G = Graph() G.add_edges_from([(1, 4), (2, 3)]) - partition = ([(1, 2), (3, 4)]) + partition = [(1, 2), (3, 4)] output = group_graph.total_cut_size(G, partition) expected_output = 2 assert output == expected_output @@ -27,8 +27,8 @@ def test_total_cut_size(): def test_compatibility_length(): """ Test if exception message is raised by unequal students scores """ - a = (2) - b = (1) + a = 2 + b = 1 with pytest.raises(Exception) as excinfo: group_graph.compatibility(a, b) exception_msg = excinfo.value.args[0] @@ -37,6 +37,5 @@ def test_compatibility_length(): def test_compatibility(): """ Test compatibility between students """ - a = (2) - b = (2) - + a = 2 + b = 2 From 4f6efec148a6c0aa4d23222afd9faf569f44973c Mon Sep 17 00:00:00 2001 From: Benjamin Watto Date: Tue, 12 Mar 2019 09:36:07 -0400 Subject: [PATCH 029/119] Changing imports for test_group_graph --- tests/test_group_graph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 6eea6bab..43a7b44a 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -1,6 +1,6 @@ """ Test group graph algorithm""" -from gatorgrouper.utils import group_graph from networkx import Graph +from gatorgrouper.utils import group_graph import pytest From f5536151efe58a2ce6dcbb52316f6fa7bd77c795 Mon Sep 17 00:00:00 2001 From: Benjamin Watto Date: Tue, 12 Mar 2019 09:37:31 -0400 Subject: [PATCH 030/119] Correcting Third Party imports --- tests/test_group_graph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 43a7b44a..0b773179 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -1,7 +1,7 @@ """ Test group graph algorithm""" from networkx import Graph -from gatorgrouper.utils import group_graph import pytest +from gatorgrouper.utils import group_graph def test_recursive_kl(): From 3149d7e636807c90cb65e79ea93f02e53c0e65a9 Mon Sep 17 00:00:00 2001 From: Benjamin Watto Date: Tue, 12 Mar 2019 09:43:51 -0400 Subject: [PATCH 031/119] Reformatting group_graph --- gatorgrouper/utils/group_graph.py | 1 + 1 file changed, 1 insertion(+) diff --git a/gatorgrouper/utils/group_graph.py b/gatorgrouper/utils/group_graph.py index 247203fe..022895b5 100644 --- a/gatorgrouper/utils/group_graph.py +++ b/gatorgrouper/utils/group_graph.py @@ -153,5 +153,6 @@ def group_graph(): student_groups = group_graph_partition(students, 4) print(student_groups) + if __name__ == "__main__": group_graph() From 3ff2e5b1d55d031c8c6b281c694dca3175e3bfd5 Mon Sep 17 00:00:00 2001 From: Dillon Thoma Date: Tue, 12 Mar 2019 09:52:00 -0400 Subject: [PATCH 032/119] Adding to the group_graph_partition docstring --- gatorgrouper/utils/group_graph.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gatorgrouper/utils/group_graph.py b/gatorgrouper/utils/group_graph.py index 022895b5..3369ad9c 100644 --- a/gatorgrouper/utils/group_graph.py +++ b/gatorgrouper/utils/group_graph.py @@ -96,7 +96,8 @@ def group_graph_partition( preferences_weight_match=1.3, ): """ - Form groups using recursive Kernighan-Lin algorithm. + Form groups using recursive Kernighan-Lin algorithm by reading in students list + and weight list and partitioning the vertices. """ # Read in students list and the weight list students = [item[0] for item in inputlist] From 81cb63b40c19bd445100bcd7025000975acd6d55 Mon Sep 17 00:00:00 2001 From: Dillon Thoma Date: Tue, 12 Mar 2019 09:52:28 -0400 Subject: [PATCH 033/119] Specifications to group_graph docstring --- gatorgrouper/utils/group_graph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gatorgrouper/utils/group_graph.py b/gatorgrouper/utils/group_graph.py index 3369ad9c..73bf30ed 100644 --- a/gatorgrouper/utils/group_graph.py +++ b/gatorgrouper/utils/group_graph.py @@ -138,7 +138,7 @@ def group_graph_partition( def group_graph(): """ - Create student groups using list of list containing student names + Create student groups of 4 using list of list containing student names and their weights. """ students = [ From 8f433d7b60986733a90da7e9fbb1367794b84b11 Mon Sep 17 00:00:00 2001 From: Dillon Thoma Date: Tue, 12 Mar 2019 09:54:47 -0400 Subject: [PATCH 034/119] Changing the name of group_graph function so it differs from file name --- gatorgrouper/utils/group_graph.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gatorgrouper/utils/group_graph.py b/gatorgrouper/utils/group_graph.py index 73bf30ed..037f4e5f 100644 --- a/gatorgrouper/utils/group_graph.py +++ b/gatorgrouper/utils/group_graph.py @@ -136,7 +136,7 @@ def group_graph_partition( return groups -def group_graph(): +def group_creator(): """ Create student groups of 4 using list of list containing student names and their weights. @@ -156,4 +156,4 @@ def group_graph(): if __name__ == "__main__": - group_graph() + group_creator() From 2cf452b90a5a90f212716d7068fbdbee7bd1f8f2 Mon Sep 17 00:00:00 2001 From: Dillon Thoma Date: Tue, 12 Mar 2019 10:21:40 -0400 Subject: [PATCH 035/119] Specifying test_recursive_kl docstring --- tests/test_group_graph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 0b773179..73ae9440 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -5,7 +5,7 @@ def test_recursive_kl(): - """ Test if groups made match recursion """ + """ Test if groups made match recursion from Kernighan-Lin algorithm """ G = Graph() with pytest.raises(ValueError) as excinfo: group_graph.recursive_kl(G, numgrp=1) From dbf8970269728a3d7cac022c38d2ac8866fe08ae Mon Sep 17 00:00:00 2001 From: Dillon Thoma Date: Tue, 12 Mar 2019 10:24:24 -0400 Subject: [PATCH 036/119] Dosctring changes --- gatorgrouper/utils/group_graph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gatorgrouper/utils/group_graph.py b/gatorgrouper/utils/group_graph.py index 037f4e5f..244ffbad 100644 --- a/gatorgrouper/utils/group_graph.py +++ b/gatorgrouper/utils/group_graph.py @@ -10,7 +10,7 @@ def recursive_kl(graph: Graph, numgrp=2) -> List[Set[int]]: """ - Recursively use Kernighan-Lin algorithm to create a k-way graph partition + Recursively use the Kernighan-Lin algorithm to create a k-way graph partition """ power = log(numgrp, 2) if power != int(power) or power < 1: From 82fd9d3c36aeb923a63af6ed6005826eb5e06500 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Tue, 12 Mar 2019 11:23:35 -0400 Subject: [PATCH 037/119] Fixed pylint error --- tests/test_group_graph.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 322d1535..a9831d62 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -8,7 +8,7 @@ def test_recursive_kl(): """ Test if groups made match recursion """ G = Graph() with pytest.raises(ValueError) as excinfo: - group_graph.recursive_kl(G,numgrp=1) + group_graph.recursive_kl(G, numgrp=1) exception_msg = excinfo.value.args[0] assert exception_msg == "numgrp must be a power of 2 and at least 2." @@ -39,4 +39,3 @@ def test_compatibility(): """ Test compatibility between students """ a = (2) b = (2) - From 45274e6afbd5563a1ed95a6a7607125360dbf265 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Tue, 12 Mar 2019 11:23:49 -0400 Subject: [PATCH 038/119] Fixed another pylint error --- gatorgrouper/utils/group_graph.py | 1 + 1 file changed, 1 insertion(+) diff --git a/gatorgrouper/utils/group_graph.py b/gatorgrouper/utils/group_graph.py index 247203fe..58365315 100644 --- a/gatorgrouper/utils/group_graph.py +++ b/gatorgrouper/utils/group_graph.py @@ -152,6 +152,7 @@ def group_graph(): ] student_groups = group_graph_partition(students, 4) print(student_groups) + if __name__ == "__main__": group_graph() From 234e8976b7293ffc485407aface17e0252404bf3 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Tue, 12 Mar 2019 15:16:05 -0400 Subject: [PATCH 039/119] Refactored working test case compatibility_objective_weights() --- tests/test_group_graph.py | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index c23b9d47..e2e97148 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -27,15 +27,36 @@ def test_total_cut_size(): def test_compatibility_length(): """ Test if exception message is raised by unequal students scores """ - a = 2 - b = 1 + a = (1.0, "python") + b = (2.0, "java") with pytest.raises(Exception) as excinfo: group_graph.compatibility(a, b) exception_msg = excinfo.value.args[0] assert exception_msg == "Tuples passed to compatibility() must have same size." +# Run objective_weights test case using None -def test_compatibility(): - """ Test compatibility between students """ - a = (2) - b = (2) +def test_compatibility_objective_weights(): + """ Test if objective_weights is empty """ + a = [1, 1] + b = [0, 0.5] + objective_weights = (2.0, 1.0) + output = group_graph.compatibility(a, b, objective_weights) + expected_output = 1.75 + assert output == expected_output + + +# def test_compatibility_objective_measures(): +# """ Test if objective measures """ +# def test_compatibility_measure(): +# """ Test compatibility between students """ +# a_score = 2 +# b_score = 2 +# output = group_graph.compatibility(a_score, b_score) +# expected_output = something #whatever measure is called +# assert output == expected_output +# +# # Need test cases for every branch of compatibility function +# +# +# def From 5924342de375b27b4e260523e5d3e4184f4fd793 Mon Sep 17 00:00:00 2001 From: Benjamin Watto Date: Tue, 12 Mar 2019 15:21:50 -0400 Subject: [PATCH 040/119] adding test_group_graph_partition --- tests/test_group_graph.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index e2e97148..97408e32 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -60,3 +60,5 @@ def test_compatibility_objective_weights(): # # # def +def test_group_graph_partition(): + From b4074d82e57c5386f2ecc67441dcc02f6a980e87 Mon Sep 17 00:00:00 2001 From: Dillon Thoma Date: Tue, 12 Mar 2019 15:23:00 -0400 Subject: [PATCH 041/119] Adding a docstring to the test_group_graph_partition test --- tests/test_group_graph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 97408e32..fc9a5406 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -61,4 +61,4 @@ def test_compatibility_objective_weights(): # # def def test_group_graph_partition(): - + """ Tests that the output of the group_graph_partition is correct """ From a14f20245ba33f1b145d2c507385f93a738055f9 Mon Sep 17 00:00:00 2001 From: Benjamin Watto Date: Tue, 12 Mar 2019 15:24:05 -0400 Subject: [PATCH 042/119] Adding Expected outputs for test_group_graph_partition --- tests/test_group_graph.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index fc9a5406..618d4720 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -62,3 +62,13 @@ def test_compatibility_objective_weights(): # def def test_group_graph_partition(): """ Tests that the output of the group_graph_partition is correct """ + students = [ + ["one", 0, 0], + ["two", 0, 0.5], + ["three", 0.5, 0], + ["four", 0.75, 0.75], + ["five", 0.8, 0.1], + ["six", 0, 1], + ["seven", 1, 0], + ["eight", 1, 1], + ] From c276dfe6680cacdbc6484f4ddf3306a7bbddce72 Mon Sep 17 00:00:00 2001 From: Dillon Thoma Date: Tue, 12 Mar 2019 15:25:41 -0400 Subject: [PATCH 043/119] Adding the assertion to the test case --- tests/test_group_graph.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 618d4720..40b41674 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -72,3 +72,4 @@ def test_group_graph_partition(): ["seven", 1, 0], ["eight", 1, 1], ] + assert group_graph.group_graph_partition() From 18d2b7370ce6bf7b8a1b59b55358bc98fb4fd027 Mon Sep 17 00:00:00 2001 From: Benjamin Watto Date: Tue, 12 Mar 2019 15:27:16 -0400 Subject: [PATCH 044/119] Adding parameters to test_group_graph_partition --- tests/test_group_graph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 40b41674..e8653921 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -72,4 +72,4 @@ def test_group_graph_partition(): ["seven", 1, 0], ["eight", 1, 1], ] - assert group_graph.group_graph_partition() + assert group_graph.group_graph_partition(students, 4) From ffbc07346727a7db8b4f91dc8eb78f0091dab972 Mon Sep 17 00:00:00 2001 From: Dillon Thoma Date: Tue, 12 Mar 2019 15:31:25 -0400 Subject: [PATCH 045/119] Running black for group_graph.py --- gatorgrouper/utils/group_graph.py | 1 - 1 file changed, 1 deletion(-) diff --git a/gatorgrouper/utils/group_graph.py b/gatorgrouper/utils/group_graph.py index 5bc28756..244ffbad 100644 --- a/gatorgrouper/utils/group_graph.py +++ b/gatorgrouper/utils/group_graph.py @@ -153,7 +153,6 @@ def group_creator(): ] student_groups = group_graph_partition(students, 4) print(student_groups) - if __name__ == "__main__": From 4dd02d465d5f27313d9d5e729b9d864933594142 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Tue, 12 Mar 2019 15:36:47 -0400 Subject: [PATCH 046/119] Refined test case test_compatability_objective_measures --- tests/test_group_graph.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index e2e97148..d4e56594 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -46,8 +46,16 @@ def test_compatibility_objective_weights(): assert output == expected_output -# def test_compatibility_objective_measures(): -# """ Test if objective measures """ +def test_compatibility_objective_measures(): + """ Test if objective measures """ + a = [0, 1] + b = [0.75, 0.75] + objective_measures = ("avg", "match") + output = group_graph.compatibility(a, b, objective_measures=objective_measures) + expected_output = 0.375 + assert output == expected_output + + # def test_compatibility_measure(): # """ Test compatibility between students """ # a_score = 2 From 4d4d83903fbcc6f0ccb7ec70fe2e74e60f2ff3a7 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Tue, 12 Mar 2019 16:30:39 -0400 Subject: [PATCH 047/119] Change docstring of test_compatibility_objective_weights() --- tests/test_group_graph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index d85bab9f..31f4a79a 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -37,7 +37,7 @@ def test_compatibility_length(): # Run objective_weights test case using None def test_compatibility_objective_weights(): - """ Test if objective_weights is empty """ + """ Test if objective_weights returns the objective weights of students """ a = [1, 1] b = [0, 0.5] objective_weights = (2.0, 1.0) From b313daa4769b8e2aa834bf0e8ae3a3d3b9bf4d83 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Tue, 12 Mar 2019 16:31:10 -0400 Subject: [PATCH 048/119] Change docstring of test_compatibility_objective_measures() --- tests/test_group_graph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 31f4a79a..4ce3c2b4 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -47,7 +47,7 @@ def test_compatibility_objective_weights(): def test_compatibility_objective_measures(): - """ Test if objective measures """ + """ Test if objective_measures returns the objective measure of students """ a = [0, 1] b = [0.75, 0.75] objective_measures = ("avg", "match") From debfd4955abf64efd0982edd76f03c0ef7aee866 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Tue, 12 Mar 2019 16:32:41 -0400 Subject: [PATCH 049/119] Remove comment indicating improvement of test case test_total_cut_size --- tests/test_group_graph.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 4ce3c2b4..119d8b3c 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -13,8 +13,6 @@ def test_recursive_kl(): assert exception_msg == "numgrp must be a power of 2 and at least 2." -# Need to parametrize test_total_cut_size because it would, but should not, handle -# groups of 1 def test_total_cut_size(): """ Test if cut size of subsets in partition match """ G = Graph() From 34303d170d20ad2556519cc18551eedebec85cda Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Tue, 12 Mar 2019 16:32:54 -0400 Subject: [PATCH 050/119] Remove another comment --- tests/test_group_graph.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 119d8b3c..cdc63736 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -32,7 +32,6 @@ def test_compatibility_length(): exception_msg = excinfo.value.args[0] assert exception_msg == "Tuples passed to compatibility() must have same size." -# Run objective_weights test case using None def test_compatibility_objective_weights(): """ Test if objective_weights returns the objective weights of students """ From 7e521734a7be070084c7d131383cd34a947ae3d8 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Tue, 12 Mar 2019 16:33:22 -0400 Subject: [PATCH 051/119] Added necessary test cases for group_graph.py --- tests/test_group_graph.py | 61 +++++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 12 deletions(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index cdc63736..22f321f2 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -53,18 +53,55 @@ def test_compatibility_objective_measures(): assert output == expected_output -# def test_compatibility_measure(): -# """ Test compatibility between students """ -# a_score = 2 -# b_score = 2 -# output = group_graph.compatibility(a_score, b_score) -# expected_output = something #whatever measure is called -# assert output == expected_output -# -# # Need test cases for every branch of compatibility function -# -# -# def +def test_compatability_measure_average(): + """ Test if measure of different student scores return an average """ + a = [1, 1] + b = [0, 1] + output = group_graph.compatibility(a, b) + expected_output = 1.5 + assert output == expected_output + + +def test_compatability_measure_max(): + """ Test if measure of different student scores return a maximum """ + a = [1, 0] + b = [0, 0.5] + objective_measures = ("max", "max") + output = group_graph.compatibility(a, b, objective_measures=objective_measures) + expected_output = 1.5 + assert output == expected_output + + +def test_compatability_measure_min(): + """ Test if measure of different student scores return a minimum """ + a = [1, 0] + b = [0, 0.5] + objective_measures = ("min", "min") + output = group_graph.compatibility(a, b, objective_measures=objective_measures) + expected_output = 0 + assert output == expected_output + + +def test_compatability_measure_int(): + """ Test if measure of different student scores are both equal """ + a = [1, 0] + b = [0, 0.5] + objective_measures = ("match", "match") + output = group_graph.compatibility(a, b, objective_measures=objective_measures) + expected_output = 0 + assert output == expected_output + + +def test_compatability_measure_diff(): + """ Test if measure of different student scores returns an absolute value difference """ + a = [1, 0] + b = [0, 0.5] + objective_measures = ("diff", "diff") + output = group_graph.compatibility(a, b, objective_measures=objective_measures) + expected_output = 1.5 + assert output == expected_output + + def test_group_graph_partition(): """ Tests that the output of the group_graph_partition is correct """ students = [ From 8c9580d6eea4a56c66397489600875c66e1d6ee6 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Tue, 12 Mar 2019 17:32:23 -0400 Subject: [PATCH 052/119] Change docstring of test_recursive_kl Co-authored-by: Josh Yee --- tests/test_group_graph.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 22f321f2..1b784810 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -4,8 +4,8 @@ from gatorgrouper.utils import group_graph -def test_recursive_kl(): - """ Test if groups made match recursion from Kernighan-Lin algorithm """ +def test_recursive_kl_error(): + """ Test if ValueError is called if numgrp is not a power of 2 and not at least 2 """ G = Graph() with pytest.raises(ValueError) as excinfo: group_graph.recursive_kl(G, numgrp=1) From 094f8c0de25ef76f70fb317c3b6de8d74850a5f8 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Tue, 12 Mar 2019 17:33:32 -0400 Subject: [PATCH 053/119] Add test case for recursive_kl() Co-authored-by: Josh Yee --- tests/test_group_graph.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 1b784810..8c09da74 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -13,6 +13,21 @@ def test_recursive_kl_error(): assert exception_msg == "numgrp must be a power of 2 and at least 2." +def test_recursive_kl_two(): + """ Test if recursive Kernighan-Lin algorithm returns two groups recursively """ + G = Graph() + student1 = [(1, 4)] + student2 = [(2, 3)] + input = [(1, 4), (2, 3)] + G.add_edges_from([(1, 4), (2, 3)]) + actual_output = group_graph.recursive_kl(G, 2) + print(actual_output) + assert actual_output == [{2, 3}, {1, 4}] or actual_output == [{1, 4}, {2, 3}] + +# def test_recursive_kl_multi(): +# """ Test if recursive Kernighan-Lin algorithm returns more than two groups """ + + def test_total_cut_size(): """ Test if cut size of subsets in partition match """ G = Graph() From c37b926034c9a38b04b39989b3e8f58b6a79c785 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Tue, 12 Mar 2019 17:34:22 -0400 Subject: [PATCH 054/119] Add docstring for test_recursive_kl_multi() --- tests/test_group_graph.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 8c09da74..5744bbe6 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -24,8 +24,10 @@ def test_recursive_kl_two(): print(actual_output) assert actual_output == [{2, 3}, {1, 4}] or actual_output == [{1, 4}, {2, 3}] -# def test_recursive_kl_multi(): -# """ Test if recursive Kernighan-Lin algorithm returns more than two groups """ + +def test_recursive_kl_multi(): + """ Test if recursive Kernighan-Lin algorithm returns more than two groups """ + def test_total_cut_size(): From 2b5a9aa4680ff50f6f19fe467bb31fa769252786 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Tue, 12 Mar 2019 17:59:48 -0400 Subject: [PATCH 055/119] Finish test cases for recursive_kl() Co-authored-by: Josh Yee --- tests/test_group_graph.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 5744bbe6..a17130ea 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -1,6 +1,7 @@ """ Test group graph algorithm""" from networkx import Graph import pytest +import itertools from gatorgrouper.utils import group_graph @@ -16,18 +17,28 @@ def test_recursive_kl_error(): def test_recursive_kl_two(): """ Test if recursive Kernighan-Lin algorithm returns two groups recursively """ G = Graph() - student1 = [(1, 4)] - student2 = [(2, 3)] - input = [(1, 4), (2, 3)] - G.add_edges_from([(1, 4), (2, 3)]) + student1 = (1, 4) + student2 = (2, 3) + G.add_edge(student1, student2) actual_output = group_graph.recursive_kl(G, 2) print(actual_output) - assert actual_output == [{2, 3}, {1, 4}] or actual_output == [{1, 4}, {2, 3}] + assert actual_output == [{student2}, {student1}] or actual_output == [{student1}, {student2}] def test_recursive_kl_multi(): """ Test if recursive Kernighan-Lin algorithm returns more than two groups """ - + G = Graph() + student1 = (1, 4) + student2 = (2, 3) + student3 = (5, 7) + student4 = (6, 8) + students = [student1, student2, student3, student4] + input = list(itertools.combinations(students,2)) + G.add_edges_from(input) + actual_output = group_graph.recursive_kl(G, 2) + assert len(actual_output) == 2 + assert len(actual_output[0]) == 2 + assert len(actual_output[1]) == 2 def test_total_cut_size(): From bbe9cc35bd97f1c1df91980447e75af004976fbe Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Tue, 12 Mar 2019 18:31:29 -0400 Subject: [PATCH 056/119] Fixed pylint issue regarding imports Co-authored-by: Josh Yee --- tests/test_group_graph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index a17130ea..91266fe3 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -1,7 +1,7 @@ """ Test group graph algorithm""" +import itertools from networkx import Graph import pytest -import itertools from gatorgrouper.utils import group_graph From 362a9dff3dce0b23aefca0c67045f26af023fb71 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Tue, 12 Mar 2019 18:40:36 -0400 Subject: [PATCH 057/119] Changed the equality sign to in for assertion Co-authored-by: Josh Yee --- tests/test_group_graph.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 91266fe3..d6485d80 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -22,7 +22,10 @@ def test_recursive_kl_two(): G.add_edge(student1, student2) actual_output = group_graph.recursive_kl(G, 2) print(actual_output) - assert actual_output == [{student2}, {student1}] or actual_output == [{student1}, {student2}] + assert actual_output in [{student2}, {student1}] or actual_output in [ + {student1}, + {student2}, + ] def test_recursive_kl_multi(): From 71265abf98c115b8873d401b66a4244e7de217d7 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Tue, 12 Mar 2019 18:41:25 -0400 Subject: [PATCH 058/119] Changed variable input because its a predefined function --- tests/test_group_graph.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index d6485d80..8a980bc5 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -36,8 +36,8 @@ def test_recursive_kl_multi(): student3 = (5, 7) student4 = (6, 8) students = [student1, student2, student3, student4] - input = list(itertools.combinations(students,2)) - G.add_edges_from(input) + group_list = list(itertools.combinations(students, 2)) + G.add_edges_from(group_list) actual_output = group_graph.recursive_kl(G, 2) assert len(actual_output) == 2 assert len(actual_output[0]) == 2 From 7c6f5a17b567d5682b93b826fe00df9648323252 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Tue, 12 Mar 2019 18:42:42 -0400 Subject: [PATCH 059/119] Final pylint change --- gatorgrouper/utils/group_graph.py | 1 - 1 file changed, 1 deletion(-) diff --git a/gatorgrouper/utils/group_graph.py b/gatorgrouper/utils/group_graph.py index 7b756822..244ffbad 100644 --- a/gatorgrouper/utils/group_graph.py +++ b/gatorgrouper/utils/group_graph.py @@ -155,6 +155,5 @@ def group_creator(): print(student_groups) - if __name__ == "__main__": group_creator() From 7dea7b73a7d9afd071c71b6a3ae916c2596d0d14 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Tue, 12 Mar 2019 18:52:58 -0400 Subject: [PATCH 060/119] Refactor assert statement to pass pylint and pytest Co-authored-by: Josh Yee --- tests/test_group_graph.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 8a980bc5..bc86ce19 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -22,10 +22,11 @@ def test_recursive_kl_two(): G.add_edge(student1, student2) actual_output = group_graph.recursive_kl(G, 2) print(actual_output) - assert actual_output in [{student2}, {student1}] or actual_output in [ - {student1}, - {student2}, - ] + assert actual_output in ([{student2}, {student1}], [{student1}, {student2}]) + # assert actual_output == [{student2}, {student1}] or actual_output == [ + # {student1}, + # {student2}, + # ] def test_recursive_kl_multi(): From cb1aa6b1ae035727ca49e22ef5a42f494047e068 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Wed, 13 Mar 2019 12:07:55 -0400 Subject: [PATCH 061/119] Add documentation for recursive_kl() --- gatorgrouper/utils/group_graph.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gatorgrouper/utils/group_graph.py b/gatorgrouper/utils/group_graph.py index 244ffbad..75d239de 100644 --- a/gatorgrouper/utils/group_graph.py +++ b/gatorgrouper/utils/group_graph.py @@ -10,14 +10,18 @@ def recursive_kl(graph: Graph, numgrp=2) -> List[Set[int]]: """ - Recursively use the Kernighan-Lin algorithm to create a k-way graph partition + Recursively use the Kernighan-Lin algorithm to create a k-way graph partition. + This function will either return two groups or more than two depending on the + value of numgrp. Each group generated is different from the previous. """ power = log(numgrp, 2) if power != int(power) or power < 1: raise ValueError("numgrp must be a power of 2 and at least 2.") + # For a group of two bisect it and return two groups if numgrp == 2: # Base case for recursion: use Kernighan-Lin to create 2 groups return list(kernighan_lin_bisection(graph)) + # For the next group of two divide numgrp by 2 next_numgrp = numgrp / 2 groups = [] for subset in kernighan_lin_bisection(graph): From 094620803b8887de22e307eb73e94c43a77fc925 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Wed, 13 Mar 2019 12:08:20 -0400 Subject: [PATCH 062/119] Add documentation for total_cut_size() --- gatorgrouper/utils/group_graph.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gatorgrouper/utils/group_graph.py b/gatorgrouper/utils/group_graph.py index 75d239de..ae768882 100644 --- a/gatorgrouper/utils/group_graph.py +++ b/gatorgrouper/utils/group_graph.py @@ -35,8 +35,10 @@ def total_cut_size(graph: Graph, partition: List[int]) -> float: Computes the sum of weights of all edges between different subsets in the partition """ cut = 0.0 + # Edges are added from the nodes on the graph, creating subsets for i, subset1 in enumerate(partition): for subset2 in partition[i:]: + # Sum of weights added from all subsets and set equal to cut cut += cut_size(graph, subset1, T=subset2) print(subset1, subset2, cut) return cut From 56a0380e0ecd51c611d4abe29cc8f0ff340312fd Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Wed, 13 Mar 2019 12:08:46 -0400 Subject: [PATCH 063/119] Add documentation for compatability --- gatorgrouper/utils/group_graph.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gatorgrouper/utils/group_graph.py b/gatorgrouper/utils/group_graph.py index ae768882..11f4809e 100644 --- a/gatorgrouper/utils/group_graph.py +++ b/gatorgrouper/utils/group_graph.py @@ -64,10 +64,13 @@ def compatibility( If no measures are specified, "avg" is used as a default. """ if not len(a) == len(b): + # Raise an exception notice if student tuples don't match raise Exception("Tuples passed to compatibility() must have same size.") if objective_weights is None: + # Return length objective_weights = [1] * len(a) if objective_measures is None: + # Default to return average if set equal to None objective_measures = ["avg"] * len(a) scores = [] for a_score, b_score, weight, measure in zip( From d1824e142b8b13681bde21cde2ca3f16948065af Mon Sep 17 00:00:00 2001 From: Dillon Thoma Date: Wed, 13 Mar 2019 15:01:19 -0400 Subject: [PATCH 064/119] Removing main method from group_graph --- gatorgrouper/utils/group_graph.py | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/gatorgrouper/utils/group_graph.py b/gatorgrouper/utils/group_graph.py index 11f4809e..07601340 100644 --- a/gatorgrouper/utils/group_graph.py +++ b/gatorgrouper/utils/group_graph.py @@ -143,26 +143,3 @@ def group_graph_partition( for p in partition: groups.append([inputlist[i] for i in p]) return groups - - -def group_creator(): - """ - Create student groups of 4 using list of list containing student names - and their weights. - """ - students = [ - ["one", 0, 0], - ["two", 0, 0.5], - ["three", 0.5, 0], - ["four", 0.75, 0.75], - ["five", 0.8, 0.1], - ["six", 0, 1], - ["seven", 1, 0], - ["eight", 1, 1], - ] - student_groups = group_graph_partition(students, 4) - print(student_groups) - - -if __name__ == "__main__": - group_creator() From d5d83bf2fdd60ffa900630bdfc5cbfebe9b6fe97 Mon Sep 17 00:00:00 2001 From: Dillon Thoma Date: Wed, 13 Mar 2019 15:02:19 -0400 Subject: [PATCH 065/119] Remove incorrect assertion --- tests/test_group_graph.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index bc86ce19..343a985f 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -146,4 +146,3 @@ def test_group_graph_partition(): ["seven", 1, 0], ["eight", 1, 1], ] - assert group_graph.group_graph_partition(students, 4) From 448bff6b065e5b84b58879adc53a6f60c1acee4d Mon Sep 17 00:00:00 2001 From: Dillon Thoma Date: Wed, 13 Mar 2019 15:03:53 -0400 Subject: [PATCH 066/119] Adding a dictionary to check the preferences of students --- tests/test_group_graph.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 343a985f..655018ca 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -146,3 +146,4 @@ def test_group_graph_partition(): ["seven", 1, 0], ["eight", 1, 1], ] +preference = {"one" : 1, "two" : 1, "three" : 1, "four" : 1, "five" : 1, "six" : 1, "seven" : 1, "eight" : 1} From 9ee64c483a966ad0fda628b12e56e65a85fa2ae0 Mon Sep 17 00:00:00 2001 From: Dillon Thoma Date: Wed, 13 Mar 2019 15:04:43 -0400 Subject: [PATCH 067/119] Declaring the output of the function --- tests/test_group_graph.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 655018ca..1d5cd5f2 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -147,3 +147,4 @@ def test_group_graph_partition(): ["eight", 1, 1], ] preference = {"one" : 1, "two" : 1, "three" : 1, "four" : 1, "five" : 1, "six" : 1, "seven" : 1, "eight" : 1} +output = group_graph.group_graph_partition(students, 4) From 123ff07bad0b0cfc2c260709b647a05c6bb1e482 Mon Sep 17 00:00:00 2001 From: Dillon Thoma Date: Wed, 13 Mar 2019 15:05:12 -0400 Subject: [PATCH 068/119] Adding the dictionary to the parameters --- tests/test_group_graph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 1d5cd5f2..48c1a49f 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -147,4 +147,4 @@ def test_group_graph_partition(): ["eight", 1, 1], ] preference = {"one" : 1, "two" : 1, "three" : 1, "four" : 1, "five" : 1, "six" : 1, "seven" : 1, "eight" : 1} -output = group_graph.group_graph_partition(students, 4) +output = group_graph.group_graph_partition(students, 4, preferences=preference) From 972102546608110d8d1628b932ebac096a5e9393 Mon Sep 17 00:00:00 2001 From: Dillon Thoma Date: Wed, 13 Mar 2019 15:06:25 -0400 Subject: [PATCH 069/119] Adding the assertion to the test --- tests/test_group_graph.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 48c1a49f..e019ba7a 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -148,3 +148,4 @@ def test_group_graph_partition(): ] preference = {"one" : 1, "two" : 1, "three" : 1, "four" : 1, "five" : 1, "six" : 1, "seven" : 1, "eight" : 1} output = group_graph.group_graph_partition(students, 4, preferences=preference) +assert (output[0]) == 2 From 4dc3878732d2a9a30bc6ef5371e4f79a9b89ae69 Mon Sep 17 00:00:00 2001 From: Dillon Thoma Date: Wed, 13 Mar 2019 15:10:46 -0400 Subject: [PATCH 070/119] Fixing indentation of test --- tests/test_group_graph.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index e019ba7a..ee2a956f 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -146,6 +146,6 @@ def test_group_graph_partition(): ["seven", 1, 0], ["eight", 1, 1], ] -preference = {"one" : 1, "two" : 1, "three" : 1, "four" : 1, "five" : 1, "six" : 1, "seven" : 1, "eight" : 1} -output = group_graph.group_graph_partition(students, 4, preferences=preference) -assert (output[0]) == 2 + preference = {"one" : 1, "two" : 1, "three" : 1, "four" : 1, "five" : 1, "six" : 1, "seven" : 1, "eight" : 1} + output = group_graph.group_graph_partition(students, 4, preferences=preference) + assert (output[0]) == 2 From bb55ecd85ac5bdb5266608b5eb2bc5503eba79cc Mon Sep 17 00:00:00 2001 From: Ben <31478967+wattob@users.noreply.github.com> Date: Wed, 13 Mar 2019 15:13:39 -0400 Subject: [PATCH 071/119] Fixing dictionary for int not iterable error --- tests/test_group_graph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index ee2a956f..416d68d0 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -146,6 +146,6 @@ def test_group_graph_partition(): ["seven", 1, 0], ["eight", 1, 1], ] - preference = {"one" : 1, "two" : 1, "three" : 1, "four" : 1, "five" : 1, "six" : 1, "seven" : 1, "eight" : 1} + preference = {"one" : "one", "two" : "three", "three" : "two", "four" : "four", "five" : "six", "six" : "five", "seven" : "eight", "eight" : "seven"} output = group_graph.group_graph_partition(students, 4, preferences=preference) assert (output[0]) == 2 From 569bf0e407a2d304d28b47df663852d8014d8e87 Mon Sep 17 00:00:00 2001 From: Ben <31478967+wattob@users.noreply.github.com> Date: Wed, 13 Mar 2019 15:14:40 -0400 Subject: [PATCH 072/119] Adding len to fix assertion error --- tests/test_group_graph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 416d68d0..19d89543 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -148,4 +148,4 @@ def test_group_graph_partition(): ] preference = {"one" : "one", "two" : "three", "three" : "two", "four" : "four", "five" : "six", "six" : "five", "seven" : "eight", "eight" : "seven"} output = group_graph.group_graph_partition(students, 4, preferences=preference) - assert (output[0]) == 2 + assert len(output[0]) == 2 From 1aeaa5240e55cb1186920c43e53badfe9e336692 Mon Sep 17 00:00:00 2001 From: Ben <31478967+wattob@users.noreply.github.com> Date: Wed, 13 Mar 2019 15:16:31 -0400 Subject: [PATCH 073/119] Updating Dictionary to cover line 137 --- tests/test_group_graph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 19d89543..0461f009 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -146,6 +146,6 @@ def test_group_graph_partition(): ["seven", 1, 0], ["eight", 1, 1], ] - preference = {"one" : "one", "two" : "three", "three" : "two", "four" : "four", "five" : "six", "six" : "five", "seven" : "eight", "eight" : "seven"} + preference = {"one" : "one", "two" : "three", "three" : "two", "four" : "four", "five" : "six", "six" : "five", "seven" : "fix", "eight" : "seven"} output = group_graph.group_graph_partition(students, 4, preferences=preference) assert len(output[0]) == 2 From f8d204673f33a657ca38d49edcfd99ee163f6761 Mon Sep 17 00:00:00 2001 From: Ben <31478967+wattob@users.noreply.github.com> Date: Wed, 13 Mar 2019 15:20:38 -0400 Subject: [PATCH 074/119] Updating docstring for test_group_graph_partition function --- tests/test_group_graph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 0461f009..4d71d075 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -135,7 +135,7 @@ def test_compatability_measure_diff(): def test_group_graph_partition(): - """ Tests that the output of the group_graph_partition is correct """ + """ Test for using recursive Kernighan-Lin algorithm that checks the output of the group_graph_partition function """ students = [ ["one", 0, 0], ["two", 0, 0.5], From 034dc3c2755c9fdfbfd5eb82c90a39da420e76ed Mon Sep 17 00:00:00 2001 From: Dillon Thoma Date: Wed, 13 Mar 2019 15:21:29 -0400 Subject: [PATCH 075/119] Running black for the formatting of the test case --- tests/test_group_graph.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 4d71d075..f59d7c08 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -146,6 +146,15 @@ def test_group_graph_partition(): ["seven", 1, 0], ["eight", 1, 1], ] - preference = {"one" : "one", "two" : "three", "three" : "two", "four" : "four", "five" : "six", "six" : "five", "seven" : "fix", "eight" : "seven"} + preference = { + "one": "one", + "two": "three", + "three": "two", + "four": "four", + "five": "six", + "six": "five", + "seven": "fix", + "eight": "seven", + } output = group_graph.group_graph_partition(students, 4, preferences=preference) assert len(output[0]) == 2 From e9f0c6f4f308d77d9199c54e03be95cf219e23c0 Mon Sep 17 00:00:00 2001 From: Ben <31478967+wattob@users.noreply.github.com> Date: Wed, 13 Mar 2019 15:22:49 -0400 Subject: [PATCH 076/119] Edits to follow Pylint --- tests/test_group_graph.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index f59d7c08..00f3024d 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -135,7 +135,10 @@ def test_compatability_measure_diff(): def test_group_graph_partition(): - """ Test for using recursive Kernighan-Lin algorithm that checks the output of the group_graph_partition function """ + """ + Test for using recursive Kernighan-Lin algorithm that checks the output of + the group_graph_partition function + """ students = [ ["one", 0, 0], ["two", 0, 0.5], From ca35fc5941d140d132e5ff81f774abae3159242a Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Wed, 13 Mar 2019 15:36:48 -0400 Subject: [PATCH 077/119] Refactor compatability test case to handle raise Exception --- tests/test_group_graph.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index bc86ce19..667817b8 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -56,9 +56,9 @@ def test_total_cut_size(): def test_compatibility_length(): - """ Test if exception message is raised by unequal students scores """ - a = (1.0, "python") - b = (2.0, "java") + """ Test if exception message is raised by unequal students' scores """ + a = (1.0, ) + b = (2.0, 0.5) with pytest.raises(Exception) as excinfo: group_graph.compatibility(a, b) exception_msg = excinfo.value.args[0] From 6e316af01592248f28c9946df05942e6ab9610c6 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Wed, 13 Mar 2019 20:05:45 -0400 Subject: [PATCH 078/119] Delete unecessary print statement Co-authored-by: Josh Yee --- gatorgrouper/utils/group_graph.py | 1 - 1 file changed, 1 deletion(-) diff --git a/gatorgrouper/utils/group_graph.py b/gatorgrouper/utils/group_graph.py index 07601340..a24e8641 100644 --- a/gatorgrouper/utils/group_graph.py +++ b/gatorgrouper/utils/group_graph.py @@ -40,7 +40,6 @@ def total_cut_size(graph: Graph, partition: List[int]) -> float: for subset2 in partition[i:]: # Sum of weights added from all subsets and set equal to cut cut += cut_size(graph, subset1, T=subset2) - print(subset1, subset2, cut) return cut From 016cc58b3ebbff43490653c714be371da4a99bfc Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Wed, 13 Mar 2019 20:07:19 -0400 Subject: [PATCH 079/119] Add exception raising to compatibility function --- gatorgrouper/utils/group_graph.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gatorgrouper/utils/group_graph.py b/gatorgrouper/utils/group_graph.py index a24e8641..16e7f2ec 100644 --- a/gatorgrouper/utils/group_graph.py +++ b/gatorgrouper/utils/group_graph.py @@ -88,6 +88,8 @@ def compatibility( compat = int(a_score == b_score) elif measure == "diff": compat = abs(a_score - b_score) + else: + raise Exception("Invalid measure") # Scale the compatibility of a[i] and b[i] using the i-th objective weight scores.append(compat * weight) From b67aeb0f315fc305a28ccc1d245d66094b486e80 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Wed, 13 Mar 2019 20:08:27 -0400 Subject: [PATCH 080/119] Fix exception raising for recursive_kl function Co-authored-by: Josh Yee --- tests/test_group_graph.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 677da6f0..78a713ba 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -10,8 +10,8 @@ def test_recursive_kl_error(): G = Graph() with pytest.raises(ValueError) as excinfo: group_graph.recursive_kl(G, numgrp=1) - exception_msg = excinfo.value.args[0] - assert exception_msg == "numgrp must be a power of 2 and at least 2." + exception_msg = excinfo.value.args[0] + assert exception_msg == "numgrp must be a power of 2 and at least 2." def test_recursive_kl_two(): From 3fbbcc325e2ed7d4910deb5b8a0cb2d46fc40397 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Wed, 13 Mar 2019 20:09:41 -0400 Subject: [PATCH 081/119] Delete unecessary print statement Co-authored-by: Josh Yee --- tests/test_group_graph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 78a713ba..3e84aa59 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -21,7 +21,7 @@ def test_recursive_kl_two(): student2 = (2, 3) G.add_edge(student1, student2) actual_output = group_graph.recursive_kl(G, 2) - print(actual_output) + assert actual_output in ([{student2}, {student1}], [{student1}, {student2}]) # assert actual_output == [{student2}, {student1}] or actual_output == [ # {student1}, From 1befc9ae742abfbf94eecf2fd1115b42f92dbaf5 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Wed, 13 Mar 2019 20:11:24 -0400 Subject: [PATCH 082/119] Refactor exception raising for compatibility length Co-authored-by: Josh Yee --- tests/test_group_graph.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 3e84aa59..30545f10 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -57,12 +57,13 @@ def test_total_cut_size(): def test_compatibility_length(): """ Test if exception message is raised by unequal students' scores """ - a = (1.0, ) - b = (2.0, 0.5) + a = tuple([1.0]) + b = tuple([2.0, 0.5]) with pytest.raises(Exception) as excinfo: group_graph.compatibility(a, b) - exception_msg = excinfo.value.args[0] - assert exception_msg == "Tuples passed to compatibility() must have same size." + exception_msg = excinfo.value.args[0] + assert exception_msg == "Tuples passed to compatibility() must have same size." + def test_compatibility_objective_weights(): From b90af4d7894a5657442779c8ced67cf7290f4c39 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Wed, 13 Mar 2019 20:11:55 -0400 Subject: [PATCH 083/119] Add test case for callable function in compatibility Co-authored-by: Josh Yee --- tests/test_group_graph.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 30545f10..3646ff9a 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -65,6 +65,32 @@ def test_compatibility_length(): assert exception_msg == "Tuples passed to compatibility() must have same size." +def test_compatibility_measure_callable(): + """ Gives a callable measure to compatibility and tests if it is used """ + def score(a, b): + return a + b + + a = [1, 1] + b = [0, 0.5] + output = group_graph.compatibility(a, b, objective_measures=[score, score]) + assert output == sum([1, 1.5]) + +def test_compatibility_measure_preset(): + """ """ + a = [1, 1] + b = [0, 0.5] + + output = group_graph.compatibility(a, b, objective_measures=["avg", "avg"]) + assert output == sum([0.5, 0.75]) + output = group_graph.compatibility(a, b, objective_measures=["max", "max"]) + assert output == sum([1, 1]) + output = group_graph.compatibility(a, b, objective_measures=["min", "min"]) + assert output == sum([0, 0.5]) + output = group_graph.compatibility(a, b, objective_measures=["match", "match"]) + assert output == sum([0, 0]) + output = group_graph.compatibility(a, b, objective_measures=["diff", "diff"]) + assert output == sum([1, 0.5]) + def test_compatibility_objective_weights(): """ Test if objective_weights returns the objective weights of students """ From 5a28583c7e7fed155e67c0eaa6f6b47f78d66a21 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Wed, 13 Mar 2019 20:12:46 -0400 Subject: [PATCH 084/119] Refactor match test case for compatibility Co-authored-by: Josh Yee --- tests/test_group_graph.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 3646ff9a..ec13a1eb 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -141,14 +141,13 @@ def test_compatability_measure_min(): assert output == expected_output -def test_compatability_measure_int(): +def test_compatability_measure_match(): """ Test if measure of different student scores are both equal """ a = [1, 0] - b = [0, 0.5] + b = [1, 0.5] objective_measures = ("match", "match") output = group_graph.compatibility(a, b, objective_measures=objective_measures) - expected_output = 0 - assert output == expected_output + assert output == sum([1, 0]) def test_compatability_measure_diff(): From 74bf7dd60417f3c50e44a00447db22c2730f7a47 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Wed, 13 Mar 2019 20:13:41 -0400 Subject: [PATCH 085/119] Add test case for raising error for inappropriate measure Co-authored-by: Josh Yee --- tests/test_group_graph.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index ec13a1eb..82e2f50d 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -160,6 +160,16 @@ def test_compatability_measure_diff(): assert output == expected_output +def test_compatibility_measure_error(): + """ Test if wrong measure raises Exception error """ + a = tuple([1.0, 0.8]) + b = tuple([2.0, 0.5]) + with pytest.raises(Exception) as excinfo: + group_graph.compatibility(a, b, objective_measures=["su", "mu"]) + exception_msg = excinfo.value.args[0] + assert exception_msg == "Invalid measure" + + def test_group_graph_partition(): """ Test for using recursive Kernighan-Lin algorithm that checks the output of From 4c9522abd1770fd2ed974fa612588c89d7452772 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Wed, 13 Mar 2019 20:22:27 -0400 Subject: [PATCH 086/119] Correctly adds set of preferred student preferences --- tests/test_group_graph.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 82e2f50d..2a7ffb77 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -186,14 +186,14 @@ def test_group_graph_partition(): ["eight", 1, 1], ] preference = { - "one": "one", - "two": "three", - "three": "two", - "four": "four", - "five": "six", - "six": "five", - "seven": "fix", - "eight": "seven", + "one": {"seven", "five"}, + "two": {"three", "six"}, + "three": {"two", "four"}, + "four": {"four", "three"}, + "five": {"six", "one"}, + "six": {"five"}, + "seven": {"six"}, + "eight": {"seven"}, } output = group_graph.group_graph_partition(students, 4, preferences=preference) assert len(output[0]) == 2 From 86c37d0bc9aa0eabbb3ab47cc28dad96c1abe718 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Wed, 13 Mar 2019 20:31:51 -0400 Subject: [PATCH 087/119] Add docstring to test_compatibility_measure_preset Co-authored-by: Josh Yee --- tests/test_group_graph.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 2a7ffb77..fda80a99 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -67,6 +67,7 @@ def test_compatibility_length(): def test_compatibility_measure_callable(): """ Gives a callable measure to compatibility and tests if it is used """ + def score(a, b): return a + b @@ -75,8 +76,9 @@ def score(a, b): output = group_graph.compatibility(a, b, objective_measures=[score, score]) assert output == sum([1, 1.5]) + def test_compatibility_measure_preset(): - """ """ + """ Test all preset measures """ a = [1, 1] b = [0, 0.5] From 706e047fab0a35caeee476d558031073a1418077 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Wed, 13 Mar 2019 21:23:54 -0400 Subject: [PATCH 088/119] Fix spelling of compatibility in all function declarations --- tests/test_group_graph.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index fda80a99..783e3bd9 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -114,7 +114,7 @@ def test_compatibility_objective_measures(): assert output == expected_output -def test_compatability_measure_average(): +def test_compatibility_measure_average(): """ Test if measure of different student scores return an average """ a = [1, 1] b = [0, 1] @@ -123,7 +123,7 @@ def test_compatability_measure_average(): assert output == expected_output -def test_compatability_measure_max(): +def test_compatibility_measure_max(): """ Test if measure of different student scores return a maximum """ a = [1, 0] b = [0, 0.5] @@ -133,7 +133,7 @@ def test_compatability_measure_max(): assert output == expected_output -def test_compatability_measure_min(): +def test_compatibility_measure_min(): """ Test if measure of different student scores return a minimum """ a = [1, 0] b = [0, 0.5] @@ -143,7 +143,7 @@ def test_compatability_measure_min(): assert output == expected_output -def test_compatability_measure_match(): +def test_compatibility_measure_match(): """ Test if measure of different student scores are both equal """ a = [1, 0] b = [1, 0.5] @@ -152,7 +152,7 @@ def test_compatability_measure_match(): assert output == sum([1, 0]) -def test_compatability_measure_diff(): +def test_compatibility_measure_diff(): """ Test if measure of different student scores returns an absolute value difference """ a = [1, 0] b = [0, 0.5] From 8b8d80b1e867aca38d742497fe5c40452d87da6f Mon Sep 17 00:00:00 2001 From: LancasterDesktop Date: Wed, 13 Mar 2019 23:59:49 -0400 Subject: [PATCH 089/119] Clearify the docstring for test_group_graph_partition --- tests/test_group_graph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 783e3bd9..82659f16 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -175,7 +175,7 @@ def test_compatibility_measure_error(): def test_group_graph_partition(): """ Test for using recursive Kernighan-Lin algorithm that checks the output of - the group_graph_partition function + the group_graph_partition function with preferences as input """ students = [ ["one", 0, 0], From d068f775f1c1e85215c832c23239d1e8c7c73e2b Mon Sep 17 00:00:00 2001 From: LancasterDesktop Date: Thu, 14 Mar 2019 00:00:25 -0400 Subject: [PATCH 090/119] Removed unnessesary testing code --- tests/test_group_graph.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/test_group_graph.py b/tests/test_group_graph.py index 82659f16..b8d9549e 100644 --- a/tests/test_group_graph.py +++ b/tests/test_group_graph.py @@ -23,10 +23,6 @@ def test_recursive_kl_two(): actual_output = group_graph.recursive_kl(G, 2) assert actual_output in ([{student2}, {student1}], [{student1}, {student2}]) - # assert actual_output == [{student2}, {student1}] or actual_output == [ - # {student1}, - # {student2}, - # ] def test_recursive_kl_multi(): From 262c4e0fe2a44082585ddf5462d9ef16f9717e11 Mon Sep 17 00:00:00 2001 From: LancasterDesktop Date: Thu, 14 Mar 2019 00:47:11 -0400 Subject: [PATCH 091/119] Add a new default for preference --- gatorgrouper/utils/constants.py | 1 + 1 file changed, 1 insertion(+) diff --git a/gatorgrouper/utils/constants.py b/gatorgrouper/utils/constants.py index dfd26362..5ee00c2c 100644 --- a/gatorgrouper/utils/constants.py +++ b/gatorgrouper/utils/constants.py @@ -8,6 +8,7 @@ DEFAULT_GRPSIZE = 3 DEFAULT_NUMGRP = 3 DEFAULT_ABSENT = "" +DEFAULT_PREFERENCES = None # assertion NONE = "" From d2a903d3980f204c0c3838f75cef3e146296c3f5 Mon Sep 17 00:00:00 2001 From: LancasterDesktop Date: Thu, 14 Mar 2019 00:47:36 -0400 Subject: [PATCH 092/119] generate a new parser to read the preference --- gatorgrouper/utils/parse_arguments.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gatorgrouper/utils/parse_arguments.py b/gatorgrouper/utils/parse_arguments.py index fbaf5bf3..3e0e3171 100644 --- a/gatorgrouper/utils/parse_arguments.py +++ b/gatorgrouper/utils/parse_arguments.py @@ -2,6 +2,7 @@ import argparse import logging +import json from gatorgrouper.utils import read_student_file from gatorgrouper.utils import constants @@ -74,6 +75,14 @@ def parse_arguments(args): required=False, ) + gg_parser.add_argument( + "--preferences", + help="Preferences of students for graph algorithm", + type=str, + default=constants.DEFAULT_PREFERENCES, + required=False, + ) + gg_arguments_finished = gg_parser.parse_args(args) logging.basicConfig( From add9a2149a935061a8735daeda76e19bf1176aa4 Mon Sep 17 00:00:00 2001 From: LancasterDesktop Date: Thu, 14 Mar 2019 00:49:16 -0400 Subject: [PATCH 093/119] Call preferences in gatorgrouper_cli --- gatorgrouper_cli.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gatorgrouper_cli.py b/gatorgrouper_cli.py index 7b177978..2e93087c 100644 --- a/gatorgrouper_cli.py +++ b/gatorgrouper_cli.py @@ -22,6 +22,7 @@ # read in the student identifiers from the specified file input_list = read_student_file.read_csv_data(GG_ARGUMENTS.file) + preference = read_student_file.read_csv_data(GG_ARGUMENTS.preferences) check_if_arguments_valid = parse_arguments.check_valid(GG_ARGUMENTS, input_list) if check_if_arguments_valid is False: print("Incorrect command-line arguments.") @@ -66,7 +67,7 @@ and GG_ARGUMENTS.num_group is not constants.DEFAULT_NUMGRP ): GROUPED_STUDENT_IDENTIFIERS = group_graph.group_graph_partition( - SHUFFLED_STUDENT_IDENTIFIERS, GG_ARGUMENTS.num_group + SHUFFLED_STUDENT_IDENTIFIERS, GG_ARGUMENTS.num_group, preferences=preference ) elif ( GG_ARGUMENTS.num_group is constants.DEFAULT_NUMGRP From 14550c8dc203669397524c77719a49313883595f Mon Sep 17 00:00:00 2001 From: LancasterDesktop Date: Thu, 14 Mar 2019 00:49:56 -0400 Subject: [PATCH 094/119] error that the readcsv function would be able to read students name after the first column, add a if statement to check --- gatorgrouper/utils/read_student_file.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gatorgrouper/utils/read_student_file.py b/gatorgrouper/utils/read_student_file.py index 93a1f2a7..d793e5da 100644 --- a/gatorgrouper/utils/read_student_file.py +++ b/gatorgrouper/utils/read_student_file.py @@ -1,6 +1,7 @@ """ Reads CSV data file """ import csv +import string from pathlib import Path @@ -28,8 +29,10 @@ def read_csv_data(filepath): temp.append(True) elif value.lower() == "false": temp.append(False) - else: + elif value.isdigit(): temp.append(float(value)) + else: + temp.append(value) responses.append(temp) else: for record in csvdata: @@ -40,7 +43,9 @@ def read_csv_data(filepath): temp.append(True) elif value.lower() == "false": temp.append(False) - else: + elif value.isdigit(): temp.append(float(value)) + else: + temp.append(value) responses.append(temp) return responses From a9df671db0df3e30c4a864e60fe52a07ff75b8bb Mon Sep 17 00:00:00 2001 From: LancasterDesktop Date: Thu, 14 Mar 2019 00:57:10 -0400 Subject: [PATCH 095/119] Fixed a bug that elif in readstudent file was not check if it is float --- gatorgrouper/utils/read_student_file.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gatorgrouper/utils/read_student_file.py b/gatorgrouper/utils/read_student_file.py index d793e5da..b749c52c 100644 --- a/gatorgrouper/utils/read_student_file.py +++ b/gatorgrouper/utils/read_student_file.py @@ -1,7 +1,7 @@ """ Reads CSV data file """ import csv -import string +import re from pathlib import Path @@ -29,7 +29,7 @@ def read_csv_data(filepath): temp.append(True) elif value.lower() == "false": temp.append(False) - elif value.isdigit(): + elif re.match("^\d+?\.\d+?$", value) is True: temp.append(float(value)) else: temp.append(value) @@ -43,7 +43,7 @@ def read_csv_data(filepath): temp.append(True) elif value.lower() == "false": temp.append(False) - elif value.isdigit(): + elif re.match("^\d+?\.\d+?$", value) is True: temp.append(float(value)) else: temp.append(value) From 2b6aced24f5b09cf04cc48d6aed822b395e74a8b Mon Sep 17 00:00:00 2001 From: LancasterDesktop Date: Thu, 14 Mar 2019 01:07:05 -0400 Subject: [PATCH 096/119] Fixed a bug that elif statement should include .isdigit otherwise 0 and 1 will not convert to float --- gatorgrouper/utils/read_student_file.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gatorgrouper/utils/read_student_file.py b/gatorgrouper/utils/read_student_file.py index b749c52c..f722ee92 100644 --- a/gatorgrouper/utils/read_student_file.py +++ b/gatorgrouper/utils/read_student_file.py @@ -2,6 +2,7 @@ import csv import re +import string from pathlib import Path @@ -29,7 +30,7 @@ def read_csv_data(filepath): temp.append(True) elif value.lower() == "false": temp.append(False) - elif re.match("^\d+?\.\d+?$", value) is True: + elif re.match("^\d+?\.\d+?$", value) or value.isdigit(): temp.append(float(value)) else: temp.append(value) @@ -43,7 +44,7 @@ def read_csv_data(filepath): temp.append(True) elif value.lower() == "false": temp.append(False) - elif re.match("^\d+?\.\d+?$", value) is True: + elif re.match("^\d+?\.\d+?$", value) or value.isdigit(): temp.append(float(value)) else: temp.append(value) From 8dc63be89f802b8a84af5a2e4942f4ca1149b2ca Mon Sep 17 00:00:00 2001 From: LancasterDesktop Date: Thu, 14 Mar 2019 01:07:29 -0400 Subject: [PATCH 097/119] test statement --- gatorgrouper/utils/group_graph.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gatorgrouper/utils/group_graph.py b/gatorgrouper/utils/group_graph.py index 16e7f2ec..33b8eb73 100644 --- a/gatorgrouper/utils/group_graph.py +++ b/gatorgrouper/utils/group_graph.py @@ -120,6 +120,8 @@ def group_graph_partition( # Add edges between distinct vertices, weighted by compatibility score for i, w1 in enumerate(weights): for j, w2 in enumerate(weights[:i]): + print("w1:", w1) + print("w2:", w2) score = compatibility( w1, w2, From 378104080a7c93caec552546f751dfeb0361708a Mon Sep 17 00:00:00 2001 From: LancasterDesktop Date: Thu, 14 Mar 2019 01:08:07 -0400 Subject: [PATCH 098/119] preference should be dictionary since .get can not be used on string --- gatorgrouper_cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gatorgrouper_cli.py b/gatorgrouper_cli.py index 2e93087c..2da1d846 100644 --- a/gatorgrouper_cli.py +++ b/gatorgrouper_cli.py @@ -22,7 +22,7 @@ # read in the student identifiers from the specified file input_list = read_student_file.read_csv_data(GG_ARGUMENTS.file) - preference = read_student_file.read_csv_data(GG_ARGUMENTS.preferences) + preference = dict(read_student_file.read_csv_data(GG_ARGUMENTS.preferences)) check_if_arguments_valid = parse_arguments.check_valid(GG_ARGUMENTS, input_list) if check_if_arguments_valid is False: print("Incorrect command-line arguments.") From 55d6ca7827ac03dd5866162f6e69122723e15d28 Mon Sep 17 00:00:00 2001 From: LancasterDesktop Date: Thu, 14 Mar 2019 01:08:42 -0400 Subject: [PATCH 099/119] remove testing printline --- gatorgrouper/utils/group_graph.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/gatorgrouper/utils/group_graph.py b/gatorgrouper/utils/group_graph.py index 33b8eb73..16e7f2ec 100644 --- a/gatorgrouper/utils/group_graph.py +++ b/gatorgrouper/utils/group_graph.py @@ -120,8 +120,6 @@ def group_graph_partition( # Add edges between distinct vertices, weighted by compatibility score for i, w1 in enumerate(weights): for j, w2 in enumerate(weights[:i]): - print("w1:", w1) - print("w2:", w2) score = compatibility( w1, w2, From cb0bdd7239cca54c8baf56271476ff72e074960c Mon Sep 17 00:00:00 2001 From: LancasterDesktop Date: Thu, 14 Mar 2019 01:20:48 -0400 Subject: [PATCH 100/119] Added new default value for preference weight and preference weight match --- gatorgrouper/utils/constants.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gatorgrouper/utils/constants.py b/gatorgrouper/utils/constants.py index 5ee00c2c..c8104de9 100644 --- a/gatorgrouper/utils/constants.py +++ b/gatorgrouper/utils/constants.py @@ -9,6 +9,8 @@ DEFAULT_NUMGRP = 3 DEFAULT_ABSENT = "" DEFAULT_PREFERENCES = None +DEFAULT_PREFERENCES_WEIGHT = 1.1 +DEFAULT_PREFERENCES_WEIGHT_MATCH = 1.3 # assertion NONE = "" From 69787a2eb4ffd012f5c1d478bf6afdd97a17aaaf Mon Sep 17 00:00:00 2001 From: LancasterDesktop Date: Thu, 14 Mar 2019 01:21:28 -0400 Subject: [PATCH 101/119] Added the new parser for both preference weight and preference weight match --- gatorgrouper/utils/parse_arguments.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/gatorgrouper/utils/parse_arguments.py b/gatorgrouper/utils/parse_arguments.py index 3e0e3171..d2de8df6 100644 --- a/gatorgrouper/utils/parse_arguments.py +++ b/gatorgrouper/utils/parse_arguments.py @@ -83,6 +83,22 @@ def parse_arguments(args): required=False, ) + gg_parser.add_argument( + "--preferences-weight", + help="something", + type=float, + default=constants.DEFAULT_PREFERENCES_WEIGHT, + required=False, + ) + + gg_parser.add_argument( + "--preferences-weight-match", + help="something", + type=float, + default=constants.DEFAULT_PREFERENCES_WEIGHT_MATCH, + required=False, + ) + gg_arguments_finished = gg_parser.parse_args(args) logging.basicConfig( From 9bf51029abffb09e763e8091e1fd1ca80a924bbf Mon Sep 17 00:00:00 2001 From: LancasterDesktop Date: Thu, 14 Mar 2019 01:21:59 -0400 Subject: [PATCH 102/119] Added these two new command to gatorgrouper_cli.py --- gatorgrouper_cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gatorgrouper_cli.py b/gatorgrouper_cli.py index 2da1d846..68b8f453 100644 --- a/gatorgrouper_cli.py +++ b/gatorgrouper_cli.py @@ -67,7 +67,7 @@ and GG_ARGUMENTS.num_group is not constants.DEFAULT_NUMGRP ): GROUPED_STUDENT_IDENTIFIERS = group_graph.group_graph_partition( - SHUFFLED_STUDENT_IDENTIFIERS, GG_ARGUMENTS.num_group, preferences=preference + SHUFFLED_STUDENT_IDENTIFIERS, GG_ARGUMENTS.num_group, preferences=preference, preferences_weight=GG_ARGUMENTS.preferences_weight, preferences_weight_match=GG_ARGUMENTS.preferences_weight_match ) elif ( GG_ARGUMENTS.num_group is constants.DEFAULT_NUMGRP From 3b3b3e5367fe900fc8e974a7222411e1eabc7d89 Mon Sep 17 00:00:00 2001 From: LancasterDesktop Date: Thu, 14 Mar 2019 01:25:04 -0400 Subject: [PATCH 103/119] Reformate gatorgrouper_cli.py --- gatorgrouper_cli.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gatorgrouper_cli.py b/gatorgrouper_cli.py index 68b8f453..01a0514a 100644 --- a/gatorgrouper_cli.py +++ b/gatorgrouper_cli.py @@ -67,7 +67,11 @@ and GG_ARGUMENTS.num_group is not constants.DEFAULT_NUMGRP ): GROUPED_STUDENT_IDENTIFIERS = group_graph.group_graph_partition( - SHUFFLED_STUDENT_IDENTIFIERS, GG_ARGUMENTS.num_group, preferences=preference, preferences_weight=GG_ARGUMENTS.preferences_weight, preferences_weight_match=GG_ARGUMENTS.preferences_weight_match + SHUFFLED_STUDENT_IDENTIFIERS, + GG_ARGUMENTS.num_group, + preferences=preference, + preferences_weight=GG_ARGUMENTS.preferences_weight, + preferences_weight_match=GG_ARGUMENTS.preferences_weight_match, ) elif ( GG_ARGUMENTS.num_group is constants.DEFAULT_NUMGRP From 991c3ebf2a7ee488876c89c9abe86cfd7603fcca Mon Sep 17 00:00:00 2001 From: LancasterDesktop Date: Thu, 14 Mar 2019 01:34:05 -0400 Subject: [PATCH 104/119] Increase the test coverage --- tests/conftest.py | 8 ++++---- tests/test_read_student_file.py | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index bd0b9e1e..d0679831 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -97,12 +97,12 @@ def generate_csv_no_header(tmpdir_factory): def generate_csv_float(tmpdir_factory): """ Generate a tempory sample csv """ fn = tmpdir_factory.mktemp("data").join("csvNg.csv") - headers = ["NAME", "Q1", "Q2", "Q3", "Q4"] + headers = ["NAME", "Q1", "Q2", "Q3", "Q4", "Q5"] with open(str(fn), "w") as csvfile: writer = csv.DictWriter(csvfile, fieldnames=headers) writer.writeheader() writer.writerow( - {"NAME": "delgrecoj", "Q1": "1.2", "Q2": "1.1", "Q3": "0.9", "Q4": "2.3"} + {"NAME": "delgrecoj", "Q1": "1.2", "Q2": "1.1", "Q3": "0.9", "Q4": "2.3", "Q5": "Name"} ) return str(fn) @@ -113,8 +113,8 @@ def generate_csv_float_no_header(tmpdir_factory): fn = tmpdir_factory.mktemp("data").join("csvNg1.csv") data = [ # optionally include headers as the first entry - ["delgrecoj", "1.2", "0.7", "1.1", "0.2"], - ["delgrecoj2", "0.1", "0.5", "0.8", "0.6"], + ["delgrecoj", "1.2", "0.7", "1.1", "0.2", "Name"], + ["delgrecoj2", "0.1", "0.5", "0.8", "0.6", "Name"], ] csv_string = "" for entry in data: diff --git a/tests/test_read_student_file.py b/tests/test_read_student_file.py index 633647a8..33afbfe8 100644 --- a/tests/test_read_student_file.py +++ b/tests/test_read_student_file.py @@ -32,15 +32,15 @@ def test_read_student_file_no_header(generate_csv_no_header): def test_read_student_file_float(generate_csv_float): """ Test read_student_file """ - expectedoutput = [["delgrecoj", 1.2, 1.1, 0.9, 2.3]] + expectedoutput = [["delgrecoj", 1.2, 1.1, 0.9, 2.3, "Name"]] assert read_student_file.read_csv_data(generate_csv_float) == expectedoutput def test_read_student_file_no_header_float(generate_csv_float_no_header): """ Test read_student_file """ expectedoutput = [ - ["delgrecoj", 1.2, 0.7, 1.1, 0.2], - ["delgrecoj2", 0.1, 0.5, 0.8, 0.6], + ["delgrecoj", 1.2, 0.7, 1.1, 0.2, "Name"], + ["delgrecoj2", 0.1, 0.5, 0.8, 0.6, "Name"], ] assert ( read_student_file.read_csv_data(generate_csv_float_no_header) == expectedoutput From aacdbba9b1bf5eb654180f1cc13cad8b20667543 Mon Sep 17 00:00:00 2001 From: LancasterDesktop Date: Thu, 14 Mar 2019 01:38:47 -0400 Subject: [PATCH 105/119] Fixed linting errors --- gatorgrouper/utils/read_student_file.py | 5 ++--- tests/conftest.py | 9 ++++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/gatorgrouper/utils/read_student_file.py b/gatorgrouper/utils/read_student_file.py index f722ee92..b77d52fe 100644 --- a/gatorgrouper/utils/read_student_file.py +++ b/gatorgrouper/utils/read_student_file.py @@ -2,7 +2,6 @@ import csv import re -import string from pathlib import Path @@ -30,7 +29,7 @@ def read_csv_data(filepath): temp.append(True) elif value.lower() == "false": temp.append(False) - elif re.match("^\d+?\.\d+?$", value) or value.isdigit(): + elif re.match(r"^\d+?\.\d+?$", value) or value.isdigit(): temp.append(float(value)) else: temp.append(value) @@ -44,7 +43,7 @@ def read_csv_data(filepath): temp.append(True) elif value.lower() == "false": temp.append(False) - elif re.match("^\d+?\.\d+?$", value) or value.isdigit(): + elif re.match(r"^\d+?\.\d+?$", value) or value.isdigit(): temp.append(float(value)) else: temp.append(value) diff --git a/tests/conftest.py b/tests/conftest.py index d0679831..82c37b2e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -102,7 +102,14 @@ def generate_csv_float(tmpdir_factory): writer = csv.DictWriter(csvfile, fieldnames=headers) writer.writeheader() writer.writerow( - {"NAME": "delgrecoj", "Q1": "1.2", "Q2": "1.1", "Q3": "0.9", "Q4": "2.3", "Q5": "Name"} + { + "NAME": "delgrecoj", + "Q1": "1.2", + "Q2": "1.1", + "Q3": "0.9", + "Q4": "2.3", + "Q5": "Name", + } ) return str(fn) From 575bcb5daa17fc2778d4f3ddf5c524fcdbb670c9 Mon Sep 17 00:00:00 2001 From: LancasterDesktop Date: Thu, 14 Mar 2019 01:42:53 -0400 Subject: [PATCH 106/119] remove importing json since we are not using it --- gatorgrouper/utils/parse_arguments.py | 1 - 1 file changed, 1 deletion(-) diff --git a/gatorgrouper/utils/parse_arguments.py b/gatorgrouper/utils/parse_arguments.py index d2de8df6..d8d7d64f 100644 --- a/gatorgrouper/utils/parse_arguments.py +++ b/gatorgrouper/utils/parse_arguments.py @@ -2,7 +2,6 @@ import argparse import logging -import json from gatorgrouper.utils import read_student_file from gatorgrouper.utils import constants From 469bc41c20610eadd94b4852caa2ee51ecc73679 Mon Sep 17 00:00:00 2001 From: LancasterDesktop Date: Thu, 14 Mar 2019 02:39:21 -0400 Subject: [PATCH 107/119] Changed the -help for new parsers --- gatorgrouper/utils/parse_arguments.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gatorgrouper/utils/parse_arguments.py b/gatorgrouper/utils/parse_arguments.py index d8d7d64f..fe4d95fc 100644 --- a/gatorgrouper/utils/parse_arguments.py +++ b/gatorgrouper/utils/parse_arguments.py @@ -85,6 +85,7 @@ def parse_arguments(args): gg_parser.add_argument( "--preferences-weight", help="something", + help="Prefered weights", type=float, default=constants.DEFAULT_PREFERENCES_WEIGHT, required=False, @@ -93,6 +94,7 @@ def parse_arguments(args): gg_parser.add_argument( "--preferences-weight-match", help="something", + help="Prefered matching weights", type=float, default=constants.DEFAULT_PREFERENCES_WEIGHT_MATCH, required=False, From fdec943adb5b02bef9f92b4464a6e3a1024dd124 Mon Sep 17 00:00:00 2001 From: LancasterDesktop Date: Thu, 14 Mar 2019 02:41:33 -0400 Subject: [PATCH 108/119] Implementing the last two parameters for group graph --- gatorgrouper/utils/constants.py | 2 ++ gatorgrouper/utils/parse_arguments.py | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/gatorgrouper/utils/constants.py b/gatorgrouper/utils/constants.py index c8104de9..4ae57139 100644 --- a/gatorgrouper/utils/constants.py +++ b/gatorgrouper/utils/constants.py @@ -11,6 +11,8 @@ DEFAULT_PREFERENCES = None DEFAULT_PREFERENCES_WEIGHT = 1.1 DEFAULT_PREFERENCES_WEIGHT_MATCH = 1.3 +DEFAULT_OBJECTIVE_WEIGHTS = None +DEFAULT_OBJECTIVE_MEASURES = None # assertion NONE = "" diff --git a/gatorgrouper/utils/parse_arguments.py b/gatorgrouper/utils/parse_arguments.py index fe4d95fc..491bc5ab 100644 --- a/gatorgrouper/utils/parse_arguments.py +++ b/gatorgrouper/utils/parse_arguments.py @@ -84,7 +84,6 @@ def parse_arguments(args): gg_parser.add_argument( "--preferences-weight", - help="something", help="Prefered weights", type=float, default=constants.DEFAULT_PREFERENCES_WEIGHT, @@ -93,13 +92,28 @@ def parse_arguments(args): gg_parser.add_argument( "--preferences-weight-match", - help="something", help="Prefered matching weights", type=float, default=constants.DEFAULT_PREFERENCES_WEIGHT_MATCH, required=False, ) + gg_parser.add_argument( + "--objective-weights", + help="Objective weights for compatibility input csv file", + type=list, + default=constants.DEFAULT_OBJECTIVE_WEIGHTS, + required=False, + ) + + gg_parser.add_argument( + "--objective-measures", + help="Objective measures for compatibility input csv file: sum, avg, max, min, match, diff", + type=list, + default=constants.DEFAULT_OBJECTIVE_MEASURES, + required=False, + ) + gg_arguments_finished = gg_parser.parse_args(args) logging.basicConfig( From 7642d63cc8e881f3635dde2db0adc11db4f87628 Mon Sep 17 00:00:00 2001 From: LancasterDesktop Date: Thu, 14 Mar 2019 02:43:15 -0400 Subject: [PATCH 109/119] Added objective measures and objective weights to the main cli program --- gatorgrouper_cli.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gatorgrouper_cli.py b/gatorgrouper_cli.py index 01a0514a..f0af5bd1 100644 --- a/gatorgrouper_cli.py +++ b/gatorgrouper_cli.py @@ -72,6 +72,8 @@ preferences=preference, preferences_weight=GG_ARGUMENTS.preferences_weight, preferences_weight_match=GG_ARGUMENTS.preferences_weight_match, + objective_weights=GG_ARGUMENTS.objective_weights, + objective_measures=GG_ARGUMENTS.objective_measures ) elif ( GG_ARGUMENTS.num_group is constants.DEFAULT_NUMGRP From 9a04e12c91ff421e6b5947de5fedcd4b324b339b Mon Sep 17 00:00:00 2001 From: LancasterDesktop Date: Thu, 14 Mar 2019 02:49:49 -0400 Subject: [PATCH 110/119] ran black --- gatorgrouper_cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gatorgrouper_cli.py b/gatorgrouper_cli.py index f0af5bd1..0c280c78 100644 --- a/gatorgrouper_cli.py +++ b/gatorgrouper_cli.py @@ -73,7 +73,7 @@ preferences_weight=GG_ARGUMENTS.preferences_weight, preferences_weight_match=GG_ARGUMENTS.preferences_weight_match, objective_weights=GG_ARGUMENTS.objective_weights, - objective_measures=GG_ARGUMENTS.objective_measures + objective_measures=GG_ARGUMENTS.objective_measures, ) elif ( GG_ARGUMENTS.num_group is constants.DEFAULT_NUMGRP From 5759b9ab87474e43c99cc8337531d5ab548c0e09 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Thu, 14 Mar 2019 14:58:06 -0400 Subject: [PATCH 111/119] Add detail explaination of Kernighan-Lin Grouping Method --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 234c79e1..536e7c9d 100644 --- a/README.md +++ b/README.md @@ -257,6 +257,16 @@ pipenv run python3 gatorgrouper_cli.py --debug If neither of these flags are set, logging will only be shown if an error occurs. +### Kernighan-Lin Grouping Method + +The Kernighan-Lin algorithm creates a k-way graph partition that determines the +grouping of students based on their preferences for working with other students +and compatibility with other classmates. The graph recognizes student compatibility +through numerical weights (indicators of student positional relationship on the graph). +This grouping method allows for a systematic approach and balanced number of student +groups capable of tackling different types of work. Students should enter student name, +number of groups, objective weights (optional), objective_measures(optional), students preferred to work with (optional), preference weight(optional), and preferences_weight_match(optional). Note that number of groups must be at least 2 +and be a power of 2, i.e. 2, 4, 8... ### Full Example ```shell From 7a834fcdb545fb95bb22bcf324dea96da809cc0b Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Thu, 14 Mar 2019 14:58:55 -0400 Subject: [PATCH 112/119] Add documentation for --method graph --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 536e7c9d..2301d09d 100644 --- a/README.md +++ b/README.md @@ -267,6 +267,16 @@ This grouping method allows for a systematic approach and balanced number of stu groups capable of tackling different types of work. Students should enter student name, number of groups, objective weights (optional), objective_measures(optional), students preferred to work with (optional), preference weight(optional), and preferences_weight_match(optional). Note that number of groups must be at least 2 and be a power of 2, i.e. 2, 4, 8... + +NOTE: `--method graph` and `--num-group` are required to create groups. + +It is required to use the graph argument to generate groups through the graph partitioning. +To generate groups using the Kernighan-Lin grouping algorithm use the flag `--method graph` + +```shell +pipenv run python gatorgrouper_cli.py --file filepath --method graph --num-group NUMBER +``` + ### Full Example ```shell From 19edb175f47df22874f69cc674bea45c4b3245ec Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Thu, 14 Mar 2019 14:59:39 -0400 Subject: [PATCH 113/119] Add documentation of --preferences --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 2301d09d..136f8123 100644 --- a/README.md +++ b/README.md @@ -277,6 +277,13 @@ To generate groups using the Kernighan-Lin grouping algorithm use the flag `--me pipenv run python gatorgrouper_cli.py --file filepath --method graph --num-group NUMBER ``` +To load student preferences, a preference weight, use the flag `--preferences` + +```shell +pipenv run python gatorgrouper_cli.py --file filepath --method graph --num-group NUMBER +--preferences filepath +``` + ### Full Example ```shell From 96a134b58322d684f3e6d452b4a5953d50a4403b Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Thu, 14 Mar 2019 15:00:09 -0400 Subject: [PATCH 114/119] Add documentation for --preferences_weight --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 136f8123..67da60cf 100644 --- a/README.md +++ b/README.md @@ -284,6 +284,12 @@ pipenv run python gatorgrouper_cli.py --file filepath --method graph --num-group --preferences filepath ``` +To indicate student preference weight use the flag `--preferences_weight` + +```shell +pipenv run python gatorgrouper_cli.py --file filepath --method graph --num-group NUMBER +--preferences filepath --preferences_weight PREFERENCES_WEIGHT +``` ### Full Example ```shell From a81ef76026eba31f96c064f322aa4245a5282d66 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Thu, 14 Mar 2019 15:00:49 -0400 Subject: [PATCH 115/119] Add documentation for --preferences_weight_match --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 67da60cf..dbe9ec86 100644 --- a/README.md +++ b/README.md @@ -290,6 +290,15 @@ To indicate student preference weight use the flag `--preferences_weight` pipenv run python gatorgrouper_cli.py --file filepath --method graph --num-group NUMBER --preferences filepath --preferences_weight PREFERENCES_WEIGHT ``` + +To indicate preference weight match use the flag `--preferences_weight_match` + +```shell +pipenv run python gatorgrouper_cli.py --file filepath --method graph --num-group NUMBER +--preferences filepath --preferences_weight PREFERENCES_WEIGHT --preferences_weight_match +PREFERENCES_WEIGHT_MATCH +``` + ### Full Example ```shell From c68e5206bdede844c86c8d6295a0ca2c0cb0a899 Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Thu, 14 Mar 2019 15:01:21 -0400 Subject: [PATCH 116/119] Add documentation for --objective_measures --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index dbe9ec86..ac660cf9 100644 --- a/README.md +++ b/README.md @@ -299,6 +299,13 @@ pipenv run python gatorgrouper_cli.py --file filepath --method graph --num-group PREFERENCES_WEIGHT_MATCH ``` +To add objective measures use the flag `--objective_measures` + +```shell +pipenv run python gatorgrouper_cli.py --file filepath --method graph --num-group NUMBER +--objective_measures LIST --objective_weights LIST +``` + ### Full Example ```shell From d5a1d805932934cb920f124e9eaac6d4fcc594ef Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Thu, 14 Mar 2019 15:01:43 -0400 Subject: [PATCH 117/119] Add documentation for --objective_weights --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index ac660cf9..8c03c93d 100644 --- a/README.md +++ b/README.md @@ -306,6 +306,13 @@ pipenv run python gatorgrouper_cli.py --file filepath --method graph --num-group --objective_measures LIST --objective_weights LIST ``` +To add objective weights use the flag `--objective_weights` + +```shell +pipenv run python gatorgrouper_cli.py --file filepath --method graph --num-group NUMBER +--objective_measures LIST --objective_weights LIST +``` + ### Full Example ```shell From 980244cb10a475fceb7c52b2eaf91f05e92ea86d Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Thu, 14 Mar 2019 15:02:22 -0400 Subject: [PATCH 118/119] Add documentation for all arguments in command line --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 8c03c93d..d19cbbed 100644 --- a/README.md +++ b/README.md @@ -313,6 +313,15 @@ pipenv run python gatorgrouper_cli.py --file filepath --method graph --num-group --objective_measures LIST --objective_weights LIST ``` +A command line of all agruments would be: + +```shell +pipenv run python gatorgrouper_cli.py --file filepath --method graph --num-group NUMBER +--preferences filepath --preferences-weight PREFERENCES_WEIGHT --preferences-weight-match +PREFERENCES_WEIGHT_MATCH --objective-measures LIST --objective-weights LIST +``` + + ### Full Example ```shell From 1a24c0461d48f69f964c38c74f870dc16e6c07fb Mon Sep 17 00:00:00 2001 From: Matthew Baldeosingh Date: Thu, 14 Mar 2019 15:10:55 -0400 Subject: [PATCH 119/119] Fixed mdl error --- README.md | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index ff003465..3430d905 100644 --- a/README.md +++ b/README.md @@ -251,64 +251,68 @@ grouping of students based on their preferences for working with other students and compatibility with other classmates. The graph recognizes student compatibility through numerical weights (indicators of student positional relationship on the graph). This grouping method allows for a systematic approach and balanced number of student -groups capable of tackling different types of work. Students should enter student name, -number of groups, objective weights (optional), objective_measures(optional), students preferred to work with (optional), preference weight(optional), and preferences_weight_match(optional). Note that number of groups must be at least 2 -and be a power of 2, i.e. 2, 4, 8... +groups capable of tackling different types of work. Students should enter student +name, number of groups, objective weights (optional), objective_measures(optional), +students preferred to work with (optional), preference weight(optional), +and preferences_weight_match(optional). Note that number of groups must be at +least 2 and be a power of 2, i.e. 2, 4, 8... NOTE: `--method graph` and `--num-group` are required to create groups. -It is required to use the graph argument to generate groups through the graph partitioning. -To generate groups using the Kernighan-Lin grouping algorithm use the flag `--method graph` +It is required to use the graph argument to generate groups through the graph +partitioning. To generate groups using the Kernighan-Lin grouping algorithm use +the flag `--method graph` ```shell -pipenv run python gatorgrouper_cli.py --file filepath --method graph --num-group NUMBER +pipenv run python gatorgrouper_cli.py --file filepath --method graph +--num-group NUMBER ``` To load student preferences, a preference weight, use the flag `--preferences` ```shell -pipenv run python gatorgrouper_cli.py --file filepath --method graph --num-group NUMBER ---preferences filepath +pipenv run python gatorgrouper_cli.py --file filepath --method graph +--num-group NUMBER --preferences filepath ``` To indicate student preference weight use the flag `--preferences_weight` ```shell -pipenv run python gatorgrouper_cli.py --file filepath --method graph --num-group NUMBER ---preferences filepath --preferences_weight PREFERENCES_WEIGHT +pipenv run python gatorgrouper_cli.py --file filepath --method graph +--num-group NUMBER --preferences filepath --preferences_weight PREFERENCES_WEIGHT ``` To indicate preference weight match use the flag `--preferences_weight_match` ```shell -pipenv run python gatorgrouper_cli.py --file filepath --method graph --num-group NUMBER ---preferences filepath --preferences_weight PREFERENCES_WEIGHT --preferences_weight_match -PREFERENCES_WEIGHT_MATCH +pipenv run python gatorgrouper_cli.py --file filepath --method graph +--num-group NUMBER --preferences filepath --preferences_weight PREFERENCES_WEIGHT +--preferences_weight_match PREFERENCES_WEIGHT_MATCH ``` To add objective measures use the flag `--objective_measures` ```shell -pipenv run python gatorgrouper_cli.py --file filepath --method graph --num-group NUMBER ---objective_measures LIST --objective_weights LIST +pipenv run python gatorgrouper_cli.py --file filepath --method graph +--num-group NUMBER --objective_measures LIST --objective_weights LIST ``` To add objective weights use the flag `--objective_weights` ```shell -pipenv run python gatorgrouper_cli.py --file filepath --method graph --num-group NUMBER ---objective_measures LIST --objective_weights LIST +pipenv run python gatorgrouper_cli.py --file filepath --method graph +--num-group NUMBER --objective_measures LIST --objective_weights LIST ``` A command line of all agruments would be: ```shell -pipenv run python gatorgrouper_cli.py --file filepath --method graph --num-group NUMBER ---preferences filepath --preferences-weight PREFERENCES_WEIGHT --preferences-weight-match -PREFERENCES_WEIGHT_MATCH --objective-measures LIST --objective-weights LIST +pipenv run python gatorgrouper_cli.py --file filepath --method graph +--num-group NUMBER --preferences filepath --preferences-weight PREFERENCES_WEIGHT +--preferences-weight-match PREFERENCES_WEIGHT_MATCH --objective-measures LIST +--objective-weights LIST ``` - ### Full Example ```shell