use planets last_update to calculate the imports depletion
This commit is contained in:
@@ -351,8 +351,12 @@ export const PlanetTableRow = ({
|
|||||||
const cycleTime = schematic?.cycle_time ?? 3600;
|
const cycleTime = schematic?.cycle_time ?? 3600;
|
||||||
const consumptionPerHour = i.quantity * i.factoryCount * (3600 / cycleTime);
|
const consumptionPerHour = i.quantity * i.factoryCount * (3600 / cycleTime);
|
||||||
|
|
||||||
// Calculate time until depletion in hours
|
// Calculate time until depletion in hours, starting from last_update
|
||||||
const hoursUntilDepletion = consumptionPerHour > 0 ? totalAmount / consumptionPerHour : 0;
|
const lastUpdate = DateTime.fromISO(planet.last_update);
|
||||||
|
const now = DateTime.now();
|
||||||
|
const hoursSinceUpdate = now.diff(lastUpdate, 'hours').hours;
|
||||||
|
const remainingAmount = Math.max(0, totalAmount - (consumptionPerHour * hoursSinceUpdate));
|
||||||
|
const hoursUntilDepletion = consumptionPerHour > 0 ? remainingAmount / consumptionPerHour : 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@@ -363,7 +367,9 @@ export const PlanetTableRow = ({
|
|||||||
{totalAmount > 0 && (
|
{totalAmount > 0 && (
|
||||||
<Tooltip title={
|
<Tooltip title={
|
||||||
<>
|
<>
|
||||||
<div>Total: {totalAmount.toFixed(1)} units</div>
|
<div>Total in storage: {totalAmount.toFixed(1)} units</div>
|
||||||
|
<div>Consumption rate: {consumptionPerHour.toFixed(1)} units/hour</div>
|
||||||
|
<div>Last update: {lastUpdate.toFormat('yyyy-MM-dd HH:mm:ss')}</div>
|
||||||
<div>Will be depleted in {hoursUntilDepletion.toFixed(1)} hours</div>
|
<div>Will be depleted in {hoursUntilDepletion.toFixed(1)} hours</div>
|
||||||
</>
|
</>
|
||||||
}>
|
}>
|
||||||
|
Reference in New Issue
Block a user