def __init__(self, table, x, y): data = Personal('en') self.table = table self.x = x self.y = y self.says = '' self.table.add_unit(x, y, self) self.name = data.name(gender='male')
def __init__(self, x, y, evol): person = Personal('en') self.size = random.randint(1, 4) self.name = person.name(gender="female") self.x = x self.y = y self.evol = evol self.type = random.randint(30, 100)
def setUpClass(cls: 'DbSetUp'): connection = pyodbc.connect(CONNECTIONS.MYSQL("test")) with connection.cursor() as cursor: cursor.execute("SELECT COUNT(*) FROM person;") count = cursor.fetchone()[0] if count < cls.PERSONS_COUNT: person = Personal('en') with connection.cursor() as cursor: cursor.executemany( """INSERT INTO person(name, surname, age, email) VALUES (?, ?, ?, ?)""", [(person.name(), person.surname(), person.age(), person.email()) for _ in range(cls.PERSONS_COUNT - count)]) cursor.commit() with connection.cursor() as cursor: cursor.execute("SELECT * FROM person_money") factory: Callable[[tuple], Dict[str, Any]] = partial(dict_factory, cursor) insert = [] update = [] for person in map(factory, cursor.fetchall()): diff = cls.PERSON_MIN_MONEY - person['money'] while diff > 0: add = randint(50, diff + cls.PERSON_MIN_MONEY // 2) new_account = bool(randint(0, 1)) or person['money'] == 0 if new_account: insert.append((person['id'], add)) else: update.append((add, person['id'])) diff -= add with connection.cursor() as cursor: if insert: cursor.executemany( """INSERT INTO bank_account(person, size) VALUES (?, ?)""", insert) if update: cursor.executemany( """UPDATE bank_account SET size = size + ? WHERE person = ? LIMIT 1""", update) cursor.commit()