trains.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. """Module schemas/trains verifies table data type"""
  2. from datetime import datetime
  3. from typing import Literal, Optional
  4. from typing import Union
  5. from pydantic import BaseModel, Field
  6. from schemas.hand_peripheral import ControlMotion
  7. def get_timestamp() -> datetime:
  8. return datetime.strptime(datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
  9. "%Y-%m-%d %H:%M:%S")
  10. class TrainBase(BaseModel):
  11. position: Optional[str] = None
  12. rank: Optional[str] = None
  13. trial_num: Optional[str] = None
  14. class TrainUpdate(TrainBase):
  15. # position: str
  16. # rank: str
  17. # trial_num: int
  18. start_time: Optional[datetime] = Field(default_factory=get_timestamp)
  19. end_time: Optional[datetime] = Field(default_factory=get_timestamp)
  20. class TrainCreate(TrainBase):
  21. # position: str
  22. # rank: str
  23. # trial_num: int
  24. start_time: Optional[datetime] = Field(default_factory=get_timestamp)
  25. end_time: Optional[datetime] = Field(default_factory=get_timestamp)
  26. device_param: Union[ControlMotion, None] = None
  27. owner_id: str
  28. class ShowTrain(TrainBase):
  29. position: str
  30. rank: str
  31. trial_num: int
  32. start_time: datetime
  33. end_time: datetime
  34. grade: str = None
  35. consume_time: int = None
  36. accuracy: float = None
  37. is_train: bool = False
  38. medical_certificate: str = ""
  39. class Config():
  40. orm_mode = True
  41. class ShowTrainWithVideo(ShowTrain):
  42. video_path: list
  43. class TrainResult(BaseModel):
  44. grade: Literal["优秀", "良好", "尚可"] = Field()
  45. accuracy: float = Field()
  46. consume_time: float = Field()
  47. class TrainMedicalCertificate(BaseModel):
  48. medical_certificate: str