def create_group(self, name, default_permission=DEFAULT_PERMISSION, default_stat=DEFAULT_STAT): self.user_role = 'unknown' # mistake if we want made group in group wrap = Wrapper(group_key=self.group_key, user_roles=self.user_role) # add funktion could we made group here #if wrap.get_permission()['create'] self.user_role = '_creator' self.group_key = wrap.create_group(name, self.user_id, default_permission, default_stat) self.create_object_data(self.user_id, self.group_key, self.user_role)
def antrlparser(uinput): """ Parser based on ANTRL. It returns the following dict for query = find dataset, run where site = T2 {'ORDERING': [], 'FIND_KEYWORDS': ['dataset', 'run'], 'ORDER_BY_KEYWORDS': [], 'WHERE_CONSTRAINTS': [{'value': 'T2', 'key': 'site', 'op': '='}, {'bracket': 'T2'}]} """ from Wrapper import Wrapper parserobj = Wrapper() tokens = parserobj.parseQuery(uinput) return tokens
def __init__(self, event: threading.Event): Wrapper.__init__(self) Client.__init__(self, wrapper=self) self.started = False self.nextValidOrderId = None self.permId2ord = {} self.reqId2nErr = collections.defaultdict(int) self.globalCancelOnly = False self.simplePlaceOid = None self.event = event self.df = pd.DataFrame(columns=[ "reqId", "bar.date", "bar.open", "bar.high", "bar.low", "bar.close", "bar.volume", "bar.barCount", "bar.average" ]) self.idx = -1
def _listen(self): data = self.players_info[self.current_player][1].recv(self.buffer_size) if data: msg = Wrapper.unwrap(data) return msg.data else: return "-1, -1"
def _listen(self): data = self.client_info[-1][1].recv(self.buffer_size) if data: msg = Wrapper.unwrap(data) return msg.data else: return "-1"
def receive(self): while 1: data = self.socket.recv(self.buffer_size) if not data: break mess = Wrapper.unwrap(data) return mess
def _send(self, message, flag): info_message = Message(StateFlag(flag), message) self.players_info[self.current_player][1].send( Wrapper.wrap(info_message))
def _send(self, message): info_message = Message(StateFlag.server_waiting_for_response, message) self.client_info[-1][1].send(Wrapper.wrap(info_message))
def packing(self): return Wrapper()
class Window(QMainWindow): wrapper = Wrapper() def __init__(self): # use super to return parent object super(Window, self).__init__() self.setGeometry(50, 50, 650, 450) self.setWindowTitle("P300 Predictor") # to change this file self.raw_signal = [] # below for file menu File_Menu_Exit_Button = QAction("&Exit", self) File_Menu_Exit_Button.setShortcut("Ctrl+Q") # below for status bar File_Menu_Exit_Button.setStatusTip('Leave The App') File_Menu_Exit_Button.triggered.connect(self.close_application) File_Menu_Save_Button = QAction("&Save File", self) File_Menu_Save_Button.setShortcut("Ctrl+S") File_Menu_Save_Button.setStatusTip('Save File') #File_Menu_Save_Button.triggered.connect(self.file_save) # to add things to menu bar mainMenu = self.menuBar() # below name is 'File' fileMenu = mainMenu.addMenu('&File') fileMenu.addAction(File_Menu_Save_Button) fileMenu.addAction(File_Menu_Exit_Button) self.home() def home(self): Function_Train_Button = QPushButton("Train", self) Function_Train_Button.clicked.connect(self.train) Function_Train_Button.resize(191, 41) Function_Train_Button.move(420, 100) Function_Predict_Button = QPushButton("Predict", self) Function_Predict_Button.clicked.connect(self.predict) Function_Predict_Button.resize(191, 41) Function_Predict_Button.move(420, 150) Function_Load_Button = QPushButton("Load", self) #Function_Load_Button.clicked.connect(self.close_application) Function_Load_Button.resize(191, 41) Function_Load_Button.move(420, 200) Function_Save_Button = QPushButton("Save", self) #Function_Save_Button.clicked.connect(self.close_application) Function_Save_Button.resize(191, 41) Function_Save_Button.move(420, 250) Function_Get_Statistics_Button = QPushButton("Get Statistics", self) Function_Get_Statistics_Button.clicked.connect(self.generate_graph) Function_Get_Statistics_Button.resize(191, 41) Function_Get_Statistics_Button.move(420, 300) label_1 = QLabel("P300 \nPredictor", self) label_1.setFont(QFont("Times", 40, QFont.Bold)) label_1.resize(321, 201) label_1.move(30, 30) label_3 = QLabel("Version 1.10", self) label_3.resize(171, 16) label_3.move(20, 330) label_4 = QLabel("(c) 2018", self) label_4.resize(171, 16) label_4.move(20, 350) label_5 = QLabel("University of Essex", self) label_5.resize(171, 16) label_5.move(20, 370) label_6 = QLabel("Essex, United Kingdom", self) label_6.resize(171, 16) label_6.move(20, 390) error_msg = QMessageBox() #error_msg.setIcon(QMessageBox.critical) error_msg.setWindowTitle("Error") error_msg.setDetailedText("") self.show() def worker(self, saved_file): """thread worker function""" self.wrapper.train(saved_file) return def train(self): # Let the user chose a file. # only allows mat files to be read in filename = QFileDialog.getOpenFileName(self, 'Open File', filter="*.mat")[0] if filename: # Make sure the user wants to use train. choice = QMessageBox.question( self, 'Train', "Are you sure you want to train? If you click yes, the training might take long periods to train.", QMessageBox.Yes | QMessageBox.No) if choice == QMessageBox.Yes: # User wants to train. raw_data = Importer.mat(filename) # Make data_raw smaller. (Should be removed in future versions). for row in raw_data: raw_data[row] = raw_data[row][:1] self.wrapper.train(data_raw=raw_data, shrink_percent=0.0, verbose=True) # Statistics obtained from the data global raw_signal global filtered_signal global chunked_X global chunked_Y global accuracy raw_signal = self.wrapper.bciObject.preprocessor.preprocess_statistics.raw_signal filtered_signal = self.wrapper.bciObject.preprocessor.preprocess_statistics.filtered_signal chunked_X = self.wrapper.bciObject.preprocessor.preprocess_statistics.chunked_X chunked_Y = self.wrapper.bciObject.preprocessor.preprocess_statistics.chunked_Y accuracy = self.wrapper.bciObject.prediction_model.model_statistics.accuracy #print(accuracy) msg = QMessageBox(self) msg.resize(500, 400) msg.setText("The training accuracy is %.3f" % accuracy) msg.show() else: # User don't want to train. pass def predict(self): # Let the user chose a file. # only allows mat files to be read in filename = QFileDialog.getOpenFileName(self, 'Open File', filter="*.mat")[0] if filename: # Make sure the user wants to use train. choice = QMessageBox.question( self, 'Extract!', "Are you sure you want to run prediction? If you click yes, the prediction might take a long time to run", QMessageBox.Yes | QMessageBox.No) if choice == QMessageBox.Yes: # User wants to train. raw_data = Importer.mat(filename) # Make data_raw smaller. (Should be removed in future versions). for row in raw_data: raw_data[row] = raw_data[row][:1] prediction = self.wrapper.predict(raw_data, verbose=True) print(list(prediction)) else: # User don't want to train. pass def generate_graph(self): # Check if variable is empty try: raw_signal except NameError: msg = QMessageBox() msg.setIcon(QMessageBox.Warning) msg.setText("Error") #msg.setInformativeText("No statistics found! Please run the training function button to generate statistics for the graph.") msg.setWindowTitle("Error") else: print("Generating Statistics Now") array_raw_signal = np.asarray(raw_signal) array_filtered_signal = np.asarray(filtered_signal) array_chunked_X = np.asarray(chunked_X) array_chunked_Y = np.asarray(chunked_Y) # plot for the 1st channel and 12th example only x1 = np.arange(array_raw_signal.shape[2]) y1 = array_raw_signal[0][12] p1 = pg.plot(x1, y1, title='Raw Signal', labels={ 'left': ('Values'), 'bottom': ('Timesteps') }, enableMenu=True) p1.showGrid(x=True, y=True, alpha=0.3) p1.enableAutoScale() p1.showButtons() # plot for the 1st channel and 12th example only x2 = np.arange(array_filtered_signal.shape[2]) y2 = array_filtered_signal[0][12] p2 = pg.plot(x2, y2, title='Filtered Signal', labels={ 'left': ('Values'), 'bottom': ('Timesteps') }, enableMenu=True) p2.showGrid(x=True, y=True, alpha=0.3) p2.enableAutoScale() p2.showButtons() x3 = np.arange(array_chunked_X.shape[2]) y3 = array_chunked_X[0][12] p3 = pg.plot(x3, y3, title='Chunked_X', labels={ 'left': ('Values'), 'bottom': ('Timesteps') }, enableMenu=True) p3.showGrid(x=True, y=True, alpha=0.3) p3.enableAutoScale() p3.showButtons() def file_save(self): name = QFileDialog.getSaveFileName(self, 'Save File') file = open(name, 'w') text = self.textEdit.toPlainText() file.write(text) file.close() def color_picker(self): color = QColorDialog.getColor() self.styleChoice.setStyleSheet("QWidget { background-color: %s}" % color.name()) def close_application(self): choice = QMessageBox.question(self, 'Exit!', "Are you sure you want to exit?", QMessageBox.Yes | QMessageBox.No) if choice == QMessageBox.Yes: print("Exiting Now!") sys.exit() else: pass
def edit_group_stat(self, stat_name, stat_value, stat_opt, group_key=None): print self.get_user_role() wrap = Wrapper(user_roles=self.get_user_role(), group_key=self.group_key) wrap.get_permission() pass
from Importer import Importer from Wrapper import Wrapper from Visualization import Visualization filename_train_A = "Subject_A_Train.mat" filename_test_A = "Subject_A_Test.mat" wrapper = Wrapper() # TODO: This should be triggered through the user interface GUI. # Train the bci-classifier using input file. def development(filename): # Import mat file. data_raw = Importer.mat(filename) # Make data_raw smaller. for row in data_raw: data_raw[row] = data_raw[row][:1] # Train. wrapper.development(data_raw) development(filename_train_A)
from Wrapper import Wrapper if __name__ == '__main__': Wrapper().main()
for x in range(int(start_from), len(input_file)): try: if input_file['TO_DO'].iloc[x] == "NO": print(" SKIP") count+=1 continue company = input_file['BEDRIJVEN'].iloc[x] company2 = company.replace(",", " ") print("MAIN INPUT ---> ", company) data_main = Wrapper(company).data data = data_main['data'] print(data) if data == "Too many items": csv_file4.write(company + "\n") continue pass_fail = data_main['succesfull'] for subcompanies in data: print("SUB INPUT ---> ", subcompanies)
def main(args): parser = argparse.ArgumentParser() parser.add_argument('run_name', metavar='N', type=str, help='name of run') parser.add_argument('gpu_id', metavar='G', type=str, help='which gpu to use') parser.add_argument('network_type', metavar='N', type=str, default='AEConv', help='network type: AEConv, ClassConv, LSTM') parser.add_argument('--multi_net', metavar='G', type=int, default=1, help='number of networks') parser.add_argument('--ryu_testing', action='store_true', help='for yu') parser.add_argument('--ryu_datagen', action='store_true', help='gen data') parser.add_argument('--ryu_datagen_train', action='store_false', help='gen train?') parser.add_argument('--class_conv', action='store_true', help='class_conv') parser.add_argument('--print_network', action='store_true', help='print_network for debugging') parser.add_argument('--test', action='store_true', help='test') parser.add_argument('--fit_curve', action='store_true', help='fit gaussian?') parser.add_argument('--checkpoint_every', type=int, default=10, help='checkpoint every n epochs') parser.add_argument('--load_checkpoint', action='store_true', help='load checkpoint with same name') parser.add_argument('--resume', action='store_true', help='resume from epoch we left off of when loading') parser.add_argument('--checkpoint', type=str, default=None, help='checkpoint to load') parser.add_argument('--epochs', metavar='N', type=int, help='number of epochs to run for', default=3000) parser.add_argument('--batch_size', metavar='bs', type=int, default=512, help='batch size') parser.add_argument('--lr', metavar='lr', type=float, help='learning rate', default=1e-3) parser.add_argument('--rmsprop', action='store_true', help='use rmsprop optimizer') parser.add_argument('--sgd', action='store_true', help='use sgd optimizer') parser.add_argument('--l2_reg', metavar='lr', type=float, help='learning rate', default=0.0) network_types = { 'AEConv': AutoConvNetwork, 'ClassConv': ClassConvNetwork, 'latentConv': LatentAutoConvNetwork } network_type = args[2] network_class = network_types[network_type] PFPSampler.add_args(parser) PFPSampler2.add_args(parser) network_class.add_args(parser) args = parser.parse_args(args) #print(not args.test) #exit(1) data_loader = PFPSampler(args, train=not args.test) if args.gpu_id == '-1': os.environ['CUDA_VISIBLE_DEVICES'] = '' device = torch.device('cpu') else: print(bcolors.OKBLUE + 'Using GPU' + str(args.gpu_id) + bcolors.ENDC) os.environ['CUDA_VISIBLE_DEVICES'] = args.gpu_id device = torch.device('cuda') run_wrapper = Wrapper(args, network_class, data_loader, device, True) if args.test: if args.ryu_testing: run_wrapper.ryu_test_procedure() else: run_wrapper.test() else: run_wrapper.train()
def findInterval(t_list, zeta_list, start, stop): for ii, t in enumerate(t_list): if t > start: ii_start = ii break for ii, t in enumerate(t_list[ii_start:]): if t > stop: ii_stop = ii break if __name__ == '__main__': #buildFortranRoutine() w = Wrapper('CalWrapper.json') ip = ImgProc() o = w.getCollection()[0] obmt = o.timestamp obmt_rev = obmt2rev(obmt) dt = milliseconds2days(1000) lines = callFortranRoutine(obmt_rev, dt=dt, tmax=1) print lines[1] #lines=out.splitlines() t_list, zeta_list, eta_list, omega_list = getImageSpeed( lines, w.fov, o.ccdStrip, o.ccdRow) wdt, h = figure.figaspect(6.) fig, ax = plt.subplots(figsize=(h, wdt))
def getSmearing(zeta_list, eta_list): dt = 0.001 # 1 millisecond #AC_integration=sum(map(abs,zeta_list))*dt #AL_integration=sum(map(abs,[e+60000 for e in eta_list]))*dt AC_integration = sum(zeta_list) * dt AL_integration = sum([e + 60000 for e in eta_list]) * dt return AC_integration, AL_integration if __name__ == '__main__': matplotlib.rcParams.update({'font.size': 14}) #buildFortranRoutine_init() w = Wrapper('CalWrapper.json') fa = FrequencyAnalysis(w) ip = ImgProc() o = w.getCollection()[0] print o.day_int + o.day_float start, Omega0, nu0 = getInitParams(w) ###### original ####### #Omega0=3.0823632010724396 #nu0=5.8195930723884430 ###### shifted ####### #Omega0=2.6645082056929823 #nu0=5.8180006687463219
from Wrapper import Wrapper # initalize program and ask for information to start retrieve data from the API of overheid.io #company = Wrapper('Bejo Zaden B.V.') # Test gemeente Utrecht, #Test Triple - A rk finance #companies = dict([(name, Wrapper(name).data) for name in ['AB WERKT DETACHERING B.V.']]) companies = Wrapper('PROFOURCE SERVICE CENTER B.V.').data print(companies)
def check(self, line): generator = Wrapper(line, self.nGramModel, self.wordCount, self.posModel, self.PosTags) return [(x, y, z) for x, y, z in generator.run()]
from Wrapper import Wrapper import matplotlib.pyplot as plt wrapper = Wrapper() wrapper.start() plt.show()
A, w, p, c = popt f = w/(2.*np.pi) fitfunc = lambda t: A * np.sin(w*t + p) + c return {"amp": A, "omega": w, "phase": p, "offset": c, "freq": f, "period": 1./f, "fitfunc": fitfunc, "maxcov": np.max(pcov), "rawres": (guess,popt,pcov)} def smooth(y, box_pts): box = np.ones(box_pts)/box_pts y_smooth = np.convolve(y, box, mode='same') return y_smooth if __name__ == '__main__': print w=Wrapper('CalWrapper.json') fa=FrequencyAnalysis(w) ip=fa.improc for o in w.observations: f=open('images/'+str(o.id)+'.png', 'wb') new_img=ip.img_interpolateImage(o.window, x_dim=1800, y_dim=1200, algorithm=cv2.INTER_AREA) win = map(np.uint16,new_img) writer = png.Writer(width=len(win[0]), height=len(win), bitdepth=16, greyscale=True) writer.write(f, win) f.close() print o.id, o.ACrate, o.ACmotion ''' fa.readResultsCooccurrence('2018-09-11_13:27') fa.readResultsMoments('2018-09-11_13:27')
def respond_server(self): response_data = Message(0, self.response_data) data = Wrapper.wrap(response_data) self.socket.send(data)