def createTable(self, database: Database, name: str, columns: int, line, column): """ Method to create a table in database :param database: Table database :param name: The name of table :param columns: Number of columns :param line: The instruction line :param column: The instruction column :return: Returns nothing """ dbStatement = jsonMode.createTable(database.name, name, columns) if dbStatement == 0: table = Table(name) database.tables.append(table) self.writeFile() print('Table created successfully') return table elif dbStatement == 1: desc = f": Can't create table {name}" ErrorController().addExecutionError(34, 'Execution', desc, line, column) elif dbStatement == 2: desc = f": Database {database.name} does not exist" ErrorController().addExecutionError(35, 'Execution', desc, line, column) elif dbStatement == 3: desc = f": Table {name} already exists" ErrorController().addExecutionError(31, 'Execution', desc, line, column)
def add_table(self, *, name: str, max_number_of_players: int) -> Table: """Add to list new table""" table = Table(casino=self, name=name, max_number_of_players=max_number_of_players) self.tables[name] = table return table
def add_data(session, entry_type=None, handled_utc=None, original_url=None, canonical_url=None, canonical_type=None, note=None): try: log.info(f"Sending data to database..") new_entry = Table(entry_type=entry_type, handled_utc=handled_utc, original_url=original_url, canonical_url=canonical_url, canonical_type=canonical_type, note=note) session.add(new_entry) session.commit() log.info("Entry send to database") except ProgrammingError: log.error("ProgrammingError - max_user_connections likely exceeded!") log.warning("Couldn't send entry to database!") except (SQLAlchemyError, Exception): log.error(traceback.format_exc()) log.warning("Couldn't send entry to database!")
def loadData(self): self._typeCheckerList = [] self.openFile() for db in self._dataFile: self._typeCheckerList.append(Database(db['_name'])) database = self.searchDatabase(db['_name']) for tb in db['_tables']: table = Table(tb['_name']) database.tables.append(table) for col in tb['_colums']: column = Column(col['_name'], col['_dataType']) column.number = col['_number'] column.length = col['_length'] column.default = col['_default'] column.notNull = col['_notNull'] column.unique = col['_unique'] column.constraint = col['_constraint'] column.check = col['_check'] column.primaryKey = col['_primaryKey'] # column.autoincrement = col['_autoincrement'] # TODO FOREIGN KEY implementation column.foreignKey = col['_foreignKey'] table.columns.append(column)
def test_table(): table = Table() deck_of_cards = get_deck_of_cards() label_deck_of_cards = [(c.suit, c.number) for c in deck_of_cards] label_deck_of_cards_on_table = [(c.suit, c.number) for c in table.cards] assert label_deck_of_cards == label_deck_of_cards_on_table
def post(self): """Create a new table""" # create a new table table = Table() tables[table.name] = table dump = TableSchema().dump(table) return jsonify(dump)
def test_players_and_cards_on_a_table(): # create players player_names = ["a", "b", "c"] players = [Player(name) for name in player_names] # players joining a table table = Table() second_table = Table() for player in players: player.join_table(table) assert table.players == players for player in players: assert player.table_name == table.name assert player.table_name != second_table.name
def get_table(self, table, schema="public"): table = self.connection.get_table(DatabaseName=schema, Name=table) return Table(table['Table']['Name'], [ GlueTranslator.from_source(column['Name'], column['Type']) for column in table['Table']['StorageDescriptor']['Columns'] ], schema=schema)
def __init__(self, **kwargs): super().__init__(**kwargs) phi_data = [["Phi", "Lambda"]] + [[i * 0.1, 1 / (i * 0.1)] for i in range(1, 16)] self.table = Table(75, 95, phi_data) self.table.draw(self.canvas)
def test_not_join_croupier_to_the_table(self): # nobody is by the table self.table_green = Table(casino=self.casino, name='Green', max_number_of_players=4) self.assertEqual(len(self.table_green.person_at_the_table), 0) # croupier not join to the table because he is empolyee self.table_green.join_to_the_table(player=self.croupier) # mike not in table self.assertNotIn(self.croupier, self.table_green.person_at_the_table) self.assertEqual(len(self.table_green.person_at_the_table), 0)
def test_join_to_the_table(self): self.table_green = Table(casino=self.casino, name='Green', max_number_of_players=4) # add first player to the table self.table_green.join_to_the_table(player=self.mike) self.assertEqual(len(self.table_green.person_at_the_table), 1) self.assertIn(self.mike, self.table_green.person_at_the_table) # add another player self.table_green.join_to_the_table(player=self.peter) self.assertEqual(len(self.table_green.person_at_the_table), 2) self.assertIn(self.mike, self.table_green.person_at_the_table) self.assertIn(self.peter, self.table_green.person_at_the_table)
def get_tables(self, schema=None): if schema: return [ Table(table['Table']['Name'], [ GlueTranslator.from_source(column['Name'], column['Type']) for column in table['StorageDescriptor']['Columns'] ], schema=schema) for table in self.connection.get_tables( DatabaseName=schema)['TableList'] ] else: return [ Table(table['Table']['Name'], [ GlueTranslator.from_source(column['Name'], column['Type']) for column in table['StorageDescriptor']['Columns'] ], schema=database) for database in self.get_databases() for table in self.connection.get_tables( DatabaseName=database)['TableList'] ]
def players_and_table(): # create players player_names = ["a", "b", "c"] players = [Player(name) for name in player_names] # players joining a table table = Table() for player in players: player.join_table(table) return players, table
def createTable(self, database: Database, tableName: str) -> Table: if not database: print('No database selected') # TODO messages return None if not self.searchTable(database, tableName): database.tables.append(Table(tableName)) print('Table created successfully') return Table print(f"Table '{tableName}' already exists") return None
def __init__(self, oswald_calculations, phi_result, **kwargs): super().__init__(**kwargs) phi_data = [["Variable", "Value"]] phi_data.append(["Phi:", phi_result]) phi_data.append(["Lambda:", round(1/phi_result,2)]) phi_data.append(["Max CO:", oswald_calculations.max_co]) phi_data.append(["Max CO2:", oswald_calculations.max_co2]) phi_data.append(["Fuel:", ""]) for fuel_comp_node in oswald_calculations.fuel.composition_nodes: phi_data.append([fuel_comp_node.formula, fuel_comp_node.proportion]) self.table = Table(75, 45, phi_data) self.table.draw(self.canvas)
def test_disconnect_by_table(self): self.table_green = Table(casino=self.casino, name='Green', max_number_of_players=4) # join two player in table self.table_green.join_to_the_table(player=self.mike) self.table_green.join_to_the_table(player=self.peter) # two player in table self.assertEqual(len(self.table_green.person_at_the_table), 2) # disconnect player by table self.table_green.disconnect_by_table(player=self.mike) # mike not in table self.assertNotIn(self.mike, self.table_green.person_at_the_table) # ony one player in table self.assertEqual(len(self.table_green.person_at_the_table), 1) # peter still in table self.assertIn(self.peter, self.table_green.person_at_the_table)
def get_table(self, table, schema="public"): queries = [ f""" SELECT "column_name" AS "name", "data_type" AS "type", "character_maximum_length" AS "length", "numeric_precision" AS "precision", "numeric_precision_radix" AS "precision_radix", "numeric_scale" AS "scale", "column_default" AS "default", "is_nullable" AS "nullable" FROM SVV_COLUMNS WHERE table_schema = '{schema}' AND table_name = '{table}'; """ ] return Table(table, [ RedshiftTranslator.from_source( name, type, length, numeric_precision, precision_radix, scale, default, nullable) for (name, type, length, numeric_precision, precision_radix, scale, default, nullable) in self.fetch(queries) ], schema=schema)
def createTable(self, database: Database, tableName: str, columns: int) -> Table: if not database: print('No database selected') return None dbStatement = 0 # j.createTable(database.name, tableName, columns) if dbStatement == 0: table = Table(tableName) database.tables.append(table) self.writeFile() print('Table created successfully') return table elif dbStatement == 1: print(f"Can't create table '{tableName}'") elif dbStatement == 2: print("Database doesn't exist") elif dbStatement == 3: print(f"Table '{tableName}' already exists") return None
def createTable(self, name: str, columns: int, line, column): """ Method to create a table in database :param name: The name of table :param columns: Number of columns :param line: The instruction line :param column: The instruction column :return: Returns nothing """ database = SymbolTable().useDatabase if not database: desc = f": Database not selected" ErrorController().add(4, 'Execution', desc, line, column) return dbStatement = data_mode.mode(database.mode).createTable( database.name, name, columns) if dbStatement == 0: table = Table(name) database.tables.append(table) self.writeFile() DataWindow().consoleText( 'Query returned successfully: Table created') return table elif dbStatement == 1: desc = f": Can't create table {name}" ErrorController().add(34, 'Execution', desc, line, column) elif dbStatement == 2: desc = f": Database {database.name} does not exist" ErrorController().add(35, 'Execution', desc, line, column) elif dbStatement == 3: desc = f": Table {name} already exists" ErrorController().add(31, 'Execution', desc, line, column)
from models.table import Table from models.algorithms.kmeans import KMeans header = {"var1": Table._numeric, "var2": Table._numeric, "var3": Table._numeric, "var4": Table._numeric, "var5": Table._numeric, "class": Table._nominal} data = [ [7, 8, 4, 5, 2, ''], [6, 8, 5, 4, 2, ''], [8, 9, 7, 8, 9, ''], [6, 7, 7, 7, 8, ''], [1, 2, 5, 3, 4, ''], [3, 4, 5, 3, 5, ''], [7, 8, 8, 6, 6, ''], [8, 9, 6, 5, 5, ''], [2, 3, 5, 6, 5, ''], [1, 2, 4, 4, 2, ''], [3, 2, 6, 5, 7, ''], [2, 5, 6, 8, 9, ''], [3, 5, 4, 6, 3, ''], [3, 5, 5, 6, 3, '']] table = Table(data, header, 5) # Crea una tabla, el 3 parámetro indica el indice de la clase means = KMeans(table, 2, 3, 20, 20) # (min_k, max_k, i, r) means.run() print("Error: " + str(means.error)) print("Asignación de los clusters " + str(means.clusters)) # Esta es la columna que le interesa al maestro print("Datos y asignación de los clusters") print(means) # Imprime los datos y el cluster al que fue asignado print("Centroides:" + str(means.centroids))
def test_create_table(self): self.table_green = Table(casino=self.casino, name='Green', max_number_of_players=4) self.assertEqual(self.table_green.casino, self.casino) self.assertEqual(self.table_green.name, 'Green') self.assertEqual(self.table_green.max_number_of_players, 4) self.assertEqual(len(self.table_green.person_at_the_table), 0)
def get_tables(self): adql_tables = self.__adql_schema.select_tables() table_list = [Table(table) for table in adql_tables] return table_list
cur = db.cursor() User.create_table(cur) Table.create_table(cur) Column.create_table(cur) Task.create_table(cur) users = [ User("Ford", "zda", "*****@*****.**", "12345"), User("Arthur", "firero", "*****@*****.**", "12345"), User("ismail", "Aissami", "[email protected]", "12345"), User("sana", "kriaa", "*****@*****.**", "aaa") ] tables = [Table("Table1", "[email protected]"), Table("Table2", "[email protected]")] columns = [Column("colonne1", "Table1"), Column("colonne2", "Table1")] tasks = [Task("descrep1", "colonne1"), Task("descrep2", "colonne1")] for user in users: user.insert(cur) for table in tables: table.insert(cur) for column in columns: column.insert(cur) for task in tasks: