monkeybrain-runtime 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- monkeybrain_runtime-1.0.0.dist-info/METADATA +76 -0
- monkeybrain_runtime-1.0.0.dist-info/RECORD +838 -0
- monkeybrain_runtime-1.0.0.dist-info/WHEEL +5 -0
- monkeybrain_runtime-1.0.0.dist-info/entry_points.txt +3 -0
- monkeybrain_runtime-1.0.0.dist-info/top_level.txt +2 -0
- services/__init__.py +8 -0
- services/agentos/__init__.py +0 -0
- services/agentos/main.py +1 -0
- services/assets/helpers/__init__.py +12 -0
- services/assets/helpers/device.py +59 -0
- services/assets/helpers/equipment.py +179 -0
- services/assets/helpers/instruments.py +72 -0
- services/assets/helpers/machines.py +183 -0
- services/assets/helpers/materials.py +76 -0
- services/assets/helpers/parts.py +116 -0
- services/assets/helpers/plc.py +134 -0
- services/assets/helpers/tags.py +108 -0
- services/assets/helpers/tools.py +101 -0
- services/assets/main.py +75 -0
- services/assets/models/__init__.py +12 -0
- services/assets/models/device.py +79 -0
- services/assets/models/equipment.py +222 -0
- services/assets/models/instruments.py +85 -0
- services/assets/models/machines.py +230 -0
- services/assets/models/material.py +266 -0
- services/assets/models/parts.py +96 -0
- services/assets/models/plc.py +264 -0
- services/assets/models/tags.py +76 -0
- services/assets/models/tools.py +179 -0
- services/assets/routers/__init__.py +12 -0
- services/assets/routers/classes.py +65 -0
- services/assets/routers/device.py +86 -0
- services/assets/routers/equipment.py +145 -0
- services/assets/routers/families.py +61 -0
- services/assets/routers/instruments.py +70 -0
- services/assets/routers/machines.py +136 -0
- services/assets/routers/materials.py +105 -0
- services/assets/routers/parts.py +130 -0
- services/assets/routers/plc.py +94 -0
- services/assets/routers/subclasses.py +68 -0
- services/assets/routers/tags.py +138 -0
- services/assets/routers/tools.py +113 -0
- services/auth/helpers/__init__.py +13 -0
- services/auth/helpers/approval_decisions.py +261 -0
- services/auth/helpers/audit_elasticsearch_sync.py +350 -0
- services/auth/helpers/departments.py +53 -0
- services/auth/helpers/graph_store.py +848 -0
- services/auth/helpers/influx_store.py +280 -0
- services/auth/helpers/me.py +33 -0
- services/auth/helpers/nats_consumer.py +618 -0
- services/auth/helpers/nats_store.py +242 -0
- services/auth/helpers/permissions.py +62 -0
- services/auth/helpers/roles.py +87 -0
- services/auth/helpers/store.py +54 -0
- services/auth/helpers/team_members.py +155 -0
- services/auth/helpers/teams.py +87 -0
- services/auth/helpers/tokens.py +71 -0
- services/auth/helpers/users.py +119 -0
- services/auth/helpers/websocket_broadcast.py +41 -0
- services/auth/main.py +88 -0
- services/auth/models/__init__.py +12 -0
- services/auth/models/departments.py +55 -0
- services/auth/models/login.py +20 -0
- services/auth/models/permissions.py +61 -0
- services/auth/models/roles.py +53 -0
- services/auth/models/session.py +26 -0
- services/auth/models/teamMembers.py +59 -0
- services/auth/models/teams.py +56 -0
- services/auth/models/users.py +77 -0
- services/auth/routers/__init__.py +14 -0
- services/auth/routers/auth.py +3839 -0
- services/auth/routers/departments.py +84 -0
- services/auth/routers/integration_config.py +703 -0
- services/auth/routers/me.py +28 -0
- services/auth/routers/permissions.py +96 -0
- services/auth/routers/roles.py +139 -0
- services/auth/routers/session.py +224 -0
- services/auth/routers/team_members.py +152 -0
- services/auth/routers/teams.py +112 -0
- services/auth/routers/users.py +131 -0
- services/auth/routers/websocket_events.py +247 -0
- services/batch_execution/__init__.py +19 -0
- services/batch_execution/pipeline_triggers/__init__.py +53 -0
- services/batch_execution/pipeline_triggers/pipeline_parameter_adjuster.py +440 -0
- services/batch_execution/pipeline_triggers/pipeline_trigger_engine.py +445 -0
- services/batch_execution/pipeline_triggers/re_evaluation_queue.py +341 -0
- services/batch_execution/pipeline_triggers/test_phase3_implementation.py +553 -0
- services/batch_execution/pipeline_triggers/workflow_reevaluator.py +367 -0
- services/batch_execution/smoke_test_e2e_feedback_loop.py +704 -0
- services/batch_execution/workflow_executor.py +478 -0
- services/changeover/helpers/__init__.py +11 -0
- services/changeover/helpers/changeover.py +87 -0
- services/changeover/helpers/changeover_common.py +55 -0
- services/changeover/helpers/changeover_events.py +66 -0
- services/changeover/helpers/changeover_kpis.py +33 -0
- services/changeover/helpers/changeover_matrix.py +60 -0
- services/changeover/helpers/changeover_procedures.py +164 -0
- services/changeover/helpers/changeover_windows.py +96 -0
- services/changeover/main.py +52 -0
- services/changeover/models/__init__.py +11 -0
- services/changeover/models/changeover.py +73 -0
- services/changeover/models/changeover_events.py +142 -0
- services/changeover/models/changeover_kpis.py +75 -0
- services/changeover/models/changeover_matrix.py +63 -0
- services/changeover/models/changeover_procedures.py +108 -0
- services/changeover/models/changeover_tasks.py +87 -0
- services/changeover/models/changeover_windows.py +72 -0
- services/changeover/routers/__init__.py +9 -0
- services/changeover/routers/changeover_events.py +127 -0
- services/changeover/routers/changeover_kpis.py +80 -0
- services/changeover/routers/changeover_matrix.py +80 -0
- services/changeover/routers/changeover_procedures.py +118 -0
- services/changeover/routers/changeover_windows.py +98 -0
- services/common/__init__.py +2 -0
- services/common/approval_chains.py +648 -0
- services/common/auth.py +56 -0
- services/common/cdc.py +52 -0
- services/common/compat.py +217 -0
- services/common/compliance.py +562 -0
- services/common/config.py +134 -0
- services/common/cors.py +17 -0
- services/common/data_transformation.py +195 -0
- services/common/db.py +577 -0
- services/common/embeddings.py +97 -0
- services/common/event_reducers.py +194 -0
- services/common/event_types.py +51 -0
- services/common/integration_ingestion.py +169 -0
- services/common/logging.py +204 -0
- services/common/models/__init__.py +2 -0
- services/common/models/databricks.py +25 -0
- services/common/models/enums.py +64 -0
- services/common/module_control.py +422 -0
- services/common/mongo_cdc_watcher.py +106 -0
- services/common/n8n_auth.py +22 -0
- services/common/neo4j_mirror.py +1087 -0
- services/common/ontology_registry.py +110 -0
- services/common/reasoning_traces.py +52 -0
- services/common/supply_chain_cdc.py +555 -0
- services/common/tracing.py +159 -0
- services/common/utils.py +30 -0
- services/customers/helpers/__init__.py +8 -0
- services/customers/helpers/customer_details.py +64 -0
- services/customers/helpers/customer_metadata.py +64 -0
- services/customers/helpers/customer_order_metrics.py +67 -0
- services/customers/helpers/customer_payment_data.py +67 -0
- services/customers/main.py +50 -0
- services/customers/models/__init__.py +8 -0
- services/customers/models/customer_details.py +42 -0
- services/customers/models/customer_metadata.py +97 -0
- services/customers/models/customer_order_metrics.py +86 -0
- services/customers/models/customer_payment_data.py +60 -0
- services/customers/routers/__init__.py +8 -0
- services/customers/routers/customer_details.py +88 -0
- services/customers/routers/customer_metadata.py +88 -0
- services/customers/routers/customer_order_metrics.py +88 -0
- services/customers/routers/customer_payment_data.py +88 -0
- services/documents/__init__.py +1 -0
- services/documents/helpers/__init__.py +6 -0
- services/documents/helpers/document_metadata.py +569 -0
- services/documents/helpers/document_workflows.py +215 -0
- services/documents/helpers/report_templates.py +113 -0
- services/documents/main.py +49 -0
- services/documents/models/__init__.py +6 -0
- services/documents/models/document_metadata.py +215 -0
- services/documents/models/document_workflows.py +136 -0
- services/documents/models/report_templates.py +132 -0
- services/documents/routers/__init__.py +6 -0
- services/documents/routers/document_metadata.py +654 -0
- services/documents/routers/document_workflows.py +146 -0
- services/documents/routers/report_templates.py +86 -0
- services/events/helpers/__init__.py +5 -0
- services/events/helpers/events.py +394 -0
- services/events/main.py +40 -0
- services/events/models/__init__.py +5 -0
- services/events/models/events.py +50 -0
- services/events/routers/__init__.py +6 -0
- services/events/routers/count_events.py +109 -0
- services/events/routers/events.py +75 -0
- services/events/seed_events.py +196 -0
- services/facilities/helpers/__init__.py +8 -0
- services/facilities/helpers/lines.py +74 -0
- services/facilities/helpers/locations.py +231 -0
- services/facilities/helpers/plants.py +59 -0
- services/facilities/helpers/stages.py +110 -0
- services/facilities/helpers/workstation.py +213 -0
- services/facilities/main.py +60 -0
- services/facilities/models/__init__.py +10 -0
- services/facilities/models/industrialLine.py +72 -0
- services/facilities/models/industrialPlant.py +164 -0
- services/facilities/models/locations.py +74 -0
- services/facilities/models/stages.py +92 -0
- services/facilities/models/worker.py +73 -0
- services/facilities/models/workstation.py +117 -0
- services/facilities/models/workstation_live_state.py +59 -0
- services/facilities/routers/__init__.py +8 -0
- services/facilities/routers/bays.py +81 -0
- services/facilities/routers/buildings.py +92 -0
- services/facilities/routers/floors.py +81 -0
- services/facilities/routers/lines.py +154 -0
- services/facilities/routers/locations.py +208 -0
- services/facilities/routers/plant.py +203 -0
- services/facilities/routers/rooms.py +81 -0
- services/facilities/routers/stages.py +152 -0
- services/facilities/routers/workstation.py +173 -0
- services/file/backup.py +71 -0
- services/file/main.py +45 -0
- services/file/recieve.py +54 -0
- services/file/send.py +55 -0
- services/file/src/core/config.py +90 -0
- services/file/src/core/keycloak.py +152 -0
- services/file/src/core/logging_config.py +9 -0
- services/file/src/core/security.py +33 -0
- services/file/src/helpers/cad_conversion.py +331 -0
- services/file/src/helpers/helpers.py +825 -0
- services/file/src/routes/cad_conversion.py +26 -0
- services/file/src/routes/files.py +136 -0
- services/file/src/routes/presigned.py +154 -0
- services/file/src/services/websocket.py +293 -0
- services/floor_layout/helpers/__init__.py +8 -0
- services/floor_layout/helpers/bays.py +92 -0
- services/floor_layout/helpers/buildings.py +54 -0
- services/floor_layout/helpers/floors.py +65 -0
- services/floor_layout/helpers/rooms.py +76 -0
- services/floor_layout/main.py +52 -0
- services/floor_layout/models/__init__.py +8 -0
- services/floor_layout/models/bays.py +65 -0
- services/floor_layout/models/buildings.py +52 -0
- services/floor_layout/models/floors.py +45 -0
- services/floor_layout/models/rooms.py +61 -0
- services/floor_layout/routers/__init__.py +9 -0
- services/floor_layout/routers/bays.py +143 -0
- services/floor_layout/routers/buildings.py +116 -0
- services/floor_layout/routers/floors.py +89 -0
- services/floor_layout/routers/locations.py +80 -0
- services/floor_layout/routers/rooms.py +134 -0
- services/inventory/helpers/__init__.py +13 -0
- services/inventory/helpers/cycle_counts.py +124 -0
- services/inventory/helpers/inventory_allocations.py +134 -0
- services/inventory/helpers/inventory_item_counts.py +114 -0
- services/inventory/helpers/inventory_item_quantities.py +114 -0
- services/inventory/helpers/inventory_items.py +103 -0
- services/inventory/helpers/inventory_stage_outputs.py +134 -0
- services/inventory/helpers/inventory_transactions.py +112 -0
- services/inventory/helpers/stock_adjustment_requests.py +101 -0
- services/inventory/helpers/warehouse_cycle_counts.py +133 -0
- services/inventory/helpers/warehouse_locations.py +213 -0
- services/inventory/helpers/warehouse_regulated_records.py +123 -0
- services/inventory/main.py +62 -0
- services/inventory/models/__init__.py +17 -0
- services/inventory/models/cycle_counts.py +99 -0
- services/inventory/models/inventory_allocations.py +121 -0
- services/inventory/models/inventory_common.py +65 -0
- services/inventory/models/inventory_enums.py +21 -0
- services/inventory/models/inventory_item_count.py +65 -0
- services/inventory/models/inventory_item_quantity.py +82 -0
- services/inventory/models/inventory_items.py +168 -0
- services/inventory/models/inventory_responses.py +44 -0
- services/inventory/models/inventory_stage_outputs.py +96 -0
- services/inventory/models/inventory_state.py +15 -0
- services/inventory/models/inventory_transactions.py +80 -0
- services/inventory/models/stock_adjustment_requests.py +109 -0
- services/inventory/models/warehouse_cycle_counts.py +119 -0
- services/inventory/models/warehouse_location_models.py +708 -0
- services/inventory/models/warehouse_regulated_records.py +358 -0
- services/inventory/routers/__init__.py +13 -0
- services/inventory/routers/cycle_counts.py +106 -0
- services/inventory/routers/inventory_allocations.py +125 -0
- services/inventory/routers/inventory_item_counts.py +105 -0
- services/inventory/routers/inventory_item_quantities.py +105 -0
- services/inventory/routers/inventory_items.py +109 -0
- services/inventory/routers/inventory_stage_outputs.py +122 -0
- services/inventory/routers/inventory_transactions.py +96 -0
- services/inventory/routers/stock_adjustment_requests.py +124 -0
- services/inventory/routers/warehouse_cycle_counts.py +124 -0
- services/inventory/routers/warehouse_locations.py +426 -0
- services/inventory/routers/warehouse_regulated_records.py +273 -0
- services/iot/helpers/__init__.py +8 -0
- services/iot/helpers/ble_device.py +87 -0
- services/iot/helpers/mqtt_bridge.py +115 -0
- services/iot/helpers/sensor_readings.py +63 -0
- services/iot/helpers/sensors.py +77 -0
- services/iot/helpers/servers.py +72 -0
- services/iot/helpers/uwb_device.py +95 -0
- services/iot/main.py +53 -0
- services/iot/models/__init__.py +8 -0
- services/iot/models/ble_device.py +118 -0
- services/iot/models/sensors.py +256 -0
- services/iot/models/servers.py +206 -0
- services/iot/models/uwb_device.py +106 -0
- services/iot/routers/__init__.py +8 -0
- services/iot/routers/ble_device.py +110 -0
- services/iot/routers/sensors.py +144 -0
- services/iot/routers/servers.py +141 -0
- services/iot/routers/uwb_device.py +148 -0
- services/module_control/__init__.py +1 -0
- services/module_control/helpers/__init__.py +1 -0
- services/module_control/helpers/integration_config.py +243 -0
- services/module_control/helpers/security.py +104 -0
- services/module_control/main.py +44 -0
- services/module_control/models/__init__.py +1 -0
- services/module_control/models/module_control.py +65 -0
- services/module_control/routers/__init__.py +1 -0
- services/module_control/routers/module_control.py +219 -0
- services/orders/helpers/__init__.py +11 -0
- services/orders/helpers/invoices.py +123 -0
- services/orders/helpers/order_customer_metrics.py +61 -0
- services/orders/helpers/order_details.py +71 -0
- services/orders/helpers/order_metadata.py +61 -0
- services/orders/helpers/order_payment_metadata.py +74 -0
- services/orders/helpers/orders.py +119 -0
- services/orders/helpers/sales_orders.py +136 -0
- services/orders/main.py +56 -0
- services/orders/models/__init__.py +11 -0
- services/orders/models/invoices.py +415 -0
- services/orders/models/order_customer_metrics.py +78 -0
- services/orders/models/order_details.py +46 -0
- services/orders/models/order_metadata.py +60 -0
- services/orders/models/order_payment_metadata.py +63 -0
- services/orders/models/orders.py +64 -0
- services/orders/models/sales_orders.py +130 -0
- services/orders/routers/__init__.py +11 -0
- services/orders/routers/invoices.py +111 -0
- services/orders/routers/order_customer_metrics.py +87 -0
- services/orders/routers/order_details.py +87 -0
- services/orders/routers/order_metadata.py +87 -0
- services/orders/routers/order_payment_metadata.py +87 -0
- services/orders/routers/orders.py +74 -0
- services/orders/routers/sales_orders.py +111 -0
- services/pm/helpers/__init__.py +14 -0
- services/pm/helpers/calendar_bookings.py +114 -0
- services/pm/helpers/calibration_point.py +110 -0
- services/pm/helpers/calibrations.py +196 -0
- services/pm/helpers/checklists.py +318 -0
- services/pm/helpers/cleaning.py +333 -0
- services/pm/helpers/downtime.py +376 -0
- services/pm/helpers/kanban_boards.py +186 -0
- services/pm/helpers/maintainance.py +177 -0
- services/pm/helpers/sop.py +1155 -0
- services/pm/helpers/sop_cdc.py +324 -0
- services/pm/helpers/weekly_schedules.py +79 -0
- services/pm/main.py +62 -0
- services/pm/models/__init__.py +14 -0
- services/pm/models/calendar_booking.py +82 -0
- services/pm/models/calibration_point.py +44 -0
- services/pm/models/calibrations.py +167 -0
- services/pm/models/checklists.py +117 -0
- services/pm/models/cleaning.py +203 -0
- services/pm/models/downtime.py +109 -0
- services/pm/models/kanban_board.py +178 -0
- services/pm/models/maintainanceLog.py +148 -0
- services/pm/models/sop.py +152 -0
- services/pm/models/weekly_schedule.py +91 -0
- services/pm/routers/__init__.py +14 -0
- services/pm/routers/calendar_bookings.py +143 -0
- services/pm/routers/calibration_point.py +94 -0
- services/pm/routers/calibrations.py +232 -0
- services/pm/routers/checklists.py +188 -0
- services/pm/routers/cleaning.py +127 -0
- services/pm/routers/downtime.py +143 -0
- services/pm/routers/kanban_boards.py +283 -0
- services/pm/routers/maintainance.py +241 -0
- services/pm/routers/sop.py +437 -0
- services/pm/routers/weekly_schedules.py +108 -0
- services/process_definitions/helpers/__init__.py +11 -0
- services/process_definitions/helpers/cpp_cqa_registry.py +120 -0
- services/process_definitions/helpers/mbmr_templates.py +107 -0
- services/process_definitions/helpers/packing_instructions.py +113 -0
- services/process_definitions/helpers/process_constraints.py +495 -0
- services/process_definitions/helpers/process_corrections.py +279 -0
- services/process_definitions/helpers/process_definition.py +996 -0
- services/process_definitions/helpers/process_node_catalog.py +786 -0
- services/process_definitions/helpers/process_post_checks.py +441 -0
- services/process_definitions/helpers/process_pre_checks.py +351 -0
- services/process_definitions/helpers/process_steps.py +220 -0
- services/process_definitions/main.py +71 -0
- services/process_definitions/models/__init__.py +13 -0
- services/process_definitions/models/cpp_cqa_registry.py +145 -0
- services/process_definitions/models/gxp_change_controls.py +38 -0
- services/process_definitions/models/gxp_risk_assessments.py +30 -0
- services/process_definitions/models/gxp_validation_evidence.py +33 -0
- services/process_definitions/models/mbmr_templates.py +173 -0
- services/process_definitions/models/packing_instructions.py +176 -0
- services/process_definitions/models/process_constraints.py +159 -0
- services/process_definitions/models/process_corrections.py +118 -0
- services/process_definitions/models/process_definition.py +685 -0
- services/process_definitions/models/process_definition_common.py +48 -0
- services/process_definitions/models/process_node_catalog.py +25 -0
- services/process_definitions/models/process_post_checks.py +171 -0
- services/process_definitions/models/process_pre_checks.py +168 -0
- services/process_definitions/models/process_steps.py +170 -0
- services/process_definitions/node_services/__init__.py +8 -0
- services/process_definitions/node_services/common.py +95 -0
- services/process_definitions/node_services/executor.py +499 -0
- services/process_definitions/node_services/flow_simulator.py +733 -0
- services/process_definitions/node_services/functions.py +193 -0
- services/process_definitions/node_services/messaging.py +44 -0
- services/process_definitions/node_services/models.py +221 -0
- services/process_definitions/node_services/network.py +161 -0
- services/process_definitions/node_services/parsers.py +87 -0
- services/process_definitions/node_services/sequence.py +95 -0
- services/process_definitions/node_services/storage.py +50 -0
- services/process_definitions/node_services/webhooks.py +52 -0
- services/process_definitions/routers/__init__.py +10 -0
- services/process_definitions/routers/cpp_cqa_registry.py +86 -0
- services/process_definitions/routers/mbmr_templates.py +84 -0
- services/process_definitions/routers/packing_instructions.py +84 -0
- services/process_definitions/routers/process_constraints.py +564 -0
- services/process_definitions/routers/process_corrections.py +343 -0
- services/process_definitions/routers/process_definition.py +992 -0
- services/process_definitions/routers/process_post_checks.py +529 -0
- services/process_definitions/routers/process_pre_checks.py +435 -0
- services/process_definitions/routers/process_steps.py +274 -0
- services/procurement/helpers/__init__.py +9 -0
- services/procurement/helpers/goods_receipts.py +240 -0
- services/procurement/helpers/purchase_order_shipping_information.py +85 -0
- services/procurement/helpers/purchase_orders.py +68 -0
- services/procurement/helpers/quality_control.py +235 -0
- services/procurement/helpers/sampling.py +404 -0
- services/procurement/main.py +52 -0
- services/procurement/models/__init__.py +9 -0
- services/procurement/models/goods_receipts.py +165 -0
- services/procurement/models/purchase_orders.py +54 -0
- services/procurement/models/quality_control.py +464 -0
- services/procurement/models/reinspection_records.py +28 -0
- services/procurement/models/sampling.py +262 -0
- services/procurement/models/shipping_information.py +51 -0
- services/procurement/routers/__init__.py +9 -0
- services/procurement/routers/goods_receipts.py +201 -0
- services/procurement/routers/purchase_orders.py +106 -0
- services/procurement/routers/quality_control.py +386 -0
- services/procurement/routers/sampling.py +296 -0
- services/procurement/routers/shipping_information.py +97 -0
- services/production/__init__.py +1 -0
- services/production/agents/__init__.py +5 -0
- services/production/agents/batch_planning_agent.py +815 -0
- services/production/models/__init__.py +25 -0
- services/production/models/batch.py +253 -0
- services/products/helpers/__init__.py +10 -0
- services/products/helpers/boms.py +100 -0
- services/products/helpers/drug_research.py +644 -0
- services/products/helpers/product_component.py +168 -0
- services/products/helpers/product_inventory.py +221 -0
- services/products/helpers/product_pricing.py +123 -0
- services/products/helpers/product_utils.py +32 -0
- services/products/helpers/products.py +81 -0
- services/products/main.py +59 -0
- services/products/models/__init__.py +9 -0
- services/products/models/drug_research.py +138 -0
- services/products/models/product_common.py +60 -0
- services/products/models/product_component.py +1028 -0
- services/products/models/product_inventory.py +118 -0
- services/products/models/product_pricing.py +73 -0
- services/products/models/products.py +151 -0
- services/products/routers/__init__.py +9 -0
- services/products/routers/boms.py +116 -0
- services/products/routers/drug_research.py +115 -0
- services/products/routers/product_components.py +123 -0
- services/products/routers/product_inventory.py +185 -0
- services/products/routers/product_pricing.py +136 -0
- services/products/routers/products.py +165 -0
- services/replenishment/__init__.py +1 -0
- services/replenishment/main.py +46 -0
- services/replenishment/routers/__init__.py +1 -0
- services/replenishment/routers/replenishment.py +20 -0
- services/shifts/helpers/__init__.py +7 -0
- services/shifts/helpers/shift_templates.py +124 -0
- services/shifts/helpers/shifts.py +79 -0
- services/shifts/helpers/timesheets.py +137 -0
- services/shifts/main.py +48 -0
- services/shifts/models/__init__.py +8 -0
- services/shifts/models/shift.py +62 -0
- services/shifts/models/shift_template.py +82 -0
- services/shifts/models/time_range.py +31 -0
- services/shifts/models/timesheet.py +196 -0
- services/shifts/routers/__init__.py +7 -0
- services/shifts/routers/shift_templates.py +97 -0
- services/shifts/routers/shifts.py +117 -0
- services/shifts/routers/timesheets.py +117 -0
- services/shipping/helpers/__init__.py +15 -0
- services/shipping/helpers/carrier.py +78 -0
- services/shipping/helpers/customs_declaration.py +104 -0
- services/shipping/helpers/delivery_note.py +99 -0
- services/shipping/helpers/package.py +95 -0
- services/shipping/helpers/pallet.py +85 -0
- services/shipping/helpers/route.py +93 -0
- services/shipping/helpers/shipping_information.py +82 -0
- services/shipping/helpers/shipping_provider_details.py +59 -0
- services/shipping/helpers/shipping_provider_metadata.py +59 -0
- services/shipping/helpers/vehicle.py +85 -0
- services/shipping/helpers/waybill.py +86 -0
- services/shipping/main.py +64 -0
- services/shipping/models/__init__.py +15 -0
- services/shipping/models/carrier.py +97 -0
- services/shipping/models/customs_declaration.py +138 -0
- services/shipping/models/delivery_note.py +163 -0
- services/shipping/models/package.py +152 -0
- services/shipping/models/pallet.py +137 -0
- services/shipping/models/route.py +120 -0
- services/shipping/models/shipping_information.py +55 -0
- services/shipping/models/shipping_provider_details.py +42 -0
- services/shipping/models/shipping_provider_metadata.py +54 -0
- services/shipping/models/vehicle.py +129 -0
- services/shipping/models/waybill.py +189 -0
- services/shipping/routers/__init__.py +15 -0
- services/shipping/routers/carrier.py +99 -0
- services/shipping/routers/customs_declaration.py +132 -0
- services/shipping/routers/delivery_note.py +150 -0
- services/shipping/routers/package.py +141 -0
- services/shipping/routers/pallet.py +108 -0
- services/shipping/routers/route.py +128 -0
- services/shipping/routers/shipping_information.py +97 -0
- services/shipping/routers/shipping_provider_details.py +80 -0
- services/shipping/routers/shipping_provider_metadata.py +80 -0
- services/shipping/routers/vehicle.py +117 -0
- services/shipping/routers/waybill.py +119 -0
- services/suppliers/helpers/__init__.py +13 -0
- services/suppliers/helpers/supplier_capabilities.py +58 -0
- services/suppliers/helpers/supplier_certifications.py +67 -0
- services/suppliers/helpers/supplier_details.py +58 -0
- services/suppliers/helpers/supplier_financials.py +58 -0
- services/suppliers/helpers/supplier_inventory.py +74 -0
- services/suppliers/helpers/supplier_locations.py +60 -0
- services/suppliers/helpers/supplier_pricing.py +69 -0
- services/suppliers/helpers/supplier_quality.py +69 -0
- services/suppliers/helpers/supplier_shipping.py +69 -0
- services/suppliers/main.py +60 -0
- services/suppliers/models/__init__.py +13 -0
- services/suppliers/models/supplier_capabilities.py +70 -0
- services/suppliers/models/supplier_certifications.py +64 -0
- services/suppliers/models/supplier_details.py +75 -0
- services/suppliers/models/supplier_financials.py +69 -0
- services/suppliers/models/supplier_inventory.py +76 -0
- services/suppliers/models/supplier_locations.py +70 -0
- services/suppliers/models/supplier_pricing.py +74 -0
- services/suppliers/models/supplier_quality.py +74 -0
- services/suppliers/models/supplier_shipping.py +76 -0
- services/suppliers/routers/__init__.py +13 -0
- services/suppliers/routers/supplier_capabilities.py +88 -0
- services/suppliers/routers/supplier_certifications.py +87 -0
- services/suppliers/routers/supplier_details.py +83 -0
- services/suppliers/routers/supplier_financials.py +83 -0
- services/suppliers/routers/supplier_inventory.py +105 -0
- services/suppliers/routers/supplier_locations.py +89 -0
- services/suppliers/routers/supplier_pricing.py +96 -0
- services/suppliers/routers/supplier_quality.py +96 -0
- services/suppliers/routers/supplier_shipping.py +96 -0
- services/supply_allocation/main.py +46 -0
- services/supply_allocation/routers/__init__.py +1 -0
- services/supply_allocation/routers/allocation.py +20 -0
- services/taxonomy/helpers/__init__.py +7 -0
- services/taxonomy/helpers/classes.py +48 -0
- services/taxonomy/helpers/family.py +53 -0
- services/taxonomy/helpers/subclass.py +58 -0
- services/taxonomy/main.py +48 -0
- services/taxonomy/models/__init__.py +7 -0
- services/taxonomy/models/classes.py +52 -0
- services/taxonomy/models/family.py +60 -0
- services/taxonomy/models/subclass.py +50 -0
- services/taxonomy/routers/__init__.py +7 -0
- services/taxonomy/routers/classes.py +78 -0
- services/taxonomy/routers/family.py +77 -0
- services/taxonomy/routers/subclass.py +82 -0
- services/warehouse_execution/__init__.py +1 -0
- services/warehouse_execution/main.py +46 -0
- services/warehouse_execution/routers/__init__.py +1 -0
- services/warehouse_execution/routers/execution.py +21 -0
- services/work_order_agent/__init__.py +17 -0
- services/work_order_agent/agent/__init__.py +17 -0
- services/work_order_agent/agent/work_order_agent.py +658 -0
- services/work_order_agent/tracking/__init__.py +101 -0
- services/work_order_agent/tracking/event_system.py +182 -0
- services/work_order_agent/tracking/state_machine.py +163 -0
- services/work_order_agent/tracking/state_machine_integrator.py +295 -0
- services/work_order_agent/tracking/test_phase2_implementation.py +302 -0
- services/work_order_agent/tracking/time_analysis.py +301 -0
- services/work_order_agent/tracking/tracked_work_order.py +255 -0
- services/work_order_agent/tracking/work_order_adapter.py +367 -0
- services/work_order_agent/tracking/work_order_batch_manager.py +406 -0
- services/work_order_agent/tracking/work_order_repository.py +431 -0
- services/workorders/helpers/__init__.py +5 -0
- services/workorders/helpers/area_room_usage_ledger.py +139 -0
- services/workorders/helpers/batch_execution_records.py +265 -0
- services/workorders/helpers/batch_release_workflows.py +158 -0
- services/workorders/helpers/batch_step_executions.py +145 -0
- services/workorders/helpers/equipment_usage_ledger.py +209 -0
- services/workorders/helpers/executed_bmr_records.py +170 -0
- services/workorders/helpers/executed_bpr_records.py +170 -0
- services/workorders/helpers/executed_instruction_evidence.py +155 -0
- services/workorders/helpers/ipc_result_records.py +134 -0
- services/workorders/helpers/production_batches.py +117 -0
- services/workorders/helpers/work_orders.py +367 -0
- services/workorders/helpers/yield_reconciliation_records.py +158 -0
- services/workorders/main.py +110 -0
- services/workorders/models/__init__.py +5 -0
- services/workorders/models/area_room_usage_ledger.py +154 -0
- services/workorders/models/batch_execution_records.py +575 -0
- services/workorders/models/batch_release_workflows.py +190 -0
- services/workorders/models/batch_step_executions.py +142 -0
- services/workorders/models/equipment_usage_ledger.py +144 -0
- services/workorders/models/executed_bmr_records.py +220 -0
- services/workorders/models/executed_bpr_records.py +220 -0
- services/workorders/models/executed_instruction_evidence.py +128 -0
- services/workorders/models/ipc_result_records.py +164 -0
- services/workorders/models/production_batches.py +181 -0
- services/workorders/models/work_orders.py +255 -0
- services/workorders/models/yield_reconciliation_records.py +175 -0
- services/workorders/routers/__init__.py +5 -0
- services/workorders/routers/area_room_usage_ledger.py +117 -0
- services/workorders/routers/batch_execution_records.py +103 -0
- services/workorders/routers/batch_release_workflows.py +86 -0
- services/workorders/routers/batch_step_executions.py +88 -0
- services/workorders/routers/equipment_usage_ledger.py +115 -0
- services/workorders/routers/executed_bmr_records.py +86 -0
- services/workorders/routers/executed_bpr_records.py +86 -0
- services/workorders/routers/executed_instruction_evidence.py +86 -0
- services/workorders/routers/ipc_result_records.py +86 -0
- services/workorders/routers/production_batches.py +86 -0
- services/workorders/routers/work_orders.py +257 -0
- services/workorders/routers/yield_reconciliation_records.py +86 -0
- src/broca/__init__.py +5 -0
- src/broca/agent.py +201 -0
- src/cerebellum/__init__.py +0 -0
- src/cerebellum/adapter.py +84 -0
- src/cerebellum/capabilities/__init__.py +0 -0
- src/cerebellum/capabilities/agent/__init__.py +0 -0
- src/cerebellum/capabilities/agent/agents.py +65 -0
- src/cerebellum/capabilities/ai/__init__.py +0 -0
- src/cerebellum/capabilities/ai/providers.py +106 -0
- src/cerebellum/capabilities/api/__init__.py +0 -0
- src/cerebellum/capabilities/api/graphql.py +35 -0
- src/cerebellum/capabilities/api/rest_api.py +45 -0
- src/cerebellum/capabilities/api/webhook.py +30 -0
- src/cerebellum/capabilities/browser/__init__.py +0 -0
- src/cerebellum/capabilities/browser/browsers.py +27 -0
- src/cerebellum/capabilities/cloud/__init__.py +0 -0
- src/cerebellum/capabilities/cloud/cloud.py +46 -0
- src/cerebellum/capabilities/communication/__init__.py +0 -0
- src/cerebellum/capabilities/communication/communication.py +62 -0
- src/cerebellum/capabilities/database/__init__.py +0 -0
- src/cerebellum/capabilities/database/elasticsearch.py +40 -0
- src/cerebellum/capabilities/database/influxdb.py +37 -0
- src/cerebellum/capabilities/database/mongodb.py +50 -0
- src/cerebellum/capabilities/database/neo4j.py +32 -0
- src/cerebellum/capabilities/database/redis.py +44 -0
- src/cerebellum/capabilities/enterprise/__init__.py +0 -0
- src/cerebellum/capabilities/enterprise/opensource.py +180 -0
- src/cerebellum/capabilities/enterprise/proprietary.py +313 -0
- src/cerebellum/capabilities/event_streaming/__init__.py +0 -0
- src/cerebellum/capabilities/event_streaming/streaming.py +38 -0
- src/cerebellum/capabilities/infrastructure/__init__.py +0 -0
- src/cerebellum/capabilities/infrastructure/infrastructure.py +30 -0
- src/cerebellum/capabilities/productivity/__init__.py +0 -0
- src/cerebellum/capabilities/productivity/productivity.py +158 -0
- src/cerebellum/capabilities/robotics/__init__.py +0 -0
- src/cerebellum/capabilities/robotics/robotics.py +124 -0
- src/cerebellum/capabilities/runtime/__init__.py +0 -0
- src/cerebellum/capabilities/runtime/runtimes.py +92 -0
- src/cerebellum/capabilities/search/__init__.py +0 -0
- src/cerebellum/capabilities/search/search.py +63 -0
- src/cerebellum/capabilities/source_control/__init__.py +0 -0
- src/cerebellum/capabilities/source_control/source_control.py +113 -0
- src/cerebellum/capabilities/storage/__init__.py +0 -0
- src/cerebellum/capabilities/storage/storage.py +94 -0
- src/cerebellum/capabilities/workflow/__init__.py +0 -0
- src/cerebellum/capabilities/workflow/workflows.py +49 -0
- src/cerebellum/capability.py +108 -0
- src/cerebellum/config.py +157 -0
- src/cerebellum/fallback.py +147 -0
- src/cerebellum/fallback_engine.py +121 -0
- src/cerebellum/key_manager.py +129 -0
- src/cerebellum/keystore.py +179 -0
- src/cerebellum/lifecycle.py +54 -0
- src/cerebellum/metadata.py +61 -0
- src/cerebellum/operator/base.py +25 -0
- src/cerebellum/peripheral.py +92 -0
- src/cerebellum/registry.py +98 -0
- src/cerebellum/resolve_entity_capability.py +259 -0
- src/cingulate/benchmark/__init__.py +23 -0
- src/cingulate/benchmark/reporter.py +102 -0
- src/cingulate/benchmark/runner.py +159 -0
- src/cingulate/benchmark/scenario_runner.py +150 -0
- src/cingulate/benchmark/validator.py +102 -0
- src/cingulate/governance/__init__.py +21 -0
- src/cingulate/governance/architecture_validator.py +194 -0
- src/cingulate/governance/compliance.py +104 -0
- src/cingulate/governance/governance.py +77 -0
- src/cingulate/governance/policy_registry.py +91 -0
- src/cortex/__init__.py +33 -0
- src/cortex/cost.py +71 -0
- src/cortex/counterfactual.py +162 -0
- src/cortex/digital_twin.py +90 -0
- src/cortex/experience.py +83 -0
- src/cortex/feedback.py +144 -0
- src/cortex/loss.py +116 -0
- src/cortex/prediction.py +142 -0
- src/cortex/replay.py +130 -0
- src/cortex/reward.py +113 -0
- src/cortex/simulator.py +102 -0
- src/cortex/world_model.py +180 -0
- src/cortex/world_model_simulation.py +1591 -0
- src/cortex/world_state.py +121 -0
- src/cortex/xavier.py +250 -0
- src/deepdive/__init__.py +29 -0
- src/deepdive/aggregation.py +113 -0
- src/deepdive/digital_twin_aggregator.py +128 -0
- src/deepdive/elasticsearch_adapter.py +110 -0
- src/deepdive/fleet_analytics.py +131 -0
- src/deepdive/knowledge_aggregator.py +130 -0
- src/homeostasis/__init__.py +19 -0
- src/homeostasis/control_plane.py +159 -0
- src/introspection/__init__.py +38 -0
- src/introspection/alerting.py +142 -0
- src/introspection/health.py +101 -0
- src/introspection/lemon.py +243 -0
- src/introspection/logging.py +147 -0
- src/introspection/metrics.py +106 -0
- src/introspection/tracing.py +162 -0
- src/monkey_brain/__init__.py +1 -0
- src/monkey_brain/api/main.py +148 -0
- src/monkey_brain/api/models.py +81 -0
- src/monkey_brain/api/routes/routes/keys.py +106 -0
- src/monkey_brain/api/routes/routes/run.py +169 -0
- src/monkey_brain/api/routes/routes/simulate.py +485 -0
- src/monkey_brain/dlm/__init__.py +44 -0
- src/monkey_brain/dlm/dlm.py +139 -0
- src/monkey_brain/dlm/gc.py +115 -0
- src/monkey_brain/dlm/lifecycle.py +149 -0
- src/monkey_brain/dlm/orphans.py +99 -0
- src/monkey_brain/dlm/storage.py +149 -0
- src/monkey_brain/dlm/ttl.py +140 -0
- src/monkey_brain/documents/__init__.py +0 -0
- src/monkey_brain/documents/document_ocr.py +6 -0
- src/monkey_brain/kernel/__init__.py +53 -0
- src/monkey_brain/kernel/capability_interface.py +144 -0
- src/monkey_brain/kernel/classifier/__init__.py +1 -0
- src/monkey_brain/kernel/classifier/embed_classifier.py +125 -0
- src/monkey_brain/kernel/classifier/intent_examples.py +106 -0
- src/monkey_brain/kernel/dag.py +23 -0
- src/monkey_brain/kernel/execution_state.py +257 -0
- src/monkey_brain/kernel/goal_planner.py +85 -0
- src/monkey_brain/kernel/goal_router.py +20 -0
- src/monkey_brain/kernel/goals/__init__.py +1 -0
- src/monkey_brain/kernel/goals/goal.py +130 -0
- src/monkey_brain/kernel/goals/goal_bootstrap.py +38 -0
- src/monkey_brain/kernel/goals/goal_classifier.py +132 -0
- src/monkey_brain/kernel/goals/goal_registry.py +75 -0
- src/monkey_brain/kernel/intents/__init__.py +1 -0
- src/monkey_brain/kernel/intents/event_adapter.py +246 -0
- src/monkey_brain/kernel/intents/helpers.py +13 -0
- src/monkey_brain/kernel/intents/intent_registry.py +705 -0
- src/monkey_brain/kernel/intents/intent_router.py +102 -0
- src/monkey_brain/kernel/intents/predicates/approval_create.py +9 -0
- src/monkey_brain/kernel/intents/predicates/approval_decision.py +9 -0
- src/monkey_brain/kernel/intents/predicates/approval_hold.py +9 -0
- src/monkey_brain/kernel/intents/predicates/approval_query.py +9 -0
- src/monkey_brain/kernel/intents/predicates/batch_close.py +9 -0
- src/monkey_brain/kernel/intents/predicates/batch_creation.py +9 -0
- src/monkey_brain/kernel/intents/predicates/batch_delete.py +9 -0
- src/monkey_brain/kernel/intents/predicates/batch_hold.py +9 -0
- src/monkey_brain/kernel/intents/predicates/batch_record.py +9 -0
- src/monkey_brain/kernel/intents/predicates/batch_update.py +9 -0
- src/monkey_brain/kernel/intents/predicates/change_control.py +49 -0
- src/monkey_brain/kernel/intents/predicates/compliance_audit.py +14 -0
- src/monkey_brain/kernel/intents/predicates/decision_intelligence.py +9 -0
- src/monkey_brain/kernel/intents/predicates/drug_research.py +9 -0
- src/monkey_brain/kernel/intents/predicates/fuzzy_match.py +19 -0
- src/monkey_brain/kernel/intents/predicates/production_kpi.py +9 -0
- src/monkey_brain/kernel/intents/predicates/sop_create.py +9 -0
- src/monkey_brain/kernel/intents/predicates/sop_query.py +9 -0
- src/monkey_brain/kernel/intents/predicates/sop_update.py +9 -0
- src/monkey_brain/kernel/intents/predicates/warehouse_shipping.py +9 -0
- src/monkey_brain/kernel/intents/predicates/work_order_create.py +9 -0
- src/monkey_brain/kernel/intents/predicates/work_order_delete.py +9 -0
- src/monkey_brain/kernel/intents/predicates/work_order_hold.py +9 -0
- src/monkey_brain/kernel/intents/predicates/work_order_query.py +9 -0
- src/monkey_brain/kernel/intents/predicates/work_order_status.py +9 -0
- src/monkey_brain/kernel/intents/predicates/work_order_update.py +9 -0
- src/monkey_brain/kernel/intents/predicates/worker.py +9 -0
- src/monkey_brain/kernel/intents/telemetry_adapter.py +274 -0
- src/monkey_brain/kernel/intents/utils.py +68 -0
- src/monkey_brain/kernel/learning.py +98 -0
- src/monkey_brain/kernel/llm_explorer.py +188 -0
- src/monkey_brain/kernel/loss.py +81 -0
- src/monkey_brain/kernel/nlp/__init__.py +1 -0
- src/monkey_brain/kernel/nlp/compat.py +23 -0
- src/monkey_brain/kernel/nlp/models.py +10 -0
- src/monkey_brain/kernel/nlp/question_analyzer.py +203 -0
- src/monkey_brain/kernel/nlp/spacy_parser.py +53 -0
- src/monkey_brain/kernel/observer.py +97 -0
- src/monkey_brain/kernel/parser/__init__.py +3 -0
- src/monkey_brain/kernel/parser/ast.py +28 -0
- src/monkey_brain/kernel/parser/extractors/__init__.py +11 -0
- src/monkey_brain/kernel/parser/extractors/entities.py +21 -0
- src/monkey_brain/kernel/parser/extractors/filters.py +16 -0
- src/monkey_brain/kernel/parser/extractors/projections.py +36 -0
- src/monkey_brain/kernel/parser/extractors/verbs.py +31 -0
- src/monkey_brain/kernel/parser/parser.py +57 -0
- src/monkey_brain/kernel/parser/rules.py +75 -0
- src/monkey_brain/kernel/pipeline.py +44 -0
- src/monkey_brain/kernel/planner.py +57 -0
- src/monkey_brain/kernel/rl/__init__.py +33 -0
- src/monkey_brain/kernel/rl/learner.py +98 -0
- src/monkey_brain/kernel/rl/policy.py +254 -0
- src/monkey_brain/kernel/rl/reward.py +117 -0
- src/monkey_brain/kernel/rl/transition.py +112 -0
- src/monkey_brain/persistence/__init__.py +47 -0
- src/monkey_brain/persistence/adapters.py +49 -0
- src/monkey_brain/persistence/events.py +105 -0
- src/monkey_brain/persistence/manager.py +124 -0
- src/monkey_brain/persistence/mongodb_adapter.py +91 -0
- src/monkey_brain/persistence/redis_adapter.py +93 -0
- src/monkey_brain/persistence/reducer.py +111 -0
- src/monkey_brain/runtime/__init__.py +49 -0
- src/monkey_brain/runtime/depedencies.py +8 -0
- src/monkey_brain/runtime/engine.py +183 -0
- src/monkey_brain/runtime/message_bus.py +82 -0
- src/monkey_brain/runtime/process.py +144 -0
- src/monkey_brain/runtime/resource_manager.py +100 -0
- src/monkey_brain/runtime/routers.py +8 -0
- src/monkey_brain/runtime/runtime.py +199 -0
- src/monkey_brain/runtime/scheduler.py +165 -0
- src/monkey_brain/runtime/supervisor.py +133 -0
- src/monkey_brain/runtime/worker_pool.py +111 -0
- src/plasticity/seed/__init__.py +30 -0
- src/plasticity/seed/benchmark_generator.py +105 -0
- src/plasticity/seed/event_generator.py +122 -0
- src/plasticity/seed/scenario_builder.py +134 -0
- src/plasticity/seed/seed_data.py +206 -0
- src/plasticity/seed/seeder.py +122 -0
- src/plasticity/testing/__init__.py +28 -0
- src/plasticity/testing/performance.py +131 -0
- src/plasticity/testing/profiler.py +255 -0
- src/plasticity/testing/reporter.py +84 -0
- src/plasticity/testing/runner.py +209 -0
- src/sync/__init__.py +12 -0
- src/sync/cloud_aggregator.py +63 -0
- src/sync/edge_node.py +51 -0
- src/sync/sync_manager.py +74 -0
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
"""
|
|
2
|
+
CDC hooks that keep process_definitions in sync with SOPs,
|
|
3
|
+
and apply approved change-control changes back to SOPs.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import logging
|
|
9
|
+
from datetime import datetime, timezone
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
from motor.motor_asyncio import AsyncIOMotorDatabase
|
|
13
|
+
|
|
14
|
+
logger = logging.getLogger("pm.sop_cdc")
|
|
15
|
+
|
|
16
|
+
PD_COLLECTION = "process_definitions"
|
|
17
|
+
SOP_COLLECTION = "sops"
|
|
18
|
+
ISO_COLLECTION = "industrial_sops"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _utc_now() -> datetime:
|
|
22
|
+
return datetime.now(timezone.utc)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _build_process_step(step_text: str, index: int, pd_id: str) -> dict:
|
|
26
|
+
step_id = f"STEP-{pd_id}-{index + 1:03d}"
|
|
27
|
+
return {
|
|
28
|
+
"id": step_id,
|
|
29
|
+
"sequence": index + 1,
|
|
30
|
+
"name": step_text[:120] if isinstance(step_text, str) else f"Step {index + 1}",
|
|
31
|
+
"description": step_text if isinstance(step_text, str) else "",
|
|
32
|
+
"action_type": "MANUAL",
|
|
33
|
+
"command": None,
|
|
34
|
+
"inputs": [],
|
|
35
|
+
"outputs": [],
|
|
36
|
+
"depends_on": [f"STEP-{pd_id}-{index:03d}"] if index > 0 else [],
|
|
37
|
+
"is_optional": False,
|
|
38
|
+
"timeout_seconds": None,
|
|
39
|
+
"retry_count": 0,
|
|
40
|
+
"status": "pending",
|
|
41
|
+
"prechecks": {
|
|
42
|
+
"id": f"PRE-{step_id}",
|
|
43
|
+
"process_definition_id": pd_id,
|
|
44
|
+
"process_step_id": step_id,
|
|
45
|
+
"conditions": [],
|
|
46
|
+
"all_must_pass": True,
|
|
47
|
+
"timeout_seconds": 300,
|
|
48
|
+
"description": "",
|
|
49
|
+
},
|
|
50
|
+
"postchecks": {
|
|
51
|
+
"id": f"POST-{step_id}",
|
|
52
|
+
"process_definition_id": pd_id,
|
|
53
|
+
"process_step_id": step_id,
|
|
54
|
+
"conditions": [],
|
|
55
|
+
"all_must_pass": True,
|
|
56
|
+
"timeout_seconds": 300,
|
|
57
|
+
"description": "",
|
|
58
|
+
},
|
|
59
|
+
"constraints": {
|
|
60
|
+
"id": f"CONST-{step_id}",
|
|
61
|
+
"process_definition_id": pd_id,
|
|
62
|
+
"process_step_id": step_id,
|
|
63
|
+
"constraints": [],
|
|
64
|
+
"description": "",
|
|
65
|
+
},
|
|
66
|
+
"corrective_actions": {
|
|
67
|
+
"id": f"CA-{step_id}",
|
|
68
|
+
"process_definition_id": pd_id,
|
|
69
|
+
"process_step_id": step_id,
|
|
70
|
+
"actions": [],
|
|
71
|
+
"description": "",
|
|
72
|
+
},
|
|
73
|
+
"notes": None,
|
|
74
|
+
"created_at": _utc_now(),
|
|
75
|
+
"updated_at": _utc_now(),
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def _build_steps_from_sop(sop: dict, pd_id: str) -> dict:
|
|
80
|
+
steps_items = []
|
|
81
|
+
pd = sop.get("process_definition", {})
|
|
82
|
+
if isinstance(pd, dict):
|
|
83
|
+
raw_steps = pd.get("steps", {})
|
|
84
|
+
if isinstance(raw_steps, dict):
|
|
85
|
+
steps_items = raw_steps.get("items", [])
|
|
86
|
+
|
|
87
|
+
if not steps_items:
|
|
88
|
+
raw_steps_list = pd.get("steps", []) if isinstance(pd, dict) else []
|
|
89
|
+
if isinstance(raw_steps_list, list):
|
|
90
|
+
steps_items = raw_steps_list
|
|
91
|
+
|
|
92
|
+
if not steps_items:
|
|
93
|
+
iso = sop.get("_industrial_sop", {})
|
|
94
|
+
if isinstance(iso, dict):
|
|
95
|
+
steps_items = iso.get("steps", [])
|
|
96
|
+
|
|
97
|
+
processed = []
|
|
98
|
+
for i, item in enumerate(steps_items):
|
|
99
|
+
if isinstance(item, str):
|
|
100
|
+
processed.append(_build_process_step(item, i, pd_id))
|
|
101
|
+
elif isinstance(item, dict):
|
|
102
|
+
text = item.get("command") or item.get("description") or item.get("name") or f"Step {i + 1}"
|
|
103
|
+
step = _build_process_step(text, i, pd_id)
|
|
104
|
+
step.update({k: v for k, v in item.items() if k in step})
|
|
105
|
+
processed.append(step)
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
"id": f"STEPS-{pd_id}",
|
|
109
|
+
"process_definition_id": pd_id,
|
|
110
|
+
"description": f"Steps for {sop.get('title', pd_id)}",
|
|
111
|
+
"steps": processed,
|
|
112
|
+
"allow_parallel_execution": False,
|
|
113
|
+
"rollback_on_failure": False,
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def _build_pd_from_sop(sop: dict) -> dict:
|
|
118
|
+
sop_id = sop.get("id", "")
|
|
119
|
+
pd = sop.get("process_definition", {})
|
|
120
|
+
pd_id = pd.get("process_definition_id") if isinstance(pd, dict) else None
|
|
121
|
+
if not pd_id:
|
|
122
|
+
pd_id = f"PROC-{sop_id}"
|
|
123
|
+
|
|
124
|
+
now = _utc_now()
|
|
125
|
+
title = sop.get("title", "")
|
|
126
|
+
description = ""
|
|
127
|
+
if isinstance(pd, dict):
|
|
128
|
+
description = pd.get("description", "")
|
|
129
|
+
if not description:
|
|
130
|
+
description = sop.get("scope", "") or sop.get("purpose", "") or title
|
|
131
|
+
|
|
132
|
+
tags = list(sop.get("tags", [])) if isinstance(sop.get("tags"), list) else []
|
|
133
|
+
|
|
134
|
+
return {
|
|
135
|
+
"process_definition_id": pd_id,
|
|
136
|
+
"name": title,
|
|
137
|
+
"description": description,
|
|
138
|
+
"version": sop.get("version", "1.0.0"),
|
|
139
|
+
"route_version": "1.0.0",
|
|
140
|
+
"revision": "A",
|
|
141
|
+
"process_type": "manufacturing",
|
|
142
|
+
"product_id": None,
|
|
143
|
+
"product_family": None,
|
|
144
|
+
"plant_id": None,
|
|
145
|
+
"line_id": None,
|
|
146
|
+
"bom_id": None,
|
|
147
|
+
"recipe_id": None,
|
|
148
|
+
"owner": sop.get("entity_name"),
|
|
149
|
+
"tags": tags,
|
|
150
|
+
"status": "pending",
|
|
151
|
+
"approval_status": "draft",
|
|
152
|
+
"change_control_id": None,
|
|
153
|
+
"supersedes_process_definition_id": None,
|
|
154
|
+
"effective_from": None,
|
|
155
|
+
"effective_to": None,
|
|
156
|
+
"approved_by": None,
|
|
157
|
+
"approved_at": None,
|
|
158
|
+
"retired_at": None,
|
|
159
|
+
"route_stage_ids": [],
|
|
160
|
+
"material_flow_edge_ids": [],
|
|
161
|
+
"ipc_checkpoints": [],
|
|
162
|
+
"cleaning_requirements": [],
|
|
163
|
+
"instruction_templates": [],
|
|
164
|
+
"metadata": {
|
|
165
|
+
"source": "sop_cdc",
|
|
166
|
+
"sop_id": sop_id,
|
|
167
|
+
},
|
|
168
|
+
"steps": _build_steps_from_sop(sop, pd_id),
|
|
169
|
+
"created_at": now,
|
|
170
|
+
"updated_at": now,
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
# ─── CDC: SOP → Process Definition ───────────────────────────────────────────
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
async def sync_sop_to_process_definition(db: AsyncIOMotorDatabase, sop: dict) -> dict | None:
|
|
178
|
+
"""
|
|
179
|
+
After a SOP is created or updated, upsert the corresponding
|
|
180
|
+
process_definition record so the process-definition pages stay current.
|
|
181
|
+
Returns the upserted process_definition dict.
|
|
182
|
+
"""
|
|
183
|
+
pd_doc = _build_pd_from_sop(sop)
|
|
184
|
+
pd_id = pd_doc["process_definition_id"]
|
|
185
|
+
|
|
186
|
+
existing = await db[PD_COLLECTION].find_one(
|
|
187
|
+
{"process_definition_id": pd_id}, {"_id": 0}
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
if existing:
|
|
191
|
+
now = _utc_now()
|
|
192
|
+
pd_doc.pop("created_at", None)
|
|
193
|
+
pd_doc["updated_at"] = now
|
|
194
|
+
await db[PD_COLLECTION].update_one(
|
|
195
|
+
{"process_definition_id": pd_id},
|
|
196
|
+
{"$set": pd_doc},
|
|
197
|
+
)
|
|
198
|
+
logger.info("CDC: updated process_definition %s from SOP %s", pd_id, sop.get("id"))
|
|
199
|
+
else:
|
|
200
|
+
await db[PD_COLLECTION].insert_one(pd_doc)
|
|
201
|
+
logger.info("CDC: created process_definition %s from SOP %s", pd_id, sop.get("id"))
|
|
202
|
+
|
|
203
|
+
return pd_doc
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
async def sync_all_sops_to_process_definitions(db: AsyncIOMotorDatabase) -> int:
|
|
207
|
+
"""Bulk sync all SOPs to process_definitions. Returns count of upserted docs."""
|
|
208
|
+
count = 0
|
|
209
|
+
async for sop in db[SOP_COLLECTION].find():
|
|
210
|
+
await sync_sop_to_process_definition(db, sop)
|
|
211
|
+
count += 1
|
|
212
|
+
return count
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
# ─── CDC: Change Control Approval → SOP ──────────────────────────────────────
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
async def apply_approved_change_control_to_sop(
|
|
219
|
+
db: AsyncIOMotorDatabase,
|
|
220
|
+
change_control: dict,
|
|
221
|
+
) -> list[dict]:
|
|
222
|
+
"""
|
|
223
|
+
When a change control reaches 'Approved' status (all approvers approved),
|
|
224
|
+
apply the proposed changes to the affected SOPs.
|
|
225
|
+
|
|
226
|
+
Reads proposed changes from gxp_proposed_changes, finds matching SOPs,
|
|
227
|
+
updates the SOP's process_definition, steps, prechecks, postchecks,
|
|
228
|
+
constraints, and corrective_actions. Returns list of promotion results.
|
|
229
|
+
"""
|
|
230
|
+
cc_id = change_control.get("change_control_id", "")
|
|
231
|
+
now = _utc_now()
|
|
232
|
+
results: list[dict] = []
|
|
233
|
+
|
|
234
|
+
proposed_nodes = await db["gxp_proposed_changes"].find(
|
|
235
|
+
{
|
|
236
|
+
"change_control_id": cc_id,
|
|
237
|
+
"status": {"$in": ["Pending Approval", "Approved"]},
|
|
238
|
+
"archived": {"$ne": True},
|
|
239
|
+
},
|
|
240
|
+
{"_id": 0},
|
|
241
|
+
).to_list(length=500)
|
|
242
|
+
|
|
243
|
+
affected_sops = change_control.get("affected_sops", [])
|
|
244
|
+
affected_entities = change_control.get("affected_entities", [])
|
|
245
|
+
|
|
246
|
+
for node in proposed_nodes:
|
|
247
|
+
source_collection = node.get("source_collection", "")
|
|
248
|
+
source_id = node.get("source_id", "")
|
|
249
|
+
pending = node.get("pending_properties") or {}
|
|
250
|
+
|
|
251
|
+
target_sop_id = None
|
|
252
|
+
if source_collection == SOP_COLLECTION:
|
|
253
|
+
target_sop_id = source_id
|
|
254
|
+
elif source_collection == ISO_COLLECTION:
|
|
255
|
+
iso = await db[ISO_COLLECTION].find_one({"sop_id": source_id}, {"_id": 1})
|
|
256
|
+
if iso:
|
|
257
|
+
target_sop_id = str(iso["_id"])
|
|
258
|
+
|
|
259
|
+
if not target_sop_id and affected_sops:
|
|
260
|
+
target_sop_id = affected_sops[0]
|
|
261
|
+
|
|
262
|
+
if not target_sop_id:
|
|
263
|
+
continue
|
|
264
|
+
|
|
265
|
+
sop = await db[SOP_COLLECTION].find_one({"id": target_sop_id}, {"_id": 0})
|
|
266
|
+
if not sop:
|
|
267
|
+
continue
|
|
268
|
+
|
|
269
|
+
set_fields: dict[str, Any] = {"updated_at": now}
|
|
270
|
+
|
|
271
|
+
for field in ("title", "description", "scope", "purpose", "tags", "version"):
|
|
272
|
+
if field in pending and pending[field] is not None:
|
|
273
|
+
set_fields[field] = pending[field]
|
|
274
|
+
|
|
275
|
+
for sub_doc_key in ("process_definition", "prechecks", "postchecks", "constraints", "corrective_actions"):
|
|
276
|
+
if sub_doc_key in pending and isinstance(pending[sub_doc_key], dict):
|
|
277
|
+
merged = {**(sop.get(sub_doc_key) or {}), **pending[sub_doc_key]}
|
|
278
|
+
set_fields[sub_doc_key] = merged
|
|
279
|
+
|
|
280
|
+
if "status" in pending:
|
|
281
|
+
set_fields["status"] = pending["status"]
|
|
282
|
+
|
|
283
|
+
await db[SOP_COLLECTION].update_one(
|
|
284
|
+
{"id": target_sop_id},
|
|
285
|
+
{"$set": set_fields},
|
|
286
|
+
)
|
|
287
|
+
|
|
288
|
+
await db["gxp_proposed_changes"].update_one(
|
|
289
|
+
{"proposed_change_id": node.get("proposed_change_id")},
|
|
290
|
+
{
|
|
291
|
+
"$set": {
|
|
292
|
+
"status": "Archived",
|
|
293
|
+
"lifecycle_state": "archived",
|
|
294
|
+
"archived": True,
|
|
295
|
+
"archived_at": now,
|
|
296
|
+
"effective_at": now,
|
|
297
|
+
"live_node_touched": True,
|
|
298
|
+
"promotion_result": {
|
|
299
|
+
"collection": SOP_COLLECTION,
|
|
300
|
+
"source_id": target_sop_id,
|
|
301
|
+
"applied_values": pending,
|
|
302
|
+
},
|
|
303
|
+
"updated_at": now,
|
|
304
|
+
}
|
|
305
|
+
},
|
|
306
|
+
)
|
|
307
|
+
|
|
308
|
+
updated_sop = await db[SOP_COLLECTION].find_one({"id": target_sop_id}, {"_id": 0})
|
|
309
|
+
if updated_sop:
|
|
310
|
+
await sync_sop_to_process_definition(db, updated_sop)
|
|
311
|
+
|
|
312
|
+
results.append({
|
|
313
|
+
"proposed_change_id": node.get("proposed_change_id"),
|
|
314
|
+
"sop_id": target_sop_id,
|
|
315
|
+
"applied_values": list(pending.keys()),
|
|
316
|
+
"effective_at": now.isoformat(),
|
|
317
|
+
})
|
|
318
|
+
|
|
319
|
+
logger.info(
|
|
320
|
+
"CDC: applied change_control %s to SOP %s (proposed_change %s)",
|
|
321
|
+
cc_id, target_sop_id, node.get("proposed_change_id"),
|
|
322
|
+
)
|
|
323
|
+
|
|
324
|
+
return results
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
from datetime import date
|
|
2
|
+
from typing import Optional
|
|
3
|
+
|
|
4
|
+
from motor.motor_asyncio import AsyncIOMotorDatabase
|
|
5
|
+
from pymongo import ReturnDocument
|
|
6
|
+
|
|
7
|
+
from services.pm.models.weekly_schedule import WeeklyScheduleCreate, WeeklyScheduleUpdate
|
|
8
|
+
|
|
9
|
+
COLLECTION = "weekly_schedules"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _serialize(doc: dict) -> dict:
|
|
13
|
+
doc = dict(doc)
|
|
14
|
+
doc.pop("_id", None)
|
|
15
|
+
return doc
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _dump(data) -> dict:
|
|
19
|
+
doc = data.model_dump(mode="json", exclude_unset=True)
|
|
20
|
+
doc.pop("week_end", None)
|
|
21
|
+
doc.pop("total_shifts", None)
|
|
22
|
+
doc.pop("total_headcount", None)
|
|
23
|
+
for shift in doc.get("shifts", []):
|
|
24
|
+
if isinstance(shift, dict):
|
|
25
|
+
shift.pop("headcount", None)
|
|
26
|
+
return doc
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
async def get_all(
|
|
30
|
+
db: AsyncIOMotorDatabase,
|
|
31
|
+
page: int = 1,
|
|
32
|
+
page_size: int = 20,
|
|
33
|
+
) -> tuple[list[dict], int]:
|
|
34
|
+
query: dict = {}
|
|
35
|
+
total = await db[COLLECTION].count_documents(query)
|
|
36
|
+
cursor = db[COLLECTION].find(query).skip((page - 1) * page_size).limit(page_size)
|
|
37
|
+
return [_serialize(d) async for d in cursor], total
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
async def get_by_id(db: AsyncIOMotorDatabase, schedule_id: str) -> Optional[dict]:
|
|
41
|
+
doc = await db[COLLECTION].find_one({"id": schedule_id})
|
|
42
|
+
return _serialize(doc) if doc else None
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
async def get_by_factory(db: AsyncIOMotorDatabase, factory_id: str) -> list[dict]:
|
|
46
|
+
cursor = db[COLLECTION].find({"factory_id": factory_id})
|
|
47
|
+
return [_serialize(d) async for d in cursor]
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
async def get_by_week_start(db: AsyncIOMotorDatabase, week_start: date) -> list[dict]:
|
|
51
|
+
cursor = db[COLLECTION].find({"week_start": week_start.isoformat()})
|
|
52
|
+
return [_serialize(d) async for d in cursor]
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
async def create(db: AsyncIOMotorDatabase, data: WeeklyScheduleCreate) -> dict:
|
|
56
|
+
doc = _dump(data)
|
|
57
|
+
await db[COLLECTION].insert_one(doc)
|
|
58
|
+
return _serialize(doc)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
async def update(
|
|
62
|
+
db: AsyncIOMotorDatabase,
|
|
63
|
+
schedule_id: str,
|
|
64
|
+
data: WeeklyScheduleUpdate,
|
|
65
|
+
) -> Optional[dict]:
|
|
66
|
+
fields = _dump(data)
|
|
67
|
+
if not fields:
|
|
68
|
+
return await get_by_id(db, schedule_id)
|
|
69
|
+
result = await db[COLLECTION].find_one_and_update(
|
|
70
|
+
{"id": schedule_id},
|
|
71
|
+
{"$set": fields},
|
|
72
|
+
return_document=ReturnDocument.AFTER,
|
|
73
|
+
)
|
|
74
|
+
return _serialize(result) if result else None
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
async def delete(db: AsyncIOMotorDatabase, schedule_id: str) -> bool:
|
|
78
|
+
result = await db[COLLECTION].delete_one({"id": schedule_id})
|
|
79
|
+
return result.deleted_count == 1
|
services/pm/main.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
from contextlib import asynccontextmanager
|
|
2
|
+
|
|
3
|
+
from fastapi import FastAPI
|
|
4
|
+
from fastapi.middleware.cors import CORSMiddleware
|
|
5
|
+
|
|
6
|
+
from services.common.logging import configure_service_logging, install_request_logging
|
|
7
|
+
from services.common.tracing import install_route_tracing
|
|
8
|
+
|
|
9
|
+
from services.common.db import close_db, connect_db
|
|
10
|
+
from services.pm.routers.maintainance import router as maintenance_router
|
|
11
|
+
from services.pm.routers.calibrations import router as calibrations_router
|
|
12
|
+
from services.pm.routers.calibration_point import router as calibration_points_router
|
|
13
|
+
from services.pm.routers.cleaning import router as cleaning_router
|
|
14
|
+
from services.pm.routers.downtime import router as downtime_router
|
|
15
|
+
from services.pm.routers.checklists import router as checklists_router
|
|
16
|
+
from services.pm.routers.sop import router as sop_router
|
|
17
|
+
from services.pm.routers.weekly_schedules import router as weekly_schedules_router
|
|
18
|
+
from services.pm.routers.calendar_bookings import router as calendar_bookings_router
|
|
19
|
+
from services.pm.routers.kanban_boards import router as kanban_boards_router
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
logger = configure_service_logging("pm")
|
|
23
|
+
|
|
24
|
+
@asynccontextmanager
|
|
25
|
+
async def lifespan(app: FastAPI):
|
|
26
|
+
await connect_db()
|
|
27
|
+
yield
|
|
28
|
+
await close_db()
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
app = FastAPI(
|
|
32
|
+
title="Preventive Maintenance Service",
|
|
33
|
+
description="Microservice for preventive maintenance service.",
|
|
34
|
+
version="1.0.0",
|
|
35
|
+
lifespan=lifespan,
|
|
36
|
+
)
|
|
37
|
+
install_request_logging(app, "pm")
|
|
38
|
+
install_route_tracing(app, "pm")
|
|
39
|
+
|
|
40
|
+
app.add_middleware(
|
|
41
|
+
CORSMiddleware,
|
|
42
|
+
allow_origins=["*"],
|
|
43
|
+
allow_credentials=True,
|
|
44
|
+
allow_methods=["*"],
|
|
45
|
+
allow_headers=["*"],
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
app.include_router(maintenance_router, prefix="/api/v1/maintenance", tags=["Maintenance"])
|
|
49
|
+
app.include_router(calibrations_router, prefix="/api/v1/calibrations", tags=["Calibrations"])
|
|
50
|
+
app.include_router(calibration_points_router, prefix="/api/v1/calibrations/{calibration_id}/points", tags=["Calibration Points"])
|
|
51
|
+
app.include_router(cleaning_router, prefix="/api/v1/cleaning", tags=["Cleaning"])
|
|
52
|
+
app.include_router(downtime_router, prefix="/api/v1/downtime", tags=["Downtime"])
|
|
53
|
+
app.include_router(checklists_router, prefix="/api/v1/checklists", tags=["Checklists"])
|
|
54
|
+
app.include_router(sop_router, prefix="/api/v1/sops", tags=["SOPs"])
|
|
55
|
+
app.include_router(weekly_schedules_router, prefix="/api/v1/weekly-schedules", tags=["Weekly Schedules"])
|
|
56
|
+
app.include_router(calendar_bookings_router, prefix="/api/v1/calendar-bookings", tags=["Calendar Bookings"])
|
|
57
|
+
app.include_router(kanban_boards_router, prefix="/api/v1/kanban-boards", tags=["Kanban Boards"])
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@app.get("/health", tags=["Health"])
|
|
61
|
+
async def health_check():
|
|
62
|
+
return {"status": "healthy"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from datetime import datetime, timezone
|
|
4
|
+
from typing import Literal, Optional
|
|
5
|
+
from uuid import UUID, uuid4
|
|
6
|
+
|
|
7
|
+
from pydantic import BaseModel, Field, model_validator
|
|
8
|
+
|
|
9
|
+
BookingStatus = Literal["booked", "cancelled"]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def ensure_utc(dt: Optional[datetime]) -> Optional[datetime]:
|
|
13
|
+
if dt is None:
|
|
14
|
+
return None
|
|
15
|
+
if dt.tzinfo is None:
|
|
16
|
+
return dt.replace(tzinfo=timezone.utc)
|
|
17
|
+
return dt.astimezone(timezone.utc)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def utc_now() -> datetime:
|
|
21
|
+
return datetime.now(timezone.utc)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class CalendarBooking(BaseModel):
|
|
25
|
+
id: UUID = Field(default_factory=uuid4)
|
|
26
|
+
calendar_id: str = Field(..., min_length=1)
|
|
27
|
+
title: str = Field(..., min_length=1, max_length=160)
|
|
28
|
+
start_at: datetime
|
|
29
|
+
end_at: datetime
|
|
30
|
+
booked_by: Optional[str] = None
|
|
31
|
+
attendee_ids: list[str] = Field(default_factory=list)
|
|
32
|
+
description: Optional[str] = Field(None, max_length=1000)
|
|
33
|
+
status: BookingStatus = "booked"
|
|
34
|
+
created_at: datetime = Field(default_factory=utc_now)
|
|
35
|
+
updated_at: datetime = Field(default_factory=utc_now)
|
|
36
|
+
|
|
37
|
+
@model_validator(mode="after")
|
|
38
|
+
def normalize_and_validate(self) -> "CalendarBooking":
|
|
39
|
+
self.start_at = ensure_utc(self.start_at)
|
|
40
|
+
self.end_at = ensure_utc(self.end_at)
|
|
41
|
+
self.created_at = ensure_utc(self.created_at)
|
|
42
|
+
self.updated_at = ensure_utc(self.updated_at)
|
|
43
|
+
if self.end_at <= self.start_at:
|
|
44
|
+
raise ValueError("end_at must be after start_at")
|
|
45
|
+
return self
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class CalendarBookingCreate(CalendarBooking):
|
|
49
|
+
pass
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class CalendarBookingUpdate(BaseModel):
|
|
53
|
+
calendar_id: Optional[str] = Field(None, min_length=1)
|
|
54
|
+
title: Optional[str] = Field(None, min_length=1, max_length=160)
|
|
55
|
+
start_at: Optional[datetime] = None
|
|
56
|
+
end_at: Optional[datetime] = None
|
|
57
|
+
booked_by: Optional[str] = None
|
|
58
|
+
attendee_ids: Optional[list[str]] = None
|
|
59
|
+
description: Optional[str] = Field(None, max_length=1000)
|
|
60
|
+
status: Optional[BookingStatus] = None
|
|
61
|
+
updated_at: datetime = Field(default_factory=utc_now)
|
|
62
|
+
|
|
63
|
+
@model_validator(mode="after")
|
|
64
|
+
def normalize_and_validate(self) -> "CalendarBookingUpdate":
|
|
65
|
+
self.start_at = ensure_utc(self.start_at)
|
|
66
|
+
self.end_at = ensure_utc(self.end_at)
|
|
67
|
+
self.updated_at = ensure_utc(self.updated_at)
|
|
68
|
+
if self.start_at is not None and self.end_at is not None and self.end_at <= self.start_at:
|
|
69
|
+
raise ValueError("end_at must be after start_at")
|
|
70
|
+
return self
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class CalendarBookingResponse(CalendarBooking):
|
|
74
|
+
class Config:
|
|
75
|
+
from_attributes = True
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class PaginatedCalendarBookingResponse(BaseModel):
|
|
79
|
+
total: int
|
|
80
|
+
page: int
|
|
81
|
+
page_size: int
|
|
82
|
+
results: list[CalendarBookingResponse]
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
# ─────────────────────────────────────────────
|
|
4
|
+
# CALIBRATION POINT
|
|
5
|
+
# ─────────────────────────────────────────────
|
|
6
|
+
|
|
7
|
+
from typing import Optional
|
|
8
|
+
from pydantic import BaseModel, model_validator
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class CalibrationPoint(BaseModel):
|
|
12
|
+
reference_value: float
|
|
13
|
+
measured_value: float
|
|
14
|
+
unit: Optional[str] = None
|
|
15
|
+
deviation: Optional[float] = None # auto-computed if not provided
|
|
16
|
+
|
|
17
|
+
@model_validator(mode="after")
|
|
18
|
+
def compute_deviation(self):
|
|
19
|
+
if self.deviation is None:
|
|
20
|
+
self.deviation = round(self.measured_value - self.reference_value, 6)
|
|
21
|
+
return self
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class CalibrationPointCreate(CalibrationPoint):
|
|
25
|
+
pass
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class CalibrationPointUpdate(BaseModel):
|
|
29
|
+
reference_value: Optional[float] = None
|
|
30
|
+
measured_value: Optional[float] = None
|
|
31
|
+
unit: Optional[str] = None
|
|
32
|
+
deviation: Optional[float] = None
|
|
33
|
+
|
|
34
|
+
@model_validator(mode="after")
|
|
35
|
+
def recompute_deviation(self):
|
|
36
|
+
"""Recompute deviation if both values are supplied in the update."""
|
|
37
|
+
if self.reference_value is not None and self.measured_value is not None:
|
|
38
|
+
self.deviation = round(self.measured_value - self.reference_value, 6)
|
|
39
|
+
return self
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class CalibrationPointResponse(CalibrationPoint):
|
|
43
|
+
class Config:
|
|
44
|
+
from_attributes = True
|