forked from Lancasterwu/gatorgrouper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
group_rrobin.py
87 lines (70 loc) · 2.57 KB
/
group_rrobin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
""" group using round robin approach"""
import logging
from random import shuffle
from itertools import cycle
from group_scoring import score_groups
def group_rrobin_group_size(responses, grpsize):
""" group responses using round robin approach """
# setup target groups
groups = list() # // integer div
numgrps = len(responses) // grpsize
logging.info("target groups: " + str(numgrps))
for _ in range(numgrps):
groups.append(list())
# setup cyclical group target
indices = list(range(0, numgrps))
target_group = cycle(indices)
# randomize the order in which the columns will be drained
columns = list()
for col in range(1, len(responses[0])):
columns.append(col)
shuffle(columns)
logging.info("column priority: " + str(columns))
# iterate through the response columns
for col in columns:
for response in responses:
if response[col] is True:
groups[target_group.__next__()].append(response)
responses.remove(response)
# disperse anyone not already grouped
while responses:
groups[target_group.__next__()].append(responses[0])
responses.remove(responses[0])
# scoring and return
scores, ave = [], 0
scores, ave = score_groups(groups)
logging.info("scores: " + str(scores))
logging.info("average: " + str(ave))
return groups
def group_rrobin_num_group(responses, numgrps):
""" group responses using round robin approach """
# setup target groups
groups = list() # // integer div
logging.info("target groups: " + str(numgrps))
for _ in range(numgrps):
groups.append(list())
# setup cyclical group target
indices = list(range(0, numgrps))
target_group = cycle(indices)
# randomize the order in which the columns will be drained
columns = list()
for col in range(1, len(responses[0])):
columns.append(col)
shuffle(columns)
logging.info("column priority: " + str(columns))
# iterate through the response columns
for col in columns:
for response in responses:
if response[col] is True:
groups[target_group.__next__()].append(response)
responses.remove(response)
# disperse anyone not already grouped
while responses:
groups[target_group.__next__()].append(responses[0])
responses.remove(responses[0])
# scoring and return
scores, ave = [], 0
scores, ave = score_groups(groups)
logging.info("scores: " + str(scores))
logging.info("average: " + str(ave))
return groups