train.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. """testing subjects utils"""
  2. from sqlalchemy.orm import Session
  3. from db.repository import trains as db_rep_train
  4. from schemas.trains import TrainCreate
  5. from utils.utils import fake
  6. from utils.utils import get_random_position
  7. def generate_fake_train_data():
  8. return {
  9. "position": "左手",
  10. "rank": fake.train_rank(),
  11. "trial_num": fake.random_digit_not_null(),
  12. "start_time": "2022-11-03 00:00",
  13. "end_time": "2022-11-04 00:00"
  14. }
  15. def create_test_train2db(db: Session,
  16. subject,
  17. position=None,
  18. rank=fake.train_rank(),
  19. trial_num=fake.random_digit_not_null(),
  20. start_time="2022-11-03 00:00",
  21. end_time="2022-11-04 00:00",
  22. device_parm=None) -> TrainCreate:
  23. if position is None:
  24. position = get_random_position(subject)
  25. train = TrainCreate(position=position,
  26. rank=rank,
  27. trial_num=trial_num,
  28. start_time=start_time,
  29. end_time=end_time,
  30. device_parm=device_parm,
  31. owner_id=subject.id)
  32. train = db_rep_train.create_train(train, db)
  33. return train