def do_hand(print_read, frame): if ApClass.Application.count_click < 12: x = len(frame[0]) // 2 - size // 2 - size * 2 y = len(frame) // 2 - size // 2 - size * 2 img = frame for i in range(0, 6, 2): for j in range(0, 9, 3): if print_read == PRINT: img = cv2.rectangle( img, (x - 1 + i * size, y - 1 + j * size), (x + 1 + (i + 1) * size, y + 1 + (j + 1) * size), ( 255, 255, 255, ), 1) if print_read == READ: min_color1, max_color1 = Reading.find_all_colors( frame, x + i * size, y + j * size) ApClass.Application.min_color = Reading.find_min_coomp( ApClass.Application.min_color, min_color1) ApClass.Application.max_color = Reading.find_max_coomp( ApClass.Application.max_color, max_color1) if print_read == PRINT: return img
def cycle(self, step_size, step_length, number_of_steps, frequency=5): self.step_size = step_size self.step_length = step_length self.number_of_steps = number_of_steps self.changeFreq(frequency) pressure = 1 for n in range(1,number_of_steps): print 'this is cycle ' + str(n) t_end = time.time() + (60 * n * step_length) while time.time() < t_end: x = g.getGrms(rmsFile) print x # Check USBPIX flags print 'd1' if((x < (n*step_size - 1)) and (x > (n*step_size-3))): print 'd2' pressure = pressure + 1 if pressure > 80: pressure = 80 self.setPressure(pressure) time.sleep(1) elif((x > (n*step_size+1)) and (x < (n*step_size+3))): print 'd3' pressure = pressure - 1 if pressure < 1: pressure=1 self.setPressure(pressure) time.sleep(1) elif(x > (n*step_size +3)): print 'd4' pressure = pressure - 3 if pressure < 1: pressure=1 self.setPressure(pressure) time.sleep(1) elif(x < n*step_size-3): print 'd5' pressure = pressure + 3 if pressure > 80: pressure = 80 self.setPressure(pressure) time.sleep(1) x = g.getGrms(rmsFile) # Check USBPIX flags while ((x >= (n * step_size - 1)) and (x <= (n * step_size + 1))): print 'd6' time.sleep(1) x = g.getGrms(rmsFile) print x if time.time() >= t_end: break self.setPressure(0) print 'done'
def makeGraph(relPath, columns, resultColumn,k ,tp): dataSet = r.readDataSet(relPath, columns) trainingSets = [] avaliationSets = [] kfold = kc(dataSet, k, resultColumn, True) kfold.run(trainingSets, avaliationSets, stratified = True) dataSet = dataSet.apply(pd.to_numeric) ks = [1,2,3,5,7,9,11,13,15] means = [] for j in ks: print("Using k = " + str(j)) correctPercentage = 0 for i in range(len(trainingSets)): tset=[] aset=[] for index, row in dataSet.iterrows(): tupla = (dataSet.iloc[index][resultColumn], index) if tupla in trainingSets[i]: tset.append(row.tolist()) if tupla in avaliationSets[i]: aset.append(row.tolist()) k = Knn(tset, j, tp = tp) correctPercentage += k.test(aset) generalMean = correctPercentage / len(trainingSets) means.append(generalMean) matplotlib.pyplot.plot(ks, means) matplotlib.pyplot.show()
def _LVQ3(relPath, columns, resultColumn): dataSet = r.readDataSet(relPath, columns) trainingSets = [] avaliationSets = [] kfold = kc(dataSet, 10, resultColumn, True) kfold.run(trainingSets, avaliationSets, stratified=True) dataSet = dataSet.apply(pd.to_numeric) tset = [] aset = [] for i in range(len(trainingSets)): print("\n") print(" --------- FOLD " + str(i + 1) + " ----------------") tset = [] aset = [] for index, row in dataSet.iterrows(): tupla = (dataSet.iloc[index][resultColumn], index) if tupla in trainingSets[i]: tset.append(row.tolist()) if tupla in avaliationSets[i]: aset.append(row.tolist()) print("------------- SIMPLE KNN ----------------") k = Knn(tset, 3) k.test(aset) lvq = LVQ3(tset, resultColumn) newtset = lvq.run() print("-------------- LVQ3 ----------------------") k = Knn(newtset, 3) k.test(aset)
def _makeGraph(relPath, columns, resultColumn): dataSet = r.readDataSet(relPath, columns) trainingSets = [] avaliationSets = [] kfold = kc(dataSet, 10, resultColumn, True) kfold.run(trainingSets, avaliationSets, stratified=True) dataSet = dataSet.apply(pd.to_numeric) ks = [1, 3] nPrototypes = [3, 5, 10, 20] for k in ks: meansGeral = [] meansFalse = [] meansTrue = [] for j in nPrototypes: correctnessPercentage = 0 correctTrue = 0 correctFalse = 0 for i in range(len(trainingSets)): print("\n") print(" --------- FOLD " + str(i + 1) + " ----------------") tset = [] aset = [] for index, row in dataSet.iterrows(): tupla = (dataSet.iloc[index][resultColumn], index) if tupla in trainingSets[i]: tset.append(row.tolist()) if tupla in avaliationSets[i]: aset.append(row.tolist()) lvq = LVQ3(tset, resultColumn) newtset = lvq.run(nPrototypes=j) kn = Knn(newtset, k) result = kn.test(aset) correctnessPercentage += result[0] classErrors = result[1] classNumbers = result[2] correctFalse += ( classErrors[False] / classNumbers[False]) if False in classErrors.keys() else 0 correctTrue += ( classErrors[True] / classNumbers[True]) if True in classErrors.keys() else 0 meansGeral.append(correctnessPercentage / len(trainingSets)) meansFalse.append(correctFalse / len(trainingSets)) meansTrue.append(correctTrue / len(trainingSets)) plt.ylim(0, 1) plt.plot(nPrototypes, meansGeral, 'r', label='general') plt.plot(nPrototypes, meansFalse, 'g', label='false') plt.plot(nPrototypes, meansTrue, 'b', label='true') plt.legend(loc='upper left') plt.show()
def setGrms(self, Grms, length): self.Grms = Grms self.length = t pressure = 1 t_end = time.time() + (60 * t) while time.time() < t_end: x = g.getGrms(rmsFile) #Check USBPix Flags if (( x < (Grms - 1)) and (x > (Grms - 3))): pressure = pressure +1 if pressure > 80: pressure = 80 self.setPressure(pressure) time.sleep(1) elif ((x > (Grms + 1)) and (x < (Grms + 3))): pressure = pressure - 1 if pressure < 1: pressure = 1 self.setPressure(pressure) time.sleep(1) elif ((x > (Grms + 3))): pressure = pressure -3 if pressure < 1: pressure = 1 self.setPressure(pressure) time.sleep(1) elif ((x < (Grms - 3))): pressure = pressure + 3 if pressure > 80: pressure = 80 self.setPressure(pressure) time.sleep(1) elif ((x >= (Grms - 1)) and (X <= (Grms + 1))): time.sleep(1) x = g.getGrms(rmsFile) print x
def do_any(print_read, frame): width = len(frame[0]) height = len(frame) y_new = Y x_new = X if 3 <= ApClass.Application.count_click < 6: x_new = width - X if 6 <= ApClass.Application.count_click < 9: x_new = X y_new = height - Y if ApClass.Application.count_click >= 9: x_new = width - X y_new = height - Y if print_read == PRINT: return cv2.rectangle(frame, (x_new - 1, y_new - 1), (x_new + size + 1, y_new + size + 1), (255, 255, 255), 1) if print_read == READ: min_color1, max_color1 = Reading.find_all_colors( frame, x_new + 1, y_new + 1) ApClass.Application.min_color = Reading.find_min_coomp( ApClass.Application.min_color, min_color1) ApClass.Application.max_color = Reading.find_max_coomp( ApClass.Application.max_color, max_color1)
def simpleKnn(relPath, columns, resultColumn): dataSet = r.readDataSet(relPath, columns) trainingSets = [] avaliationSets = [] kfold = kc(dataSet, 5, resultColumn, True) kfold.run(trainingSets, avaliationSets, stratified=True) dataSet = dataSet.apply(pd.to_numeric) for i in range(len(trainingSets)): tset = [] aset = [] for index, row in dataSet.iterrows(): tupla = (dataSet.iloc[index][resultColumn], index) if tupla in trainingSets[i]: tset.append(row.tolist()) if tupla in avaliationSets[i]: aset.append(row.tolist()) i = ID3(tset, resultColumn) i.printTree()
def makeGraph(relPath, columns, classColumn): dataSet = r.readDataSet(relPath, columns) dataSet.drop(dataSet.columns[[-1,]], axis=1, inplace=True) ds = [] color = ['#FF0000', '#0055FF', '#00FF5E', '#008080', '#F7FF00', '#0D0D0B', '#00FFDE', '#6A98D2', '#239C2F', '#9FC9A3', '#6619CA', '#B98B20', '#6D2FA4'] for index, row in dataSet.iterrows(): ds.append(row.tolist()) t = AdaptativeClustering(ds) result = t.run() xAxis = [] yAxis = [] c = 0 for i in set(result.values()): xAxis = [] yAxis = [] for j in result.keys(): if result[j] == i: xAxis.append(ds[j][0]) yAxis.append(ds[j][1]) matplotlib.pyplot.plot(xAxis, yAxis, 'ro', color=color[c]) c += 1 matplotlib.pyplot.show()
import interface import number_of_symbols as nos import Reading if __name__ == '__main__': url = 'https://github.com/Vetcher/pagedownloader/blob/master/pkg/cleaner/cleaner.go' text = Reading.reading(url) dictionary = nos.numbers_of_symbols(text) histogram = interface.histogram_of_symbols(dictionary) print(histogram)
import Vibration import time import Reading as g test = Vibration.VibrationTest('COM2',5,1,5,'COM10',9600) step_size = test.step_size step_length =test.step_length number_of_steps = test.number_of_steps pressure = 1 gfile = "gfile.txt" for n in range(1,number_of_steps): t_end = time.time() + 60 * n * step_length while time.time() < t_end: x = g.getGrms(gfile) print x print 'd1' if((x < (n*step_size - 1)) and (x > (n*step_size-3))): print 'd2' pressure = pressure + 1 if pressure > 50: pressure = 50 test.setPressure(pressure) elif((x > (n*step_size+1)) and (x < (n*step_size+3))): print 'd3' pressure = pressure - 1 if pressure < 1: pressure=1 test.setPressure(pressure) elif(x > (n*step_size +3)):
def cycle(self, step_size, start_grms, step_length, number_of_steps, frequency=5): self.step_size = step_size self.start_grms = start_grms self.step_length = step_length self.number_of_steps = number_of_steps self.changeFreq(frequency) pressure = 8 for n in range(0,number_of_steps): print 'this is cycle ' + str(n+1) t_end = time.time() + (60 * step_length) while time.time() < t_end: x = g.getGrms(rmsFile) print x #If (n*step_size) < Something, use this if elif loop #Elif (n*step_size) < Something else and (n*step_size) > Something, use this if elif loop, etc. Buffer1d = (n*step_size - .2) Buffer2d = (n*step_size - .5) Buffer3d = (n*step_size - 1) Buffer1u = (n*step_size + .2) Buffer2u = (n*step_size + .5) Buffer3u = (n*step_size + 1) Shift1d = .01 Shift2d = .04 Shift3d = .08 Shift1u = .012 Shift2u = .045 Shift3u = .10 # Check USBPIX flags if(x < (start_grms + Buffer3d)): print 'd1' pressure = pressure + shift3d if pressure > 80: pressure = 80 self.setPressure(pressure) time.sleep(1) elif((x < (start_grms + Buffer2d)) and (x > (start_grms + Buffer3d))): print 'd2' pressure = pressure + shift2d if pressure > 80: pressure = 80 self.setPressure(pressure) time.sleep(1) elif((x >= (start_grms + Buffer2d)) and (x <= (start_grms + Buffer1d))): print 'd3' pressure = pressure + shift1d if pressure > 80: pressure = 80 self.setPressure(pressure) time.sleep(1) elif ((x >= (start_grms + Buffer1d)) and (x <= (start_grms + Buffer1u))): print 'd4' time.sleep(1) x = g.getGrms(rmsFile) print x elif((x <= (start_grms + Buffer2u)) and (x >= (start_grms + Buffer1u ))): print 'd5' pressure = pressure - shift1u if pressure < 1: pressure = 1 self.setPressure(pressure) time.sleep(1) elif((x > (start_grms + Buffer2u)) and (x < (start_grms + Buffer3u))): print 'd6' pressure = pressure - shift2u if pressure < 1: pressure=1 self.setPressure(pressure) time.sleep(1) elif(x > (start_grms + Buffer3u)): print 'd7' pressure = pressure - shift3u if pressure < 1: pressure=1 self.setPressure(pressure) time.sleep(1) self.setPressure(0) print 'done'
import Reading loc = "C200/C200-Assignments-cmtidmar/Assignment5/people.csv" # I keep getting a FileNotFoundError, no matter if I have Assignment5/people.csv or anything else listOfPeople = Reading.fileRead(loc) count = Reading.getAge(listOfPeople, 15) print("The number of people are or below the age of {} is {}".format(15, count)) count = Reading.getAge(listOfPeople, 30) print("The number of people are or below the age of {} is {}".format(30, count))