def do_ok(self, event): """Actually performs the connection.""" if not self.host.GetValue(): return wx.MessageBox('Hostname cannot be blank.', 'Error') if not self.port.GetValue().isdigit() or int(self.port.GetValue()) < 1 or int(self.port.GetValue()) > 65535: return wx.MessageBox('Port must be a value between 1 and 65535.', 'Error') if not self.timeout.GetValue().isdigit() or int(self.timeout.GetValue()) < 1: return wx.MessageBox('Timeout must be a positive integer.', 'Error') try: functions.connect(self.host.GetValue(), int(self.port.GetValue()), int(self.timeout.GetValue())) except Exception as e: logger.exception(e) finally: self.Close(True)
def main(): db, coll = connect('datamad1019','chats') with open('./chats.json') as f: chats_json = json.load(f) for chatmsg in chats_json: coll.insert_one(chatmsg)
def main(): conn, cur = functions.connect() status = True functions.print_menu() while status: choice = int(input('Choice: ')) if choice == 1: functions.create_table(conn, cur, 'teachers') elif choice == 2: functions.insert_data(conn, cur, 'teachers') elif choice == 3: keys = input('SELECT BY: ') records = functions.select_from_db(conn, cur, 'teachers', keys) functions.print_selected_data(records, keys) elif choice == 4: records = functions.select_from_db(conn, cur, 'teachers') functions.print_selected_data(records) elif choice == 5: functions.disconnect(conn, cur) break functions.print_menu()
###################################################### (n_neurons_rec_spike, n_neurons_rec_voltage) = functions.derive_parameters(model) ###################################################### # Create nodes ###################################################### print("Create nodes") all_GIDs = functions.create_nodes(model, pyrngs) ################################################### # Connect ################################################### print("Connect") t_connect_0 = time.time() functions.connect(model, all_GIDs, n_neurons_rec_spike, n_neurons_rec_voltage, verbose) T_connect = time.time() - t_connect_0 print("T_connect = ", T_connect) ################################################### # Get connection numbers ################################################### print("Count synapse numbers") t_count_0 = time.time() data_sup_path = sim.data_dir sub_path = "micro" data_path = os.path.join(data_sup_path, sub_path) file_name = "synapse_numbers.hdf5" neuron_GIDs = all_GIDs[0]
import datetime print("Content-Type: text/plain\n\n") # Note this line. It's the important one sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach()) try: data = json.load(sys.stdin) cookie = data["cookie"] time_before = (datetime.datetime.now() - datetime.timedelta(minutes=10)).strftime('%Y-%m-%d %H:%M:%S') connection = functions.connect() sql_select = "SELECT * FROM `sessions` WHERE `sid` LIKE '" + cookie + "' AND logged_out = 0 AND update_time >= '" + time_before + "'" cursor = connection.cursor() cursor.execute(sql_select) records = cursor.fetchall() if records: connect = True else: connect = False json_res = {'ok': connect} print(json.dumps(json_res, indent=4, default=str, ensure_ascii=False).encode('utf-8').decode())
sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach()) print("Content-Type: text/plain; charset=UTF-8\n\n") try: uid=functions.get_user_id() sid = functions.get_cookie_value('LoggedIn') if not functions.check_logged(): json_res = {"ok": False, "data": []} print(json.dumps(json_res, indent=4, default=str, ensure_ascii=False).encode('utf-8').decode()) sys.exit() list_friends_query = "SELECT friend1 FROM friends WHERE status = 2 AND friend2 = '"+str(uid)+"' UNION SELECT friend2 FROM friends WHERE status = 2 AND friend1 = '"+str(uid)+"' " sql = "SELECT id, nickname, picture_number FROM users WHERE id IN ("+list_friends_query+") " mydb = functions.connect() mycursor = mydb.cursor() mycursor.execute(sql) all_details = mycursor.fetchall() friend = [] list_of_columens = [i[0] for i in mycursor.description] for row in all_details: user = {key: val for key, val in zip(list_of_columens, row)} friend.append(user) json_res = {"ok": True,"id":uid, "data": friend} print(json.dumps(json_res, indent=4, default=str, ensure_ascii=False).encode('utf-8').decode()) except Exception as e: print(e)
###################################################### (n_neurons_rec_spike, n_neurons_rec_voltage) = functions.derive_parameters(model) ###################################################### # Create nodes ###################################################### print("Create nodes") all_GIDs = functions.create_nodes(model, pyrngs) ################################################### # Connect ################################################### print("Connect") t_connect_0 = time.time() functions.connect(model, all_GIDs, n_neurons_rec_spike, n_neurons_rec_voltage, verbose) T_connect = time.time() - t_connect_0 ################################################### # Simulate ################################################### print("Simulate") t_simulate_0 = time.time() nest.Simulate(sim.t_sim) T_simulate = time.time() - t_simulate_0 ################################################### # Save recorded data ################################################### print("Save data")
pass count_vectorizer = CountVectorizer() sparse_matrix = count_vectorizer.fit_transform(dict_users.values()) doc_term_matrix = sparse_matrix.todense() df = pd.DataFrame(doc_term_matrix, columns=count_vectorizer.get_feature_names(), index=dict_users.keys()) similarity_matrix = distance(df, df) sim_df = pd.DataFrame(similarity_matrix, columns=dict_users.keys(), index=dict_users.keys()) recommendation = list(sim_df.sort_values(by=[user_id]).index[0:3]) return {"recommendation": recommendation} database, collection = connect('datamad1019', 'chats') run(host='localhost', port=8080, debug=True) # @route('/plot/users') # def server_static(filename="output.png"): # dic = list(collection.find({"idChat": 0},{"Sentiment":1, "_id":0, "userName": 1})) # polarity = [e["Sentiment"][0] for e in dic] # subjectivity = [e["Sentiment"][1] for e in dic] # labels = [e["userName"] for e in dic] # df = pd.DataFrame(list(zip(subjectivity, polarity)), columns=["subjectivity", "polarity"]) # sns.set() # cmap = sns.cubehelix_palette(rot=-.2, as_cmap=True) # fig, ax = plt.subplots(figsize=(8,5)) # ax = sns.scatterplot(x="polarity", y="subjectivity", size="subjectivity", hue="polarity", # palette=cmap, sizes=(80, 200), # data=df, legend="brief")
import classes, paths, socket, functions files = {} host = "" port = 0 dirOrFile = int(input("Do you wish to scan a (1)File or a (2)Directory: ")) if dirOrFile == 1: inputFile = str(input("Please input the location of your file: ")) file = classes.mediaFile() file.idmedia(inputFile) functions.connect(host, port) elif dirOrFile == 2: directoryInput = str(input("Please input the directory you wish to scan: ")) print(dir(directoryInput))