def start_roadnet(self): """ Start the plugin. Log in the user, connect to database, load layers, set toolbar up appropriately. """ if config.DEBUG_MODE: print('DEBUG_MODE: Starting roadNet') # Check the database if (self.params['RNDataStorePath'] == '') or (self.params['DbName'] == ''): if not self.run_change_db_path(): return db_path = os.path.join(self.params['RNDataStorePath'], self.params['DbName']) try: database.check_file(db_path) except IOError: if not self.run_change_db_path(): return # Log the user in login.login_and_get_role(self.params) self.toolbar.set_state(self.params['role']) if self.params['role'] == 'init': return # Open database and model self.db = database.open_working_copy(self.params) # params knows role database.update_geometry_statistics(self.db) self.model = database.get_model(self.db) # Add layers + connect edit signals, zoom to rdpoly self.add_rdpoly_layer() # Layer added as self.rdpoly self.add_esu_layer() # Layer added as self.esu + selector tool init self.params['session_includes_edits'] = False # Create the street browser instance if config.DEBUG_MODE: print('DEBUG_MODE: Initialising street browser') self.street_browser_dk = StreetBrowserDlg(self.params) self.street_browser_dk.setWindowFlags(Qt.WindowMaximizeButtonHint | Qt.WindowMinimizeButtonHint) rn_icon = QIcon() rn_icon.addPixmap( QPixmap(os.path.join(self.plugin_dir, "image", "rn_logo_v2.png"))) self.street_browser_dk.setWindowIcon(rn_icon) self.street_browser = StreetBrowser(self.iface, self.street_browser_dk, self.model, self.db, self.params) self.disable_srwr() # Hide SRWR tab self.street_browser.set_buttons_initial_state(self.params['role']) if config.DEBUG_MODE: print('DEBUG_MODE: Initialising street selector tool') # Initialise selector tool self.selector_tool = EsuSelectorTool(self.street_browser_dk, self.iface, self.esu, self.toolbar, self.db, self.street_browser.mapper) # Start RAMP if self.params['RAMP'] == 'true': self.ramp.start_ramp() self.roadnet_started = True
def callback_inline(call): if call.message: model_id, user_id = call.data.split(';') if database.set_model_and_register_user(user_id=user_id, model_id=model_id): model_name = database.get_model(model_id=model_id)[0] text = 'Ваш автомобиль: {}'.format(model_name) else: text = 'Ошибка' bot.send_message(call.message.chat.id, text)
def execute_model(ui): # check that model exists model = database.get_model() if not model: ui.print_error("No model has yet been trained") return # get filename from customer if f = ui.get_file_name([".CSV"]) == None return None if tools.file_exists(f): if tools.raw_data_is_valid(f): mlalgorithms.execute(f): else: ui.print_error("Raw data file {0} not formatted correctly".format(f)) else: ui.print_error("File {0} does not exist".format(f))
def scrape(): response = requests.get(URL) soup = BeautifulSoup(response.text, 'html5lib') rows = [] injury = None for tr in soup.find_all('tbody')[0].children: row = [td for td in tr if hasattr(tr, 'children')] if len(row) == 3: name, status, datestr = [r.string for r in row] if name != 'NAME' and status != 'STATUS' and datestr != 'DATE': date = get_date(datestr) player = get_model(Player, name=name) if player: injury, _ = update_or_create(Injury, player_id=player.id, date=date, defaults={ 'status': status }) else: print 'Couldn\'t find player %s' % name elif len(row) == 1: if 'Comment:' in row[0].contents[0].string and injury: update_or_create(InjuryComment, injury_id=injury.id, comment=unicode(row[0].contents[-1]))
def model(monkeypatch, app): """This fixture provides a modified version of the app's model that tracks all created items and deletes them at the end of the test. Any tests that directly or indirectly interact with the database should use this to ensure that resources are properly cleaned up. Monkeypatch is provided by pytest and used to patch the model's create method. The app fixture is needed to provide the configuration and context needed to get the proper model object. """ model = database.get_model() # Ensure no books exist before running. This typically helps if tests # somehow left the database in a bad state. delete_all_books(model) yield model # Delete all books that we created during tests. delete_all_books(model)