-
Notifications
You must be signed in to change notification settings - Fork 41
Creating unique names for new nets #334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| def generate_cosmic_name(): | ||
| """Generates unique cosmic object name with timestamp""" | ||
| cosmic_objects = [ | ||
| "Комета", | ||
| "Звезда", | ||
| "Галактика", | ||
| "Туманность", | ||
| "Спутник", | ||
| "Вселенная", | ||
| "Астероид", | ||
| "Планета", | ||
| "Метеорит", | ||
| "Квазар", | ||
| "Пульсар", | ||
| "Чёрная дыра", | ||
| "Суперновая", | ||
| "Созвездие", | ||
| "Космодром", | ||
| "Телескоп", | ||
| "Ракета", | ||
| "Орбита", | ||
| "Экзопланета", | ||
| "Космический корабль", | ||
| "Межзвёздный объект", | ||
| "Космическая станция", | ||
| "Темная материя", | ||
| "Космический зонд", | ||
| ] | ||
| prefixes = ["", "XB-", "NGC-", "HD-", "M-", "IC-", "PG-", "PSR-"] | ||
|
|
||
| timestamp = datetime.now().strftime("%d%m%y") | ||
| random_num = random.randint(100, 999) | ||
|
|
||
| cosmic_type = random.choice(cosmic_objects) | ||
| prefix = random.choice(prefixes) | ||
|
|
||
| return f"{cosmic_type} {prefix}{timestamp}{random_num}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Может лучше из файла читать их какого-то, а то функция на 40 строчек почти
|
|
||
| guid = db.Column(Text, nullable=False, unique=True) | ||
| title = db.Column(Text, default="Новая сеть", nullable=False) | ||
| title = db.Column(Text, default=lambda: generate_cosmic_name(), nullable=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тут точно лямбда нужна? Нельзя просто default= generate_cosmic_name, если функцию передавать надо?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Да, иначе результат функции он кеширует и при создании сети каждый раз будет одно и то же название. Лямбда же позволяет при каждом создании сети вызывать функцию
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Так если default= generate_cosmic_name использовать, мы тоже чисто функцию передаём, нет?
|
Create unique cosmic name for new net (#292)
Fix README mistake