def run_ALL(): print 'ready to sample...' sample(1000000) print 'sample done!\n ready to processing data' dp.dataProcess() print 'processing data done!\nready to train data' predict() print 'train done' submit('submission_2') print 'All done'
def main(): X, Y = dataProcess() # X, Y = get_data() #tempY = np.reshape(Y, (len(X), 1)) X, Y = shuffle(X, Y) trainLen = int(len(X) * 0.7) Xtrain = X[:trainLen] Ytrain = Y[:trainLen] Xtest = X[trainLen:] Ytest = Y[trainLen:] # build a network model. model = MLPClassifier(hidden_layer_sizes=(20, 20), max_iter=2000) # train the model. model.fit(Xtrain, Ytrain) trainAccuracy = model.score(Xtrain, Ytrain) testAccuracy = model.score(Xtest, Ytest) print("train accuracy: ", trainAccuracy, "test accuracy: ", testAccuracy) # save the classifier with open('my_dumped_classifier.pkl', 'wb') as fid: cPickle.dump(model, fid) # load it again with open('my_dumped_classifier.pkl', 'rb') as fid: model_loaded = cPickle.load(fid) trainAccuracy1 = model_loaded.score(Xtrain, Ytrain) testAccuracy1 = model_loaded.score(Xtest, Ytest) print("train accuracy: ", trainAccuracy1, "test accuracy: ", testAccuracy1)
def DataExtract(self, bar): print('bar in dataExtract', bar) m = self.s.measure(bar) d = dataProcess.dataProcess(m, self.keyList[bar - 1]) d.ChordDivide1() d.DataProcess() return d.output
def predict(): ''' For rendering results on HTML GUI ''' #int_features = [int(x) for x in request.form.values()] #final_features = [np.array(int_features)] #prediction = model.predict(final_features) #output = round(prediction[0], 2) toModel = dataProcess(request.form.values()) resulter = model.predict(toModel) return render_template('index.html', prediction_text=resulter)
def routine_stat( Fs, Fr=2400e6, bw=1.5e6, offman=0, plotMode=False, path='/dev/shm/', wd=100, ): print '<' * 80 print '<' * 80 print "INIT" whiteNoiseGen(Fs) ###################### result_available = threading.Event() thread = threading.Thread(target=blader_stat, args=( Fs, Fr, bw, result_available, )) thread.start() print("transmitting...") result_available.wait() dcFilter() print("processing data ...") try: Ryx = dataProcess(Fs, wd, path, plotMode) return Ryx except ValueError as err: print "Exception in user code:" print '-' * 60 traceback.print_exc(file=sys.stdout) print '-' * 60 return None
def dataCompile(breathNumber, rawData): # Extract Breath number, Pressure and Flow rate msg = oneBreath(rawData, breathNumber) # Process data Ers, Rrs, PEEP, PIP, Vtidal, V = dataProcess(msg) compiledfile = { 'BNum': msg[0], 'Pressure': msg[2::2], 'FlowRate': msg[1::2], 'Ers': Ers, 'Rrs': Rrs, 'PEEP': PEEP, 'PIP': PIP, 'Vtidal': Vtidal, 'Volume': list(V) } output = json.dumps(compiledfile) return output
import dataProcess import SeekForPath import init import Schedue carPath = './map/config_10/car.txt' crossPath = './map/config_10/cross.txt' roadPath = './map/config_10/road.txt' if __name__ == "__main__": carData, crossData, roadData = dataProcess.dataProcess( carPath, crossPath, roadPath) carRoute = SeekForPath.Seek(carData, crossData, roadData) carList, roadList, crossList = init.MapInit(carData, crossData, roadData, carRoute) print("Initialize finish, ready to Scheduling......") Schedue.MapScheduling(carList, roadList, crossList)
from whiteNoiseGen import whiteNoiseGen from sondeoWithoutGui import * from dataProcess import dataProcess Fs = 20e6 path = '/dev/shm/' calibrationOffsetTime = 1# calibration time [s] , corresponds to parameters of signal generation offman = 15; wd = 10; # window duration [us] for the correlation purpose whiteNoiseGen(Fs) print("###############################") print("\n\n\n\n\n\n\n") result_available = threading.Event() thread = threading.Thread(target=blader, args=(result_available,)) thread.start() print("###############################") print("\n\n\n\n\n\n\n") result_available.wait() dataProcess(Fs,offman = offman)
def sounding_client( Fs, bw=1.5e6, offman=0, plotMode=False, path='/dev/shm/', wd=10, ): #os.system("bladeRF-cli -d '*:serial=179' -e \"set smb_mode input\"") HOST = '192.168.10.3' # The remote host #HOST = '127.0.0.1' PORT = 50006 # The same port as used by the server #ip = '192.168.10.4' ip = HOST name = "grzechu" #name = "udg" conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM) conn.connect((HOST, PORT)) print '<' * 80 print '<' * 80 print "INIT" whiteNoiseGen(Fs) ###################### print("Sending generated noise ..."), os.system( "scp -i ~/.ssh/id_rsa.pub /dev/shm/IPulse.dat /dev/shm/QPulse.dat " + name + "@" + ip + ":/dev/shm/") print("Done") response = "" message = "start;Fs:{0},BW:{1}".format(Fs, bw) # conn.send(message.encode()) # send message shut = False sondeoRx(Fs, bw) while message.lower().strip() != 'zamknij' and not shut: # receive data stream. it won't accept data packet greater than 1024 bytes response = conn.recv(1024).decode() print("from connected user: "******"done": shut = True conn.close() # close the connection print("\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print("processing data ...") try: Ryx = dataProcess(Fs, offman=offman, wd=wd, path=path, offsetTime=0.5, offsetThreshold=0.0035, plotMode=plotMode) return Ryx except ValueError as err: print "Exception in user code:" print '-' * 60 traceback.print_exc(file=sys.stdout) print '-' * 60 return None
q = Queue() kList = CheckConsistence(kList, vList, key) #testing function for key value def CheckConsistence(kList, vList, key): for i in range(1, len(vList) - 2): if vList[i - 1] > 50 and vList[i + 1] > 50: vList[i] = vList[i] + 20 elif vList[i - 1] < 50 and vList[i + 1] < 50: vList[i] = vList[i] - 20 for i, v in enumerate(vList): if v > KEY_THRE: kList[i] = key return vList, kList s = converter.parse(dataFile) key = key.Key(sys.argv[1]) key.show('text') measureNumber = len(s.parts[0].getElementsByClass('Measure')) for i in range(1, measureNumber): m = s.measure(i) d = dataProcess.dataProcess(m, key) d.ChordDivide1() d.DataProcess() dataList.append(d.output) Name = dataFile[:-4] WriteToFileData(Name)
def routine_remote( Fs, Fr=2.4e6, bw=1.5e6, offman=0, plotMode=False, path='/dev/shm/', wd=10, ): #os.system("bladeRF-cli -d '*:serial=179' -e \"set smb_mode input\"") HOST = '192.168.0.6' # The remote host #HOST = '127.0.0.1' PORT = 50005 # The same port as used by the server #ip = '192.168.10.4' ip = HOST name = "pi" #name = "udg" conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM) conn.connect((HOST, PORT)) print '<' * 80 print '<' * 80 print "INIT" #whiteNoiseGen(Fs) ###################### print("Sending generated noise ..."), #os.system("scp -i ~/.ssh/id_rsa.pub /dev/shm/tx.bin "+ name +"@"+ip+":/dev/shm/") print("Done") response = "" message = "start;Fs:{0},Fr:{1},BW:{2}".format(Fs, Fr, bw) # conn.send(message.encode()) # send message shut = False result_available = threading.Event() thread = threading.Thread(target=blader_Rx, args=( Fs, Fr, bw, result_available, )) thread.start() print("transmitting...") result_available.wait() while message.lower().strip() != 'zamknij' and not shut: # receive data stream. it won't accept data packet greater than 1024 bytes response = conn.recv(1024).decode() print(" from connected user: "******"done": shut = True conn.close() # close the connection dcFilter() print("processing data ...") try: Ryx = dataProcess(Fs, wd, path, plotMode) return Ryx except ValueError as err: print "Exception in user code:" print '-' * 60 traceback.print_exc(file=sys.stdout) print '-' * 60 return None
def sounding_client( Fs, event, plotMode, outputQueue, path='/dev/shm/', wd=10, ): #os.system("bladeRF-cli -d '*:serial=179' -e \"set smb_mode input\"") HOST = '192.168.10.3' # The remote host #HOST = '127.0.0.1' PORT = 50007 # The same port as used by the server #ip = '192.168.10.4' ip = HOST name = "grzechu" #name = "udg" conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM) conn.connect((HOST, PORT)) whiteNoiseGen(Fs) ###################### os.system( "scp -i ~/.ssh/id_rsa.pub /dev/shm/IPulse.dat /dev/shm/QPulse.dat " + name + "@" + ip + ":/dev/shm/") response = "" message = "start" # conn.send(message.encode()) # send message shut = False sondeoRx(Fs) while message.lower().strip() != 'zamknij' and not shut: # receive data stream. it won't accept data packet greater than 1024 bytes response = conn.recv(1024).decode() print("from connected user: "******"done": shut = True conn.close() # close the connection print("\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print("processing data ...") try: Ryx = dataProcess(Fs, offman=0, wd=wd, path=path, offsetTime=0.5, offsetThreshold=0.004, plotMode=plotMode) outputQueue.put(Ryx) event.set() # event set except ValueError as err: print("Unexpected error:", sys.exc_info()[0]) event.set() # event set
#coding:utf-8 import os from movieLensSql import movieLensSql from dataProcess import dataProcess current_path = os.path.realpath(__file__) father_path = os.path.dirname(os.path.dirname(current_path)) file_path = os.path.join(father_path, 'ml-10M100K') factory = movieLensSql() factory_data = dataProcess(file_path) def movie2Mysql(): movie_data = factory_data.get_movei_data() for movie in movie_data: movie_id = movie[0] movie_name = movie[1] movie_tag = movie[2] try: if not factory.find_movie(movie_id=movie_id): factory.add_movie(movie_id=movie_id, name=movie_name, summary=movie_tag) else: print('this movie %s is already exists' % movie_name) except: print('error in add movie to mysql') def rating2Mysql():
def save_mode_thread(args): while (True): if getVauleFromMmap() == 3 or getVauleFromMmap() == 4: break dataProcess.dataProcess(args) time.sleep(10)