Photo Management (per specs/photo-management.md): - Sharp integration for 3-size compression (thumb/medium/full) - WebP output with 80-90% quality - Client-side compression with browser-image-compression - PhotoUpload component with camera/drag-drop support - Upload API with bulk support and stats endpoint Testing: - Backend: Jest tests for all major API endpoints - Frontend: Vitest tests for utilities and API clients - CI: Updated Forgejo workflow for test execution Specs (100% coverage): - visitor-management.md (Phase 8) - messaging.md (Phase 9) - audit-and-documents.md (Phase 10) - accessibility-i18n.md (Phase 11) - hardware-integration.md (Phase 12) - advanced-features.md (Phase 13) Documentation: - OpenAPI 3.0 spec (docs/openapi.yaml) - All endpoints documented with schemas
148 lines
3.4 KiB
Markdown
148 lines
3.4 KiB
Markdown
# Feature Spec: Environmental Monitoring & Financial Tracking
|
|
|
|
**Priority**: 🟡 Medium
|
|
**Phase**: 13
|
|
**Status**: ✅ Implemented
|
|
|
|
---
|
|
|
|
## Overview
|
|
|
|
Advanced features for environmental sensor monitoring, financial tracking with cost-per-gram analysis, and AI-powered yield predictions.
|
|
|
|
---
|
|
|
|
## Environmental Monitoring
|
|
|
|
### Models
|
|
|
|
#### Sensor
|
|
|
|
- `id`: UUID
|
|
- `name`: string
|
|
- `type`: enum (TEMPERATURE, HUMIDITY, CO2, LIGHT_PAR, PH, EC, VPD, SOIL_MOISTURE)
|
|
- `roomId`: FK (optional)
|
|
- `location`: string (e.g., "North wall")
|
|
- `deviceId`: string (hardware ID)
|
|
- `minThreshold`: number
|
|
- `maxThreshold`: number
|
|
- `isActive`: boolean
|
|
|
|
#### SensorReading
|
|
|
|
- `id`: UUID
|
|
- `sensorId`: FK
|
|
- `value`: number
|
|
- `unit`: string (°F, %, ppm, etc.)
|
|
- `timestamp`: datetime
|
|
|
|
#### EnvironmentAlert
|
|
|
|
- `id`: UUID
|
|
- `sensorId`: FK (optional)
|
|
- `roomId`: FK (optional)
|
|
- `type`: string (TEMP_HIGH, HUMIDITY_LOW, etc.)
|
|
- `severity`: enum (INFO, WARNING, CRITICAL, EMERGENCY)
|
|
- `message`: string
|
|
- `acknowledgedAt`: datetime
|
|
- `resolvedAt`: datetime
|
|
|
|
### API Endpoints
|
|
|
|
- `GET /api/environment/sensors` - List sensors
|
|
- `POST /api/environment/sensors` - Create sensor
|
|
- `POST /api/environment/sensors/:id/readings` - Submit reading
|
|
- `GET /api/environment/sensors/:id/readings` - Get reading history
|
|
- `GET /api/environment/alerts` - Get alerts
|
|
- `POST /api/environment/alerts/:id/acknowledge` - Ack alert
|
|
- `GET /api/environment/dashboard` - Real-time dashboard
|
|
|
|
---
|
|
|
|
## Financial Tracking
|
|
|
|
### Models
|
|
|
|
#### FinancialTransaction
|
|
|
|
- `id`: UUID
|
|
- `type`: enum (EXPENSE, REVENUE, ADJUSTMENT)
|
|
- `category`: enum (LABOR, NUTRIENTS, SUPPLIES, EQUIPMENT, UTILITIES, etc.)
|
|
- `amount`: number
|
|
- `description`: string
|
|
- `batchId`: FK (optional)
|
|
- `date`: datetime
|
|
|
|
#### BatchCost
|
|
|
|
- `id`: UUID
|
|
- `batchId`: FK (unique)
|
|
- `laborCost`: number
|
|
- `nutrientCost`: number
|
|
- `utilityCost`: number
|
|
- `totalCost`: number
|
|
- `yieldGrams`: number
|
|
- `costPerGram`: number
|
|
|
|
#### Sale
|
|
|
|
- `id`: UUID
|
|
- `batchId`: FK (optional)
|
|
- `product`: string
|
|
- `quantity`: number
|
|
- `pricePerUnit`: number
|
|
- `totalPrice`: number
|
|
|
|
### API Endpoints
|
|
|
|
- `GET /api/financial/transactions` - List transactions with totals
|
|
- `POST /api/financial/transactions` - Create transaction
|
|
- `GET /api/financial/sales` - List sales
|
|
- `POST /api/financial/sales` - Record sale
|
|
- `GET /api/financial/batches/:id/costs` - Batch cost breakdown
|
|
- `GET /api/financial/reports/profit-loss` - P&L report
|
|
- `GET /api/financial/reports/category-breakdown` - Expense breakdown
|
|
- `GET /api/financial/reports/cost-per-gram` - CPG analysis
|
|
|
|
---
|
|
|
|
## AI/ML Insights
|
|
|
|
### Models
|
|
|
|
#### YieldPrediction
|
|
|
|
- `id`: UUID
|
|
- `batchId`: FK
|
|
- `predictedYield`: number (grams)
|
|
- `confidence`: number (0-1)
|
|
- `factors`: JSON
|
|
- `actualYield`: number (filled after harvest)
|
|
- `accuracy`: number
|
|
|
|
#### AnomalyDetection
|
|
|
|
- `id`: UUID
|
|
- `entityType`: string
|
|
- `entityId`: FK
|
|
- `anomalyType`: string
|
|
- `severity`: string
|
|
- `description`: string
|
|
- `isResolved`: boolean
|
|
|
|
### API Endpoints
|
|
|
|
- `POST /api/insights/predict/yield` - Generate yield prediction
|
|
- `GET /api/insights/predictions/:batchId` - Get predictions history
|
|
- `POST /api/insights/detect/anomalies` - Run anomaly detection
|
|
- `GET /api/insights/anomalies` - List anomalies
|
|
- `GET /api/insights/dashboard` - AI insights overview
|
|
|
|
---
|
|
|
|
## Future Enhancements
|
|
|
|
- Real ML model integration (TensorFlow/PyTorch)
|
|
- Predictive maintenance
|
|
- Automated threshold adjustment
|
|
- Integration with accounting software
|