From 6f28cc0093cd5126822cb5cc9d8cbc857ef748e1 Mon Sep 17 00:00:00 2001 From: calli Date: Mon, 28 Apr 2025 17:55:44 +0300 Subject: [PATCH] Add import exhaustion estimate --- .../PlanetaryInteraction/PlanetTableRow.tsx | 70 ++++++++++++++++--- 1 file changed, 61 insertions(+), 9 deletions(-) diff --git a/src/app/components/PlanetaryInteraction/PlanetTableRow.tsx b/src/app/components/PlanetaryInteraction/PlanetTableRow.tsx index d1d08e6..368bca8 100644 --- a/src/app/components/PlanetaryInteraction/PlanetTableRow.tsx +++ b/src/app/components/PlanetaryInteraction/PlanetTableRow.tsx @@ -1,5 +1,5 @@ import { ColorContext, SessionContext } from "@/app/context/Context"; -import { PI_TYPES_MAP, STORAGE_IDS, STORAGE_CAPACITIES, PI_PRODUCT_VOLUMES, EVE_IMAGE_URL } from "@/const"; +import { PI_TYPES_MAP, STORAGE_IDS, STORAGE_CAPACITIES, PI_PRODUCT_VOLUMES, EVE_IMAGE_URL, PI_SCHEMATICS } from "@/const"; import { planetCalculations } from "@/planets"; import { AccessToken, PlanetWithInfo } from "@/types"; import CloseIcon from "@mui/icons-material/Close"; @@ -155,6 +155,21 @@ export const PlanetTableRow = ({ }; const renderProductDisplay = (typeId: number, amount?: number) => { + if (!typeId || !PI_TYPES_MAP[typeId]) { + return ( +
+ + No product + + {amount !== undefined && ( + + {amount} + + )} +
+ ); + } + if (showProductIcons) { return (
@@ -319,14 +334,51 @@ export const PlanetTableRow = ({
- {localImports.map((i) => ( -
- {renderProductDisplay(i.type_id, i.quantity * i.factoryCount)} -
- ))} + {localImports.map((i) => { + // Find all storage facilities (including launchpads) containing this import + const storagesWithImport = storageFacilities.filter(storage => + storage.contents?.some(content => content.type_id === i.type_id) + ); + + // Get the total amount in all storage facilities + const totalAmount = storagesWithImport.reduce((sum, storage) => { + const content = storage.contents?.find(content => content.type_id === i.type_id); + return sum + (content?.amount ?? 0); + }, 0); + + // Calculate consumption rate per hour + const schematic = PI_SCHEMATICS.find(s => s.schematic_id === i.schematic_id); + const cycleTime = schematic?.cycle_time ?? 3600; + const consumptionPerHour = i.quantity * i.factoryCount * (3600 / cycleTime); + + // Calculate time until depletion in hours + const hoursUntilDepletion = consumptionPerHour > 0 ? totalAmount / consumptionPerHour : 0; + + return ( +
+ {renderProductDisplay(i.type_id, i.quantity * i.factoryCount)} + {totalAmount > 0 && ( + +
Total: {totalAmount.toFixed(1)} units
+
Will be depleted in {hoursUntilDepletion.toFixed(1)} hours
+ + }> + + ({hoursUntilDepletion.toFixed(1)}h) + +
+ )} +
+ ); + })}