@burdenoff/microfe-healthybowl 2026.1005.2 → 2026.1007.2
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.
- package/dist/healthybowl/components/BedLayoutGrid.js +128 -115
- package/dist/healthybowl/components/BedLayoutGrid.js.map +1 -1
- package/dist/healthybowl/components/CropPicker.js +37 -0
- package/dist/healthybowl/components/CropPicker.js.map +1 -0
- package/dist/healthybowl/components/DataTable.js +125 -108
- package/dist/healthybowl/components/DataTable.js.map +1 -1
- package/dist/healthybowl/components/FilterBar.js +9 -6
- package/dist/healthybowl/components/FilterBar.js.map +1 -1
- package/dist/healthybowl/components/PlantCatalogPicker.js +32 -0
- package/dist/healthybowl/components/PlantCatalogPicker.js.map +1 -0
- package/dist/healthybowl/components/WorkspaceRecordPicker.js +164 -0
- package/dist/healthybowl/components/WorkspaceRecordPicker.js.map +1 -0
- package/dist/healthybowl/components/index.js +3 -1
- package/dist/healthybowl/hooks/useCropPage.js +71 -0
- package/dist/healthybowl/hooks/useCropPage.js.map +1 -0
- package/dist/healthybowl/hooks/usePlantCatalog.js +133 -44
- package/dist/healthybowl/hooks/usePlantCatalog.js.map +1 -1
- package/dist/healthybowl/hooks/usePlantingEstimate.js +6 -6
- package/dist/healthybowl/hooks/usePlantingEstimate.js.map +1 -1
- package/dist/healthybowl/hooks/useWorkspaceRead.js +46 -0
- package/dist/healthybowl/hooks/useWorkspaceRead.js.map +1 -0
- package/dist/healthybowl/pages/HomePage.js +143 -142
- package/dist/healthybowl/pages/HomePage.js.map +1 -1
- package/dist/healthybowl/pages/analytics/ReportsPage.js +8 -8
- package/dist/healthybowl/pages/catalog/PlantCatalogPage.js +266 -192
- package/dist/healthybowl/pages/catalog/PlantCatalogPage.js.map +1 -1
- package/dist/healthybowl/pages/catalog/WorkspaceBrowseFilters.js +58 -0
- package/dist/healthybowl/pages/catalog/WorkspaceBrowseFilters.js.map +1 -0
- package/dist/healthybowl/pages/catalog/browsePagination.js +24 -0
- package/dist/healthybowl/pages/catalog/browsePagination.js.map +1 -0
- package/dist/healthybowl/pages/compliance/ComplianceDocumentsPage.js +6 -6
- package/dist/healthybowl/pages/crops/CropDetailsPage.js +340 -348
- package/dist/healthybowl/pages/crops/CropDetailsPage.js.map +1 -1
- package/dist/healthybowl/pages/crops/CropPlanningPage.js +468 -434
- package/dist/healthybowl/pages/crops/CropPlanningPage.js.map +1 -1
- package/dist/healthybowl/pages/crops/CropsPage.js +633 -542
- package/dist/healthybowl/pages/crops/CropsPage.js.map +1 -1
- package/dist/healthybowl/pages/crops/FieldDetailsPage.js +875 -800
- package/dist/healthybowl/pages/crops/FieldDetailsPage.js.map +1 -1
- package/dist/healthybowl/pages/crops/PlanningDetailsPage.js +459 -448
- package/dist/healthybowl/pages/crops/PlanningDetailsPage.js.map +1 -1
- package/dist/healthybowl/pages/crops/SuccessionCropLabel.js +21 -0
- package/dist/healthybowl/pages/crops/SuccessionCropLabel.js.map +1 -0
- package/dist/healthybowl/pages/crops/planningEdit.js +30 -0
- package/dist/healthybowl/pages/crops/planningEdit.js.map +1 -0
- package/dist/healthybowl/pages/fields/FieldMapPage.js +989 -941
- package/dist/healthybowl/pages/fields/FieldMapPage.js.map +1 -1
- package/dist/healthybowl/pages/financial/GeneralLedgerPage.js +6 -6
- package/dist/healthybowl/pages/financial/InvoiceManagementPage.js +7 -7
- package/dist/healthybowl/pages/financial/InvoiceManagementPage.js.map +1 -1
- package/dist/healthybowl/pages/financial/TransactionsPage.js +541 -541
- package/dist/healthybowl/pages/financial/TransactionsPage.js.map +1 -1
- package/dist/healthybowl/pages/government-schemes/ApplicationTrackingPage.js +10 -10
- package/dist/healthybowl/pages/government-schemes/CommunicationPage.js +207 -207
- package/dist/healthybowl/pages/government-schemes/CommunicationPage.js.map +1 -1
- package/dist/healthybowl/pages/government-schemes/SchemeAdminPage.js +38 -38
- package/dist/healthybowl/pages/government-schemes/SchemeAdminPage.js.map +1 -1
- package/dist/healthybowl/pages/government-schemes/TrainingProgramsPage.js +15 -15
- package/dist/healthybowl/pages/government-schemes/TrainingProgramsPage.js.map +1 -1
- package/dist/healthybowl/pages/livestock/AnimalRegistryPage.js +4 -4
- package/dist/healthybowl/pages/livestock/BreedingManagementPage.js +4 -4
- package/dist/healthybowl/pages/livestock/FeedManagementPage.js +4 -4
- package/dist/healthybowl/pages/livestock/HealthRecordsPage.js +16 -16
- package/dist/healthybowl/pages/livestock/HealthRecordsPage.js.map +1 -1
- package/dist/healthybowl/pages/livestock/ProductionTrackingPage.js +4 -4
- package/dist/healthybowl/pages/livestock/VaccinationSchedulePage.js +4 -4
- package/dist/healthybowl/pages/market/MarketPricesPage.js +305 -305
- package/dist/healthybowl/pages/market/MarketPricesPage.js.map +1 -1
- package/dist/healthybowl/pages/network/CohortsPage.js +107 -107
- package/dist/healthybowl/pages/network/CohortsPage.js.map +1 -1
- package/dist/healthybowl/pages/network/CommunityPage.js +247 -247
- package/dist/healthybowl/pages/network/CommunityPage.js.map +1 -1
- package/dist/healthybowl/pages/network/EventsPage.js +16 -16
- package/dist/healthybowl/pages/network/EventsPage.js.map +1 -1
- package/dist/healthybowl/pages/network/ExpertsPage.js +470 -470
- package/dist/healthybowl/pages/network/ExpertsPage.js.map +1 -1
- package/dist/healthybowl/pages/network/MentorsPage.js +6 -6
- package/dist/healthybowl/pages/pest-management/PestIssuesPage.js +8 -8
- package/dist/healthybowl/pages/pest-management/TreatmentLibraryPage.js +7 -7
- package/dist/healthybowl/pages/pest-management/TreatmentLibraryPage.js.map +1 -1
- package/dist/healthybowl/pages/production/ProductionBatchesPage.js +7 -7
- package/dist/healthybowl/pages/production/RecipeManagementPage.js +5 -5
- package/dist/healthybowl/pages/production/ValueAddedProductsPage.js +7 -7
- package/dist/healthybowl/pages/soil/SoilTestsPage.js +6 -6
- package/dist/healthybowl/pages/soil/SoilTestsPage.js.map +1 -1
- package/dist/healthybowl/pages/suppliers/SuppliersPage.js +10 -10
- package/dist/healthybowl/pages/sustainability/CarbonCreditLedgerPage.js +6 -6
- package/dist/healthybowl/pages/terrace/PlantingFormModal.js +151 -131
- package/dist/healthybowl/pages/terrace/PlantingFormModal.js.map +1 -1
- package/dist/healthybowl/pages/traceability/BatchTrackingPage.js +6 -6
- package/dist/healthybowl/utils/cropComparison.js +1 -1
- package/dist/healthybowl/utils/cropComparison.js.map +1 -1
- package/dist/healthybowl/utils/cropPicker.js +35 -0
- package/dist/healthybowl/utils/cropPicker.js.map +1 -0
- package/dist/healthybowl/utils/plantingCapacity.js +2 -2
- package/dist/healthybowl/utils/plantingCapacity.js.map +1 -1
- package/dist/healthybowl/utils/quotaLabels.js +8 -0
- package/dist/healthybowl/utils/quotaLabels.js.map +1 -0
- package/dist/healthybowl/utils/seedRate.js +1 -8
- package/dist/healthybowl/utils/seedRate.js.map +1 -1
- package/package.json +1 -1
|
@@ -2,10 +2,10 @@ import { formatDate as e } from "../../utils/helpers.js";
|
|
|
2
2
|
import { PageLayout as t } from "../../components/PageLayout.js";
|
|
3
3
|
import { useBasePath as n } from "../../hooks/useBasePath.js";
|
|
4
4
|
import { DataTable as r } from "../../components/DataTable.js";
|
|
5
|
-
import {
|
|
5
|
+
import { FilterBar as ee } from "../../components/FilterBar.js";
|
|
6
|
+
import { StatusBadge as te } from "../../components/StatusBadge.js";
|
|
6
7
|
import { EmptyState as i } from "../../components/EmptyState.js";
|
|
7
|
-
import { ErrorState as
|
|
8
|
-
import { FilterBar as ne } from "../../components/FilterBar.js";
|
|
8
|
+
import { ErrorState as ne } from "../../components/ErrorState.js";
|
|
9
9
|
import { ToastContainer as re } from "../../components/Toast.js";
|
|
10
10
|
import { useConfirm as ie } from "../../components/ConfirmDialog.js";
|
|
11
11
|
import { LoadingSkeleton as ae } from "../../components/LoadingSkeleton.js";
|
|
@@ -231,7 +231,7 @@ var be = [
|
|
|
231
231
|
{
|
|
232
232
|
key: "status",
|
|
233
233
|
header: S("healthybowl.traceability.batchTracking.table.headers.status", "Status"),
|
|
234
|
-
render: (e) => /* @__PURE__ */ p(
|
|
234
|
+
render: (e) => /* @__PURE__ */ p(te, {
|
|
235
235
|
label: (e.status ?? "unknown").replace(/_/g, " "),
|
|
236
236
|
variant: xe(e.status ?? "unknown")
|
|
237
237
|
})
|
|
@@ -351,7 +351,7 @@ var be = [
|
|
|
351
351
|
illustration: "empty-data",
|
|
352
352
|
title: S("healthybowl.traceability.batchTracking.errorState.title", "Unable to load traceability data"),
|
|
353
353
|
description: O.message
|
|
354
|
-
}) : C.length === 0 ? k.traceability ? /* @__PURE__ */ p(
|
|
354
|
+
}) : C.length === 0 ? k.traceability ? /* @__PURE__ */ p(ne, {}) : /* @__PURE__ */ p(i, {
|
|
355
355
|
illustration: "empty-search",
|
|
356
356
|
title: S("healthybowl.traceability.batchTracking.emptyState.title", "No trace batches yet"),
|
|
357
357
|
description: S("healthybowl.traceability.batchTracking.emptyState.description", "Create your first tamper-proof trace batch to record its journey from harvest to dispatch with hash-chained events and GS1-standard codes."),
|
|
@@ -366,7 +366,7 @@ var be = [
|
|
|
366
366
|
S("healthybowl.traceability.batchTracking.actions.addBatch", "Add Batch")
|
|
367
367
|
]
|
|
368
368
|
})
|
|
369
|
-
}) : /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p(
|
|
369
|
+
}) : /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p(ee, {
|
|
370
370
|
searchValue: M,
|
|
371
371
|
onSearchChange: De,
|
|
372
372
|
searchPlaceholder: S("healthybowl.traceability.batchTracking.searchPlaceholder", "Search batches...")
|
|
@@ -31,7 +31,7 @@ function i(i, a) {
|
|
|
31
31
|
label: f ? `${o.name} - ${f}` : o.name,
|
|
32
32
|
plantSpacingCm: c,
|
|
33
33
|
rowSpacingCm: l,
|
|
34
|
-
spacingFromCatalog: o.plantSpacingCm != null && o.plantSpacingCm > 0 && o.rowSpacingCm != null && o.rowSpacingCm > 0,
|
|
34
|
+
spacingFromCatalog: o.plantSpacingCm != null && Number.isFinite(o.plantSpacingCm) && o.plantSpacingCm > 0 && o.rowSpacingCm != null && Number.isFinite(o.rowSpacingCm) && o.rowSpacingCm > 0,
|
|
35
35
|
presetLabel: i.label,
|
|
36
36
|
daysToMaturity: o.daysToMaturity != null && Number.isFinite(o.daysToMaturity) ? o.daysToMaturity : null,
|
|
37
37
|
capacity: u,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cropComparison.js","names":[],"sources":["../../../src/healthybowl/utils/cropComparison.ts"],"sourcesContent":["/**\n * Per-field crop comparison.\n *\n * The planting-capacity and seed-rate panels answer \"how many beds and how much\n * seed?\" for ONE crop at a time. To compare candidates a grower had to change the\n * selector and re-read the numbers each time. This module runs the same two\n * calculations across every variety in the Master Plant List against one field,\n * so the whole shortlist can be read as a table.\n *\n * Pure functions — no I/O, no React — so the arithmetic stays unit-testable and\n * the page is only responsible for rendering.\n * @module healthybowl\n */\n\nimport { estimatePlantingCapacity, getCropSpacingPreset, type PlantingCapacityEstimate } from './plantingCapacity';\nimport { computeSeedRate, type SeedRateResult } from './seedRate';\n\n/**\n * A variety to evaluate. Structurally compatible with `PlantCatalogEntry` but\n * declared here so this module keeps the dependency-free shape of its siblings.\n */\nexport interface CropComparisonCandidate {\n id: string;\n name: string;\n variety?: string | null;\n category?: string | null;\n plantSpacingCm?: number | null;\n rowSpacingCm?: number | null;\n daysToMaturity?: number | null;\n seedsPerGram?: number | null;\n germinationRate?: number | null;\n seedsPerCell?: number | null;\n}\n\n/** One row of the comparison: a variety plus its computed capacity and seed rate. */\nexport interface CropComparisonRow {\n id: string;\n name: string;\n variety: string | null;\n /** Display label, e.g. \"Tomato - Arka Rakshak\". */\n label: string;\n /** Spacing actually used (catalog value when present, otherwise the preset). */\n plantSpacingCm: number;\n rowSpacingCm: number;\n /**\n * True only when the catalog entry supplied BOTH spacing dimensions.\n *\n * The two are recorded independently, so an entry can define plant spacing\n * and leave row spacing unset. Treating that as fully catalog-sourced would\n * hide the \"preset spacing\" disclosure and present a defaulted number as one\n * the grower had recorded — so a partially-filled entry counts as preset.\n */\n spacingFromCatalog: boolean;\n /** Crop-family preset label, e.g. \"Leafy greens\". */\n presetLabel: string;\n daysToMaturity: number | null;\n capacity: PlantingCapacityEstimate;\n seed: SeedRateResult;\n}\n\nexport interface CropComparisonOptions {\n fieldArea: number;\n fieldUnit: string;\n bedWidthM?: number;\n pathWidthM?: number;\n}\n\n/** Columns the table can be ordered by. */\nexport type CropComparisonSortKey = 'label' | 'totalPlants' | 'seedGrams' | 'trays' | 'daysToMaturity';\nexport type SortDirection = 'asc' | 'desc';\n\nconst positiveOr = (value: number | null | undefined, fallback: number): number =>\n value != null && Number.isFinite(value) && value > 0 ? value : fallback;\n\n/**\n * Evaluate every candidate against one field.\n *\n * Spacing resolution per variety: the catalog entry's own `plantSpacingCm` /\n * `rowSpacingCm` win; anything it leaves unset falls back to the crop-family\n * preset matched from its name/category/variety. Candidates are skipped when the\n * field has no usable area (capacity would be undefined, not zero).\n *\n * Rows come back ordered by label so the output is deterministic; use\n * `sortCropComparison` for any other order.\n */\nexport function buildCropComparison(\n candidates: CropComparisonCandidate[],\n options: CropComparisonOptions\n): CropComparisonRow[] {\n const rows: CropComparisonRow[] = [];\n\n for (const candidate of candidates) {\n //
|
|
1
|
+
{"version":3,"file":"cropComparison.js","names":[],"sources":["../../../src/healthybowl/utils/cropComparison.ts"],"sourcesContent":["/**\n * Per-field crop comparison.\n *\n * The planting-capacity and seed-rate panels answer \"how many beds and how much\n * seed?\" for ONE crop at a time. To compare candidates a grower had to change the\n * selector and re-read the numbers each time. This module runs the same two\n * calculations across every variety in the Master Plant List against one field,\n * so the whole shortlist can be read as a table.\n *\n * Pure functions — no I/O, no React — so the arithmetic stays unit-testable and\n * the page is only responsible for rendering.\n * @module healthybowl\n */\n\nimport { estimatePlantingCapacity, getCropSpacingPreset, type PlantingCapacityEstimate } from './plantingCapacity';\nimport { computeSeedRate, type SeedRateResult } from './seedRate';\n\n/**\n * A variety to evaluate. Structurally compatible with `PlantCatalogEntry` but\n * declared here so this module keeps the dependency-free shape of its siblings.\n */\nexport interface CropComparisonCandidate {\n id: string;\n name: string;\n variety?: string | null;\n category?: string | null;\n plantSpacingCm?: number | null;\n rowSpacingCm?: number | null;\n daysToMaturity?: number | null;\n seedsPerGram?: number | null;\n germinationRate?: number | null;\n seedsPerCell?: number | null;\n}\n\n/** One row of the comparison: a variety plus its computed capacity and seed rate. */\nexport interface CropComparisonRow {\n id: string;\n name: string;\n variety: string | null;\n /** Display label, e.g. \"Tomato - Arka Rakshak\". */\n label: string;\n /** Spacing actually used (catalog value when present, otherwise the preset). */\n plantSpacingCm: number;\n rowSpacingCm: number;\n /**\n * True only when the catalog entry supplied BOTH spacing dimensions.\n *\n * The two are recorded independently, so an entry can define plant spacing\n * and leave row spacing unset. Treating that as fully catalog-sourced would\n * hide the \"preset spacing\" disclosure and present a defaulted number as one\n * the grower had recorded — so a partially-filled entry counts as preset.\n */\n spacingFromCatalog: boolean;\n /** Crop-family preset label, e.g. \"Leafy greens\". */\n presetLabel: string;\n daysToMaturity: number | null;\n capacity: PlantingCapacityEstimate;\n seed: SeedRateResult;\n}\n\nexport interface CropComparisonOptions {\n fieldArea: number;\n fieldUnit: string;\n bedWidthM?: number;\n pathWidthM?: number;\n}\n\n/** Columns the table can be ordered by. */\nexport type CropComparisonSortKey = 'label' | 'totalPlants' | 'seedGrams' | 'trays' | 'daysToMaturity';\nexport type SortDirection = 'asc' | 'desc';\n\nconst positiveOr = (value: number | null | undefined, fallback: number): number =>\n value != null && Number.isFinite(value) && value > 0 ? value : fallback;\n\n/**\n * Evaluate every candidate against one field.\n *\n * Spacing resolution per variety: the catalog entry's own `plantSpacingCm` /\n * `rowSpacingCm` win; anything it leaves unset falls back to the crop-family\n * preset matched from its name/category/variety. Candidates are skipped when the\n * field has no usable area (capacity would be undefined, not zero).\n *\n * Rows come back ordered by label so the output is deterministic; use\n * `sortCropComparison` for any other order.\n */\nexport function buildCropComparison(\n candidates: CropComparisonCandidate[],\n options: CropComparisonOptions\n): CropComparisonRow[] {\n const rows: CropComparisonRow[] = [];\n\n for (const candidate of candidates) {\n // The combined name + variety tier wins before category; absent optional\n // catalog values are passed as empty strings to the Crop-shaped selector.\n const preset = getCropSpacingPreset({\n name: candidate.name,\n category: candidate.category ?? '',\n variety: candidate.variety ?? '',\n });\n const plantSpacingCm = positiveOr(candidate.plantSpacingCm, preset.plantSpacingCm);\n const rowSpacingCm = positiveOr(candidate.rowSpacingCm, preset.rowSpacingCm);\n\n const capacity = estimatePlantingCapacity({\n fieldArea: options.fieldArea,\n fieldUnit: options.fieldUnit,\n plantSpacingCm,\n rowSpacingCm,\n bedWidthM: options.bedWidthM,\n pathWidthM: options.pathWidthM,\n });\n // No area on the field — there is nothing honest to show for this variety.\n if (!capacity) continue;\n\n const seed = computeSeedRate({\n plantsNeeded: capacity.totalPlants,\n seedsPerGram: candidate.seedsPerGram,\n germinationRate: candidate.germinationRate,\n seedsPerCell: candidate.seedsPerCell,\n });\n\n const variety = candidate.variety?.trim() ? candidate.variety.trim() : null;\n rows.push({\n id: candidate.id,\n name: candidate.name,\n variety,\n label: variety ? `${candidate.name} - ${variety}` : candidate.name,\n plantSpacingCm,\n rowSpacingCm,\n spacingFromCatalog:\n candidate.plantSpacingCm != null &&\n Number.isFinite(candidate.plantSpacingCm) &&\n candidate.plantSpacingCm > 0 &&\n candidate.rowSpacingCm != null &&\n Number.isFinite(candidate.rowSpacingCm) &&\n candidate.rowSpacingCm > 0,\n presetLabel: preset.label,\n daysToMaturity:\n candidate.daysToMaturity != null && Number.isFinite(candidate.daysToMaturity) ? candidate.daysToMaturity : null,\n capacity,\n seed,\n });\n }\n\n return sortCropComparison(rows, 'label', 'asc');\n}\n\nconst valueForKey = (row: CropComparisonRow, key: CropComparisonSortKey): number | string | null => {\n switch (key) {\n case 'label':\n return row.label.toLowerCase();\n case 'totalPlants':\n return row.capacity.totalPlants;\n case 'seedGrams':\n return row.seed.seedGrams;\n case 'trays':\n return row.seed.trays;\n case 'daysToMaturity':\n return row.daysToMaturity;\n }\n};\n\n/**\n * Order the comparison. Unknown values (a variety with no seeds-per-gram, say)\n * always sort last regardless of direction — they are missing data, not a low\n * score, and burying them under a \"worst first\" sort would misrepresent them.\n */\nexport function sortCropComparison(\n rows: CropComparisonRow[],\n key: CropComparisonSortKey,\n direction: SortDirection\n): CropComparisonRow[] {\n const factor = direction === 'asc' ? 1 : -1;\n return [...rows].sort((a, b) => {\n const left = valueForKey(a, key);\n const right = valueForKey(b, key);\n if (left == null && right == null) return a.label.localeCompare(b.label);\n if (left == null) return 1;\n if (right == null) return -1;\n if (typeof left === 'string' || typeof right === 'string') {\n return String(left).localeCompare(String(right)) * factor;\n }\n if (left === right) return a.label.localeCompare(b.label);\n return (left - right) * factor;\n });\n}\n"],"mappings":";;;AAuEA,IAAM,KAAc,GAAkC,MACpD,KAAS,QAAQ,OAAO,SAAS,CAAK,KAAK,IAAQ,IAAI,IAAQ;AAajE,SAAgB,EACd,GACA,GACqB;CACrB,IAAM,IAA4B,CAAC;CAEnC,KAAK,IAAM,KAAa,GAAY;EAGlC,IAAM,IAAS,EAAqB;GAClC,MAAM,EAAU;GAChB,UAAU,EAAU,YAAY;GAChC,SAAS,EAAU,WAAW;EAChC,CAAC,GACK,IAAiB,EAAW,EAAU,gBAAgB,EAAO,cAAc,GAC3E,IAAe,EAAW,EAAU,cAAc,EAAO,YAAY,GAErE,IAAW,EAAyB;GACxC,WAAW,EAAQ;GACnB,WAAW,EAAQ;GACnB;GACA;GACA,WAAW,EAAQ;GACnB,YAAY,EAAQ;EACtB,CAAC;EAED,IAAI,CAAC,GAAU;EAEf,IAAM,IAAO,EAAgB;GAC3B,cAAc,EAAS;GACvB,cAAc,EAAU;GACxB,iBAAiB,EAAU;GAC3B,cAAc,EAAU;EAC1B,CAAC,GAEK,IAAU,EAAU,SAAS,KAAK,IAAI,EAAU,QAAQ,KAAK,IAAI;EACvE,EAAK,KAAK;GACR,IAAI,EAAU;GACd,MAAM,EAAU;GAChB;G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name} - ${t}` : e.name;
|
|
5
|
+
}
|
|
6
|
+
function t(e) {
|
|
7
|
+
return e.category?.trim() ? e.category : null;
|
|
8
|
+
}
|
|
9
|
+
function n(e) {
|
|
10
|
+
let t = /* @__PURE__ */ new Map();
|
|
11
|
+
for (let n of e) n.id && !t.has(n.id) && t.set(n.id, n);
|
|
12
|
+
return [...t.values()];
|
|
13
|
+
}
|
|
14
|
+
function r(e) {
|
|
15
|
+
let r = /* @__PURE__ */ new Map();
|
|
16
|
+
for (let i of n(e)) {
|
|
17
|
+
let e = t(i), n = r.get(e) ?? [];
|
|
18
|
+
n.push(i), r.set(e, n);
|
|
19
|
+
}
|
|
20
|
+
return [...r].map(([e, t]) => ({
|
|
21
|
+
category: e,
|
|
22
|
+
label: e ?? "Uncategorized",
|
|
23
|
+
items: t
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
function i(e, t, r) {
|
|
27
|
+
return n(!r.search.trim() && !r.category && !r.uncategorized && r.offset === 0 ? [...t, ...e] : e);
|
|
28
|
+
}
|
|
29
|
+
function a(e, t) {
|
|
30
|
+
return n(t ? [...e, t] : e);
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { n as deduplicatePickerRecords, r as groupPickerRecords, e as pickerRecordLabel, i as pickerVisibleRecords, a as retainedPickerRecords };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=cropPicker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cropPicker.js","names":[],"sources":["../../../src/healthybowl/utils/cropPicker.ts"],"sourcesContent":["export interface PickerRecord {\n id: string;\n name: string;\n category?: string | null;\n variety?: string | null;\n}\n\nexport interface PickerGroup<T> {\n /** Null represents missing/blank categories only; other category strings remain raw. */\n category: string | null;\n label: string;\n items: T[];\n}\n\nexport function pickerRecordLabel(record: Pick<PickerRecord, 'name' | 'variety'>): string {\n const variety = record.variety?.trim();\n return variety ? `${record.name} - ${variety}` : record.name;\n}\n\nexport function pickerCategory(record: Pick<PickerRecord, 'category'>): string | null {\n return record.category?.trim() ? record.category : null;\n}\n\n/** First occurrence wins: already-loaded field-first records keep their actual identity. */\nexport function deduplicatePickerRecords<T extends PickerRecord>(records: readonly T[]): T[] {\n const byId = new Map<string, T>();\n for (const record of records) {\n if (record.id && !byId.has(record.id)) byId.set(record.id, record);\n }\n return [...byId.values()];\n}\n\nexport function groupPickerRecords<T extends PickerRecord>(records: readonly T[]): PickerGroup<T>[] {\n const groups = new Map<string | null, T[]>();\n for (const record of deduplicatePickerRecords(records)) {\n const category = pickerCategory(record);\n const group = groups.get(category) ?? [];\n group.push(record);\n groups.set(category, group);\n }\n return [...groups].map(([category, items]) => ({ category, label: category ?? 'Uncategorized', items }));\n}\n\n/** Supplied options are preferences on the unfiltered first page, not exhaustive server results. */\nexport function pickerVisibleRecords<T extends PickerRecord>(\n page: readonly T[],\n supplied: readonly T[],\n browse: { search: string; category: string; uncategorized: boolean; offset: number }\n): T[] {\n const unfilteredFirstPage = !browse.search.trim() && !browse.category && !browse.uncategorized && browse.offset === 0;\n return deduplicatePickerRecords(unfilteredFirstPage ? [...supplied, ...page] : page);\n}\n\nexport function retainedPickerRecords<T extends PickerRecord>(records: readonly T[], selected: T | null): T[] {\n return deduplicatePickerRecords(selected ? [...records, selected] : records);\n}\n"],"mappings":";AAcA,SAAgB,EAAkB,GAAwD;CACxF,IAAM,IAAU,EAAO,SAAS,KAAK;CACrC,OAAO,IAAU,GAAG,EAAO,KAAK,KAAK,MAAY,EAAO;AAC1D;AAEA,SAAgB,EAAe,GAAuD;CACpF,OAAO,EAAO,UAAU,KAAK,IAAI,EAAO,WAAW;AACrD;AAGA,SAAgB,EAAiD,GAA4B;CAC3F,IAAM,oBAAO,IAAI,IAAe;CAChC,KAAK,IAAM,KAAU,GACnB,AAAI,EAAO,MAAM,CAAC,EAAK,IAAI,EAAO,EAAE,KAAG,EAAK,IAAI,EAAO,IAAI,CAAM;CAEnE,OAAO,CAAC,GAAG,EAAK,OAAO,CAAC;AAC1B;AAEA,SAAgB,EAA2C,GAAyC;CAClG,IAAM,oBAAS,IAAI,IAAwB;CAC3C,KAAK,IAAM,KAAU,EAAyB,CAAO,GAAG;EACtD,IAAM,IAAW,EAAe,CAAM,GAChC,IAAQ,EAAO,IAAI,CAAQ,KAAK,CAAC;EAEvC,AADA,EAAM,KAAK,CAAM,GACjB,EAAO,IAAI,GAAU,CAAK;CAC5B;CACA,OAAO,CAAC,GAAG,CAAM,EAAE,KAAK,CAAC,GAAU,QAAY;EAAE;EAAU,OAAO,KAAY;EAAiB;CAAM,EAAE;AACzG;AAGA,SAAgB,EACd,GACA,GACA,GACK;CAEL,OAAO,EADqB,CAAC,EAAO,OAAO,KAAK,KAAK,CAAC,EAAO,YAAY,CAAC,EAAO,iBAAiB,EAAO,WAAW,IAC9D,CAAC,GAAG,GAAU,GAAG,CAAI,IAAI,CAAI;AACrF;AAEA,SAAgB,EAA8C,GAAuB,GAAyB;CAC5G,OAAO,EAAyB,IAAW,CAAC,GAAG,GAAS,CAAQ,IAAI,CAAO;AAC7E"}
|
|
@@ -65,13 +65,13 @@ var t = 1.2, n = .45, r = 4046.8564224, i = 1e4, a = 1.1, o = {
|
|
|
65
65
|
rowSpacingCm: 30,
|
|
66
66
|
match: /\b(?:herb|herbs|basil|mint|peppermint|spearmint|dill|parsley)\b/i
|
|
67
67
|
}
|
|
68
|
-
], c = (e, t) => Number.isFinite(e) &&
|
|
68
|
+
], c = (e, t) => typeof e == "number" && Number.isFinite(e) && e > 0 ? e : t, l = (e, t) => {
|
|
69
69
|
if (!Number.isFinite(e) || e <= 0) return 0;
|
|
70
70
|
let n = String(t).trim().toLowerCase();
|
|
71
71
|
return n === "hectares" || n === "hectare" || n === "ha" ? e * i : n === "sqm" || n === "m2" || n === "sq_m" || n === "square_meters" || n === "square meters" || n === "square_metres" || n === "square metres" ? e : e * r;
|
|
72
72
|
}, u = (e) => {
|
|
73
73
|
if (!e) return o;
|
|
74
|
-
let t = `${e.name ?? ""} ${e.
|
|
74
|
+
let t = `${e.name ?? ""} ${e.variety ?? ""}`, n = s.find((e) => e.match.test(t)) ?? s.find((t) => t.match.test(e.category ?? ""));
|
|
75
75
|
return n ? {
|
|
76
76
|
label: n.label,
|
|
77
77
|
plantSpacingCm: n.plantSpacingCm,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plantingCapacity.js","names":[],"sources":["../../../src/healthybowl/utils/plantingCapacity.ts"],"sourcesContent":["import type { Crop, Field } from '../types';\nimport { capacityModelFor, type CapacityModel } from './growLocationType';\n\nexport const DEFAULT_BED_WIDTH_M = 1.2;\nexport const DEFAULT_PATH_WIDTH_M = 0.45;\nexport const DEFAULT_PLANT_SPACING_CM = 45;\nexport const DEFAULT_ROW_SPACING_CM = 60;\n\nconst ACRE_TO_SQUARE_METERS = 4046.8564224;\nconst HECTARE_TO_SQUARE_METERS = 10_000;\nconst SEEDLING_BUFFER = 1.1;\n\nexport interface CropSpacingPreset {\n label: string;\n plantSpacingCm: number;\n rowSpacingCm: number;\n}\n\nexport interface PlantingCapacityInput {\n fieldArea: number;\n fieldUnit: Field['unit'] | string;\n plantSpacingCm?: number;\n rowSpacingCm?: number;\n bedWidthM?: number;\n pathWidthM?: number;\n}\n\nexport interface PlantingCapacityEstimate {\n areaSqm: number;\n cultivableAreaSqm: number;\n bedCount: number;\n bedLengthM: number;\n rowsPerBed: number;\n plantsPerRow: number;\n plantsPerBed: number;\n totalPlants: number;\n seedlingTarget: number;\n plantSpacingCm: number;\n rowSpacingCm: number;\n bedWidthM: number;\n pathWidthM: number;\n densityPlantsPerSqm: number;\n}\n\nexport const DEFAULT_CROP_SPACING_PRESET: CropSpacingPreset = {\n label: 'Standard vegetables',\n plantSpacingCm: DEFAULT_PLANT_SPACING_CM,\n rowSpacingCm: DEFAULT_ROW_SPACING_CM,\n};\n\n/**\n * Spacing presets, matched against a crop's name / category / variety.\n *\n * **Every pattern is word-anchored (`\\b…\\b`) — a fix, not a style choice (BOFF-6100).** The\n * patterns used to match bare substrings, so real crops landed on the wrong preset:\n *\n * | crop | matched | via | spacing it got |\n * |---|---|---|---|\n * | Peach | Legumes | `pea` in \"**Pea**ch\" | 15cm — an orchard tree at pea spacing |\n * | Peppermint | Tomato | `pepper` in \"**Pepper**mint\" | 45cm instead of 25cm |\n * | Spearmint | Legumes | `pea` in \"S**pea**rmint\" | 15cm |\n * | Green Gram | Leafy greens | `green`, checked before Legumes | 20/25 instead of 15/45 |\n * | *anything* named \"Something…\" | Leafy greens | `methi` in \"So**methi**ng\" | 20cm |\n *\n * `greens?` also lost its optional `s` — bare \"green\" was too weak a signal and was stealing green\n * gram (moong, a pulse) from Legumes purely by list order. The mints, peanut and groundnut are now\n * named explicitly rather than caught by accident.\n *\n * `wspace-healthybowl-svc`'s `planting/planting-math.ts` carries the identical table: BOFF-6100\n * made the server derive what it persists, and the two copies share their test vectors so they\n * cannot drift.\n */\nconst CROP_SPACING_PRESETS: Array<CropSpacingPreset & { match: RegExp }> = [\n {\n label: 'Leafy greens',\n plantSpacingCm: 20,\n rowSpacingCm: 25,\n match: /\\b(?:leafy|lettuce|spinach|amaranth|coriander|cilantro|fenugreek|methi|greens)\\b/i,\n },\n {\n label: 'Tomato and fruiting vegetables',\n plantSpacingCm: 45,\n rowSpacingCm: 60,\n match: /\\b(?:tomato|tomatoes|brinjal|eggplant|chilli|chillies|chili|pepper|peppers|capsicum|okra|bhindi)\\b/i,\n },\n { label: 'Brassicas', plantSpacingCm: 45, rowSpacingCm: 60, match: /\\b(?:cabbage|cauliflower|broccoli|kale)\\b/i },\n {\n label: 'Root crops',\n plantSpacingCm: 10,\n rowSpacingCm: 30,\n match: /\\b(?:carrot|carrots|radish|beet|beetroot|onion|onions|garlic|root)\\b/i,\n },\n { label: 'Potato', plantSpacingCm: 30, rowSpacingCm: 60, match: /\\bpotato(?:es)?\\b/i },\n {\n label: 'Legumes',\n plantSpacingCm: 15,\n rowSpacingCm: 45,\n match: /\\b(?:bean|beans|pea|peas|legume|legumes|lentil|lentils|gram|peanut|groundnut)\\b/i,\n },\n {\n label: 'Cucurbits',\n plantSpacingCm: 90,\n rowSpacingCm: 120,\n match: /\\b(?:cucumber|pumpkin|melon|watermelon|muskmelon|squash|gourd|zucchini)\\b/i,\n },\n { label: 'Grains', plantSpacingCm: 20, rowSpacingCm: 20, match: /\\b(?:rice|paddy|wheat|millet|grain|grains)\\b/i },\n { label: 'Maize', plantSpacingCm: 20, rowSpacingCm: 60, match: /\\b(?:maize|corn)\\b/i },\n {\n label: 'Herbs',\n plantSpacingCm: 25,\n rowSpacingCm: 30,\n match: /\\b(?:herb|herbs|basil|mint|peppermint|spearmint|dill|parsley)\\b/i,\n },\n];\n\nconst positiveNumber = (value: number | undefined, fallback: number) =>\n Number.isFinite(value) && (value ?? 0) > 0 ? (value as number) : fallback;\n\nexport const areaToSquareMeters = (area: number, unit: Field['unit'] | string): number => {\n if (!Number.isFinite(area) || area <= 0) return 0;\n\n const normalizedUnit = String(unit).trim().toLowerCase();\n\n if (normalizedUnit === 'hectares' || normalizedUnit === 'hectare' || normalizedUnit === 'ha') {\n return area * HECTARE_TO_SQUARE_METERS;\n }\n\n if (\n normalizedUnit === 'sqm' ||\n normalizedUnit === 'm2' ||\n normalizedUnit === 'sq_m' ||\n normalizedUnit === 'square_meters' ||\n normalizedUnit === 'square meters' ||\n normalizedUnit === 'square_metres' ||\n normalizedUnit === 'square metres'\n ) {\n return area;\n }\n\n return area * ACRE_TO_SQUARE_METERS;\n};\n\nexport const getCropSpacingPreset = (crop?: Pick<Crop, 'name' | 'category' | 'variety'> | null): CropSpacingPreset => {\n if (!crop) return DEFAULT_CROP_SPACING_PRESET;\n\n const searchable = `${crop.name ?? ''} ${crop.category ?? ''} ${crop.variety ?? ''}`;\n const preset = CROP_SPACING_PRESETS.find((item) => item.match.test(searchable));\n\n return preset\n ? { label: preset.label, plantSpacingCm: preset.plantSpacingCm, rowSpacingCm: preset.rowSpacingCm }\n : DEFAULT_CROP_SPACING_PRESET;\n};\n\nexport const estimatePlantingCapacity = (input: PlantingCapacityInput): PlantingCapacityEstimate | null => {\n const areaSqm = areaToSquareMeters(input.fieldArea, input.fieldUnit);\n if (areaSqm <= 0) return null;\n\n const bedWidthM = positiveNumber(input.bedWidthM, DEFAULT_BED_WIDTH_M);\n const pathWidthM = Math.max(0, input.pathWidthM ?? DEFAULT_PATH_WIDTH_M);\n const plantSpacingCm = positiveNumber(input.plantSpacingCm, DEFAULT_PLANT_SPACING_CM);\n const rowSpacingCm = positiveNumber(input.rowSpacingCm, DEFAULT_ROW_SPACING_CM);\n const bedModuleWidthM = bedWidthM + pathWidthM;\n const approximateFieldWidthM = Math.sqrt(areaSqm);\n const bedCount = Math.max(1, Math.floor(approximateFieldWidthM / bedModuleWidthM));\n const cultivableAreaSqm = areaSqm * (bedWidthM / bedModuleWidthM);\n const bedLengthM = cultivableAreaSqm / bedCount / bedWidthM;\n const rowsPerBed = Math.max(1, Math.floor((bedWidthM * 100) / rowSpacingCm));\n const plantsPerRow = Math.max(1, Math.floor((bedLengthM * 100) / plantSpacingCm));\n const plantsPerBed = rowsPerBed * plantsPerRow;\n const totalPlants = plantsPerBed * bedCount;\n\n return {\n areaSqm,\n cultivableAreaSqm,\n bedCount,\n bedLengthM,\n rowsPerBed,\n plantsPerRow,\n plantsPerBed,\n totalPlants,\n seedlingTarget: Math.ceil(totalPlants * SEEDLING_BUFFER),\n plantSpacingCm,\n rowSpacingCm,\n bedWidthM,\n pathWidthM,\n densityPlantsPerSqm: totalPlants / areaSqm,\n };\n};\n\n// ── Per-type capacity (BOFF-6040) ────────────────────────────────────────────\n//\n// `estimatePlantingCapacity` above is untouched on purpose: three pages read its\n// bed-specific fields, and OPEN_FIELD / RAISED_BED numbers must not move. What\n// follows is a SEPARATE entry point for the types the bed model never described.\n\n/** Per-type growing geometry, as stored on `Field.growGeometry`. */\nexport interface GrowGeometry {\n /**\n * Index signature so a geometry is assignable to the `JSON` scalar's generated\n * `Record<string, unknown>` at the mutation boundary without a cast. The named keys\n * below still constrain everything the app itself writes.\n */\n [key: string]: number | undefined;\n benchCount?: number;\n benchLengthM?: number;\n benchWidthM?: number;\n aisleWidthM?: number;\n treeSpacingM?: number;\n rowWidthM?: number;\n rackCount?: number;\n tiers?: number;\n trayLengthM?: number;\n trayWidthM?: number;\n}\n\nexport interface GrowCapacityEstimate {\n model: CapacityModel;\n /** Benches, racks, or 1 for an orchard (the block itself). */\n unitCount: number;\n plantsPerUnit: number;\n totalPlants: number;\n /** Raise-for-losses target. Null for TREE — you buy saplings, you do not sow them. */\n seedlingTarget: number | null;\n /** The area the plants actually occupy, not the building footprint. */\n usableAreaSqm: number;\n plantSpacingCm: number;\n rowSpacingCm: number;\n /** False for TREE, so the caller renders saplings instead of grams and trays. */\n usesSeed: boolean;\n}\n\n/**\n * Plants that fit on one rectangle, at the given spacing.\n *\n * Mirrors the grid the Home Garden already ships in `terrace-service.computeCapacity`\n * — rows across the width, plants along the length — but takes METRES, because every\n * `growGeometry` dimension is in metres while the spacing presets are in centimetres.\n * That unit boundary is the easiest thing to get wrong here, so it is crossed once,\n * in this function, and nowhere else.\n */\nconst plantsOnRectangle = (lengthM: number, widthM: number, plantSpacingCm: number, rowSpacingCm: number): number => {\n if (lengthM <= 0 || widthM <= 0) return 0;\n const rows = Math.floor((widthM * 100) / rowSpacingCm);\n const perRow = Math.floor((lengthM * 100) / plantSpacingCm);\n return Math.max(0, rows) * Math.max(0, perRow);\n};\n\nconst positive = (value: unknown): number | null =>\n typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : null;\n\nexport interface GrowCapacityInput {\n type: unknown;\n geometry?: GrowGeometry | null;\n fieldArea: number;\n fieldUnit: Field['unit'] | string;\n plantSpacingCm?: number;\n rowSpacingCm?: number;\n}\n\n/**\n * Capacity for a non-bed grow location.\n *\n * Returns `null` when no number can honestly be produced — a PASTURE (grazing is a\n * stocking rate, not a plant count), a BED type (use `estimatePlantingCapacity`), or\n * a type whose geometry has not been recorded yet. A null is the caller's signal to\n * PROMPT for geometry, never to fall back to an open-field number: printing bed maths\n * for a greenhouse is the exact thing BOFF-5977's guard exists to prevent.\n */\nexport const estimateGrowCapacity = (input: GrowCapacityInput): GrowCapacityEstimate | null => {\n const model = capacityModelFor(input.type);\n if (model === 'BED' || model === 'NONE') return null;\n\n const geometry = input.geometry ?? {};\n const plantSpacingCm = positive(input.plantSpacingCm) ?? DEFAULT_PLANT_SPACING_CM;\n const rowSpacingCm = positive(input.rowSpacingCm) ?? DEFAULT_ROW_SPACING_CM;\n\n if (model === 'BENCH') {\n const benchCount = positive(geometry.benchCount);\n const benchLengthM = positive(geometry.benchLengthM);\n const benchWidthM = positive(geometry.benchWidthM);\n if (!benchCount || !benchLengthM || !benchWidthM) return null;\n const plantsPerUnit = plantsOnRectangle(benchLengthM, benchWidthM, plantSpacingCm, rowSpacingCm);\n const totalPlants = plantsPerUnit * Math.floor(benchCount);\n return {\n model,\n unitCount: Math.floor(benchCount),\n plantsPerUnit,\n totalPlants,\n seedlingTarget: Math.ceil(totalPlants * SEEDLING_BUFFER),\n // Bench area, NOT the building footprint: the aisles are not plantable, which is\n // precisely why a greenhouse cannot be estimated from its `Field.area`.\n usableAreaSqm: benchCount * benchLengthM * benchWidthM,\n plantSpacingCm,\n rowSpacingCm,\n usesSeed: true,\n };\n }\n\n if (model === 'TREE') {\n const treeSpacingM = positive(geometry.treeSpacingM);\n const rowWidthM = positive(geometry.rowWidthM);\n if (!treeSpacingM || !rowWidthM) return null;\n const areaSqm = areaToSquareMeters(input.fieldArea, input.fieldUnit);\n if (areaSqm <= 0) return null;\n const totalPlants = Math.floor(areaSqm / (treeSpacingM * rowWidthM));\n return {\n model,\n unitCount: 1,\n plantsPerUnit: totalPlants,\n totalPlants,\n // No seed target: an orchard is planted from saplings, so a grams-of-seed or\n // nursery-tray number would be fiction dressed as precision.\n seedlingTarget: null,\n usableAreaSqm: areaSqm,\n // Tree spacing is its own geometry — the vegetable spacing presets top out at\n // 120cm, so echoing them here would be misleading.\n plantSpacingCm: treeSpacingM * 100,\n rowSpacingCm: rowWidthM * 100,\n usesSeed: false,\n };\n }\n\n // RACK\n const rackCount = positive(geometry.rackCount);\n const tiers = positive(geometry.tiers);\n const trayLengthM = positive(geometry.trayLengthM);\n const trayWidthM = positive(geometry.trayWidthM);\n if (!rackCount || !tiers || !trayLengthM || !trayWidthM) return null;\n const plantsPerTray = plantsOnRectangle(trayLengthM, trayWidthM, plantSpacingCm, rowSpacingCm);\n const plantsPerUnit = plantsPerTray * Math.floor(tiers);\n const totalPlants = plantsPerUnit * Math.floor(rackCount);\n return {\n model,\n unitCount: Math.floor(rackCount),\n plantsPerUnit,\n totalPlants,\n seedlingTarget: Math.ceil(totalPlants * SEEDLING_BUFFER),\n // Tiers stack vertically, so growing area is many times the floor area — the\n // single clearest reason an indoor rack cannot be sized from `Field.area`.\n usableAreaSqm: rackCount * tiers * trayLengthM * trayWidthM,\n plantSpacingCm,\n rowSpacingCm,\n usesSeed: true,\n };\n};\n"],"mappings":";;AAGA,IAAa,IAAsB,KACtB,IAAuB,KAI9B,IAAwB,cACxB,IAA2B,KAC3B,IAAkB,KAkCX,IAAiD;CAC5D,OAAO;CACP,gBAAA;CACA,cAAA;AACF,GAwBM,IAAqE;CACzE;EACE,OAAO;EACP,gBAAgB;EAChB,cAAc;EACd,OAAO;CACT;CACA;EACE,OAAO;EACP,gBAAgB;EAChB,cAAc;EACd,OAAO;CACT;CACA;EAAE,OAAO;EAAa,gBAAgB;EAAI,cAAc;EAAI,OAAO;CAA6C;CAChH;EACE,OAAO;EACP,gBAAgB;EAChB,cAAc;EACd,OAAO;CACT;CACA;EAAE,OAAO;EAAU,gBAAgB;EAAI,cAAc;EAAI,OAAO;CAAqB;CACrF;EACE,OAAO;EACP,gBAAgB;EAChB,cAAc;EACd,OAAO;CACT;CACA;EACE,OAAO;EACP,gBAAgB;EAChB,cAAc;EACd,OAAO;CACT;CACA;EAAE,OAAO;EAAU,gBAAgB;EAAI,cAAc;E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KAAK,KAAK,IAAc,CAAe;GAGvD,eAAe,IAAa,IAAe;GAC3C;GACA;GACA,UAAU;EACZ;CACF;CAEA,IAAI,MAAU,QAAQ;EACpB,IAAM,IAAe,EAAS,EAAS,YAAY,GAC7C,IAAY,EAAS,EAAS,SAAS;EAC7C,IAAI,CAAC,KAAgB,CAAC,GAAW,OAAO;EACxC,IAAM,IAAU,EAAmB,EAAM,WAAW,EAAM,SAAS;EACnE,IAAI,KAAW,GAAG,OAAO;EACzB,IAAM,IAAc,KAAK,MAAM,KAAW,IAAe,EAAU;EACnE,OAAO;GACL;GACA,WAAW;GACX,eAAe;GACf;GAGA,gBAAgB;GAChB,eAAe;GAGf,gBAAgB,IAAe;GAC/B,cAAc,IAAY;GAC1B,UAAU;EACZ;CACF;CAGA,IAAM,IAAY,EAAS,EAAS,SAAS,GACvC,IAAQ,EAAS,EAAS,KAAK,GAC/B,IAAc,EAAS,EAAS,WAAW,GAC3C,IAAa,EAAS,EAAS,UAAU;CAC/C,IAAI,CAAC,KAAa,CAAC,KAAS,CAAC,KAAe,CAAC,GAAY,OAAO;CAEhE,IAAM,IADgB,EAAkB,GAAa,GAAY,GAAgB,CAC3D,IAAgB,KAAK,MAAM,CAAK,GAChD,IAAc,IAAgB,KAAK,MAAM,CAAS;CACxD,OAAO;EACL;EACA,WAAW,KAAK,MAAM,CAAS;EAC/B;EACA;EACA,gBAAgB,KAAK,KAAK,IAAc,CAAe;EAGvD,eAAe,IAAY,IAAQ,IAAc;EACjD;EACA;EACA,UAAU;CACZ;AACF"}
|
|
1
|
+
{"version":3,"file":"plantingCapacity.js","names":[],"sources":["../../../src/healthybowl/utils/plantingCapacity.ts"],"sourcesContent":["import type { Crop, Field } from '../types';\nimport { capacityModelFor, type CapacityModel } from './growLocationType';\n\nexport const DEFAULT_BED_WIDTH_M = 1.2;\nexport const DEFAULT_PATH_WIDTH_M = 0.45;\nexport const DEFAULT_PLANT_SPACING_CM = 45;\nexport const DEFAULT_ROW_SPACING_CM = 60;\n\nconst ACRE_TO_SQUARE_METERS = 4046.8564224;\nconst HECTARE_TO_SQUARE_METERS = 10_000;\nconst SEEDLING_BUFFER = 1.1;\n\nexport interface CropSpacingPreset {\n label: string;\n plantSpacingCm: number;\n rowSpacingCm: number;\n}\n\nexport interface PlantingCapacityInput {\n fieldArea: number;\n fieldUnit: Field['unit'] | string;\n plantSpacingCm?: number;\n rowSpacingCm?: number;\n bedWidthM?: number;\n pathWidthM?: number;\n}\n\nexport interface PlantingCapacityEstimate {\n areaSqm: number;\n cultivableAreaSqm: number;\n bedCount: number;\n bedLengthM: number;\n rowsPerBed: number;\n plantsPerRow: number;\n plantsPerBed: number;\n totalPlants: number;\n seedlingTarget: number;\n plantSpacingCm: number;\n rowSpacingCm: number;\n bedWidthM: number;\n pathWidthM: number;\n densityPlantsPerSqm: number;\n}\n\nexport const DEFAULT_CROP_SPACING_PRESET: CropSpacingPreset = {\n label: 'Standard vegetables',\n plantSpacingCm: DEFAULT_PLANT_SPACING_CM,\n rowSpacingCm: DEFAULT_ROW_SPACING_CM,\n};\n\n/**\n * Spacing presets, matched against a crop's name / category / variety.\n *\n * **Every pattern is word-anchored (`\\b…\\b`) — a fix, not a style choice (BOFF-6100).** The\n * patterns used to match bare substrings, so real crops landed on the wrong preset:\n *\n * | crop | matched | via | spacing it got |\n * |---|---|---|---|\n * | Peach | Legumes | `pea` in \"**Pea**ch\" | 15cm — an orchard tree at pea spacing |\n * | Peppermint | Tomato | `pepper` in \"**Pepper**mint\" | 45cm instead of 25cm |\n * | Spearmint | Legumes | `pea` in \"S**pea**rmint\" | 15cm |\n * | Green Gram | Leafy greens | `green`, checked before Legumes | 20/25 instead of 15/45 |\n * | *anything* named \"Something…\" | Leafy greens | `methi` in \"So**methi**ng\" | 20cm |\n *\n * `greens?` also lost its optional `s` — bare \"green\" was too weak a signal and was stealing green\n * gram (moong, a pulse) from Legumes purely by list order. The mints, peanut and groundnut are now\n * named explicitly rather than caught by accident.\n *\n * `wspace-healthybowl-svc`'s `planting/planting-math.ts` carries the identical table: BOFF-6100\n * made the server derive what it persists, and the two copies share their test vectors so they\n * cannot drift.\n */\nconst CROP_SPACING_PRESETS: Array<CropSpacingPreset & { match: RegExp }> = [\n {\n label: 'Leafy greens',\n plantSpacingCm: 20,\n rowSpacingCm: 25,\n match: /\\b(?:leafy|lettuce|spinach|amaranth|coriander|cilantro|fenugreek|methi|greens)\\b/i,\n },\n {\n label: 'Tomato and fruiting vegetables',\n plantSpacingCm: 45,\n rowSpacingCm: 60,\n match: /\\b(?:tomato|tomatoes|brinjal|eggplant|chilli|chillies|chili|pepper|peppers|capsicum|okra|bhindi)\\b/i,\n },\n { label: 'Brassicas', plantSpacingCm: 45, rowSpacingCm: 60, match: /\\b(?:cabbage|cauliflower|broccoli|kale)\\b/i },\n {\n label: 'Root crops',\n plantSpacingCm: 10,\n rowSpacingCm: 30,\n match: /\\b(?:carrot|carrots|radish|beet|beetroot|onion|onions|garlic|root)\\b/i,\n },\n { label: 'Potato', plantSpacingCm: 30, rowSpacingCm: 60, match: /\\bpotato(?:es)?\\b/i },\n {\n label: 'Legumes',\n plantSpacingCm: 15,\n rowSpacingCm: 45,\n match: /\\b(?:bean|beans|pea|peas|legume|legumes|lentil|lentils|gram|peanut|groundnut)\\b/i,\n },\n {\n label: 'Cucurbits',\n plantSpacingCm: 90,\n rowSpacingCm: 120,\n match: /\\b(?:cucumber|pumpkin|melon|watermelon|muskmelon|squash|gourd|zucchini)\\b/i,\n },\n { label: 'Grains', plantSpacingCm: 20, rowSpacingCm: 20, match: /\\b(?:rice|paddy|wheat|millet|grain|grains)\\b/i },\n { label: 'Maize', plantSpacingCm: 20, rowSpacingCm: 60, match: /\\b(?:maize|corn)\\b/i },\n {\n label: 'Herbs',\n plantSpacingCm: 25,\n rowSpacingCm: 30,\n match: /\\b(?:herb|herbs|basil|mint|peppermint|spearmint|dill|parsley)\\b/i,\n },\n];\n\nconst positiveNumber = (value: number | undefined, fallback: number) =>\n typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : fallback;\n\nexport const areaToSquareMeters = (area: number, unit: Field['unit'] | string): number => {\n if (!Number.isFinite(area) || area <= 0) return 0;\n\n const normalizedUnit = String(unit).trim().toLowerCase();\n\n if (normalizedUnit === 'hectares' || normalizedUnit === 'hectare' || normalizedUnit === 'ha') {\n return area * HECTARE_TO_SQUARE_METERS;\n }\n\n if (\n normalizedUnit === 'sqm' ||\n normalizedUnit === 'm2' ||\n normalizedUnit === 'sq_m' ||\n normalizedUnit === 'square_meters' ||\n normalizedUnit === 'square meters' ||\n normalizedUnit === 'square_metres' ||\n normalizedUnit === 'square metres'\n ) {\n return area;\n }\n\n return area * ACRE_TO_SQUARE_METERS;\n};\n\nexport const getCropSpacingPreset = (crop?: Pick<Crop, 'name' | 'category' | 'variety'> | null): CropSpacingPreset => {\n if (!crop) return DEFAULT_CROP_SPACING_PRESET;\n\n // Match the combined name + variety tier first, just like the server. Within\n // either tier the existing table order still breaks ties (name does not beat variety).\n const nameAndVariety = `${crop.name ?? ''} ${crop.variety ?? ''}`;\n const preset =\n CROP_SPACING_PRESETS.find((item) => item.match.test(nameAndVariety)) ??\n CROP_SPACING_PRESETS.find((item) => item.match.test(crop.category ?? ''));\n\n return preset\n ? { label: preset.label, plantSpacingCm: preset.plantSpacingCm, rowSpacingCm: preset.rowSpacingCm }\n : DEFAULT_CROP_SPACING_PRESET;\n};\n\nexport const estimatePlantingCapacity = (input: PlantingCapacityInput): PlantingCapacityEstimate | null => {\n const areaSqm = areaToSquareMeters(input.fieldArea, input.fieldUnit);\n if (areaSqm <= 0) return null;\n\n const bedWidthM = positiveNumber(input.bedWidthM, DEFAULT_BED_WIDTH_M);\n const pathWidthM = Math.max(0, input.pathWidthM ?? DEFAULT_PATH_WIDTH_M);\n const plantSpacingCm = positiveNumber(input.plantSpacingCm, DEFAULT_PLANT_SPACING_CM);\n const rowSpacingCm = positiveNumber(input.rowSpacingCm, DEFAULT_ROW_SPACING_CM);\n const bedModuleWidthM = bedWidthM + pathWidthM;\n const approximateFieldWidthM = Math.sqrt(areaSqm);\n const bedCount = Math.max(1, Math.floor(approximateFieldWidthM / bedModuleWidthM));\n const cultivableAreaSqm = areaSqm * (bedWidthM / bedModuleWidthM);\n const bedLengthM = cultivableAreaSqm / bedCount / bedWidthM;\n const rowsPerBed = Math.max(1, Math.floor((bedWidthM * 100) / rowSpacingCm));\n const plantsPerRow = Math.max(1, Math.floor((bedLengthM * 100) / plantSpacingCm));\n const plantsPerBed = rowsPerBed * plantsPerRow;\n const totalPlants = plantsPerBed * bedCount;\n\n return {\n areaSqm,\n cultivableAreaSqm,\n bedCount,\n bedLengthM,\n rowsPerBed,\n plantsPerRow,\n plantsPerBed,\n totalPlants,\n seedlingTarget: Math.ceil(totalPlants * SEEDLING_BUFFER),\n plantSpacingCm,\n rowSpacingCm,\n bedWidthM,\n pathWidthM,\n densityPlantsPerSqm: totalPlants / areaSqm,\n };\n};\n\n// ── Per-type capacity (BOFF-6040) ────────────────────────────────────────────\n//\n// `estimatePlantingCapacity` above is untouched on purpose: three pages read its\n// bed-specific fields, and OPEN_FIELD / RAISED_BED numbers must not move. What\n// follows is a SEPARATE entry point for the types the bed model never described.\n\n/** Per-type growing geometry, as stored on `Field.growGeometry`. */\nexport interface GrowGeometry {\n /**\n * Index signature so a geometry is assignable to the `JSON` scalar's generated\n * `Record<string, unknown>` at the mutation boundary without a cast. The named keys\n * below still constrain everything the app itself writes.\n */\n [key: string]: number | undefined;\n benchCount?: number;\n benchLengthM?: number;\n benchWidthM?: number;\n aisleWidthM?: number;\n treeSpacingM?: number;\n rowWidthM?: number;\n rackCount?: number;\n tiers?: number;\n trayLengthM?: number;\n trayWidthM?: number;\n}\n\nexport interface GrowCapacityEstimate {\n model: CapacityModel;\n /** Benches, racks, or 1 for an orchard (the block itself). */\n unitCount: number;\n plantsPerUnit: number;\n totalPlants: number;\n /** Raise-for-losses target. Null for TREE — you buy saplings, you do not sow them. */\n seedlingTarget: number | null;\n /** The area the plants actually occupy, not the building footprint. */\n usableAreaSqm: number;\n plantSpacingCm: number;\n rowSpacingCm: number;\n /** False for TREE, so the caller renders saplings instead of grams and trays. */\n usesSeed: boolean;\n}\n\n/**\n * Plants that fit on one rectangle, at the given spacing.\n *\n * Mirrors the grid the Home Garden already ships in `terrace-service.computeCapacity`\n * — rows across the width, plants along the length — but takes METRES, because every\n * `growGeometry` dimension is in metres while the spacing presets are in centimetres.\n * That unit boundary is the easiest thing to get wrong here, so it is crossed once,\n * in this function, and nowhere else.\n */\nconst plantsOnRectangle = (lengthM: number, widthM: number, plantSpacingCm: number, rowSpacingCm: number): number => {\n if (lengthM <= 0 || widthM <= 0) return 0;\n const rows = Math.floor((widthM * 100) / rowSpacingCm);\n const perRow = Math.floor((lengthM * 100) / plantSpacingCm);\n return Math.max(0, rows) * Math.max(0, perRow);\n};\n\nconst positive = (value: unknown): number | null =>\n typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : null;\n\nexport interface GrowCapacityInput {\n type: unknown;\n geometry?: GrowGeometry | null;\n fieldArea: number;\n fieldUnit: Field['unit'] | string;\n plantSpacingCm?: number;\n rowSpacingCm?: number;\n}\n\n/**\n * Capacity for a non-bed grow location.\n *\n * Returns `null` when no number can honestly be produced — a PASTURE (grazing is a\n * stocking rate, not a plant count), a BED type (use `estimatePlantingCapacity`), or\n * a type whose geometry has not been recorded yet. A null is the caller's signal to\n * PROMPT for geometry, never to fall back to an open-field number: printing bed maths\n * for a greenhouse is the exact thing BOFF-5977's guard exists to prevent.\n */\nexport const estimateGrowCapacity = (input: GrowCapacityInput): GrowCapacityEstimate | null => {\n const model = capacityModelFor(input.type);\n if (model === 'BED' || model === 'NONE') return null;\n\n const geometry = input.geometry ?? {};\n const plantSpacingCm = positive(input.plantSpacingCm) ?? DEFAULT_PLANT_SPACING_CM;\n const rowSpacingCm = positive(input.rowSpacingCm) ?? DEFAULT_ROW_SPACING_CM;\n\n if (model === 'BENCH') {\n const benchCount = positive(geometry.benchCount);\n const benchLengthM = positive(geometry.benchLengthM);\n const benchWidthM = positive(geometry.benchWidthM);\n if (!benchCount || !benchLengthM || !benchWidthM) return null;\n const plantsPerUnit = plantsOnRectangle(benchLengthM, benchWidthM, plantSpacingCm, rowSpacingCm);\n const totalPlants = plantsPerUnit * Math.floor(benchCount);\n return {\n model,\n unitCount: Math.floor(benchCount),\n plantsPerUnit,\n totalPlants,\n seedlingTarget: Math.ceil(totalPlants * SEEDLING_BUFFER),\n // Bench area, NOT the building footprint: the aisles are not plantable, which is\n // precisely why a greenhouse cannot be estimated from its `Field.area`.\n usableAreaSqm: benchCount * benchLengthM * benchWidthM,\n plantSpacingCm,\n rowSpacingCm,\n usesSeed: true,\n };\n }\n\n if (model === 'TREE') {\n const treeSpacingM = positive(geometry.treeSpacingM);\n const rowWidthM = positive(geometry.rowWidthM);\n if (!treeSpacingM || !rowWidthM) return null;\n const areaSqm = areaToSquareMeters(input.fieldArea, input.fieldUnit);\n if (areaSqm <= 0) return null;\n const totalPlants = Math.floor(areaSqm / (treeSpacingM * rowWidthM));\n return {\n model,\n unitCount: 1,\n plantsPerUnit: totalPlants,\n totalPlants,\n // No seed target: an orchard is planted from saplings, so a grams-of-seed or\n // nursery-tray number would be fiction dressed as precision.\n seedlingTarget: null,\n usableAreaSqm: areaSqm,\n // Tree spacing is its own geometry — the vegetable spacing presets top out at\n // 120cm, so echoing them here would be misleading.\n plantSpacingCm: treeSpacingM * 100,\n rowSpacingCm: rowWidthM * 100,\n usesSeed: false,\n };\n }\n\n // RACK\n const rackCount = positive(geometry.rackCount);\n const tiers = positive(geometry.tiers);\n const trayLengthM = positive(geometry.trayLengthM);\n const trayWidthM = positive(geometry.trayWidthM);\n if (!rackCount || !tiers || !trayLengthM || !trayWidthM) return null;\n const plantsPerTray = plantsOnRectangle(trayLengthM, trayWidthM, plantSpacingCm, rowSpacingCm);\n const plantsPerUnit = plantsPerTray * Math.floor(tiers);\n const totalPlants = plantsPerUnit * Math.floor(rackCount);\n return {\n model,\n unitCount: Math.floor(rackCount),\n plantsPerUnit,\n totalPlants,\n seedlingTarget: Math.ceil(totalPlants * SEEDLING_BUFFER),\n // Tiers stack vertically, so growing area is many times the floor area — the\n // single clearest reason an indoor rack cannot be sized from `Field.area`.\n usableAreaSqm: rackCount * tiers * trayLengthM * trayWidthM,\n plantSpacingCm,\n rowSpacingCm,\n usesSeed: true,\n };\n};\n"],"mappings":";;AAGA,IAAa,IAAsB,KACtB,IAAuB,KAI9B,IAAwB,cACxB,IAA2B,KAC3B,IAAkB,KAkCX,IAAiD;CAC5D,OAAO;CACP,gBAAA;CACA,cAAA;AACF,GAwBM,IAAqE;CACzE;EACE,OAAO;EACP,gBAAgB;EAChB,cAAc;EACd,OAAO;CACT;CACA;EACE,OAAO;EACP,gBAAgB;EAChB,cAAc;EACd,OAAO;CACT;CACA;EAAE,OAAO;EAAa,gBAAgB;EAAI,cAAc;EAAI,OAAO;CAA6C;CAChH;EACE,OAAO;EACP,gBAAgB;EAChB,cAAc;EACd,OAAO;CACT;CACA;EAAE,OAAO;EAAU,gBAAgB;EAAI,cAAc;EAAI,OAAO;CAAqB;CACrF;EACE,OAAO;EACP,gBAAgB;EAChB,cAAc;EACd,OAAO;CACT;CACA;EACE,OAAO;EACP,gBAAgB;EAChB,cAAc;EACd,OAAO;CACT;CACA;EAAE,OAAO;EAAU,gBAAgB;EAAI,cAAc;EAAI,OAAO;CAAgD;CAChH;EAAE,OAAO;EAAS,gBAAgB;EAAI,cAAc;EAAI,OAAO;CAAsB;CACrF;EACE,OAAO;EACP,gBAAgB;EAChB,cAAc;EACd,OAAO;CACT;AACF,GAEM,KAAkB,GAA2B,MACjD,OAAO,KAAU,YAAY,OAAO,SAAS,CAAK,KAAK,IAAQ,IAAI,IAAQ,GAEhE,KAAsB,GAAc,MAAyC;CACxF,IAAI,CAAC,OAAO,SAAS,CAAI,KAAK,KAAQ,GAAG,OAAO;CAEhD,IAAM,IAAiB,OAAO,CAAI,EAAE,KAAK,EAAE,YAAY;C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,MAAM,KAAW,IAAe,EAAU;EACnE,OAAO;GACL;GACA,WAAW;GACX,eAAe;GACf;GAGA,gBAAgB;GAChB,eAAe;GAGf,gBAAgB,IAAe;GAC/B,cAAc,IAAY;GAC1B,UAAU;EACZ;CACF;CAGA,IAAM,IAAY,EAAS,EAAS,SAAS,GACvC,IAAQ,EAAS,EAAS,KAAK,GAC/B,IAAc,EAAS,EAAS,WAAW,GAC3C,IAAa,EAAS,EAAS,UAAU;CAC/C,IAAI,CAAC,KAAa,CAAC,KAAS,CAAC,KAAe,CAAC,GAAY,OAAO;CAEhE,IAAM,IADgB,EAAkB,GAAa,GAAY,GAAgB,CAC3D,IAAgB,KAAK,MAAM,CAAK,GAChD,IAAc,IAAgB,KAAK,MAAM,CAAS;CACxD,OAAO;EACL;EACA,WAAW,KAAK,MAAM,CAAS;EAC/B;EACA;EACA,gBAAgB,KAAK,KAAK,IAAc,CAAe;EAGvD,eAAe,IAAY,IAAQ,IAAc;EACjD;EACA;EACA,UAAU;CACZ;AACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region src/healthybowl/utils/quotaLabels.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
return `healthybowl.home.quotas.label.${e.trim().replace(/^healthybowl\./, "").toLowerCase().replace(/[^a-z0-9]+([a-z0-9])/g, (e, t) => t.toUpperCase()).replace(/[^a-zA-Z0-9]/g, "") || "unknown"}`;
|
|
4
|
+
}
|
|
5
|
+
//#endregion
|
|
6
|
+
export { e as quotaLabelKey };
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=quotaLabels.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quotaLabels.js","names":[],"sources":["../../../src/healthybowl/utils/quotaLabels.ts"],"sourcesContent":["/**\n * Translation key for a plan-usage quota label (BOFF-8851).\n *\n * The server sends each quota's English label (`HealthyBowlQuotaProvider`), so\n * the dashboard keys the label client-side by its stable `quotaName` and falls\n * back to the server's English when no translation exists.\n *\n * healthybowl.farms.active -> healthybowl.home.quotas.label.farmsActive\n * healthybowl.sensor_probes.active -> healthybowl.home.quotas.label.sensorProbesActive\n */\nexport function quotaLabelKey(quotaName: string): string {\n const slug = quotaName\n .trim()\n .replace(/^healthybowl\\./, '')\n .toLowerCase()\n .replace(/[^a-z0-9]+([a-z0-9])/g, (_match, next: string) => next.toUpperCase())\n .replace(/[^a-zA-Z0-9]/g, '');\n return `healthybowl.home.quotas.label.${slug || 'unknown'}`;\n}\n"],"mappings":";AAUA,SAAgB,EAAc,GAA2B;CAOvD,OAAO,iCANM,EACV,KAAK,EACL,QAAQ,kBAAkB,EAAE,EAC5B,YAAY,EACZ,QAAQ,0BAA0B,GAAQ,MAAiB,EAAK,YAAY,CAAC,EAC7E,QAAQ,iBAAiB,EACY,KAAQ;AAClD"}
|
|
@@ -12,14 +12,7 @@ function a(a) {
|
|
|
12
12
|
trays: i(l / 128)
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
|
-
var o = (e) => (e ?? "").trim().toLowerCase();
|
|
16
|
-
function s(e, t) {
|
|
17
|
-
let n = o(e?.name);
|
|
18
|
-
if (!n || t.length === 0) return;
|
|
19
|
-
let r = o(e?.variety);
|
|
20
|
-
return t.find((e) => o(e.name) === n && o(e.variety) === r) ?? t.find((e) => o(e.name) === n);
|
|
21
|
-
}
|
|
22
15
|
//#endregion
|
|
23
|
-
export { a as computeSeedRate
|
|
16
|
+
export { a as computeSeedRate };
|
|
24
17
|
|
|
25
18
|
//# sourceMappingURL=seedRate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seedRate.js","names":[],"sources":["../../../src/healthybowl/utils/seedRate.ts"],"sourcesContent":["/**\n * Seed-rate calculator (roadmap I-4/I-5).\n *\n * Turns a plant target into the practical seed/nursery numbers a grower needs:\n * how many seedlings to raise (with spares), how many seeds to sow (over-sown\n * for germination loss), the seed weight in grams, and the number of nursery\n * trays. Pure functions — no I/O — so they can be unit-tested and reused by the\n * field planner and the succession scheduler.\n * @module healthybowl\n */\n\n/** Inputs for a seed-rate calculation. Seed metadata is optional. */\nexport interface SeedRateInput {\n /** Total plants the grower wants in the ground. */\n plantsNeeded: number;\n /** Approximate seed count per gram (from the Master Plant List). */\n seedsPerGram?: number | null;\n /** Germination rate as a fraction in [0, 1] (e.g. 0.85 = 85%). */\n germinationRate?: number | null;\n /** Seeds sown per nursery cell/plug when raising transplants. */\n seedsPerCell?: number | null;\n}\n\n/** Result of a seed-rate calculation. Grams/trays are null when unknown. */\nexport interface SeedRateResult {\n /** Seedlings/transplants to raise in the nursery (plants + 10% spares). */\n seedlingsToRaise: number;\n /** Seeds to sow, over-sown to cover germination loss. */\n seedsNeeded: number;\n /** Grams of seed required, or null when seedsPerGram is unknown. */\n seedGrams: number | null;\n /** Nursery trays/cells required, or null when seedsPerCell is unknown. */\n trays: number | null;\n}\n\n/** Default germination rate assumed when a variety has none recorded. */\nexport const DEFAULT_GERMINATION_RATE = 0.85;\n/** Spare-seedling factor: raise 10% more than needed to cover losses. */\nexport const SEEDLING_SPARE_FACTOR = 1.1;\n/** Cells in a standard propagation/plug tray — used to convert seedlings → trays. */\nexport const DEFAULT_CELLS_PER_TRAY = 128;\n\nconst clamp = (value: number, min: number, max: number): number => Math.min(max, Math.max(min, value));\n\nconst roundTo = (value: number, digits: number): number => {\n const factor = 10 ** digits;\n return Math.round(value * factor) / factor;\n};\n\n// Ceil after stripping binary-float noise (e.g. 100 * 1.1 === 110.00000000000001,\n// which would otherwise ceil to 111). 6 dp keeps genuine fractions intact.\nconst ceilClean = (value: number): number => Math.ceil(roundTo(value, 6));\n\n/**\n * Compute the seed rate for a planting.\n *\n * - `germ` defaults to 0.85 and is clamped to [0.05, 1] so a nonsense value\n * never divides seed counts into infinity.\n * - `seedlingsToRaise` adds a 10% spare buffer over `plantsNeeded`.\n * - `seedsNeeded` over-sows so that, after germination, enough seedlings emerge.\n * - `seedGrams` / `trays` are only returned when the matching seed metadata is\n * available, otherwise they are null.\n */\nexport function computeSeedRate(input: SeedRateInput): SeedRateResult {\n const plantsNeeded = Number.isFinite(input.plantsNeeded) && input.plantsNeeded > 0 ? input.plantsNeeded : 0;\n const germ = clamp(\n input.germinationRate != null && Number.isFinite(input.germinationRate)\n ? input.germinationRate\n : DEFAULT_GERMINATION_RATE,\n 0.05,\n 1\n );\n\n // Seeds sown per cell (default 1); over-sowing per cell is a germination hedge.\n const seedsPerCell =\n input.seedsPerCell != null && Number.isFinite(input.seedsPerCell) && input.seedsPerCell > 0\n ? input.seedsPerCell\n : 1;\n\n const seedlingsToRaise = ceilClean(plantsNeeded * SEEDLING_SPARE_FACTOR);\n // Sow `seedsPerCell` seeds per cell, over-sown for germination so enough emerge.\n const seedsNeeded = ceilClean((seedlingsToRaise * seedsPerCell) / germ);\n\n const seedsPerGram =\n input.seedsPerGram != null && Number.isFinite(input.seedsPerGram) && input.seedsPerGram > 0\n ? input.seedsPerGram\n : null;\n\n return {\n seedlingsToRaise,\n seedsNeeded,\n seedGrams: seedsPerGram ? roundTo(seedsNeeded / seedsPerGram, 2) : null,\n // Nursery trays = cells needed ÷ cells-per-tray (standard 128-cell plug tray),\n // NOT ÷ seedsPerCell (that was the earlier bug — 1 seed/cell ≠ 1 cell/tray).\n trays: ceilClean(seedlingsToRaise / DEFAULT_CELLS_PER_TRAY),\n };\n}\n\n/**\n * The shape a plant-catalog entry needs for matching (BOFF-6098).\n *\n * Structural on purpose: `utils/` must not import from `hooks/`, and this needs to accept both the\n * catalog rows `usePlantCatalog` returns and anything else carrying a name.\n */\nexport interface MatchableCatalogEntry {\n id: string;\n name?: string | null;\n variety?: string | null;\n}\n\n/** What a crop needs to expose to be matched against the catalog. */\nexport interface MatchableCrop {\n name?: string | null;\n variety?: string | null;\n}\n\nconst normalize = (value: string | null | undefined): string => (value ?? '').trim().toLowerCase();\n\n/**\n * Find the Master Plant List entry that describes a crop.\n *\n * Exact name+variety first, then name alone. The two-step matters: a farmer growing\n * \"Tomato / Arka Rakshak\" should get that variety's seed data, but a farmer who just wrote \"Tomato\"\n * with no variety should still get tomato seed data rather than nothing — seed counts vary far more\n * between species than between varieties of one.\n *\n * The name-only fallback takes the FIRST matching entry, which for an unlisted variety may be some\n * other variety's row rather than a generic one. That is the behaviour `FieldDetailsPage` has\n * shipped with and it is preserved deliberately; preferring a variety-less row would be defensible\n * but would move a number on a page unrelated to the change that lifted this out.\n *\n * Returns `undefined` rather than a guess when nothing matches. `computeSeedRate` then produces a\n * null `seedGrams`, and the UI shows \"—\". Inventing a seeds-per-gram figure would put a purchase\n * quantity in front of a farmer that no catalogue supports.\n *\n * Lifted out of `FieldDetailsPage`'s `seedMeta` memo so the planning form and the field detail page\n * cannot drift on what \"the same crop\" means.\n */\nexport function matchPlantCatalogEntry<T extends MatchableCatalogEntry>(\n crop: MatchableCrop | null | undefined,\n entries: readonly T[]\n): T | undefined {\n const name = normalize(crop?.name);\n if (!name || entries.length === 0) return undefined;\n const variety = normalize(crop?.variety);\n return (\n entries.find((entry) => normalize(entry.name) === name && normalize(entry.variety) === variety) ??\n entries.find((entry) => normalize(entry.name) === name)\n );\n}\n"],"mappings":";AAoCA,IAAa,IAA2B,KAE3B,IAAwB,KAI/B,KAAS,GAAe,GAAa,MAAwB,KAAK,IAAI,GAAK,KAAK,IAAI,GAAK,CAAK,CAAC,GAE/F,KAAW,GAAe,MAA2B;CACzD,IAAM,IAAS,MAAM;CACrB,OAAO,KAAK,MAAM,IAAQ,CAAM,IAAI;AACtC,GAIM,KAAa,MAA0B,KAAK,KAAK,EAAQ,GAAO,CAAC,CAAC;AAYxE,SAAgB,EAAgB,GAAsC;CACpE,IAAM,IAAe,OAAO,SAAS,EAAM,YAAY,KAAK,EAAM,eAAe,IAAI,EAAM,eAAe,GACpG,IAAO,EACX,EAAM,mBAAmB,QAAQ,OAAO,SAAS,EAAM,eAAe,IAClE,EAAM,kBACN,GACJ,KACA,CACF,GAGM,IACJ,EAAM,gBAAgB,QAAQ,OAAO,SAAS,EAAM,YAAY,KAAK,EAAM,eAAe,IACtF,EAAM,eACN,GAEA,IAAmB,EAAU,IAAe,CAAqB,GAEjE,IAAc,EAAW,IAAmB,IAAgB,CAAI,GAEhE,IACJ,EAAM,gBAAgB,QAAQ,OAAO,SAAS,EAAM,YAAY,KAAK,EAAM,eAAe,IACtF,EAAM,eACN;CAEN,OAAO;EACL;EACA;EACA,WAAW,IAAe,EAAQ,IAAc,GAAc,CAAC,IAAI;EAGnE,OAAO,EAAU,IAAA,GAAyC;CAC5D;AACF
|
|
1
|
+
{"version":3,"file":"seedRate.js","names":[],"sources":["../../../src/healthybowl/utils/seedRate.ts"],"sourcesContent":["/**\n * Seed-rate calculator (roadmap I-4/I-5).\n *\n * Turns a plant target into the practical seed/nursery numbers a grower needs:\n * how many seedlings to raise (with spares), how many seeds to sow (over-sown\n * for germination loss), the seed weight in grams, and the number of nursery\n * trays. Pure functions — no I/O — so they can be unit-tested and reused by the\n * field planner and the succession scheduler.\n * @module healthybowl\n */\n\n/** Inputs for a seed-rate calculation. Seed metadata is optional. */\nexport interface SeedRateInput {\n /** Total plants the grower wants in the ground. */\n plantsNeeded: number;\n /** Approximate seed count per gram (from the Master Plant List). */\n seedsPerGram?: number | null;\n /** Germination rate as a fraction in [0, 1] (e.g. 0.85 = 85%). */\n germinationRate?: number | null;\n /** Seeds sown per nursery cell/plug when raising transplants. */\n seedsPerCell?: number | null;\n}\n\n/** Result of a seed-rate calculation. Grams/trays are null when unknown. */\nexport interface SeedRateResult {\n /** Seedlings/transplants to raise in the nursery (plants + 10% spares). */\n seedlingsToRaise: number;\n /** Seeds to sow, over-sown to cover germination loss. */\n seedsNeeded: number;\n /** Grams of seed required, or null when seedsPerGram is unknown. */\n seedGrams: number | null;\n /** Nursery trays/cells required, or null when seedsPerCell is unknown. */\n trays: number | null;\n}\n\n/** Default germination rate assumed when a variety has none recorded. */\nexport const DEFAULT_GERMINATION_RATE = 0.85;\n/** Spare-seedling factor: raise 10% more than needed to cover losses. */\nexport const SEEDLING_SPARE_FACTOR = 1.1;\n/** Cells in a standard propagation/plug tray — used to convert seedlings → trays. */\nexport const DEFAULT_CELLS_PER_TRAY = 128;\n\nconst clamp = (value: number, min: number, max: number): number => Math.min(max, Math.max(min, value));\n\nconst roundTo = (value: number, digits: number): number => {\n const factor = 10 ** digits;\n return Math.round(value * factor) / factor;\n};\n\n// Ceil after stripping binary-float noise (e.g. 100 * 1.1 === 110.00000000000001,\n// which would otherwise ceil to 111). 6 dp keeps genuine fractions intact.\nconst ceilClean = (value: number): number => Math.ceil(roundTo(value, 6));\n\n/**\n * Compute the seed rate for a planting.\n *\n * - `germ` defaults to 0.85 and is clamped to [0.05, 1] so a nonsense value\n * never divides seed counts into infinity.\n * - `seedlingsToRaise` adds a 10% spare buffer over `plantsNeeded`.\n * - `seedsNeeded` over-sows so that, after germination, enough seedlings emerge.\n * - `seedGrams` / `trays` are only returned when the matching seed metadata is\n * available, otherwise they are null.\n */\nexport function computeSeedRate(input: SeedRateInput): SeedRateResult {\n const plantsNeeded = Number.isFinite(input.plantsNeeded) && input.plantsNeeded > 0 ? input.plantsNeeded : 0;\n const germ = clamp(\n input.germinationRate != null && Number.isFinite(input.germinationRate)\n ? input.germinationRate\n : DEFAULT_GERMINATION_RATE,\n 0.05,\n 1\n );\n\n // Seeds sown per cell (default 1); over-sowing per cell is a germination hedge.\n const seedsPerCell =\n input.seedsPerCell != null && Number.isFinite(input.seedsPerCell) && input.seedsPerCell > 0\n ? input.seedsPerCell\n : 1;\n\n const seedlingsToRaise = ceilClean(plantsNeeded * SEEDLING_SPARE_FACTOR);\n // Sow `seedsPerCell` seeds per cell, over-sown for germination so enough emerge.\n const seedsNeeded = ceilClean((seedlingsToRaise * seedsPerCell) / germ);\n\n const seedsPerGram =\n input.seedsPerGram != null && Number.isFinite(input.seedsPerGram) && input.seedsPerGram > 0\n ? input.seedsPerGram\n : null;\n\n return {\n seedlingsToRaise,\n seedsNeeded,\n seedGrams: seedsPerGram ? roundTo(seedsNeeded / seedsPerGram, 2) : null,\n // Nursery trays = cells needed ÷ cells-per-tray (standard 128-cell plug tray),\n // NOT ÷ seedsPerCell (that was the earlier bug — 1 seed/cell ≠ 1 cell/tray).\n trays: ceilClean(seedlingsToRaise / DEFAULT_CELLS_PER_TRAY),\n };\n}\n\n/**\n * The shape a plant-catalog entry needs for matching (BOFF-6098).\n *\n * Structural on purpose: `utils/` must not import from `hooks/`, and this needs to accept both the\n * catalog rows `usePlantCatalog` returns and anything else carrying a name.\n */\nexport interface MatchableCatalogEntry {\n id: string;\n name?: string | null;\n variety?: string | null;\n}\n\n/** What a crop needs to expose to be matched against the catalog. */\nexport interface MatchableCrop {\n name?: string | null;\n variety?: string | null;\n}\n\nconst normalize = (value: string | null | undefined): string => (value ?? '').trim().toLowerCase();\n\n/**\n * Find the Master Plant List entry that describes a crop.\n *\n * Exact name+variety first, then name alone. The two-step matters: a farmer growing\n * \"Tomato / Arka Rakshak\" should get that variety's seed data, but a farmer who just wrote \"Tomato\"\n * with no variety should still get tomato seed data rather than nothing — seed counts vary far more\n * between species than between varieties of one.\n *\n * The name-only fallback takes the FIRST matching entry, which for an unlisted variety may be some\n * other variety's row rather than a generic one. That is the behaviour `FieldDetailsPage` has\n * shipped with and it is preserved deliberately; preferring a variety-less row would be defensible\n * but would move a number on a page unrelated to the change that lifted this out.\n *\n * Returns `undefined` rather than a guess when nothing matches. `computeSeedRate` then produces a\n * null `seedGrams`, and the UI shows \"—\". Inventing a seeds-per-gram figure would put a purchase\n * quantity in front of a farmer that no catalogue supports.\n *\n * Lifted out of `FieldDetailsPage`'s `seedMeta` memo so the planning form and the field detail page\n * cannot drift on what \"the same crop\" means.\n */\nexport function matchPlantCatalogEntry<T extends MatchableCatalogEntry>(\n crop: MatchableCrop | null | undefined,\n entries: readonly T[]\n): T | undefined {\n const name = normalize(crop?.name);\n if (!name || entries.length === 0) return undefined;\n const variety = normalize(crop?.variety);\n return (\n entries.find((entry) => normalize(entry.name) === name && normalize(entry.variety) === variety) ??\n entries.find((entry) => normalize(entry.name) === name)\n );\n}\n"],"mappings":";AAoCA,IAAa,IAA2B,KAE3B,IAAwB,KAI/B,KAAS,GAAe,GAAa,MAAwB,KAAK,IAAI,GAAK,KAAK,IAAI,GAAK,CAAK,CAAC,GAE/F,KAAW,GAAe,MAA2B;CACzD,IAAM,IAAS,MAAM;CACrB,OAAO,KAAK,MAAM,IAAQ,CAAM,IAAI;AACtC,GAIM,KAAa,MAA0B,KAAK,KAAK,EAAQ,GAAO,CAAC,CAAC;AAYxE,SAAgB,EAAgB,GAAsC;CACpE,IAAM,IAAe,OAAO,SAAS,EAAM,YAAY,KAAK,EAAM,eAAe,IAAI,EAAM,eAAe,GACpG,IAAO,EACX,EAAM,mBAAmB,QAAQ,OAAO,SAAS,EAAM,eAAe,IAClE,EAAM,kBACN,GACJ,KACA,CACF,GAGM,IACJ,EAAM,gBAAgB,QAAQ,OAAO,SAAS,EAAM,YAAY,KAAK,EAAM,eAAe,IACtF,EAAM,eACN,GAEA,IAAmB,EAAU,IAAe,CAAqB,GAEjE,IAAc,EAAW,IAAmB,IAAgB,CAAI,GAEhE,IACJ,EAAM,gBAAgB,QAAQ,OAAO,SAAS,EAAM,YAAY,KAAK,EAAM,eAAe,IACtF,EAAM,eACN;CAEN,OAAO;EACL;EACA;EACA,WAAW,IAAe,EAAQ,IAAc,GAAc,CAAC,IAAI;EAGnE,OAAO,EAAU,IAAA,GAAyC;CAC5D;AACF"}
|
package/package.json
CHANGED