archive.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. from datetime import datetime
  2. from pydantic import BaseModel
  3. class ArchiveBase(BaseModel):
  4. print_name: str | None = None
  5. is_favorite: bool | None = None
  6. tags: str | None = None
  7. notes: str | None = None
  8. cost: float | None = None
  9. failure_reason: str | None = None
  10. quantity: int | None = None # Number of items printed
  11. class ArchiveUpdate(ArchiveBase):
  12. printer_id: int | None = None
  13. project_id: int | None = None
  14. status: str | None = None # Allow changing status (e.g., clearing failed flag)
  15. class ArchiveDuplicate(BaseModel):
  16. """Reference to a duplicate archive."""
  17. id: int
  18. print_name: str | None
  19. created_at: datetime
  20. match_type: str # "exact" (hash match) or "similar" (name match)
  21. class ArchiveResponse(BaseModel):
  22. id: int
  23. printer_id: int | None
  24. project_id: int | None = None
  25. project_name: str | None = None # Included for convenience
  26. filename: str
  27. file_path: str
  28. file_size: int
  29. content_hash: str | None
  30. thumbnail_path: str | None
  31. timelapse_path: str | None
  32. source_3mf_path: str | None = None # Original project 3MF from slicer
  33. # Duplicate detection
  34. duplicates: list[ArchiveDuplicate] | None = None
  35. duplicate_count: int = 0 # Quick count for list views
  36. print_name: str | None
  37. print_time_seconds: int | None # Estimated time from slicer
  38. actual_time_seconds: int | None = None # Computed from started_at/completed_at
  39. time_accuracy: float | None = None # Percentage: 100 = perfect, >100 = faster than estimated
  40. filament_used_grams: float | None
  41. filament_type: str | None
  42. filament_color: str | None
  43. layer_height: float | None
  44. total_layers: int | None = None
  45. nozzle_diameter: float | None
  46. bed_temperature: int | None
  47. nozzle_temperature: int | None
  48. status: str
  49. started_at: datetime | None
  50. completed_at: datetime | None
  51. extra_data: dict | None
  52. makerworld_url: str | None
  53. designer: str | None
  54. is_favorite: bool
  55. tags: str | None
  56. notes: str | None
  57. cost: float | None
  58. photos: list | None
  59. failure_reason: str | None
  60. quantity: int = 1 # Number of items printed
  61. # Energy tracking
  62. energy_kwh: float | None = None
  63. energy_cost: float | None = None
  64. created_at: datetime
  65. class Config:
  66. from_attributes = True
  67. class ArchiveStats(BaseModel):
  68. total_prints: int
  69. successful_prints: int
  70. failed_prints: int
  71. total_print_time_hours: float
  72. total_filament_grams: float
  73. total_cost: float
  74. prints_by_filament_type: dict
  75. prints_by_printer: dict
  76. # Time accuracy stats
  77. average_time_accuracy: float | None = None # Average across all prints with data
  78. time_accuracy_by_printer: dict | None = None # Per-printer accuracy
  79. # Energy stats
  80. total_energy_kwh: float = 0.0
  81. total_energy_cost: float = 0.0
  82. class ProjectPageImage(BaseModel):
  83. """Image embedded in 3MF project page."""
  84. name: str
  85. path: str # Path within 3MF
  86. url: str # API URL to fetch image
  87. class ProjectPageResponse(BaseModel):
  88. """Project page data extracted from 3MF file."""
  89. # Model info
  90. title: str | None = None
  91. description: str | None = None # HTML content
  92. designer: str | None = None
  93. designer_user_id: str | None = None
  94. license: str | None = None
  95. copyright: str | None = None
  96. creation_date: str | None = None
  97. modification_date: str | None = None
  98. origin: str | None = None # "original" or "remix"
  99. # Profile info
  100. profile_title: str | None = None
  101. profile_description: str | None = None
  102. profile_cover: str | None = None
  103. profile_user_id: str | None = None
  104. profile_user_name: str | None = None
  105. # MakerWorld info
  106. design_model_id: str | None = None
  107. design_profile_id: str | None = None
  108. design_region: str | None = None
  109. # Images
  110. model_pictures: list[ProjectPageImage] = []
  111. profile_pictures: list[ProjectPageImage] = []
  112. thumbnails: list[ProjectPageImage] = []
  113. class ProjectPageUpdate(BaseModel):
  114. """Update project page data in 3MF file."""
  115. title: str | None = None
  116. description: str | None = None
  117. designer: str | None = None
  118. license: str | None = None
  119. copyright: str | None = None
  120. profile_title: str | None = None
  121. profile_description: str | None = None
  122. class ReprintRequest(BaseModel):
  123. """Request body for reprinting an archive."""
  124. # AMS slot mapping: list of tray IDs for each filament slot in the 3MF
  125. # Global tray ID = (ams_id * 4) + slot_id, external = 254
  126. ams_mapping: list[int] | None = None
  127. # Print options
  128. bed_levelling: bool = True
  129. flow_cali: bool = False
  130. vibration_cali: bool = True
  131. layer_inspect: bool = False
  132. timelapse: bool = False
  133. use_ams: bool = True # Not exposed in UI, but needed for API