-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestDataManagerbis2.py
More file actions
116 lines (99 loc) · 4.08 KB
/
testDataManagerbis2.py
File metadata and controls
116 lines (99 loc) · 4.08 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# -*- coding: utf-8 -*-
"""
Éditeur de Spyder
Ceci est un script temporaire.
"""
import random
class DataManager():
def setNotNullFeatures(self, featuresList, meanValues):
'''save null features in a list as attribute'''
featuresNotNull = []
for i in range (len(meanValues)) :
if meanValues[i] != 0 :
featuresNotNull.append(featuresList[i])
self.notNullFeatures = featuresNotNull
class testDataManager:
'''
this class has differents methods useful to test the differents
methods from the zDataManager class
'''
def __init__(self, featuresList, meanValues, zDataManager, randomize):
'''
construct a new test object with 2 arrays and one array
with the null features from zDataManager class
'''
if randomize:
self.randomize()
else:
self.featuresList = featuresList
self.meanValues = meanValues
self.notNullFeatures = zDataManager.notNullFeatures
def randomize(self):
featuresList = []
meanValues = []
manager = DataManager()
rand1 = random.randint(1, 10)
for i in range (rand1+1):
rand2 = random.randint(0, 2)
featuresList.append(i)
meanValues.append(rand2)
manager.setNotNullFeatures(featuresList, meanValues)
self.featuresList = featuresList
self.meanValues = meanValues
self.notNullFeatures = manager.notNullFeatures
def printDatas(self):
'''print the differents attributes in this class'''
print("list of features : ")
print(self.featuresList)
print("mean values for each features : ")
print(self.meanValues)
print("list of features with mean values not at 0 : ")
print(self.notNullFeatures)
def zeroValuesCount(self, tab):
'''return the number of zero values in an array of numbers'''
count = 0
for i in tab:
if i == 0:
count+=1
return count
def notNullCount(self):
'''
return the size of the array which contains the null features
list
'''
'''
important thing : the object need to bee instanciated before
using this method
'''
return len(self.notNullFeatures)
def testFeaturesNotNull(self, nullCount):
'''
this method tests the setNotNullFeatures method from
zDataManager for one example
'''
if len(self.featuresList) - self.notNullCount() != nullCount:
print("error in testFeaturesNotNull the method setNullFeatures in class zDataManager need improvements")
def testFeaturesNotNull2(self, number):
'''
this method tests the setNotNullFeatures method from
zDataManager for number examples
'''
manager = DataManager()
for i in range (number):
self = testDataManager([], [], manager, True)
self.testFeaturesNotNull(self.zeroValuesCount(self.meanValues))
print("\nObject 1 : \n")
manager = DataManager()
featuresList = [0, 1, 2]
meanValues = [2, 9, 0]
manager.setNotNullFeatures(featuresList, meanValues)
test1 = testDataManager(featuresList, meanValues, manager, False)
test1.printDatas()
test1.testFeaturesNotNull(test1.zeroValuesCount(test1.meanValues))
print("\nObject 2 (random) : \n")
test2 = testDataManager([], [], manager, True)
test2.printDatas()
test2.testFeaturesNotNull(test2.zeroValuesCount(test2.meanValues))
number = 1000000
print("applying now testFeaturesNotNull on", number, "objects")
test1.testFeaturesNotNull2(number)