-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdataManagement.py
More file actions
83 lines (56 loc) · 1.93 KB
/
dataManagement.py
File metadata and controls
83 lines (56 loc) · 1.93 KB
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
import random
# represents an attribute
class Attribute(object):
def __init__(self, name):
self._values = []
self._name = name
def add(self, *args):
map(self._addSingle, args)
def _addSingle(self, value):
#possible attribute values
self._values.append(value)
def getValues(self):
return self._values
def valueCount(self):
return len(self._values)
def __str__(self):
return self._name
#generates attributes with random number of values, used for testing
class RandomAttributeFactory(object):
def __init__(self, start):
#The first attribute's id will be labeled 'start',
#the second at start + 1, etc.
self._next = start
def getNext(self):
#assign a random attribute name
randomAtt = RandomAttribute('rand' + str(self._next))
self._next = self._next + 1
#assign a random number of values from 2 to 14
str_list = map(str, range(1, random.randint(2, 5)))
map(randomAtt.add, str_list)
return randomAtt
class RandomAttribute(Attribute):
def sample(self):
return self._values[random.randint(0, self.valueCount() - 1)]
def setValues(self, values):
self._values = values
class SampleSet(object):
def __init__(self):
self.values = []
self.parameters = []
def addDefinition(self, attribute):
self.parameters.append(attribute)
def addSample(self, line):
sample = [line.split()[0]]
for token in line.split()[1:self.size()]:
sample.append(token.split(':')[1])
if len(sample) < len(self.parameters):
return
self.values.append(sample)
def size(self):
return len(self.parameters)
def startIdx(self):
self._idx = 0
def getNext(self, attr):
self._idx += 1
return self._values[self._idx][attr]