def main(): global db, points, equations # id, id_problem_params, dxi, fx, gx, dti, time_modif id_problem_params = 4 dti = 69 db = sql.database(settings['sql_host'], settings['sql_user'], settings['sql_passwd'], settings['sql_db']) points = db.getDictFromQueryRes("galerkin.aprox_decision", { "id_problem_params": id_problem_params, "dti": dti }) fluxes = db.getDictFromQueryRes("galerkin.fluxes", None) id_equation = 3 id_flux = 2 rates = getDataRates(id_equation, id_flux) print(rates) genenerate_table_rates(rates) getJPGFromFormulaLatex(fluxes[2]["formula_latex"], fluxes[0]["name"]) #genenerate_longtabu() params = db.getDictFromQueryRes("galerkin.problem_params", {"id": id_problem_params}) lx = float(params[0]["lx"]) rx = float(params[0]["rx"]) qty_dx = int(params[0]["qty_dx"]) dx = (rx - lx) / qty_dx points = [{ "x": lx + p["dxi"] * dx, "fx": p["fx"], "gx": p["gx"] } for p in points] print(points)
def test_database_creation(self): """ Is the database connection being established? Author: Jake """ db = sql.database("UnitTest") self.assertIsNotNone(db.conn)
def test_database_exception(self): """ Will an SQLError be thrown when a bad query is entered? Author: Jake """ db = sql.database("UnitTest") with self.assertRaises(sql.SQLError): db.query("""SELECT * FROM UnknownTable""")
def init_data(): global db, points, equations # id, id_problem_params, dxi, fx, gx, dti, time_modif id_problem_params = 4 dti = 69 db = sql.database(settings['sql_host'], settings['sql_user'], settings['sql_passwd'], settings['sql_db']) equations = db.getDictFromQueryRes("equations", None) fluxes = db.getDictFromQueryRes("fluxes", None) print(equations)
def test_database_query_table_create(self): """ Is the table being created? Author: Jake """ db = sql.database("UnitTest") query = db.query("""CREATE TABLE IF NOT EXISTS TestTable ( id INTEGER PRIMARY KEY AUTOINCREMENT, data TEXT)""") self.assertTrue(query)
def test_database_query_insert_data(self): """ Is the data being inserted into the table? Author: Jake """ db = sql.database("UnitTest") db.query("""CREATE TABLE IF NOT EXISTS TestTable ( id INTEGER PRIMARY KEY AUTOINCREMENT, data TEXT)""") query = db.query("""INSERT INTO TestTable VALUES(NULL, 'TestData')""") self.assertTrue(query)
def test_database_get_size_query_result(self): """ Can the count of items returned be gathered? Author: Jake """ db = sql.database("UnitTest") db.query("""CREATE TABLE IF NOT EXISTS TestTable ( id INTEGER PRIMARY KEY AUTOINCREMENT, data TEXT)""") db.query("""INSERT INTO TestTable VALUES(NULL, 'TestData')""") query = db.query("""SELECT data FROM TestTable WHERE id=1""") self.assertEqual(query.size(), 1)
def test_database_get_data_from_query(self): """ Can data be obtained from the query result Author: Jake """ db = sql.database("UnitTest") db.query("""CREATE TABLE IF NOT EXISTS TestTable ( id INTEGER PRIMARY KEY AUTOINCREMENT, data TEXT)""") db.query("""INSERT INTO TestTable VALUES(NULL, 'TestData')""") query = db.query("""SELECT data FROM TestTable WHERE id=1""") self.assertEqual(query.fetch()[0]['data'], "TestData")
def test_database_query_fetch_data(self): """ Can the data be fetched from the table? Author: Jake """ db = sql.database("UnitTest") db.query("""CREATE TABLE IF NOT EXISTS TestTable ( id INTEGER PRIMARY KEY AUTOINCREMENT, data TEXT)""") db.query("""INSERT INTO TestTable VALUES(NULL, 'TestData')""") query = db.query("""SELECT data FROM TestTable""") self.assertTrue(query)
lambda d: 'soundcloud' in d.data) dp.register_callback_query_handler( callback_handlers.artist_callback_handler, lambda d: 'artist' in d.data) dp.register_callback_query_handler(callback_handlers.callback_handler) dp.register_chosen_inline_handler(inline_handlers.finish_download_handler) dp.middleware.setup(Middleware()) try: global session bot = Bot(token=config.bot_token, loop=loop) storage = MemoryStorage() dp = Dispatcher(bot, storage=storage) var.downloading = {} var.session = aiohttp.ClientSession(raise_for_status=True) print('created session') var.CSRFToken = None var.loop = loop from spotify import Spotify_API var.spot = Spotify_API( config.spotify_client, config.spotify_secret) var.db = database('db.sqlite') var.conn = loop.run_until_complete(aioredis.create_connection( ('localhost', 6379), encoding='utf-8', db=4, loop=loop)) print('datebase connected') except Exception as e: print(e)
'Cache-Control': 'no-cache', 'Upgrade-Insecure-Requests': '1', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36', 'Accept-Encoding': 'gzip, deflate, br', 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8', 'Content-Length': '0' } response = requests.get('https://wiki.biligame.com/blhx/重樱船名称对照表', headers=headers) soup = BeautifulSoup(response.text, features="lxml") soup = soup.select_one('table[id="FlourPackage"]') soup_list = soup.select('tr[class="Flour"]') db = database('User') code_list = list(map(lambda x: x[0], db.select('Roster'))) name_list = list(map(lambda x: x[1], db.select('Roster'))) print(code_list) print(name_list) z = 1 for i in soup_list: z += 1 #print("{}/{}".format(z, len(soup_list)),end="\r") j = i.select_one("span[lang='zh']").text k = i.select_one('span[class="nowrap"]') if not k: k = i.select_one('span[class="new nowrap"]') k = k.text if j in code_list:
def main_loop(self): print("initializing camera") frames_new_face = 0 camera = PiCamera() camera.resolution = (320,192) camera.framerate = 30 rawCapture = PiRGBArray(camera, size=(320,192)) time.sleep(.1) for image in camera.capture_continuous(rawCapture, format='bgr', use_video_port=True): frame = image.array rawCapture.truncate(0) names_to_remove = [] for name in self.seen_people.keys(): self.seen_people[name] -= 1 if(self.seen_people[name] < 0): names_to_remove.append(name) for each in names_to_remove: del self.seen_people[each] if(not self.camera_on): #no motion detected so camera not needed time.sleep(.1) continue # Resize frame of video to 1/4 size for faster face recognition processing small_frame = frame # Convert the image from BGR color (which OpenCV uses) to RGB color (which face_recognition uses) rgb_small_frame = cv2.cvtColor(small_frame, cv2.COLOR_BGR2RGB) face_locations = face_recognition.face_locations(rgb_small_frame) face_encodings = face_recognition.face_encodings(rgb_small_frame, face_locations) face_names = [] all_matches = [] if(len(face_encodings) > 0): print(len(face_encodings)) for face_encoding in face_encodings: # See if the face is a match for the known face(s) matches = face_recognition.compare_faces(self.known_encodings, face_encoding) encodings_to_check = [] names_to_check = [] for i in range(len(matches)): if(matches[i]): encodings_to_check.append(self.known_encodings[i]) names_to_check.append(self.names[i]) closest_person = None min_distance = None difference = -1 if(len(encodings_to_check) != 0): distances = face_recognition.face_distance(encodings_to_check,face_encoding) min_distance = min(distances) closest_person = names_to_check[np.argmin(distances)] if(len(distances) > 1): difference = min([each - min_distance for each in distances if each - min_distance != 0]) if(closest_person is not None): frames_new_face = 0 all_matches.append((closest_person, min_distance, difference)) else: frames_new_face += 1 # Has to see 3 frames of new person in a row to try to add them if(frames_new_face == 2): if(len(face_encodings) == 1): frames_new_face = 0 self.speech.say("Please say your first name after the reeee") self.audio_input = InterpretAudio() self.speech.say("rrrrrrreeeeeeee") response = self.audio_input.listen_for_response() name = self._return_name(response) if(name is not None and len(name) != 0): self._add_new_face(name, frame) self.speech.say("nice to meet you {}".format(name)) if(face_locations is not None): db = database() for each in all_matches: person, surity, difference = each if(person not in self.seen_people): self.speech.say("hey good to see you {}".format(person)) db.add_row(person, surity, difference) self.seen_people[person] = wait_loops db.shutdown()
def __init__(self, db_name): self.db = sql.database(db_name)