end write script and update dump with data
This commit is contained in:
parent
d7bde8f4d2
commit
db85be0262
2277
dumps/dump.sql
2277
dumps/dump.sql
File diff suppressed because it is too large
Load Diff
@ -1,22 +1,76 @@
|
||||
import random
|
||||
from datetime import datetime
|
||||
from calendar import monthrange
|
||||
|
||||
from src.database_adapter import async_session_maker, Log, UserActions
|
||||
|
||||
MAX_ID = 10**5
|
||||
|
||||
def generate_record() -> Log:
|
||||
return Log(
|
||||
user_id=2,
|
||||
date_time=datetime.now(),
|
||||
action=UserActions.FIRST_ENTRY,
|
||||
def generate_records() -> list[Log]:
|
||||
result_records = []
|
||||
balance_authorized_user_count = 0
|
||||
|
||||
year = 2020
|
||||
month = random.randint(1, 12)
|
||||
|
||||
result_records.append(Log(
|
||||
user_id=None,
|
||||
date_time=datetime(year, month, 1),
|
||||
action=UserActions.CREATE_THEME,
|
||||
object_id=None,
|
||||
response=200
|
||||
)
|
||||
success_response=False
|
||||
))
|
||||
result_records.append(Log(
|
||||
user_id=None,
|
||||
date_time=datetime(year, month, 1),
|
||||
action=random.choice([UserActions.ENTRY_THEME, UserActions.DELETE_THEME, UserActions.LOGOUT]),
|
||||
object_id=random.randint(1, MAX_ID),
|
||||
success_response=False
|
||||
))
|
||||
balance_authorized_user_count += 2
|
||||
|
||||
for day in range(*monthrange(year, month)):
|
||||
for action in UserActions:
|
||||
for _ in range(random.randint(5, 15)):
|
||||
if balance_authorized_user_count <= 0:
|
||||
user_id = random.randint(1, MAX_ID)
|
||||
balance_authorized_user_count += 1
|
||||
else:
|
||||
user_id = None
|
||||
balance_authorized_user_count -= 1
|
||||
|
||||
if action in [
|
||||
UserActions.LOGIN,
|
||||
UserActions.LOGOUT,
|
||||
UserActions.FIRST_ENTRY,
|
||||
UserActions.REGISTRATION,
|
||||
UserActions.CREATE_THEME
|
||||
]:
|
||||
object_id = None
|
||||
else:
|
||||
object_id = random.randint(1, MAX_ID)
|
||||
|
||||
if action == UserActions.CREATE_THEME and user_id is None:
|
||||
success_response = False
|
||||
elif action == UserActions.WRITE_MESSAGE:
|
||||
success_response = True
|
||||
else:
|
||||
success_response = random.choice([False, True])
|
||||
|
||||
result_records.append(Log(
|
||||
user_id=user_id,
|
||||
date_time=datetime(year, month, day),
|
||||
action=action,
|
||||
object_id=object_id,
|
||||
success_response=success_response
|
||||
))
|
||||
|
||||
return result_records
|
||||
|
||||
|
||||
async def script():
|
||||
async with async_session_maker() as session:
|
||||
record = generate_record()
|
||||
session.add(record)
|
||||
session.add_all(generate_records())
|
||||
await session.commit()
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user