localgreenchain/lib/environment/types.ts
Claude 85591fc348
Add comprehensive environmental tracking for plants
Implements detailed tracking of soil composition, nutrients, climate,
lighting, and surrounding environment to help understand plant success
and optimize growing conditions.

Environmental Data Types (lib/environment/types.ts):
- Soil composition (type, pH, texture, drainage, organic matter)
- Soil amendments (compost, perlite, amendments tracking)
- Nutrient profiles (NPK, secondary nutrients, micronutrients, EC, TDS)
- Fertilizer applications (type, schedule, NPK values)
- Lighting conditions (natural/artificial, hours, spectrum, PPFD/DLI)
- Climate tracking (temperature, humidity, airflow, CO2, USDA zones)
- Growing location (indoor/outdoor/greenhouse with details)
- Container information (type, material, size, drainage)
- Watering schedule (method, frequency, water quality/pH)
- Surrounding environment (companion plants, pests, diseases, ecosystem)
- Growth metrics (measurements, health scores, vigor tracking)

Environmental Analysis (lib/environment/analysis.ts):
- Compare environments with similarity scoring (0-100)
- Generate personalized growing recommendations
- Calculate environmental health scores
- Find plants with similar conditions
- Analyze growth correlations across network
- Identify optimal growing conditions

API Endpoints:
- /api/environment/recommendations - Get plant-specific advice
- /api/environment/similar - Find plants with similar conditions
- /api/environment/compare - Compare two plants environments
- /api/environment/analysis - Network-wide growth correlation

Features:
- Comprehensive soil tracking (pH, texture, drainage, amendments)
- Full NPK and micronutrient monitoring
- Sunlight exposure and artificial light tracking
- Temperature and humidity ranges
- Water quality monitoring (pH, TDS, chlorine)
- Pest and disease tracking
- Companion planting recommendations
- Environmental health scoring with priority-based recommendations
- Growth success analysis across similar environments

Integration:
- Updated PlantData type to include environment and growthMetrics
- Compatible with existing blockchain structure
- Optional environmental data (backward compatible)

Use Cases:
- Track what works for your plants
- Learn from successful growers with similar conditions
- Get personalized recommendations based on your setup
- Compare your environment with thriving plants
- Optimize conditions for better yield/health
- Share growing knowledge with the community
- Research optimal conditions by species

This enables growers to:
- Understand why plants thrive or struggle
- Replicate successful growing conditions
- Make data-driven decisions
- Learn from the collective experience
- Improve propagation success rates
2025-11-16 16:24:38 +00:00

253 lines
7 KiB
TypeScript

/**
* Environmental Data Types for LocalGreenChain
* Tracks soil, climate, nutrients, and growing conditions
*/
// Soil Composition
export interface SoilComposition {
type: 'clay' | 'sand' | 'silt' | 'loam' | 'peat' | 'chalk' | 'custom';
customType?: string;
// Soil properties
pH: number; // 0-14, most plants 6.0-7.5
texture: 'heavy' | 'medium' | 'light';
drainage: 'poor' | 'moderate' | 'good' | 'excellent';
organicMatter: number; // percentage 0-100
// Composition percentages (should sum to ~100)
clayPercent?: number;
sandPercent?: number;
siltPercent?: number;
// Amendments/additives
amendments?: SoilAmendment[];
notes?: string;
}
export interface SoilAmendment {
type: 'compost' | 'manure' | 'perlite' | 'vermiculite' | 'peat_moss' | 'coco_coir' | 'biochar' | 'lime' | 'sulfur' | 'other';
name: string;
amount?: string; // e.g., "2 cups per gallon", "10%"
dateAdded: string;
}
// Nutrients & Fertilization
export interface NutrientProfile {
// NPK values (percentage)
nitrogen: number; // N
phosphorus: number; // P
potassium: number; // K
// Secondary nutrients
calcium?: number;
magnesium?: number;
sulfur?: number;
// Micronutrients (ppm or mg/L)
iron?: number;
manganese?: number;
zinc?: number;
copper?: number;
boron?: number;
molybdenum?: number;
// EC (Electrical Conductivity) - measure of nutrient concentration
ec?: number; // mS/cm
// TDS (Total Dissolved Solids)
tds?: number; // ppm
lastTested?: string;
}
export interface FertilizerApplication {
id: string;
date: string;
type: 'organic' | 'synthetic' | 'liquid' | 'granular' | 'foliar' | 'slow_release';
name: string;
npk?: string; // e.g., "10-10-10", "5-2-3"
amount: string;
frequency?: string; // e.g., "weekly", "bi-weekly", "monthly"
notes?: string;
}
// Sunlight & Climate
export interface LightingConditions {
type: 'natural' | 'artificial' | 'mixed';
// Natural light
naturalLight?: {
exposure: 'full_sun' | 'partial_sun' | 'partial_shade' | 'full_shade';
hoursPerDay: number; // 0-24
direction: 'north' | 'south' | 'east' | 'west' | 'multiple';
quality: 'direct' | 'filtered' | 'dappled' | 'indirect';
};
// Artificial light
artificialLight?: {
type: 'LED' | 'fluorescent' | 'HPS' | 'MH' | 'incandescent' | 'mixed';
spectrum?: string; // e.g., "full spectrum", "6500K", "2700K"
wattage?: number;
hoursPerDay: number;
distance?: number; // cm from plant
};
// Light measurements
ppfd?: number; // Photosynthetic Photon Flux Density (μmol/m²/s)
dli?: number; // Daily Light Integral (mol/m²/day)
}
export interface ClimateConditions {
// Temperature (Celsius)
temperatureDay: number;
temperatureNight: number;
temperatureMin?: number;
temperatureMax?: number;
// Humidity (percentage)
humidityAverage: number;
humidityMin?: number;
humidityMax?: number;
// Air circulation
airflow: 'none' | 'minimal' | 'moderate' | 'strong';
ventilation: 'poor' | 'adequate' | 'good' | 'excellent';
// CO2 levels (ppm)
co2?: number; // ambient ~400, enhanced ~1200-1500
// Seasonal variation
season?: 'spring' | 'summer' | 'fall' | 'winter';
zone?: string; // USDA hardiness zone, e.g., "9b", "10a"
}
// Growing Environment
export interface GrowingEnvironment {
location: EnvironmentLocation;
container?: ContainerInfo;
soil: SoilComposition;
nutrients: NutrientProfile;
fertilizers?: FertilizerApplication[];
lighting: LightingConditions;
climate: ClimateConditions;
watering: WateringSchedule;
surroundings?: SurroundingEnvironment;
// Tracking
monitoringFrequency?: 'daily' | 'weekly' | 'bi-weekly' | 'monthly';
lastUpdated: string;
notes?: string;
}
export interface EnvironmentLocation {
type: 'indoor' | 'outdoor' | 'greenhouse' | 'polytunnel' | 'shade_house' | 'window' | 'balcony';
description?: string;
// For indoor
room?: string; // e.g., "bedroom", "basement", "grow tent"
// For outdoor
exposureToElements?: 'protected' | 'semi_protected' | 'exposed';
elevation?: number; // meters above sea level
slope?: 'flat' | 'gentle' | 'moderate' | 'steep';
aspect?: 'north' | 'south' | 'east' | 'west'; // slope direction
}
export interface ContainerInfo {
type: 'pot' | 'raised_bed' | 'ground' | 'hydroponic' | 'aeroponic' | 'aquaponic' | 'fabric_pot' | 'hanging_basket';
material?: 'plastic' | 'terracotta' | 'ceramic' | 'fabric' | 'wood' | 'metal' | 'concrete';
size?: string; // e.g., "5 gallon", "30cm diameter", "4x8 feet"
volume?: number; // liters
depth?: number; // cm
drainage: 'yes' | 'no';
drainageHoles?: number;
}
export interface WateringSchedule {
method: 'hand_water' | 'drip' | 'soaker_hose' | 'sprinkler' | 'self_watering' | 'hydroponic' | 'rain';
frequency?: string; // e.g., "daily", "every 2-3 days", "weekly"
amount?: string; // e.g., "1 liter", "until runoff", "1 inch"
waterSource: 'tap' | 'well' | 'rain' | 'filtered' | 'distilled' | 'RO';
waterQuality?: {
pH?: number;
tds?: number; // ppm
chlorine?: 'yes' | 'no' | 'filtered';
};
}
export interface SurroundingEnvironment {
// Companion plants
companionPlants?: string[]; // other plant species nearby
// Nearby features
nearbyTrees?: boolean;
nearbyStructures?: string; // e.g., "building", "wall", "fence"
groundCover?: string; // e.g., "mulch", "grass", "bare soil", "gravel"
// Wildlife & pests
pollinators?: string[]; // e.g., "bees", "butterflies", "hummingbirds"
beneficialInsects?: string[]; // e.g., "ladybugs", "lacewings"
pests?: PestInfo[];
diseases?: DiseaseInfo[];
// Microclimate factors
windExposure?: 'sheltered' | 'moderate' | 'exposed' | 'windy';
frostPocket?: boolean;
heatTrap?: boolean;
// Ecosystem type
ecosystem?: 'urban' | 'suburban' | 'rural' | 'forest' | 'desert' | 'coastal' | 'mountain' | 'tropical';
}
export interface PestInfo {
name: string;
severity: 'minor' | 'moderate' | 'severe';
treatment?: string;
dateObserved: string;
}
export interface DiseaseInfo {
name: string;
symptoms?: string;
severity: 'minor' | 'moderate' | 'severe';
treatment?: string;
dateObserved: string;
}
// Environmental Comparison & Analysis
export interface EnvironmentalComparison {
plant1: string; // plant ID
plant2: string; // plant ID
similarities: string[];
differences: string[];
score: number; // 0-100, how similar the environments are
}
export interface GrowthMetrics {
plantId: string;
measurements: PlantMeasurement[];
healthScore: number; // 0-100
vigor: 'poor' | 'fair' | 'good' | 'excellent';
issues?: string[];
}
export interface PlantMeasurement {
date: string;
height?: number; // cm
width?: number; // cm
leafCount?: number;
flowerCount?: number;
fruitCount?: number;
notes?: string;
photos?: string[];
}
// Helper types for environmental recommendations
export interface EnvironmentalRecommendation {
category: 'soil' | 'nutrients' | 'light' | 'water' | 'climate' | 'general';
priority: 'low' | 'medium' | 'high' | 'critical';
issue: string;
recommendation: string;
impact: string;
}