mirror of
https://github.com/calli-eve/eve-pi.git
synced 2026-06-11 16:45:42 +02:00
Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f49cc61da4 | |||
| c37578c4e5 | |||
| 48da721980 | |||
| bf31a7e2cb | |||
| 6b47b34ddf | |||
| e8f69b15a4 | |||
| ebd39243b2 | |||
| 0ee129b3ca | |||
| 7a09503ffa | |||
| 9de91f9982 | |||
| 14c2732fa0 | |||
| e47c572423 | |||
| 5c6f912721 | |||
| 470935fe9d | |||
| 7ce238c9c7 | |||
| 6523000e69 | |||
| b993b28840 | |||
| c036bc10e1 | |||
| b743193f46 | |||
| 02ebaf6e35 | |||
| 3a0843e54c | |||
| e43bd91bef | |||
| cc76765278 | |||
| 73b54f6bf5 | |||
| cbef0fd39b | |||
| e085fcd59b | |||
| 370400ce99 | |||
| 93507ea98e | |||
| 7915d2bd29 | |||
| 294720f776 |
@@ -2,9 +2,19 @@
|
|||||||
|
|
||||||
Simple tool to track your PI planet extractors. Login with your characters and enjoy the PI!
|
Simple tool to track your PI planet extractors. Login with your characters and enjoy the PI!
|
||||||
|
|
||||||
Any questions, feedback or suggestions are welcome at [EVE PI Discord](https://discord.gg/GPtw5kfuJu)
|
Any questions, feedback or suggestions are welcome at
|
||||||
|
[EVE PI Matrix](https://matrix.to/#/#eve-pi:calli.fi)
|
||||||
|
[EVE PI Discord](https://discord.gg/bCdXzU8PHK)
|
||||||
|
|
||||||
## [Avanto hosted PI tool](https://pi.avanto.tk)
|
## Partner code
|
||||||
|
|
||||||
|
Consider using EVE partner code to support the project:
|
||||||
|
|
||||||
|
```
|
||||||
|
CALLIEVE
|
||||||
|
```
|
||||||
|
|
||||||
|
## [Hosted PI tool](https://pi.calli.fi)
|
||||||
|
|
||||||

|

|
||||||

|

|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
---
|
|
||||||
version: "2.1"
|
|
||||||
services:
|
services:
|
||||||
eve-pi:
|
eve-pi:
|
||||||
image: ghcr.io/calli-eve/eve-pi:latest
|
image: ghcr.io/calli-eve/eve-pi:latest
|
||||||
Generated
+1191
-1120
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -26,7 +26,7 @@
|
|||||||
"crypto-js": "^4.1.1",
|
"crypto-js": "^4.1.1",
|
||||||
"eslint": "8.42.0",
|
"eslint": "8.42.0",
|
||||||
"luxon": "^3.6.1",
|
"luxon": "^3.6.1",
|
||||||
"next": "^14.2.23",
|
"next": "14.2.35",
|
||||||
"next-plausible": "^3.12.0",
|
"next-plausible": "^3.12.0",
|
||||||
"pino": "^9.6.0",
|
"pino": "^9.6.0",
|
||||||
"pino-pretty": "^13.0.0",
|
"pino-pretty": "^13.0.0",
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { AccessToken } from "@/types";
|
import { AccessToken, PlanetWithInfo, Pin } from "@/types";
|
||||||
import { Box, Stack, Typography, useTheme, Paper, IconButton, Divider } from "@mui/material";
|
import { Box, Stack, Typography, useTheme, Paper, IconButton, Divider } from "@mui/material";
|
||||||
import { CharacterRow } from "../Characters/CharacterRow";
|
import { CharacterRow } from "../Characters/CharacterRow";
|
||||||
import { PlanetaryInteractionRow } from "../PlanetaryInteraction/PlanetaryInteractionRow";
|
import { PlanetaryInteractionRow } from "../PlanetaryInteraction/PlanetaryInteractionRow";
|
||||||
@@ -7,9 +7,14 @@ import { useContext, useState, useEffect } from "react";
|
|||||||
import { PlanRow } from "./PlanRow";
|
import { PlanRow } from "./PlanRow";
|
||||||
import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown';
|
import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown';
|
||||||
import KeyboardArrowUpIcon from '@mui/icons-material/KeyboardArrowUp';
|
import KeyboardArrowUpIcon from '@mui/icons-material/KeyboardArrowUp';
|
||||||
|
import ChevronRightIcon from '@mui/icons-material/ChevronRight';
|
||||||
|
import { DragDropContext, Droppable, Draggable, DropResult } from "@hello-pangea/dnd";
|
||||||
import { planetCalculations } from "@/planets";
|
import { planetCalculations } from "@/planets";
|
||||||
import { EvePraisalResult } from "@/eve-praisal";
|
import { EvePraisalResult } from "@/eve-praisal";
|
||||||
import { STORAGE_IDS } from "@/const";
|
import { STORAGE_IDS, PI_SCHEMATICS, PI_PRODUCT_VOLUMES, STORAGE_CAPACITIES } from "@/const";
|
||||||
|
import { DateTime } from "luxon";
|
||||||
|
import { PlanetCalculations, AlertState, StorageContent, StorageInfo } from "@/types/planet";
|
||||||
|
import { getProgramOutputPrediction } from "../PlanetaryInteraction/ExtractionSimulation";
|
||||||
|
|
||||||
interface AccountTotals {
|
interface AccountTotals {
|
||||||
monthlyEstimate: number;
|
monthlyEstimate: number;
|
||||||
@@ -20,6 +25,158 @@ interface AccountTotals {
|
|||||||
totalExtractors: number;
|
totalExtractors: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const calculateAlertState = (planetDetails: PlanetCalculations, minExtractionRate: number): AlertState => {
|
||||||
|
const hasLowStorage = planetDetails.storageInfo.some(storage => storage.fillRate > 60);
|
||||||
|
const hasLowImports = planetDetails.importDepletionTimes.some(depletion => depletion.hoursUntilDepletion < 24);
|
||||||
|
const hasLowExtractionRate = planetDetails.extractorAverages.length > 0 && minExtractionRate > 0 && planetDetails.extractorAverages.some(avg => avg.averagePerHour < minExtractionRate);
|
||||||
|
|
||||||
|
return {
|
||||||
|
expired: planetDetails.expired,
|
||||||
|
hasLowStorage,
|
||||||
|
hasLowImports,
|
||||||
|
hasLargeExtractorDifference: planetDetails.hasLargeExtractorDifference,
|
||||||
|
hasLowExtractionRate
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const calculatePlanetDetails = (planet: PlanetWithInfo, piPrices: EvePraisalResult | undefined, balanceThreshold: number): PlanetCalculations => {
|
||||||
|
const { expired, extractors, localProduction: rawProduction, localImports, localExports: rawExports } = planetCalculations(planet);
|
||||||
|
|
||||||
|
// Convert localProduction to include factoryCount
|
||||||
|
const localProduction = new Map(Array.from(rawProduction).map(([key, value]) => [
|
||||||
|
key,
|
||||||
|
{
|
||||||
|
...value,
|
||||||
|
factoryCount: value.count || 1
|
||||||
|
}
|
||||||
|
]));
|
||||||
|
|
||||||
|
// Calculate extractor averages and check for large differences
|
||||||
|
const CYCLE_TIME = 30 * 60; // 30 minutes in seconds
|
||||||
|
const extractorAverages = extractors
|
||||||
|
.filter(e => e.extractor_details?.product_type_id && e.extractor_details?.qty_per_cycle)
|
||||||
|
.map(e => {
|
||||||
|
const installDate = new Date(e.install_time ?? "");
|
||||||
|
const expiryDate = new Date(e.expiry_time ?? "");
|
||||||
|
const programDuration = (expiryDate.getTime() - installDate.getTime()) / 1000;
|
||||||
|
const cycles = Math.floor(programDuration / CYCLE_TIME);
|
||||||
|
|
||||||
|
const qtyPerCycle = e.extractor_details?.qty_per_cycle || 0;
|
||||||
|
const prediction = getProgramOutputPrediction(qtyPerCycle, CYCLE_TIME, cycles);
|
||||||
|
const totalOutput = prediction.reduce((sum, val) => sum + val, 0);
|
||||||
|
const averagePerHour = totalOutput / cycles * 2;
|
||||||
|
|
||||||
|
return {
|
||||||
|
typeId: e.extractor_details!.product_type_id!,
|
||||||
|
averagePerHour
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const hasLargeExtractorDifference = extractorAverages.length === 2 &&
|
||||||
|
Math.abs(extractorAverages[0].averagePerHour - extractorAverages[1].averagePerHour) > balanceThreshold;
|
||||||
|
|
||||||
|
// Calculate storage info
|
||||||
|
const storageFacilities = planet.info.pins.filter((pin: Pin) =>
|
||||||
|
STORAGE_IDS().some(storage => storage.type_id === pin.type_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
const storageInfo = storageFacilities.map((storage: Pin) => {
|
||||||
|
if (!storage || !storage.contents) return null;
|
||||||
|
|
||||||
|
const storageType = STORAGE_IDS().find(s => s.type_id === storage.type_id)?.name || 'Unknown';
|
||||||
|
const storageCapacity = STORAGE_CAPACITIES[storage.type_id] || 0;
|
||||||
|
|
||||||
|
const totalVolume = (storage.contents || [])
|
||||||
|
.reduce((sum: number, item: StorageContent) => {
|
||||||
|
const volume = PI_PRODUCT_VOLUMES[item.type_id] || 0;
|
||||||
|
return sum + (item.amount * volume);
|
||||||
|
}, 0);
|
||||||
|
|
||||||
|
const totalValue = (storage.contents || [])
|
||||||
|
.reduce((sum: number, item: StorageContent) => {
|
||||||
|
const price = piPrices?.appraisal.items.find((a) => a.typeID === item.type_id)?.prices.sell.min ?? 0;
|
||||||
|
return sum + (item.amount * price);
|
||||||
|
}, 0);
|
||||||
|
|
||||||
|
const fillRate = storageCapacity > 0 ? (totalVolume / storageCapacity) * 100 : 0;
|
||||||
|
|
||||||
|
return {
|
||||||
|
pin_id: storage.pin_id,
|
||||||
|
type: storageType,
|
||||||
|
type_id: storage.type_id,
|
||||||
|
capacity: storageCapacity,
|
||||||
|
used: totalVolume,
|
||||||
|
fillRate: fillRate,
|
||||||
|
value: totalValue
|
||||||
|
};
|
||||||
|
}).filter(Boolean) as StorageInfo[];
|
||||||
|
|
||||||
|
// Calculate import depletion times
|
||||||
|
const importDepletionTimes = localImports.map(i => {
|
||||||
|
// Find all storage facilities containing this import
|
||||||
|
const storagesWithImport = storageFacilities.filter((storage: Pin) =>
|
||||||
|
storage.contents?.some((content: StorageContent) => content.type_id === i.type_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Get the total amount in all storage facilities
|
||||||
|
const totalAmount = storagesWithImport.reduce((sum: number, storage: Pin) => {
|
||||||
|
const content = storage.contents?.find((content: StorageContent) => 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, starting from last_update
|
||||||
|
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;
|
||||||
|
|
||||||
|
// Calculate monthly cost
|
||||||
|
const price = piPrices?.appraisal.items.find((a) => a.typeID === i.type_id)?.prices.sell.min ?? 0;
|
||||||
|
const monthlyCost = (consumptionPerHour * 24 * 30 * price) / 1000000; // Cost in millions
|
||||||
|
|
||||||
|
return {
|
||||||
|
typeId: i.type_id,
|
||||||
|
hoursUntilDepletion,
|
||||||
|
monthlyCost
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// Convert localExports to match the LocalExport interface
|
||||||
|
const localExports = rawExports.map(e => {
|
||||||
|
const schematic = PI_SCHEMATICS.flatMap(s => s.outputs)
|
||||||
|
.find(s => s.type_id === e.typeId)?.schematic_id ?? 0;
|
||||||
|
const factoryCount = planet.info.pins
|
||||||
|
.filter(p => p.schematic_id === schematic)
|
||||||
|
.length;
|
||||||
|
|
||||||
|
return {
|
||||||
|
type_id: e.typeId,
|
||||||
|
schematic_id: schematic,
|
||||||
|
quantity: e.amount / factoryCount, // Convert total amount back to per-factory quantity
|
||||||
|
factoryCount
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
expired,
|
||||||
|
extractors,
|
||||||
|
localProduction,
|
||||||
|
localImports,
|
||||||
|
localExports,
|
||||||
|
storageInfo,
|
||||||
|
extractorAverages,
|
||||||
|
hasLargeExtractorDifference,
|
||||||
|
importDepletionTimes,
|
||||||
|
visibility: 'visible' as const
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
const calculateAccountTotals = (characters: AccessToken[], piPrices: EvePraisalResult | undefined): AccountTotals => {
|
const calculateAccountTotals = (characters: AccessToken[], piPrices: EvePraisalResult | undefined): AccountTotals => {
|
||||||
let totalMonthlyEstimate = 0;
|
let totalMonthlyEstimate = 0;
|
||||||
let totalStorageValue = 0;
|
let totalStorageValue = 0;
|
||||||
@@ -86,14 +243,114 @@ const calculateAccountTotals = (characters: AccessToken[], piPrices: EvePraisalR
|
|||||||
export const AccountCard = ({ characters, isCollapsed: propIsCollapsed }: { characters: AccessToken[], isCollapsed?: boolean }) => {
|
export const AccountCard = ({ characters, isCollapsed: propIsCollapsed }: { characters: AccessToken[], isCollapsed?: boolean }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const [localIsCollapsed, setLocalIsCollapsed] = useState(false);
|
const [localIsCollapsed, setLocalIsCollapsed] = useState(false);
|
||||||
const { planMode, piPrices } = useContext(SessionContext);
|
const { planMode, piPrices, alertMode, balanceThreshold, minExtractionRate } = useContext(SessionContext);
|
||||||
|
const accountName = characters.length > 0 ? (characters[0].account ?? "-") : "-";
|
||||||
|
const [characterOrder, setCharacterOrder] = useState<number[]>(() => {
|
||||||
|
try {
|
||||||
|
const saved = localStorage.getItem(`characterOrder-${accountName}`);
|
||||||
|
if (saved) {
|
||||||
|
const parsed: number[] = JSON.parse(saved);
|
||||||
|
const ids = characters.map(c => c.character.characterId);
|
||||||
|
const valid = parsed.filter(id => ids.includes(id));
|
||||||
|
const newIds = ids.filter(id => !valid.includes(id));
|
||||||
|
return [...valid, ...newIds];
|
||||||
|
}
|
||||||
|
} catch (_) { /* ignore corrupt localStorage */ }
|
||||||
|
return characters.map(c => c.character.characterId);
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const ids = characters.map(c => c.character.characterId);
|
||||||
|
setCharacterOrder(prev => {
|
||||||
|
const valid = prev.filter(id => ids.includes(id));
|
||||||
|
const newIds = ids.filter(id => !valid.includes(id));
|
||||||
|
return [...valid, ...newIds];
|
||||||
|
});
|
||||||
|
}, [characters]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (characterOrder.length > 0) {
|
||||||
|
localStorage.setItem(`characterOrder-${accountName}`, JSON.stringify(characterOrder));
|
||||||
|
}
|
||||||
|
}, [characterOrder, accountName]);
|
||||||
|
|
||||||
|
const [collapsedCharacters, setCollapsedCharacters] = useState<Set<number>>(() => {
|
||||||
|
try {
|
||||||
|
const saved = localStorage.getItem(`collapsedCharacters-${accountName}`);
|
||||||
|
if (saved) return new Set<number>(JSON.parse(saved));
|
||||||
|
} catch (_) { /* ignore corrupt localStorage */ }
|
||||||
|
return new Set<number>();
|
||||||
|
});
|
||||||
|
|
||||||
|
const toggleCharacterCollapsed = (characterId: number) => {
|
||||||
|
setCollapsedCharacters(prev => {
|
||||||
|
const next = new Set(prev);
|
||||||
|
if (next.has(characterId)) next.delete(characterId);
|
||||||
|
else next.add(characterId);
|
||||||
|
localStorage.setItem(`collapsedCharacters-${accountName}`, JSON.stringify(Array.from(next)));
|
||||||
|
return next;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const orderedCharacters = characterOrder
|
||||||
|
.map(id => characters.find(c => c.character.characterId === id))
|
||||||
|
.filter((c): c is AccessToken => c !== undefined);
|
||||||
|
|
||||||
|
const handleCharacterDragEnd = (result: DropResult) => {
|
||||||
|
if (!result.destination) return;
|
||||||
|
const items = Array.from(characterOrder);
|
||||||
|
const [moved] = items.splice(result.source.index, 1);
|
||||||
|
items.splice(result.destination.index, 0, moved);
|
||||||
|
setCharacterOrder(items);
|
||||||
|
};
|
||||||
|
|
||||||
|
const DragDropContextComponent = DragDropContext as any;
|
||||||
|
const DroppableComponent = Droppable as any;
|
||||||
|
const DraggableComponent = Draggable as any;
|
||||||
const { monthlyEstimate, storageValue, planetCount, characterCount, runningExtractors, totalExtractors } = calculateAccountTotals(characters, piPrices);
|
const { monthlyEstimate, storageValue, planetCount, characterCount, runningExtractors, totalExtractors } = calculateAccountTotals(characters, piPrices);
|
||||||
|
|
||||||
|
// Calculate planet details and alert states for each planet
|
||||||
|
const planetDetails = characters.reduce((acc, character) => {
|
||||||
|
character.planets.forEach(planet => {
|
||||||
|
const details = calculatePlanetDetails(planet, piPrices, balanceThreshold);
|
||||||
|
acc[`${character.character.characterId}-${planet.planet_id}`] = {
|
||||||
|
...details,
|
||||||
|
alertState: calculateAlertState(details, minExtractionRate)
|
||||||
|
};
|
||||||
|
});
|
||||||
|
return acc;
|
||||||
|
}, {} as Record<string, PlanetCalculations & { alertState: AlertState }>);
|
||||||
|
|
||||||
// Update local collapse state when prop changes
|
// Update local collapse state when prop changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setLocalIsCollapsed(propIsCollapsed ?? false);
|
setLocalIsCollapsed(propIsCollapsed ?? false);
|
||||||
}, [propIsCollapsed]);
|
}, [propIsCollapsed]);
|
||||||
|
|
||||||
|
const getAlertVisibility = (alertState: AlertState) => {
|
||||||
|
if (!alertMode) return 'visible';
|
||||||
|
if (alertState.expired) return 'visible';
|
||||||
|
if (alertState.hasLowStorage) return 'visible';
|
||||||
|
if (alertState.hasLowImports) return 'visible';
|
||||||
|
if (alertState.hasLargeExtractorDifference) return 'visible';
|
||||||
|
if (alertState.hasLowExtractionRate) return 'visible';
|
||||||
|
return 'hidden';
|
||||||
|
};
|
||||||
|
|
||||||
|
// Check if any planet in the account has alerts
|
||||||
|
const hasAnyAlerts = Object.values(planetDetails).some(details => {
|
||||||
|
const alertState = calculateAlertState(details, minExtractionRate);
|
||||||
|
return alertState.expired ||
|
||||||
|
alertState.hasLowStorage ||
|
||||||
|
alertState.hasLowImports ||
|
||||||
|
alertState.hasLargeExtractorDifference ||
|
||||||
|
alertState.hasLowExtractionRate;
|
||||||
|
});
|
||||||
|
|
||||||
|
// If in alert mode and no alerts, hide the entire card
|
||||||
|
if (alertMode && !hasAnyAlerts) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Paper
|
<Paper
|
||||||
elevation={2}
|
elevation={2}
|
||||||
@@ -199,6 +456,24 @@ export const AccountCard = ({ characters, isCollapsed: propIsCollapsed }: { char
|
|||||||
>
|
>
|
||||||
Extractors: {runningExtractors}/{totalExtractors}
|
Extractors: {runningExtractors}/{totalExtractors}
|
||||||
</Typography>
|
</Typography>
|
||||||
|
<Divider orientation="vertical" flexItem sx={{ height: 16, borderColor: theme.palette.divider }} />
|
||||||
|
<Typography
|
||||||
|
sx={{
|
||||||
|
fontSize: "0.8rem",
|
||||||
|
color: Object.values(planetDetails).some(d => d.alertState.hasLowStorage) ? theme.palette.error.main : theme.palette.text.secondary,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Storage Alerts: {Object.values(planetDetails).filter(d => d.alertState.hasLowStorage).length}
|
||||||
|
</Typography>
|
||||||
|
<Divider orientation="vertical" flexItem sx={{ height: 16, borderColor: theme.palette.divider }} />
|
||||||
|
<Typography
|
||||||
|
sx={{
|
||||||
|
fontSize: "0.8rem",
|
||||||
|
color: Object.values(planetDetails).some(d => d.alertState.hasLargeExtractorDifference) ? theme.palette.error.main : theme.palette.text.secondary,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Balance Alerts: {Object.values(planetDetails).filter(d => d.alertState.hasLargeExtractorDifference).length}
|
||||||
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
<IconButton
|
<IconButton
|
||||||
@@ -211,20 +486,94 @@ export const AccountCard = ({ characters, isCollapsed: propIsCollapsed }: { char
|
|||||||
{localIsCollapsed ? <KeyboardArrowUpIcon /> : <KeyboardArrowDownIcon />}
|
{localIsCollapsed ? <KeyboardArrowUpIcon /> : <KeyboardArrowDownIcon />}
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Box>
|
</Box>
|
||||||
{!localIsCollapsed && characters.map((c) => (
|
{!localIsCollapsed && (
|
||||||
<Stack
|
<DragDropContextComponent onDragEnd={handleCharacterDragEnd}>
|
||||||
key={c.character.characterId}
|
<DroppableComponent droppableId={`characters-${accountName}`} direction="vertical">
|
||||||
direction="row"
|
{(provided: any) => (
|
||||||
alignItems="flex-start"
|
<Box ref={provided.innerRef} {...provided.droppableProps}>
|
||||||
>
|
{orderedCharacters.map((c, index) => (
|
||||||
<CharacterRow character={c} />
|
<DraggableComponent
|
||||||
{planMode ? (
|
key={c.character.characterId}
|
||||||
<PlanRow character={c} />
|
draggableId={`char-${c.character.characterId}`}
|
||||||
) : (
|
index={index}
|
||||||
<PlanetaryInteractionRow character={c} />
|
>
|
||||||
)}
|
{(provided: any, snapshot: any) => (
|
||||||
</Stack>
|
<Stack
|
||||||
))}
|
ref={provided.innerRef}
|
||||||
|
{...provided.draggableProps}
|
||||||
|
direction="row"
|
||||||
|
alignItems="flex-start"
|
||||||
|
sx={{
|
||||||
|
opacity: snapshot.isDragging ? 0.8 : 1,
|
||||||
|
backgroundColor: snapshot.isDragging ? theme.palette.action.hover : 'transparent',
|
||||||
|
borderRadius: 1,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
alignItems: 'center',
|
||||||
|
pt: 1,
|
||||||
|
gap: 0.5,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Box
|
||||||
|
{...provided.dragHandleProps}
|
||||||
|
sx={{
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
cursor: 'grab',
|
||||||
|
px: 0.5,
|
||||||
|
color: theme.palette.text.disabled,
|
||||||
|
'&:hover': { color: theme.palette.text.secondary },
|
||||||
|
'&:active': { cursor: 'grabbing' },
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
⠿
|
||||||
|
</Box>
|
||||||
|
<IconButton
|
||||||
|
size="small"
|
||||||
|
onClick={() => toggleCharacterCollapsed(c.character.characterId)}
|
||||||
|
sx={{
|
||||||
|
p: 0.25,
|
||||||
|
color: theme.palette.text.disabled,
|
||||||
|
'&:hover': { color: theme.palette.text.secondary },
|
||||||
|
transform: collapsedCharacters.has(c.character.characterId) ? 'rotate(0deg)' : 'rotate(90deg)',
|
||||||
|
transition: 'transform 0.2s ease-in-out',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<ChevronRightIcon fontSize="small" />
|
||||||
|
</IconButton>
|
||||||
|
</Box>
|
||||||
|
<CharacterRow character={c} />
|
||||||
|
{!collapsedCharacters.has(c.character.characterId) && (
|
||||||
|
planMode ? (
|
||||||
|
<PlanRow character={c} />
|
||||||
|
) : (
|
||||||
|
<PlanetaryInteractionRow
|
||||||
|
character={c}
|
||||||
|
planetDetails={c.planets.reduce((acc, planet) => {
|
||||||
|
const details = planetDetails[`${c.character.characterId}-${planet.planet_id}`];
|
||||||
|
acc[planet.planet_id] = {
|
||||||
|
...details,
|
||||||
|
visibility: getAlertVisibility(details.alertState)
|
||||||
|
};
|
||||||
|
return acc;
|
||||||
|
}, {} as Record<number, PlanetCalculations & { visibility: string }>)}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
</Stack>
|
||||||
|
)}
|
||||||
|
</DraggableComponent>
|
||||||
|
))}
|
||||||
|
{provided.placeholder}
|
||||||
|
</Box>
|
||||||
|
)}
|
||||||
|
</DroppableComponent>
|
||||||
|
</DragDropContextComponent>
|
||||||
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
</Paper>
|
</Paper>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -15,7 +15,9 @@ import { CCPButton } from "../CCP/CCPButton";
|
|||||||
import { DiscordButton } from "../Discord/DiscordButton";
|
import { DiscordButton } from "../Discord/DiscordButton";
|
||||||
import { GitHubButton } from "../Github/GitHubButton";
|
import { GitHubButton } from "../Github/GitHubButton";
|
||||||
import { LoginButton } from "../Login/LoginButton";
|
import { LoginButton } from "../Login/LoginButton";
|
||||||
|
import { PartnerCodeButton } from "../PartnerCode/PartnerCodeButton";
|
||||||
import { SettingsButton } from "../Settings/SettingsButtons";
|
import { SettingsButton } from "../Settings/SettingsButtons";
|
||||||
|
import { BuyMeCoffeeButton } from "../BuyMeCoffee/BuyMeCoffeeButton";
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
Dialog,
|
Dialog,
|
||||||
@@ -128,6 +130,12 @@ function ResponsiveAppBar() {
|
|||||||
<MenuItem onClick={handleCloseNavMenu}>
|
<MenuItem onClick={handleCloseNavMenu}>
|
||||||
<CCPButton />
|
<CCPButton />
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
<MenuItem onClick={handleCloseNavMenu}>
|
||||||
|
<PartnerCodeButton />
|
||||||
|
</MenuItem>
|
||||||
|
<MenuItem onClick={handleCloseNavMenu}>
|
||||||
|
<BuyMeCoffeeButton />
|
||||||
|
</MenuItem>
|
||||||
</Menu>
|
</Menu>
|
||||||
</Box>
|
</Box>
|
||||||
<PublicIcon sx={{ display: { xs: "flex", md: "none" }, mr: 1 }} />
|
<PublicIcon sx={{ display: { xs: "flex", md: "none" }, mr: 1 }} />
|
||||||
@@ -162,12 +170,14 @@ function ResponsiveAppBar() {
|
|||||||
<UploadButton />
|
<UploadButton />
|
||||||
<DiscordButton />
|
<DiscordButton />
|
||||||
<GitHubButton />
|
<GitHubButton />
|
||||||
|
|
||||||
<SettingsButton />
|
<SettingsButton />
|
||||||
<Button onClick={() => setFaqOpen(true)} color="inherit">
|
<Button onClick={() => setFaqOpen(true)} color="inherit">
|
||||||
FAQ
|
FAQ
|
||||||
</Button>
|
</Button>
|
||||||
<CCPButton />
|
<CCPButton />
|
||||||
|
<PartnerCodeButton />
|
||||||
|
<BuyMeCoffeeButton />
|
||||||
</Box>
|
</Box>
|
||||||
</Toolbar>
|
</Toolbar>
|
||||||
</Container>
|
</Container>
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import { Box, Button, Tooltip } from "@mui/material";
|
||||||
|
export const BuyMeCoffeeButton = () => {
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<Tooltip title="Support the development of this tool">
|
||||||
|
<Button
|
||||||
|
href="https://buymeacoffee.com/evepi"
|
||||||
|
target="_blank"
|
||||||
|
style={{ width: "100%" }}
|
||||||
|
sx={{ color: "white", display: "block" }}
|
||||||
|
>
|
||||||
|
By me a beer
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -4,7 +4,7 @@ export const DiscordButton = () => {
|
|||||||
<Box>
|
<Box>
|
||||||
<Tooltip title="Come nerd out in discord about PI and this tool">
|
<Tooltip title="Come nerd out in discord about PI and this tool">
|
||||||
<Button
|
<Button
|
||||||
href="https://discord.gg/GPtw5kfuJu"
|
href="https://discord.gg/bCdXzU8PHK"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
style={{ width: "100%" }}
|
style={{ width: "100%" }}
|
||||||
sx={{ color: "white", display: "block" }}
|
sx={{ color: "white", display: "block" }}
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ export const LoginDialog = ({
|
|||||||
DEFAULT_SCOPES_TO_SELECT
|
DEFAULT_SCOPES_TO_SELECT
|
||||||
);
|
);
|
||||||
const [ssoUrl, setSsoUrl] = useState<string | undefined>(undefined);
|
const [ssoUrl, setSsoUrl] = useState<string | undefined>(undefined);
|
||||||
const [loginUrl, setLoginUrl] = useState<string | undefined>(undefined);
|
|
||||||
|
|
||||||
const { EVE_SSO_CLIENT_ID, EVE_SSO_CALLBACK_URL } =
|
const { EVE_SSO_CLIENT_ID, EVE_SSO_CALLBACK_URL } =
|
||||||
useContext(SessionContext);
|
useContext(SessionContext);
|
||||||
@@ -30,15 +29,6 @@ export const LoginDialog = ({
|
|||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!ssoUrl || selectedScopes.length === 0) return;
|
|
||||||
loginParameters(
|
|
||||||
selectedScopes,
|
|
||||||
EVE_SSO_CLIENT_ID,
|
|
||||||
EVE_SSO_CALLBACK_URL
|
|
||||||
).then((res) => setLoginUrl(ssoUrl + "?" + res));
|
|
||||||
}, [selectedScopes, ssoUrl, EVE_SSO_CLIENT_ID, EVE_SSO_CALLBACK_URL]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} onClose={closeDialog}>
|
<Dialog open={open} onClose={closeDialog}>
|
||||||
<DialogTitle>Select scopes to login with</DialogTitle>
|
<DialogTitle>Select scopes to login with</DialogTitle>
|
||||||
@@ -59,8 +49,11 @@ export const LoginDialog = ({
|
|||||||
<DialogActions>
|
<DialogActions>
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
|
disabled={!ssoUrl || selectedScopes.length === 0}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
window.open(loginUrl, "_self");
|
if (!ssoUrl) return;
|
||||||
|
const params = loginParameters(selectedScopes, EVE_SSO_CLIENT_ID, EVE_SSO_CALLBACK_URL);
|
||||||
|
window.open(ssoUrl + "?" + params, "_self");
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Login
|
Login
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ declare module "@mui/material/styles" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const MainGrid = () => {
|
export const MainGrid = () => {
|
||||||
const { characters, updateCharacter } = useContext(CharacterContext);
|
const { characters } = useContext(CharacterContext);
|
||||||
const { compactMode, toggleCompactMode, alertMode, toggleAlertMode, planMode, togglePlanMode, extractionTimeMode, toggleExtractionTimeMode } = useContext(SessionContext);
|
const { compactMode, toggleCompactMode, alertMode, toggleAlertMode, planMode, togglePlanMode, extractionTimeMode, toggleExtractionTimeMode } = useContext(SessionContext);
|
||||||
const [accountOrder, setAccountOrder] = useState<string[]>([]);
|
const [accountOrder, setAccountOrder] = useState<string[]>([]);
|
||||||
const [allCollapsed, setAllCollapsed] = useState(false);
|
const [allCollapsed, setAllCollapsed] = useState(false);
|
||||||
@@ -170,7 +170,7 @@ export const MainGrid = () => {
|
|||||||
size="small"
|
size="small"
|
||||||
style={{
|
style={{
|
||||||
backgroundColor: compactMode
|
backgroundColor: compactMode
|
||||||
? "rgba(144, 202, 249, 0.08)"
|
? "rgba(144, 202, 249, 0.16)"
|
||||||
: "inherit",
|
: "inherit",
|
||||||
}}
|
}}
|
||||||
onClick={toggleCompactMode}
|
onClick={toggleCompactMode}
|
||||||
@@ -183,7 +183,7 @@ export const MainGrid = () => {
|
|||||||
size="small"
|
size="small"
|
||||||
style={{
|
style={{
|
||||||
backgroundColor: alertMode
|
backgroundColor: alertMode
|
||||||
? "rgba(144, 202, 249, 0.08)"
|
? "rgba(144, 202, 249, 0.16)"
|
||||||
: "inherit",
|
: "inherit",
|
||||||
}}
|
}}
|
||||||
onClick={toggleAlertMode}
|
onClick={toggleAlertMode}
|
||||||
@@ -196,7 +196,7 @@ export const MainGrid = () => {
|
|||||||
size="small"
|
size="small"
|
||||||
style={{
|
style={{
|
||||||
backgroundColor: planMode
|
backgroundColor: planMode
|
||||||
? "rgba(144, 202, 249, 0.08)"
|
? "rgba(144, 202, 249, 0.16)"
|
||||||
: "inherit",
|
: "inherit",
|
||||||
}}
|
}}
|
||||||
onClick={togglePlanMode}
|
onClick={togglePlanMode}
|
||||||
@@ -209,7 +209,7 @@ export const MainGrid = () => {
|
|||||||
size="small"
|
size="small"
|
||||||
style={{
|
style={{
|
||||||
backgroundColor: extractionTimeMode
|
backgroundColor: extractionTimeMode
|
||||||
? "rgba(144, 202, 249, 0.08)"
|
? "rgba(144, 202, 249, 0.16)"
|
||||||
: "inherit",
|
: "inherit",
|
||||||
}}
|
}}
|
||||||
onClick={toggleExtractionTimeMode}
|
onClick={toggleExtractionTimeMode}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import { Box, Button, Tooltip } from "@mui/material";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
|
export const PartnerCodeButton = () => {
|
||||||
|
const [copied, setCopied] = useState(false);
|
||||||
|
|
||||||
|
const handleClick = () => {
|
||||||
|
navigator.clipboard.writeText("CALLIEVE");
|
||||||
|
setCopied(true);
|
||||||
|
setTimeout(() => setCopied(false), 2000);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<Tooltip
|
||||||
|
title={
|
||||||
|
copied
|
||||||
|
? "Copied to clipboard!"
|
||||||
|
: "Click to copy partner code - Use for CCP purchases to support this project"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
onClick={handleClick}
|
||||||
|
style={{ width: "100%" }}
|
||||||
|
sx={{ color: "white", display: "block" }}
|
||||||
|
>
|
||||||
|
Partner Code: CALLIEVE
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import { DateTime } from "luxon";
|
import { DateTime } from "luxon";
|
||||||
import Countdown from "react-countdown";
|
import Countdown from "react-countdown";
|
||||||
import { timeColor } from "../PlanetaryInteraction/timeColors";
|
import { timeColor } from "../PlanetaryInteraction/alerts";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import { ColorContext, SessionContext } from "@/app/context/Context";
|
import { ColorContext, SessionContext } from "@/app/context/Context";
|
||||||
import { useContext } from "react";
|
import { useContext } from "react";
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import React from 'react';
|
import React, { useContext } from 'react';
|
||||||
import { Box, Paper, Typography, Stack } from '@mui/material';
|
import { Box, Paper, Typography, Stack } from '@mui/material';
|
||||||
import { Line } from 'react-chartjs-2';
|
import { Line } from 'react-chartjs-2';
|
||||||
import { getProgramOutputPrediction } from './ExtractionSimulation';
|
import { getProgramOutputPrediction } from './ExtractionSimulation';
|
||||||
import { PI_TYPES_MAP } from '@/const';
|
import { PI_TYPES_MAP } from '@/const';
|
||||||
|
import { SessionContext } from '@/app/context/Context';
|
||||||
import {
|
import {
|
||||||
Chart as ChartJS,
|
Chart as ChartJS,
|
||||||
CategoryScale,
|
CategoryScale,
|
||||||
@@ -41,6 +42,7 @@ interface ExtractionSimulationTooltipProps {
|
|||||||
export const ExtractionSimulationTooltip: React.FC<ExtractionSimulationTooltipProps> = ({
|
export const ExtractionSimulationTooltip: React.FC<ExtractionSimulationTooltipProps> = ({
|
||||||
extractors
|
extractors
|
||||||
}) => {
|
}) => {
|
||||||
|
const { minExtractionRate } = useContext(SessionContext);
|
||||||
const CYCLE_TIME = 30 * 60; // 30 minutes in seconds
|
const CYCLE_TIME = 30 * 60; // 30 minutes in seconds
|
||||||
|
|
||||||
// Calculate program duration and cycles for each extractor
|
// Calculate program duration and cycles for each extractor
|
||||||
@@ -133,7 +135,7 @@ export const ExtractionSimulationTooltip: React.FC<ExtractionSimulationTooltipPr
|
|||||||
</Box>
|
</Box>
|
||||||
<Box sx={{ flex: 1, minWidth: 0 }}>
|
<Box sx={{ flex: 1, minWidth: 0 }}>
|
||||||
<Stack spacing={1}>
|
<Stack spacing={1}>
|
||||||
{extractorPrograms.map(({ typeId, cycleTime, cycles, installTime, expiryTime }, idx) => {
|
{extractorPrograms.map(({ typeId, cycleTime, cycles, expiryTime }, idx) => {
|
||||||
const prediction = getProgramOutputPrediction(
|
const prediction = getProgramOutputPrediction(
|
||||||
extractors[idx].baseValue,
|
extractors[idx].baseValue,
|
||||||
CYCLE_TIME,
|
CYCLE_TIME,
|
||||||
@@ -159,8 +161,15 @@ export const ExtractionSimulationTooltip: React.FC<ExtractionSimulationTooltipPr
|
|||||||
<Typography variant="body2">
|
<Typography variant="body2">
|
||||||
• Average per Cycle: {(totalOutput / cycles).toFixed(1)} units
|
• Average per Cycle: {(totalOutput / cycles).toFixed(1)} units
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography variant="body2">
|
<Typography
|
||||||
• Average per hour: {(totalOutput / cycles * 2).toFixed(1)} units
|
variant="body2"
|
||||||
|
color={
|
||||||
|
minExtractionRate > 0 && (extractors[idx].baseValue * 3600) / extractors[idx].cycleTime < minExtractionRate
|
||||||
|
? 'error'
|
||||||
|
: 'inherit'
|
||||||
|
}
|
||||||
|
>
|
||||||
|
• Average per hour: {(totalOutput / cycles * 2).toFixed(1)} units
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography variant="body2">
|
<Typography variant="body2">
|
||||||
• Expires in: <Countdown overtime={true} date={DateTime.fromISO(expiryTime).toMillis()} />
|
• Expires in: <Countdown overtime={true} date={DateTime.fromISO(expiryTime).toMillis()} />
|
||||||
@@ -176,17 +185,24 @@ export const ExtractionSimulationTooltip: React.FC<ExtractionSimulationTooltipPr
|
|||||||
</Typography>
|
</Typography>
|
||||||
<Stack spacing={0.5}>
|
<Stack spacing={0.5}>
|
||||||
{extractors.map((extractor, index) => {
|
{extractors.map((extractor, index) => {
|
||||||
const averagePerHour = (extractor.baseValue * 3600) / extractor.cycleTime;
|
const prediction = getProgramOutputPrediction(
|
||||||
|
extractor.baseValue,
|
||||||
|
CYCLE_TIME,
|
||||||
|
extractorPrograms[index].cycles
|
||||||
|
);
|
||||||
|
const totalOutput = prediction.reduce((sum, val) => sum + val, 0);
|
||||||
|
const cycles = extractorPrograms[index].cycles;
|
||||||
|
const averagePerHour = totalOutput / cycles * 2;
|
||||||
return (
|
return (
|
||||||
<Typography key={index} variant="body2">
|
<Typography key={index} variant="body2">
|
||||||
• {PI_TYPES_MAP[extractor.typeId]?.name}: {averagePerHour.toFixed(1)} u/h
|
• {PI_TYPES_MAP[extractor.typeId]?.name}: {averagePerHour.toFixed(1)} u/h
|
||||||
</Typography>
|
</Typography>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
<Typography
|
<Typography
|
||||||
variant="body2"
|
variant="body2"
|
||||||
color="error"
|
color="error"
|
||||||
sx={{
|
sx={{
|
||||||
mt: 1,
|
mt: 1,
|
||||||
fontWeight: 'bold',
|
fontWeight: 'bold',
|
||||||
borderTop: '1px solid',
|
borderTop: '1px solid',
|
||||||
@@ -194,10 +210,27 @@ export const ExtractionSimulationTooltip: React.FC<ExtractionSimulationTooltipPr
|
|||||||
pt: 1
|
pt: 1
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Difference: {Math.abs(
|
Difference: {(() => {
|
||||||
(extractors[0].baseValue * 3600 / extractors[0].cycleTime) -
|
const prediction0 = getProgramOutputPrediction(
|
||||||
(extractors[1].baseValue * 3600 / extractors[1].cycleTime)
|
extractors[0].baseValue,
|
||||||
).toFixed(1)} u/h
|
CYCLE_TIME,
|
||||||
|
extractorPrograms[0].cycles
|
||||||
|
);
|
||||||
|
const totalOutput0 = prediction0.reduce((sum, val) => sum + val, 0);
|
||||||
|
const cycles0 = extractorPrograms[0].cycles;
|
||||||
|
const avg0 = totalOutput0 / cycles0 * 2;
|
||||||
|
|
||||||
|
const prediction1 = getProgramOutputPrediction(
|
||||||
|
extractors[1].baseValue,
|
||||||
|
CYCLE_TIME,
|
||||||
|
extractorPrograms[1].cycles
|
||||||
|
);
|
||||||
|
const totalOutput1 = prediction1.reduce((sum, val) => sum + val, 0);
|
||||||
|
const cycles1 = extractorPrograms[1].cycles;
|
||||||
|
const avg1 = totalOutput1 / cycles1 * 2;
|
||||||
|
|
||||||
|
return Math.abs(avg0 - avg1).toFixed(1);
|
||||||
|
})()} u/h
|
||||||
</Typography>
|
</Typography>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Paper>
|
</Paper>
|
||||||
|
|||||||
@@ -4,18 +4,21 @@ import {
|
|||||||
AccessToken,
|
AccessToken,
|
||||||
PlanetWithInfo,
|
PlanetWithInfo,
|
||||||
} from "@/types";
|
} from "@/types";
|
||||||
|
import { PlanetCalculations } from "@/types/planet";
|
||||||
import React, { useContext } from "react";
|
import React, { useContext } from "react";
|
||||||
import { DateTime } from "luxon";
|
import { DateTime } from "luxon";
|
||||||
import { EXTRACTOR_TYPE_IDS } from "@/const";
|
|
||||||
import Countdown from "react-countdown";
|
import Countdown from "react-countdown";
|
||||||
import { getProgramOutputPrediction } from "./ExtractionSimulation";
|
|
||||||
import {
|
|
||||||
alertModeVisibility,
|
|
||||||
extractorsHaveExpired,
|
|
||||||
timeColor,
|
|
||||||
} from "./timeColors";
|
|
||||||
import { ColorContext, SessionContext } from "@/app/context/Context";
|
import { ColorContext, SessionContext } from "@/app/context/Context";
|
||||||
import { ExtractionSimulationTooltip } from "./ExtractionSimulationTooltip";
|
import { ExtractionSimulationTooltip } from "./ExtractionSimulationTooltip";
|
||||||
|
import { timeColor } from "./alerts";
|
||||||
|
|
||||||
|
interface ExtractorConfig {
|
||||||
|
typeId: number;
|
||||||
|
baseValue: number;
|
||||||
|
cycleTime: number;
|
||||||
|
installTime: string;
|
||||||
|
expiryTime: string;
|
||||||
|
}
|
||||||
|
|
||||||
const StackItem = styled(Stack)(({ theme }) => ({
|
const StackItem = styled(Stack)(({ theme }) => ({
|
||||||
...theme.typography.body2,
|
...theme.typography.body2,
|
||||||
@@ -29,82 +32,34 @@ const StackItem = styled(Stack)(({ theme }) => ({
|
|||||||
export const PlanetCard = ({
|
export const PlanetCard = ({
|
||||||
character,
|
character,
|
||||||
planet,
|
planet,
|
||||||
|
planetDetails,
|
||||||
}: {
|
}: {
|
||||||
character: AccessToken;
|
character: AccessToken;
|
||||||
planet: PlanetWithInfo;
|
planet: PlanetWithInfo;
|
||||||
|
planetDetails: PlanetCalculations;
|
||||||
}) => {
|
}) => {
|
||||||
const { alertMode } = useContext(SessionContext);
|
|
||||||
|
|
||||||
const planetInfo = planet.info;
|
|
||||||
const planetInfoUniverse = planet.infoUniverse;
|
|
||||||
|
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
const extractorsExpiryTime =
|
|
||||||
(planetInfo &&
|
|
||||||
planetInfo.pins
|
|
||||||
.filter((p) => EXTRACTOR_TYPE_IDS.some((e) => e === p.type_id))
|
|
||||||
.map((p) => p.expiry_time)) ??
|
|
||||||
[];
|
|
||||||
|
|
||||||
const { colors } = useContext(ColorContext);
|
const { colors } = useContext(ColorContext);
|
||||||
const expired = extractorsHaveExpired(extractorsExpiryTime);
|
const { minExtractionRate } = useContext(SessionContext);
|
||||||
|
|
||||||
const CYCLE_TIME = 30 * 60; // 30 minutes in seconds
|
const extractorConfigs: ExtractorConfig[] = planetDetails.extractors
|
||||||
|
.filter(e => e.extractor_details?.product_type_id && e.extractor_details?.qty_per_cycle)
|
||||||
|
.map(e => ({
|
||||||
|
typeId: e.extractor_details!.product_type_id!,
|
||||||
|
baseValue: e.extractor_details!.qty_per_cycle!,
|
||||||
|
cycleTime: e.extractor_details?.cycle_time || 3600,
|
||||||
|
installTime: e.install_time ?? "",
|
||||||
|
expiryTime: e.expiry_time ?? ""
|
||||||
|
}));
|
||||||
|
|
||||||
const extractors = planetInfo?.pins
|
const hasLowExtractionRate = planetDetails.extractorAverages.length > 0 && minExtractionRate > 0 && planetDetails.extractorAverages.some(avg => avg.averagePerHour < minExtractionRate);
|
||||||
.filter((p) => EXTRACTOR_TYPE_IDS.some((e) => e === p.type_id))
|
|
||||||
.map((p) => ({
|
|
||||||
typeId: p.type_id,
|
|
||||||
baseValue: p.extractor_details?.qty_per_cycle || 0,
|
|
||||||
cycleTime: p.extractor_details?.cycle_time || 3600,
|
|
||||||
installTime: p.install_time || "",
|
|
||||||
expiryTime: p.expiry_time || "",
|
|
||||||
installedSchematicId: p.extractor_details?.product_type_id || undefined
|
|
||||||
})) || [];
|
|
||||||
|
|
||||||
// Calculate program duration and cycles for each extractor
|
|
||||||
const extractorPrograms = extractors.map(extractor => {
|
|
||||||
const installDate = new Date(extractor.installTime);
|
|
||||||
const expiryDate = new Date(extractor.expiryTime);
|
|
||||||
const programDuration = (expiryDate.getTime() - installDate.getTime()) / 1000; // Convert to seconds
|
|
||||||
return {
|
|
||||||
...extractor,
|
|
||||||
programDuration,
|
|
||||||
cycles: Math.floor(programDuration / CYCLE_TIME)
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
// Get output predictions for each extractor
|
|
||||||
const extractorOutputs = extractorPrograms.map(extractor => ({
|
|
||||||
typeId: extractor.typeId,
|
|
||||||
cycleTime: CYCLE_TIME,
|
|
||||||
cycles: extractor.cycles,
|
|
||||||
prediction: getProgramOutputPrediction(
|
|
||||||
extractor.baseValue,
|
|
||||||
CYCLE_TIME,
|
|
||||||
extractor.cycles
|
|
||||||
)
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Calculate average per hour for each extractor
|
|
||||||
const extractorAverages = extractorOutputs.map(extractor => {
|
|
||||||
const totalOutput = extractor.prediction.reduce((sum, val) => sum + val, 0);
|
|
||||||
const programDuration = extractor.cycles * CYCLE_TIME;
|
|
||||||
const averagePerHour = (totalOutput / programDuration) * 3600;
|
|
||||||
return {
|
|
||||||
typeId: extractor.typeId,
|
|
||||||
averagePerHour
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tooltip
|
<Tooltip
|
||||||
title={
|
title={
|
||||||
extractors.length > 0 ? (
|
planetDetails.extractors.length > 0 ? (
|
||||||
<ExtractionSimulationTooltip
|
<ExtractionSimulationTooltip
|
||||||
extractors={extractors}
|
extractors={extractorConfigs}
|
||||||
/>
|
/>
|
||||||
) : null
|
) : null
|
||||||
}
|
}
|
||||||
@@ -121,14 +76,13 @@ export const PlanetCard = ({
|
|||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<StackItem
|
<StackItem
|
||||||
alignItems="flex-start"
|
alignItems="flex-start"
|
||||||
height="100%"
|
height="100%"
|
||||||
position="relative"
|
position="relative"
|
||||||
minHeight={theme.custom.cardMinHeight}
|
minHeight={theme.custom.cardMinHeight}
|
||||||
visibility={alertModeVisibility(alertMode, expired)}
|
style={{ visibility: planetDetails.visibility }}
|
||||||
>
|
>
|
||||||
|
|
||||||
<div style={{ position: 'relative' }}>
|
<div style={{ position: 'relative' }}>
|
||||||
<Image
|
<Image
|
||||||
unoptimized
|
unoptimized
|
||||||
@@ -153,55 +107,74 @@ export const PlanetCard = ({
|
|||||||
borderRadius: 8,
|
borderRadius: 8,
|
||||||
}} />
|
}} />
|
||||||
</div>
|
</div>
|
||||||
|
{planetDetails.expired && (
|
||||||
{expired && (
|
<Image
|
||||||
<Image
|
width={32}
|
||||||
width={32}
|
height={32}
|
||||||
height={32}
|
src={`/stopped.png`}
|
||||||
src={`/stopped.png`}
|
alt=""
|
||||||
alt=""
|
style={{ position: "absolute", top: theme.custom.stoppedPosition }}
|
||||||
style={{ position: "absolute", top: theme.custom.stoppedPosition }}
|
/>
|
||||||
/>
|
)}
|
||||||
)}
|
<div style={{ position: "absolute", top: 5, left: 10 }}>
|
||||||
<div style={{ position: "absolute", top: 5, left: 10 }}>
|
<Typography
|
||||||
<Typography fontSize={theme.custom.smallText}>
|
fontSize={theme.custom.smallText}
|
||||||
{planetInfoUniverse?.name}
|
color={(planetDetails.hasLargeExtractorDifference || hasLowExtractionRate) ? 'error' : 'inherit'}
|
||||||
</Typography>
|
>
|
||||||
{extractorsExpiryTime.map((e, idx) => {
|
{planet.infoUniverse?.name}
|
||||||
const extractor = extractors[idx];
|
</Typography>
|
||||||
const average = extractorAverages[idx];
|
{planetDetails.hasLargeExtractorDifference && (
|
||||||
return (
|
<Typography
|
||||||
<div key={`${e}-${idx}-${character.character.characterId}`}>
|
fontSize={theme.custom.smallText}
|
||||||
<Typography
|
color="error"
|
||||||
color={timeColor(e, colors)}
|
sx={{ opacity: 0.7 }}
|
||||||
fontSize={theme.custom.smallText}
|
>
|
||||||
>
|
off-balance
|
||||||
{!expired && e && <Countdown
|
</Typography>
|
||||||
overtime={true}
|
)}
|
||||||
date={DateTime.fromISO(e).toMillis()}
|
{hasLowExtractionRate && (
|
||||||
/>
|
<Typography
|
||||||
}
|
fontSize={theme.custom.smallText}
|
||||||
</Typography>
|
color="error"
|
||||||
{!expired && extractor && average && (
|
sx={{ opacity: 0.7 }}
|
||||||
<div style={{ display: 'flex', alignItems: 'center', gap: 4 }}>
|
>
|
||||||
<Image
|
low-extraction
|
||||||
unoptimized
|
</Typography>
|
||||||
src={`https://images.evetech.net/types/${extractor.installedSchematicId}/icon?size=32`}
|
)}
|
||||||
alt=""
|
{planetDetails.extractors.map((e, idx) => {
|
||||||
width={16}
|
const average = planetDetails.extractorAverages[idx];
|
||||||
height={16}
|
return (
|
||||||
style={{ borderRadius: 4 }}
|
<div key={`${e}-${idx}-${character.character.characterId}`}>
|
||||||
/>
|
<Typography
|
||||||
<Typography fontSize={theme.custom.smallText}>
|
color={timeColor(e.expiry_time, colors)}
|
||||||
{average.averagePerHour.toFixed(1)}/h
|
fontSize={theme.custom.smallText}
|
||||||
</Typography>
|
>
|
||||||
</div>
|
{!planetDetails.expired && e.expiry_time && <Countdown
|
||||||
)}
|
overtime={true}
|
||||||
</div>
|
date={DateTime.fromISO(e.expiry_time).toMillis()}
|
||||||
);
|
/>
|
||||||
})}
|
}
|
||||||
</div>
|
</Typography>
|
||||||
</StackItem>
|
{!planetDetails.expired && e && average && (
|
||||||
|
<div style={{ display: 'flex', alignItems: 'center', gap: 4 }}>
|
||||||
|
<Image
|
||||||
|
unoptimized
|
||||||
|
src={`https://images.evetech.net/types/${e.extractor_details?.product_type_id}/icon?size=32`}
|
||||||
|
alt=""
|
||||||
|
width={16}
|
||||||
|
height={16}
|
||||||
|
style={{ borderRadius: 4 }}
|
||||||
|
/>
|
||||||
|
<Typography fontSize={theme.custom.smallText}>
|
||||||
|
{average.averagePerHour.toFixed(1)}/h
|
||||||
|
</Typography>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</StackItem>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { ColorContext, SessionContext } from "@/app/context/Context";
|
import { ColorContext, SessionContext } from "@/app/context/Context";
|
||||||
import { PI_TYPES_MAP, STORAGE_IDS, STORAGE_CAPACITIES, PI_PRODUCT_VOLUMES, EVE_IMAGE_URL, PI_SCHEMATICS } from "@/const";
|
import { PI_TYPES_MAP, EVE_IMAGE_URL, LAUNCHPAD_IDS } from "@/const";
|
||||||
import { planetCalculations } from "@/planets";
|
|
||||||
import { AccessToken, PlanetWithInfo } from "@/types";
|
import { AccessToken, PlanetWithInfo } from "@/types";
|
||||||
|
import { PlanetCalculations, StorageInfo } from "@/types/planet";
|
||||||
import CloseIcon from "@mui/icons-material/Close";
|
import CloseIcon from "@mui/icons-material/Close";
|
||||||
import MoreVertIcon from '@mui/icons-material/MoreVert';
|
import MoreVertIcon from '@mui/icons-material/MoreVert';
|
||||||
import { Button, Tooltip, Typography, useTheme, Menu, MenuItem, IconButton, Checkbox, FormControlLabel } from "@mui/material";
|
import { Button, Tooltip, Typography, useTheme, Menu, MenuItem, IconButton, Checkbox, FormControlLabel } from "@mui/material";
|
||||||
@@ -18,11 +18,13 @@ import React, { forwardRef, useContext, useState } from "react";
|
|||||||
import Countdown from "react-countdown";
|
import Countdown from "react-countdown";
|
||||||
import { PlanetConfigDialog } from "../PlanetConfig/PlanetConfigDialog";
|
import { PlanetConfigDialog } from "../PlanetConfig/PlanetConfigDialog";
|
||||||
import PinsCanvas3D from "./PinsCanvas3D";
|
import PinsCanvas3D from "./PinsCanvas3D";
|
||||||
import { alertModeVisibility, timeColor } from "./timeColors";
|
import { timeColor } from "./alerts";
|
||||||
import { ExtractionSimulationDisplay } from './ExtractionSimulationDisplay';
|
import { ExtractionSimulationDisplay } from './ExtractionSimulationDisplay';
|
||||||
import { ExtractionSimulationTooltip } from './ExtractionSimulationTooltip';
|
import { ExtractionSimulationTooltip } from './ExtractionSimulationTooltip';
|
||||||
import { ProductionNode } from './ExtractionSimulation';
|
|
||||||
import { Collapse, Box, Stack } from "@mui/material";
|
import { Collapse, Box, Stack } from "@mui/material";
|
||||||
|
import Table from "@mui/material/Table";
|
||||||
|
import TableHead from "@mui/material/TableHead";
|
||||||
|
import TableBody from "@mui/material/TableBody";
|
||||||
|
|
||||||
const Transition = forwardRef(function Transition(
|
const Transition = forwardRef(function Transition(
|
||||||
props: TransitionProps & {
|
props: TransitionProps & {
|
||||||
@@ -33,15 +35,28 @@ const Transition = forwardRef(function Transition(
|
|||||||
return <Slide direction="up" ref={ref} {...props} />;
|
return <Slide direction="up" ref={ref} {...props} />;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
interface SchematicInput {
|
||||||
|
type_id: number;
|
||||||
|
quantity: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SchematicOutput {
|
||||||
|
type_id: number;
|
||||||
|
quantity: number;
|
||||||
|
}
|
||||||
|
|
||||||
export const PlanetTableRow = ({
|
export const PlanetTableRow = ({
|
||||||
planet,
|
planet,
|
||||||
character,
|
character,
|
||||||
|
planetDetails,
|
||||||
}: {
|
}: {
|
||||||
planet: PlanetWithInfo;
|
planet: PlanetWithInfo;
|
||||||
character: AccessToken;
|
character: AccessToken;
|
||||||
|
planetDetails: PlanetCalculations;
|
||||||
}) => {
|
}) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { showProductIcons, extractionTimeMode } = useContext(SessionContext);
|
const { showProductIcons, extractionTimeMode, alertMode, minExtractionRate } = useContext(SessionContext);
|
||||||
|
const { colors } = useContext(ColorContext);
|
||||||
|
|
||||||
const [planetRenderOpen, setPlanetRenderOpen] = useState(false);
|
const [planetRenderOpen, setPlanetRenderOpen] = useState(false);
|
||||||
const [planetConfigOpen, setPlanetConfigOpen] = useState(false);
|
const [planetConfigOpen, setPlanetConfigOpen] = useState(false);
|
||||||
@@ -72,80 +87,13 @@ export const PlanetTableRow = ({
|
|||||||
setPlanetConfigOpen(false);
|
setPlanetConfigOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const { piPrices, alertMode, updatePlanetConfig, readPlanetConfig, balanceThreshold } = useContext(SessionContext);
|
const { piPrices, updatePlanetConfig, readPlanetConfig } = useContext(SessionContext);
|
||||||
const planetInfo = planet.info;
|
const planetInfo = planet.info;
|
||||||
const planetInfoUniverse = planet.infoUniverse;
|
const planetInfoUniverse = planet.infoUniverse;
|
||||||
const { expired, extractors, localProduction, localImports, localExports } =
|
|
||||||
planetCalculations(planet);
|
|
||||||
const planetConfig = readPlanetConfig({
|
const planetConfig = readPlanetConfig({
|
||||||
characterId: character.character.characterId,
|
characterId: character.character.characterId,
|
||||||
planetId: planet.planet_id,
|
planetId: planet.planet_id,
|
||||||
});
|
});
|
||||||
const { colors } = useContext(ColorContext);
|
|
||||||
// Convert local production to ProductionNode array for simulation
|
|
||||||
const productionNodes: ProductionNode[] = Array.from(localProduction).map(([schematicId, schematic]) => ({
|
|
||||||
schematicId: schematicId,
|
|
||||||
typeId: schematic.outputs[0].type_id,
|
|
||||||
name: schematic.name,
|
|
||||||
inputs: schematic.inputs.map(input => ({
|
|
||||||
typeId: input.type_id,
|
|
||||||
quantity: input.quantity
|
|
||||||
})),
|
|
||||||
outputs: schematic.outputs.map(output => ({
|
|
||||||
typeId: output.type_id,
|
|
||||||
quantity: output.quantity
|
|
||||||
})),
|
|
||||||
cycleTime: schematic.cycle_time,
|
|
||||||
factoryCount: schematic.count || 1
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Calculate extractor averages and check for large differences
|
|
||||||
const extractorAverages = extractors
|
|
||||||
.filter(e => e.extractor_details?.product_type_id && e.extractor_details?.qty_per_cycle)
|
|
||||||
.map(e => {
|
|
||||||
const cycleTime = e.extractor_details?.cycle_time || 3600;
|
|
||||||
const qtyPerCycle = e.extractor_details?.qty_per_cycle || 0;
|
|
||||||
return {
|
|
||||||
typeId: e.extractor_details!.product_type_id!,
|
|
||||||
averagePerHour: (qtyPerCycle * 3600) / cycleTime
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
const hasLargeExtractorDifference = extractorAverages.length === 2 &&
|
|
||||||
Math.abs(extractorAverages[0].averagePerHour - extractorAverages[1].averagePerHour) > balanceThreshold;
|
|
||||||
|
|
||||||
const storageFacilities = planetInfo.pins.filter(pin =>
|
|
||||||
STORAGE_IDS().some(storage => storage.type_id === pin.type_id)
|
|
||||||
);
|
|
||||||
|
|
||||||
const getStorageInfo = (pin: any) => {
|
|
||||||
if (!pin || !pin.contents) return null;
|
|
||||||
|
|
||||||
const storageType = PI_TYPES_MAP[pin.type_id].name;
|
|
||||||
const storageCapacity = STORAGE_CAPACITIES[pin.type_id] || 0;
|
|
||||||
|
|
||||||
const totalVolume = (pin.contents || [])
|
|
||||||
.reduce((sum: number, item: any) => {
|
|
||||||
const volume = PI_PRODUCT_VOLUMES[item.type_id] || 0;
|
|
||||||
return sum + (item.amount * volume);
|
|
||||||
}, 0);
|
|
||||||
|
|
||||||
const totalValue = (pin.contents || [])
|
|
||||||
.reduce((sum: number, item: any) => {
|
|
||||||
const price = piPrices?.appraisal.items.find((a) => a.typeID === item.type_id)?.prices.sell.min ?? 0;
|
|
||||||
return sum + (item.amount * price);
|
|
||||||
}, 0);
|
|
||||||
|
|
||||||
const fillRate = storageCapacity > 0 ? (totalVolume / storageCapacity) * 100 : 0;
|
|
||||||
|
|
||||||
return {
|
|
||||||
type: storageType,
|
|
||||||
capacity: storageCapacity,
|
|
||||||
used: totalVolume,
|
|
||||||
fillRate: fillRate,
|
|
||||||
value: totalValue
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleExcludeChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
const handleExcludeChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
updatePlanetConfig({
|
updatePlanetConfig({
|
||||||
@@ -154,6 +102,21 @@ export const PlanetTableRow = ({
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Check if there are any alerts
|
||||||
|
const hasLowExtractionRate = planetDetails.extractorAverages.length > 0 && minExtractionRate > 0 && planetDetails.extractorAverages.some(avg => avg.averagePerHour < minExtractionRate);
|
||||||
|
const hasAlerts = alertMode && (
|
||||||
|
planetDetails.expired ||
|
||||||
|
planetDetails.storageInfo.some(storage => storage.fillRate > 60) ||
|
||||||
|
planetDetails.importDepletionTimes.some(depletion => depletion.hoursUntilDepletion < 24) ||
|
||||||
|
planetDetails.hasLargeExtractorDifference ||
|
||||||
|
hasLowExtractionRate
|
||||||
|
);
|
||||||
|
|
||||||
|
// If in alert mode and no alerts, hide the row
|
||||||
|
if (alertMode && !hasAlerts) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const renderProductDisplay = (typeId: number, amount?: number) => {
|
const renderProductDisplay = (typeId: number, amount?: number) => {
|
||||||
if (!typeId || !PI_TYPES_MAP[typeId]) {
|
if (!typeId || !PI_TYPES_MAP[typeId]) {
|
||||||
return (
|
return (
|
||||||
@@ -205,7 +168,7 @@ export const PlanetTableRow = ({
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<TableRow
|
<TableRow
|
||||||
style={{ visibility: alertModeVisibility(alertMode, expired) }}
|
style={{ visibility: planetDetails.visibility }}
|
||||||
sx={{
|
sx={{
|
||||||
"&:last-child td, &:last-child th": { border: 0 },
|
"&:last-child td, &:last-child th": { border: 0 },
|
||||||
cursor: 'pointer',
|
cursor: 'pointer',
|
||||||
@@ -213,7 +176,7 @@ export const PlanetTableRow = ({
|
|||||||
backgroundColor: 'action.hover'
|
backgroundColor: 'action.hover'
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
onClick={(e) => {
|
onClick={(e: React.MouseEvent<HTMLTableRowElement>) => {
|
||||||
if (!(e.target as HTMLElement).closest('.clickable-cell')) return;
|
if (!(e.target as HTMLElement).closest('.clickable-cell')) return;
|
||||||
setSimulationOpen(!simulationOpen);
|
setSimulationOpen(!simulationOpen);
|
||||||
}}
|
}}
|
||||||
@@ -236,9 +199,9 @@ export const PlanetTableRow = ({
|
|||||||
<Tooltip
|
<Tooltip
|
||||||
placement="right"
|
placement="right"
|
||||||
title={
|
title={
|
||||||
extractors.length > 0 ? (
|
planetDetails.extractors.length > 0 ? (
|
||||||
<ExtractionSimulationTooltip
|
<ExtractionSimulationTooltip
|
||||||
extractors={extractors
|
extractors={planetDetails.extractors
|
||||||
.filter(e => e.extractor_details?.product_type_id && e.extractor_details?.qty_per_cycle)
|
.filter(e => e.extractor_details?.product_type_id && e.extractor_details?.qty_per_cycle)
|
||||||
.map(e => ({
|
.map(e => ({
|
||||||
typeId: e.extractor_details!.product_type_id!,
|
typeId: e.extractor_details!.product_type_id!,
|
||||||
@@ -264,14 +227,14 @@ export const PlanetTableRow = ({
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Stack spacing={0}>
|
<Stack spacing={0}>
|
||||||
<Typography
|
<Typography
|
||||||
fontSize={theme.custom.smallText}
|
fontSize={theme.custom.smallText}
|
||||||
color={hasLargeExtractorDifference ? 'error' : 'inherit'}
|
color={(planetDetails.hasLargeExtractorDifference || hasLowExtractionRate) ? 'error' : 'inherit'}
|
||||||
>
|
>
|
||||||
{planetInfoUniverse?.name}
|
{planetInfoUniverse?.name}
|
||||||
</Typography>
|
</Typography>
|
||||||
{hasLargeExtractorDifference && (
|
{planetDetails.hasLargeExtractorDifference && (
|
||||||
<Typography
|
<Typography
|
||||||
fontSize={theme.custom.smallText}
|
fontSize={theme.custom.smallText}
|
||||||
color="error"
|
color="error"
|
||||||
sx={{ opacity: 0.7 }}
|
sx={{ opacity: 0.7 }}
|
||||||
@@ -279,6 +242,15 @@ export const PlanetTableRow = ({
|
|||||||
off-balance
|
off-balance
|
||||||
</Typography>
|
</Typography>
|
||||||
)}
|
)}
|
||||||
|
{hasLowExtractionRate && (
|
||||||
|
<Typography
|
||||||
|
fontSize={theme.custom.smallText}
|
||||||
|
color="error"
|
||||||
|
sx={{ opacity: 0.7 }}
|
||||||
|
>
|
||||||
|
low-extraction
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</div>
|
</div>
|
||||||
@@ -287,8 +259,8 @@ export const PlanetTableRow = ({
|
|||||||
<TableCell className="clickable-cell">{planet.upgrade_level}</TableCell>
|
<TableCell className="clickable-cell">{planet.upgrade_level}</TableCell>
|
||||||
<TableCell className="clickable-cell">
|
<TableCell className="clickable-cell">
|
||||||
<div style={{ display: "flex", flexDirection: "column" }}>
|
<div style={{ display: "flex", flexDirection: "column" }}>
|
||||||
{extractors.length === 0 &&<Typography fontSize={theme.custom.smallText}>No extractors</Typography>}
|
{planetDetails.extractors.length === 0 &&<Typography fontSize={theme.custom.smallText}>No extractors</Typography>}
|
||||||
{extractors.map((e, idx) => {
|
{planetDetails.extractors.map((e, idx) => {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={`${e}-${idx}-${character.character.characterId}`}
|
key={`${e}-${idx}-${character.character.characterId}`}
|
||||||
@@ -320,7 +292,7 @@ export const PlanetTableRow = ({
|
|||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className="clickable-cell">
|
<TableCell className="clickable-cell">
|
||||||
<div style={{ display: "flex", flexDirection: "column" }}>
|
<div style={{ display: "flex", flexDirection: "column" }}>
|
||||||
{Array.from(localProduction).map((schematic, idx) => {
|
{Array.from(planetDetails.localProduction).map((schematic, idx) => {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={`prod-${character.character.characterId}-${planet.planet_id}-${idx}`}
|
key={`prod-${character.character.characterId}-${planet.planet_id}-${idx}`}
|
||||||
@@ -334,48 +306,32 @@ export const PlanetTableRow = ({
|
|||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className="clickable-cell">
|
<TableCell className="clickable-cell">
|
||||||
<div style={{ display: "flex", flexDirection: "column" }}>
|
<div style={{ display: "flex", flexDirection: "column" }}>
|
||||||
{localImports.map((i) => {
|
{planetDetails.localImports.map((i) => {
|
||||||
// Find all storage facilities (including launchpads) containing this import
|
const depletionTime = planetDetails.importDepletionTimes.find(d => d.typeId === i.type_id);
|
||||||
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 (
|
return (
|
||||||
<div
|
<div
|
||||||
key={`import-${character.character.characterId}-${planet.planet_id}-${i.type_id}`}
|
key={`import-${character.character.characterId}-${planet.planet_id}-${i.type_id}`}
|
||||||
style={{ display: "flex", alignItems: "center" }}
|
style={{ display: "flex", alignItems: "center" }}
|
||||||
>
|
>
|
||||||
{renderProductDisplay(i.type_id, i.quantity * i.factoryCount)}
|
<Tooltip title={
|
||||||
{totalAmount > 0 && (
|
<>
|
||||||
<Tooltip title={
|
<div>Will be depleted in {depletionTime?.hoursUntilDepletion.toFixed(1)} hours</div>
|
||||||
<>
|
<div>Monthly cost: {depletionTime?.monthlyCost.toFixed(2)}M ISK</div>
|
||||||
<div>Total: {totalAmount.toFixed(1)} units</div>
|
</>
|
||||||
<div>Will be depleted in {hoursUntilDepletion.toFixed(1)} hours</div>
|
}>
|
||||||
</>
|
<div style={{ display: "flex", alignItems: "center" }}>
|
||||||
}>
|
{renderProductDisplay(i.type_id, i.quantity * i.factoryCount)}
|
||||||
<Typography
|
{depletionTime && (
|
||||||
fontSize={theme.custom.smallText}
|
<Typography
|
||||||
color={hoursUntilDepletion < 24 ? 'error' : hoursUntilDepletion < 48 ? 'warning' : 'success'}
|
fontSize={theme.custom.smallText}
|
||||||
sx={{ ml: 1 }}
|
color={depletionTime.hoursUntilDepletion < 24 ? 'error' : depletionTime.hoursUntilDepletion < 48 ? 'warning' : 'success'}
|
||||||
>
|
sx={{ ml: 1 }}
|
||||||
({hoursUntilDepletion.toFixed(1)}h)
|
>
|
||||||
</Typography>
|
({depletionTime.hoursUntilDepletion.toFixed(1)}h)
|
||||||
</Tooltip>
|
</Typography>
|
||||||
)}
|
)}
|
||||||
|
</div>
|
||||||
|
</Tooltip>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
@@ -383,21 +339,21 @@ export const PlanetTableRow = ({
|
|||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className="clickable-cell">
|
<TableCell className="clickable-cell">
|
||||||
<div style={{ display: "flex", flexDirection: "column" }}>
|
<div style={{ display: "flex", flexDirection: "column" }}>
|
||||||
{localExports.map((exports) => (
|
{planetDetails.localExports.map((exports) => (
|
||||||
<div
|
<div
|
||||||
key={`export-${character.character.characterId}-${planet.planet_id}-${exports.typeId}`}
|
key={`export-${character.character.characterId}-${planet.planet_id}-${exports.type_id}`}
|
||||||
style={{ display: "flex", alignItems: "center" }}
|
style={{ display: "flex", alignItems: "center" }}
|
||||||
>
|
>
|
||||||
{renderProductDisplay(exports.typeId, exports.amount)}
|
{renderProductDisplay(exports.type_id, exports.quantity * exports.factoryCount)}
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<div style={{ display: "flex", flexDirection: "column" }}>
|
<div style={{ display: "flex", flexDirection: "column" }}>
|
||||||
{localExports.map((exports) => (
|
{planetDetails.localExports.map((exports) => (
|
||||||
<FormControlLabel
|
<FormControlLabel
|
||||||
key={`export-excluded-${character.character.characterId}-${planet.planet_id}-${exports.typeId}`}
|
key={`export-excluded-${character.character.characterId}-${planet.planet_id}-${exports.type_id}`}
|
||||||
control={
|
control={
|
||||||
<Checkbox
|
<Checkbox
|
||||||
checked={planetConfig.excludeFromTotals}
|
checked={planetConfig.excludeFromTotals}
|
||||||
@@ -412,12 +368,12 @@ export const PlanetTableRow = ({
|
|||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className="clickable-cell">
|
<TableCell className="clickable-cell">
|
||||||
<div style={{ display: "flex", flexDirection: "column" }}>
|
<div style={{ display: "flex", flexDirection: "column" }}>
|
||||||
{localExports.map((exports) => (
|
{planetDetails.localExports.map((exports) => (
|
||||||
<Typography
|
<Typography
|
||||||
key={`export-uph-${character.character.characterId}-${planet.planet_id}-${exports.typeId}`}
|
key={`export-uph-${character.character.characterId}-${planet.planet_id}-${exports.type_id}`}
|
||||||
fontSize={theme.custom.smallText}
|
fontSize={theme.custom.smallText}
|
||||||
>
|
>
|
||||||
{exports.amount}
|
{exports.quantity * exports.factoryCount}
|
||||||
</Typography>
|
</Typography>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
@@ -431,11 +387,11 @@ export const PlanetTableRow = ({
|
|||||||
textAlign: "end",
|
textAlign: "end",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{localExports.map((e) => {
|
{planetDetails.localExports.map((e) => {
|
||||||
const valueInMillions =
|
const valueInMillions =
|
||||||
(((piPrices?.appraisal.items.find((a) => a.typeID === e.typeId)
|
(((piPrices?.appraisal.items.find((a) => a.typeID === e.type_id)
|
||||||
?.prices.sell.min ?? 0) *
|
?.prices.sell.min ?? 0) *
|
||||||
e.amount) /
|
e.quantity * e.factoryCount) /
|
||||||
1000000) *
|
1000000) *
|
||||||
24 *
|
24 *
|
||||||
30;
|
30;
|
||||||
@@ -446,7 +402,7 @@ export const PlanetTableRow = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Typography
|
<Typography
|
||||||
key={`export-praisal-${character.character.characterId}-${planet.planet_id}-${e.typeId}`}
|
key={`export-praisal-${character.character.characterId}-${planet.planet_id}-${e.type_id}`}
|
||||||
fontSize={theme.custom.smallText}
|
fontSize={theme.custom.smallText}
|
||||||
>
|
>
|
||||||
{displayValue}
|
{displayValue}
|
||||||
@@ -456,47 +412,119 @@ export const PlanetTableRow = ({
|
|||||||
</div>
|
</div>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className="clickable-cell">
|
<TableCell className="clickable-cell">
|
||||||
<div style={{ display: "flex", flexDirection: "column" }}>
|
<Tooltip
|
||||||
{storageFacilities.length === 0 &&<Typography fontSize={theme.custom.smallText}>No storage</Typography>}
|
title={
|
||||||
{storageFacilities
|
<Box sx={{ p: 1 }}>
|
||||||
.sort((a, b) => {
|
<Typography variant="subtitle2" sx={{ mb: 1 }}>
|
||||||
const isALaunchpad = a.type_id === 2256 || a.type_id === 2542 || a.type_id === 2543 || a.type_id === 2544 || a.type_id === 2552 || a.type_id === 2555 || a.type_id === 2556 || a.type_id === 2557;
|
Storage Facilities
|
||||||
const isBLaunchpad = b.type_id === 2256 || b.type_id === 2542 || b.type_id === 2543 || b.type_id === 2544 || b.type_id === 2552 || b.type_id === 2555 || b.type_id === 2556 || b.type_id === 2557;
|
</Typography>
|
||||||
return isALaunchpad === isBLaunchpad ? 0 : isALaunchpad ? -1 : 1;
|
<Table size="small">
|
||||||
})
|
<TableHead>
|
||||||
.map((storage) => {
|
<TableRow>
|
||||||
const storageInfo = getStorageInfo(storage);
|
<TableCell>Type</TableCell>
|
||||||
if (!storageInfo) return null;
|
<TableCell align="right">Capacity</TableCell>
|
||||||
|
<TableCell align="right">Used</TableCell>
|
||||||
const isLaunchpad = storage.type_id === 2256 ||
|
<TableCell align="right">Fill Rate</TableCell>
|
||||||
storage.type_id === 2542 ||
|
<TableCell align="right">Value</TableCell>
|
||||||
storage.type_id === 2543 ||
|
</TableRow>
|
||||||
storage.type_id === 2544 ||
|
</TableHead>
|
||||||
storage.type_id === 2552 ||
|
<TableBody>
|
||||||
storage.type_id === 2555 ||
|
{planetDetails.storageInfo
|
||||||
storage.type_id === 2556 ||
|
.map(storage => ({
|
||||||
storage.type_id === 2557;
|
...storage,
|
||||||
|
isLaunchpad: LAUNCHPAD_IDS.includes(storage.type_id)
|
||||||
const fillRate = storageInfo.fillRate;
|
}))
|
||||||
const color = fillRate > 95 ? '#ff0000' : fillRate > 80 ? '#ffd700' : 'inherit';
|
.sort((a, b) => (b.isLaunchpad ? 1 : 0) - (a.isLaunchpad ? 1 : 0))
|
||||||
|
.map((storage, idx) => {
|
||||||
return (
|
const fillRate = storage.fillRate;
|
||||||
<div key={`storage-${character.character.characterId}-${planet.planet_id}-${storage.pin_id}`} style={{ display: "flex", alignItems: "center" }}>
|
const color = fillRate > 90 ? '#ff0000' : fillRate > 80 ? '#ffa500' : fillRate > 60 ? '#ffd700' : 'inherit';
|
||||||
<Typography fontSize={theme.custom.smallText} style={{ marginRight: "5px" }}>
|
const contents = planet.info.pins.find(p => p.pin_id === storage.pin_id)?.contents || [];
|
||||||
{isLaunchpad ? 'L' : 'S'}
|
|
||||||
</Typography>
|
return (
|
||||||
<Typography fontSize={theme.custom.smallText} style={{ color }}>
|
<React.Fragment key={`storage-${character.character.characterId}-${planet.planet_id}-${storage.type}-${idx}`}>
|
||||||
{fillRate.toFixed(1)}%
|
<TableRow>
|
||||||
</Typography>
|
<TableCell>{storage.isLaunchpad ? 'Launchpad' : 'Storage'}</TableCell>
|
||||||
{storageInfo.value > 0 && (
|
<TableCell align="right">{storage.capacity.toFixed(1)} m³</TableCell>
|
||||||
<Typography fontSize={theme.custom.smallText} style={{ marginLeft: "5px" }}>
|
<TableCell align="right">{storage.used.toFixed(1)} m³</TableCell>
|
||||||
({Math.round(storageInfo.value / 1000000)}M)
|
<TableCell align="right" sx={{ color }}>{fillRate.toFixed(1)}%</TableCell>
|
||||||
|
<TableCell align="right">
|
||||||
|
{storage.value > 0 ? (
|
||||||
|
storage.value >= 1000000000
|
||||||
|
? `${(storage.value / 1000000000).toFixed(2)} B`
|
||||||
|
: `${(storage.value / 1000000).toFixed(0)} M`
|
||||||
|
) : '-'} ISK
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
{contents.length > 0 && (
|
||||||
|
<TableRow>
|
||||||
|
<TableCell colSpan={5} sx={{ pt: 0, pb: 0 }}>
|
||||||
|
<Table size="small">
|
||||||
|
<TableBody>
|
||||||
|
{contents.map((content, idy) => (
|
||||||
|
<TableRow key={`content-${character.character.characterId}-${planet.planet_id}-${storage.type}-${content.type_id}-${idx}-${idy}`}>
|
||||||
|
<TableCell sx={{ pl: 2 }}>
|
||||||
|
{PI_TYPES_MAP[content.type_id]?.name}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell align="right" colSpan={4}>
|
||||||
|
{content.amount.toFixed(1)} units
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
)}
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</Box>
|
||||||
|
}
|
||||||
|
componentsProps={{
|
||||||
|
tooltip: {
|
||||||
|
sx: {
|
||||||
|
bgcolor: 'background.paper',
|
||||||
|
'& .MuiTooltip-arrow': {
|
||||||
|
color: 'background.paper',
|
||||||
|
},
|
||||||
|
maxWidth: 'none',
|
||||||
|
width: 'fit-content'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div style={{ display: "flex", flexDirection: "column" }}>
|
||||||
|
{planetDetails.storageInfo.length === 0 &&<Typography fontSize={theme.custom.smallText}>No storage</Typography>}
|
||||||
|
{planetDetails.storageInfo
|
||||||
|
.map(storage => ({
|
||||||
|
...storage,
|
||||||
|
isLaunchpad: LAUNCHPAD_IDS.includes(storage.type_id)
|
||||||
|
}))
|
||||||
|
.sort((a, b) => (b.isLaunchpad ? 1 : 0) - (a.isLaunchpad ? 1 : 0))
|
||||||
|
.map((storage, idx) => {
|
||||||
|
const fillRate = storage.fillRate;
|
||||||
|
const color = fillRate > 90 ? '#ff0000' : fillRate > 80 ? '#ffa500' : fillRate > 60 ? '#ffd700' : 'inherit';
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div key={`storage-${character.character.characterId}-${planet.planet_id}-${storage.type}-${idx}`} style={{ display: "flex", alignItems: "center" }}>
|
||||||
|
<Typography fontSize={theme.custom.smallText} style={{ marginRight: "5px" }}>
|
||||||
|
{storage.isLaunchpad ? 'L' : 'S'}
|
||||||
</Typography>
|
</Typography>
|
||||||
)}
|
<Typography fontSize={theme.custom.smallText} style={{ color }}>
|
||||||
</div>
|
{fillRate.toFixed(1)}%
|
||||||
);
|
</Typography>
|
||||||
})}
|
{storage.value > 0 && (
|
||||||
</div>
|
<Typography fontSize={theme.custom.smallText} style={{ marginLeft: "5px" }}>
|
||||||
|
({Math.round(storage.value / 1000000)}M)
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</Tooltip>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className="menu-cell">
|
<TableCell className="menu-cell">
|
||||||
<IconButton
|
<IconButton
|
||||||
@@ -534,7 +562,7 @@ export const PlanetTableRow = ({
|
|||||||
<Collapse in={simulationOpen} timeout="auto" unmountOnExit>
|
<Collapse in={simulationOpen} timeout="auto" unmountOnExit>
|
||||||
<Box sx={{ my: 2 }}>
|
<Box sx={{ my: 2 }}>
|
||||||
<ExtractionSimulationDisplay
|
<ExtractionSimulationDisplay
|
||||||
extractors={extractors
|
extractors={planetDetails.extractors
|
||||||
.filter(e => e.extractor_details?.product_type_id && e.extractor_details?.qty_per_cycle)
|
.filter(e => e.extractor_details?.product_type_id && e.extractor_details?.qty_per_cycle)
|
||||||
.map(e => ({
|
.map(e => ({
|
||||||
typeId: e.extractor_details!.product_type_id!,
|
typeId: e.extractor_details!.product_type_id!,
|
||||||
@@ -543,7 +571,21 @@ export const PlanetTableRow = ({
|
|||||||
installTime: e.install_time ?? "",
|
installTime: e.install_time ?? "",
|
||||||
expiryTime: e.expiry_time ?? ""
|
expiryTime: e.expiry_time ?? ""
|
||||||
}))}
|
}))}
|
||||||
productionNodes={productionNodes}
|
productionNodes={Array.from(planetDetails.localProduction).map(([schematicId, schematic]) => ({
|
||||||
|
schematicId: schematicId,
|
||||||
|
typeId: schematic.outputs[0].type_id,
|
||||||
|
name: schematic.name,
|
||||||
|
inputs: schematic.inputs.map((input: SchematicInput) => ({
|
||||||
|
typeId: input.type_id,
|
||||||
|
quantity: input.quantity
|
||||||
|
})),
|
||||||
|
outputs: schematic.outputs.map((output: SchematicOutput) => ({
|
||||||
|
typeId: output.type_id,
|
||||||
|
quantity: output.quantity
|
||||||
|
})),
|
||||||
|
cycleTime: schematic.cycle_time,
|
||||||
|
factoryCount: schematic.factoryCount || 1
|
||||||
|
}))}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
</Collapse>
|
</Collapse>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { AccessToken } from "@/types";
|
import { AccessToken } from "@/types";
|
||||||
import { Icon, IconButton, Stack, Tooltip, Typography, styled, useTheme } from "@mui/material";
|
import { IconButton, Stack, Tooltip, Typography, styled, useTheme } from "@mui/material";
|
||||||
import { PlanetCard } from "./PlanetCard";
|
import { PlanetCard } from "./PlanetCard";
|
||||||
import { NoPlanetCard } from "./NoPlanetCard";
|
import { NoPlanetCard } from "./NoPlanetCard";
|
||||||
import Table from "@mui/material/Table";
|
import Table from "@mui/material/Table";
|
||||||
@@ -11,6 +11,7 @@ import TableRow from "@mui/material/TableRow";
|
|||||||
import Paper from "@mui/material/Paper";
|
import Paper from "@mui/material/Paper";
|
||||||
import { PlanetTableRow } from "./PlanetTableRow";
|
import { PlanetTableRow } from "./PlanetTableRow";
|
||||||
import { Settings } from "@mui/icons-material";
|
import { Settings } from "@mui/icons-material";
|
||||||
|
import { PlanetCalculations } from "@/types/planet";
|
||||||
|
|
||||||
const StackItem = styled(Stack)(({ theme }) => ({
|
const StackItem = styled(Stack)(({ theme }) => ({
|
||||||
...theme.typography.body2,
|
...theme.typography.body2,
|
||||||
@@ -22,8 +23,10 @@ const StackItem = styled(Stack)(({ theme }) => ({
|
|||||||
|
|
||||||
const PlanetaryIteractionTable = ({
|
const PlanetaryIteractionTable = ({
|
||||||
character,
|
character,
|
||||||
|
planetDetails,
|
||||||
}: {
|
}: {
|
||||||
character: AccessToken;
|
character: AccessToken;
|
||||||
|
planetDetails: Record<number, PlanetCalculations>;
|
||||||
}) => {
|
}) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
@@ -117,6 +120,7 @@ const PlanetaryIteractionTable = ({
|
|||||||
key={`${character.character.characterId}-${planet.planet_id}`}
|
key={`${character.character.characterId}-${planet.planet_id}`}
|
||||||
planet={planet}
|
planet={planet}
|
||||||
character={character}
|
character={character}
|
||||||
|
planetDetails={planetDetails[planet.planet_id]}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
@@ -128,8 +132,10 @@ const PlanetaryIteractionTable = ({
|
|||||||
|
|
||||||
const PlanetaryInteractionIconsRow = ({
|
const PlanetaryInteractionIconsRow = ({
|
||||||
character,
|
character,
|
||||||
|
planetDetails,
|
||||||
}: {
|
}: {
|
||||||
character: AccessToken;
|
character: AccessToken;
|
||||||
|
planetDetails: Record<number, PlanetCalculations>;
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
<StackItem>
|
<StackItem>
|
||||||
@@ -139,6 +145,7 @@ const PlanetaryInteractionIconsRow = ({
|
|||||||
key={`${character.character.characterId}-${planet.planet_id}`}
|
key={`${character.character.characterId}-${planet.planet_id}`}
|
||||||
planet={planet}
|
planet={planet}
|
||||||
character={character}
|
character={character}
|
||||||
|
planetDetails={planetDetails[planet.planet_id]}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
{Array.from(Array(6 - character.planets.length).keys()).map((i, id) => (
|
{Array.from(Array(6 - character.planets.length).keys()).map((i, id) => (
|
||||||
@@ -153,14 +160,16 @@ const PlanetaryInteractionIconsRow = ({
|
|||||||
|
|
||||||
export const PlanetaryInteractionRow = ({
|
export const PlanetaryInteractionRow = ({
|
||||||
character,
|
character,
|
||||||
|
planetDetails,
|
||||||
}: {
|
}: {
|
||||||
character: AccessToken;
|
character: AccessToken;
|
||||||
|
planetDetails: Record<number, PlanetCalculations>;
|
||||||
}) => {
|
}) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
return theme.custom.compactMode ? (
|
return theme.custom.compactMode ? (
|
||||||
<div style={{ marginTop: "1.2rem" }}><PlanetaryInteractionIconsRow character={character} /></div>
|
<div style={{ marginTop: "1.2rem" }}><PlanetaryInteractionIconsRow character={character} planetDetails={planetDetails} /></div>
|
||||||
) : (
|
) : (
|
||||||
<div style={{ marginTop: "1.4rem" }}><PlanetaryIteractionTable character={character} /></div>
|
<div style={{ marginTop: "1.4rem" }}><PlanetaryIteractionTable character={character} planetDetails={planetDetails} /></div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import React, { useState, useContext } from "react";
|
|||||||
|
|
||||||
export const SettingsButton = () => {
|
export const SettingsButton = () => {
|
||||||
const { colors, setColors } = useContext(ColorContext);
|
const { colors, setColors } = useContext(ColorContext);
|
||||||
const { balanceThreshold, setBalanceThreshold, showProductIcons, setShowProductIcons } = useContext(SessionContext);
|
const { balanceThreshold, setBalanceThreshold, minExtractionRate, setMinExtractionRate, showProductIcons, setShowProductIcons } = useContext(SessionContext);
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
|
|
||||||
const handleClickOpen = () => {
|
const handleClickOpen = () => {
|
||||||
@@ -51,6 +51,13 @@ export const SettingsButton = () => {
|
|||||||
setShowProductIcons(event.target.checked);
|
setShowProductIcons(event.target.checked);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleMinExtractionRateChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
const value = parseInt(event.target.value);
|
||||||
|
if (!isNaN(value) && value >= 0 && value <= 100000) {
|
||||||
|
setMinExtractionRate(value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tooltip title="Toggle settings dialog">
|
<Tooltip title="Toggle settings dialog">
|
||||||
<>
|
<>
|
||||||
@@ -93,6 +100,19 @@ export const SettingsButton = () => {
|
|||||||
error={balanceThreshold < 0 || balanceThreshold > 100000}
|
error={balanceThreshold < 0 || balanceThreshold > 100000}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
|
<Box sx={{ mt: 2 }}>
|
||||||
|
<Typography variant="subtitle1">Minimum Extraction Rate</Typography>
|
||||||
|
<TextField
|
||||||
|
type="number"
|
||||||
|
value={minExtractionRate}
|
||||||
|
onChange={handleMinExtractionRateChange}
|
||||||
|
fullWidth
|
||||||
|
margin="normal"
|
||||||
|
inputProps={{ min: 0, max: 100000 }}
|
||||||
|
helperText="Alert if extraction per hour is below this value (0-100,000, 0 = disabled)"
|
||||||
|
error={minExtractionRate < 0 || minExtractionRate > 100000}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
{Object.keys(colors).map((key) => {
|
{Object.keys(colors).map((key) => {
|
||||||
return (
|
return (
|
||||||
<div key={`color-row-${key}`}>
|
<div key={`color-row-${key}`}>
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ export const SessionContext = createContext<{
|
|||||||
}) => PlanetConfig;
|
}) => PlanetConfig;
|
||||||
balanceThreshold: number;
|
balanceThreshold: number;
|
||||||
setBalanceThreshold: Dispatch<SetStateAction<number>>;
|
setBalanceThreshold: Dispatch<SetStateAction<number>>;
|
||||||
|
minExtractionRate: number;
|
||||||
|
setMinExtractionRate: Dispatch<SetStateAction<number>>;
|
||||||
showProductIcons: boolean;
|
showProductIcons: boolean;
|
||||||
setShowProductIcons: (show: boolean) => void;
|
setShowProductIcons: (show: boolean) => void;
|
||||||
}>({
|
}>({
|
||||||
@@ -68,6 +70,8 @@ export const SessionContext = createContext<{
|
|||||||
},
|
},
|
||||||
balanceThreshold: 1000,
|
balanceThreshold: 1000,
|
||||||
setBalanceThreshold: () => {},
|
setBalanceThreshold: () => {},
|
||||||
|
minExtractionRate: 0,
|
||||||
|
setMinExtractionRate: () => {},
|
||||||
showProductIcons: false,
|
showProductIcons: false,
|
||||||
setShowProductIcons: () => {},
|
setShowProductIcons: () => {},
|
||||||
});
|
});
|
||||||
|
|||||||
+62
-41
@@ -3,7 +3,7 @@ import "@fontsource/roboto/300.css";
|
|||||||
import "@fontsource/roboto/400.css";
|
import "@fontsource/roboto/400.css";
|
||||||
import "@fontsource/roboto/500.css";
|
import "@fontsource/roboto/500.css";
|
||||||
import "@fontsource/roboto/700.css";
|
import "@fontsource/roboto/700.css";
|
||||||
import { memo, useCallback, useEffect, useState, Suspense } from "react";
|
import { memo, useCallback, useEffect, useRef, useState, Suspense } from "react";
|
||||||
import { AccessToken, CharacterUpdate, Env, PlanetWithInfo } from "../types";
|
import { AccessToken, CharacterUpdate, Env, PlanetWithInfo } from "../types";
|
||||||
import { MainGrid } from "./components/MainGrid";
|
import { MainGrid } from "./components/MainGrid";
|
||||||
import { refreshToken } from "@/esi-sso";
|
import { refreshToken } from "@/esi-sso";
|
||||||
@@ -18,9 +18,26 @@ import { useSearchParams } from "next/navigation";
|
|||||||
import { EvePraisalResult, fetchAllPrices } from "@/eve-praisal";
|
import { EvePraisalResult, fetchAllPrices } from "@/eve-praisal";
|
||||||
import { getPlanet, getPlanetUniverse, getPlanets } from "@/planets";
|
import { getPlanet, getPlanetUniverse, getPlanets } from "@/planets";
|
||||||
import { PlanetConfig } from "@/types";
|
import { PlanetConfig } from "@/types";
|
||||||
|
import { saveCharacters as saveCharactersDB, loadCharacters } from "@/storage";
|
||||||
|
|
||||||
|
// Add batch processing utility
|
||||||
|
const processInBatches = async <T, R>(
|
||||||
|
items: T[],
|
||||||
|
batchSize: number,
|
||||||
|
processFn: (item: T) => Promise<R>
|
||||||
|
): Promise<R[]> => {
|
||||||
|
const results: R[] = [];
|
||||||
|
for (let i = 0; i < items.length; i += batchSize) {
|
||||||
|
const batch = items.slice(i, i + batchSize);
|
||||||
|
const batchResults = await Promise.all(batch.map(processFn));
|
||||||
|
results.push(...batchResults);
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
};
|
||||||
|
|
||||||
const Home = () => {
|
const Home = () => {
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
|
const callbackHandled = useRef(false);
|
||||||
const [characters, setCharacters] = useState<AccessToken[]>([]);
|
const [characters, setCharacters] = useState<AccessToken[]>([]);
|
||||||
const [sessionReady, setSessionReady] = useState(false);
|
const [sessionReady, setSessionReady] = useState(false);
|
||||||
const [environment, setEnvironment] = useState<Env | undefined>(undefined);
|
const [environment, setEnvironment] = useState<Env | undefined>(undefined);
|
||||||
@@ -30,6 +47,7 @@ const Home = () => {
|
|||||||
undefined,
|
undefined,
|
||||||
);
|
);
|
||||||
const [balanceThreshold, setBalanceThreshold] = useState(1000);
|
const [balanceThreshold, setBalanceThreshold] = useState(1000);
|
||||||
|
const [minExtractionRate, setMinExtractionRate] = useState(0);
|
||||||
const [showProductIcons, setShowProductIcons] = useState(false);
|
const [showProductIcons, setShowProductIcons] = useState(false);
|
||||||
const [extractionTimeMode, setExtractionTimeMode] = useState(false);
|
const [extractionTimeMode, setExtractionTimeMode] = useState(false);
|
||||||
|
|
||||||
@@ -63,22 +81,29 @@ const Home = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const refreshSession = async (characters: AccessToken[]) => {
|
const refreshSession = async (characters: AccessToken[]) => {
|
||||||
return Promise.all(
|
return processInBatches(characters, 50, async (c) => {
|
||||||
characters.map((c) => {
|
try {
|
||||||
try {
|
return await refreshToken(c);
|
||||||
return refreshToken(c);
|
} catch {
|
||||||
} catch {
|
return { ...c, needsLogin: true };
|
||||||
return { ...c, needsLogin: true };
|
}
|
||||||
}
|
});
|
||||||
}),
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCallback = async (
|
const handleCallback = async (
|
||||||
characters: AccessToken[],
|
characters: AccessToken[],
|
||||||
): Promise<AccessToken[]> => {
|
): Promise<AccessToken[]> => {
|
||||||
const code = searchParams?.get("code");
|
const code = searchParams?.get("code");
|
||||||
if (code) {
|
const returnedState = searchParams?.get("state");
|
||||||
|
if (code && !callbackHandled.current) {
|
||||||
|
callbackHandled.current = true;
|
||||||
|
const expectedState = localStorage.getItem("oauth_state");
|
||||||
|
localStorage.removeItem("oauth_state");
|
||||||
|
if (!expectedState || returnedState !== expectedState) {
|
||||||
|
console.error("OAuth state mismatch — possible CSRF attack");
|
||||||
|
window.history.replaceState(null, "", "/");
|
||||||
|
return Promise.resolve(characters);
|
||||||
|
}
|
||||||
window.history.replaceState(null, "", "/");
|
window.history.replaceState(null, "", "/");
|
||||||
const res = await fetch(`api/token?code=${code}`);
|
const res = await fetch(`api/token?code=${code}`);
|
||||||
const newCharacter: AccessToken = await res.json();
|
const newCharacter: AccessToken = await res.json();
|
||||||
@@ -95,40 +120,34 @@ const Home = () => {
|
|||||||
return Promise.resolve(characters);
|
return Promise.resolve(characters);
|
||||||
};
|
};
|
||||||
|
|
||||||
const initializeCharacters = useCallback((): AccessToken[] => {
|
const initializeCharacters = useCallback(async (): Promise<AccessToken[]> => {
|
||||||
const localStorageCharacters = localStorage.getItem("characters");
|
return await loadCharacters();
|
||||||
if (localStorageCharacters) {
|
|
||||||
const characterArray: AccessToken[] = JSON.parse(localStorageCharacters);
|
|
||||||
return characterArray.filter((c) => c.access_token && c.character);
|
|
||||||
}
|
|
||||||
return [];
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const initializeCharacterPlanets = (
|
const initializeCharacterPlanets = (
|
||||||
characters: AccessToken[],
|
characters: AccessToken[],
|
||||||
): Promise<AccessToken[]> =>
|
): Promise<AccessToken[]> =>
|
||||||
Promise.all(
|
processInBatches(characters, 50, async (c) => {
|
||||||
characters.map(async (c) => {
|
if (c.needsLogin || c.character === undefined)
|
||||||
if (c.needsLogin || c.character === undefined)
|
return { ...c, planets: [] };
|
||||||
return { ...c, planets: [] };
|
const planets = await getPlanets(c);
|
||||||
const planets = await getPlanets(c);
|
const planetsWithInfo: PlanetWithInfo[] = await processInBatches(
|
||||||
const planetsWithInfo: PlanetWithInfo[] = await Promise.all(
|
planets,
|
||||||
planets.map(async (p) => ({
|
3,
|
||||||
...p,
|
async (p) => ({
|
||||||
info: await getPlanet(c, p),
|
...p,
|
||||||
infoUniverse: await getPlanetUniverse(p),
|
info: await getPlanet(c, p),
|
||||||
})),
|
infoUniverse: await getPlanetUniverse(p),
|
||||||
);
|
})
|
||||||
return {
|
);
|
||||||
...c,
|
return {
|
||||||
planets: planetsWithInfo,
|
...c,
|
||||||
};
|
planets: planetsWithInfo,
|
||||||
}),
|
};
|
||||||
);
|
});
|
||||||
|
|
||||||
const saveCharacters = (characters: AccessToken[]): AccessToken[] => {
|
const saveCharacters = async (characters: AccessToken[]): Promise<AccessToken[]> => {
|
||||||
localStorage.setItem("characters", JSON.stringify(characters));
|
return await saveCharactersDB(characters);
|
||||||
return characters;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const restoreCharacters = (characters: AccessToken[]) => {
|
const restoreCharacters = (characters: AccessToken[]) => {
|
||||||
@@ -266,8 +285,8 @@ const Home = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const ESI_CACHE_TIME_MS = 3000000;
|
const ESI_CACHE_TIME_MS = 3000000;
|
||||||
const interval = setInterval(() => {
|
const interval = setInterval(async () => {
|
||||||
const characters = initializeCharacters();
|
const characters = await initializeCharacters();
|
||||||
refreshSession(characters)
|
refreshSession(characters)
|
||||||
.then(saveCharacters)
|
.then(saveCharacters)
|
||||||
.then(initializeCharacterPlanets)
|
.then(initializeCharacterPlanets)
|
||||||
@@ -297,6 +316,8 @@ const Home = () => {
|
|||||||
readPlanetConfig,
|
readPlanetConfig,
|
||||||
balanceThreshold,
|
balanceThreshold,
|
||||||
setBalanceThreshold,
|
setBalanceThreshold,
|
||||||
|
minExtractionRate,
|
||||||
|
setMinExtractionRate,
|
||||||
showProductIcons,
|
showProductIcons,
|
||||||
setShowProductIcons,
|
setShowProductIcons,
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -1080,3 +1080,5 @@ export const STORAGE_CAPACITIES: Record<number, number> = {
|
|||||||
2556: 10000, // Plasma Launchpad
|
2556: 10000, // Plasma Launchpad
|
||||||
2557: 10000, // Storm Launchpad
|
2557: 10000, // Storm Launchpad
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const LAUNCHPAD_IDS = [2256, 2542, 2543, 2544, 2552, 2555, 2556, 2557];
|
||||||
|
|||||||
+4
-2
@@ -37,17 +37,19 @@ export const revokeToken = async (
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const loginParameters = async (
|
export const loginParameters = (
|
||||||
selectedScopes: string[],
|
selectedScopes: string[],
|
||||||
EVE_SSO_CLIENT_ID: string,
|
EVE_SSO_CLIENT_ID: string,
|
||||||
EVE_SSO_CALLBACK_URL: string,
|
EVE_SSO_CALLBACK_URL: string,
|
||||||
) => {
|
) => {
|
||||||
|
const state = crypto.randomUUID();
|
||||||
|
localStorage.setItem("oauth_state", state);
|
||||||
return new URLSearchParams({
|
return new URLSearchParams({
|
||||||
response_type: "code",
|
response_type: "code",
|
||||||
redirect_uri: EVE_SSO_CALLBACK_URL,
|
redirect_uri: EVE_SSO_CALLBACK_URL,
|
||||||
client_id: EVE_SSO_CLIENT_ID,
|
client_id: EVE_SSO_CLIENT_ID,
|
||||||
scope: selectedScopes.join(" "),
|
scope: selectedScopes.join(" "),
|
||||||
state: "asfe",
|
state,
|
||||||
}).toString();
|
}).toString();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -9,11 +9,25 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const praisalRequest: { quantity: number; type_id: number }[] = JSON.parse(
|
const parsed = JSON.parse(req.body);
|
||||||
req.body
|
|
||||||
|
if (!Array.isArray(parsed)) {
|
||||||
|
return res.status(400).json({ error: 'Invalid input' });
|
||||||
|
}
|
||||||
|
|
||||||
|
const praisalRequest: { quantity: number; type_id: number }[] = parsed.filter(
|
||||||
|
(item): item is { quantity: number; type_id: number } =>
|
||||||
|
item !== null &&
|
||||||
|
typeof item === 'object' &&
|
||||||
|
typeof item.quantity === 'number' &&
|
||||||
|
Number.isFinite(item.quantity) &&
|
||||||
|
item.quantity >= 0 &&
|
||||||
|
typeof item.type_id === 'number' &&
|
||||||
|
Number.isInteger(item.type_id) &&
|
||||||
|
item.type_id > 0
|
||||||
);
|
);
|
||||||
|
|
||||||
logger.info({
|
logger.info({
|
||||||
event: 'praisal_request_parsed',
|
event: 'praisal_request_parsed',
|
||||||
items: praisalRequest.length
|
items: praisalRequest.length
|
||||||
});
|
});
|
||||||
@@ -27,10 +41,9 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
|||||||
|
|
||||||
return res.json(praisal);
|
return res.json(praisal);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error({
|
logger.error({
|
||||||
event: 'praisal_request_failed',
|
event: 'praisal_request_failed',
|
||||||
error: e,
|
error: e,
|
||||||
body: req.body
|
|
||||||
});
|
});
|
||||||
return res.status(500).json({ error: 'Failed to get praisal' });
|
return res.status(500).json({ error: 'Failed to get praisal' });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,9 +20,8 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
|||||||
return res.status(404).end();
|
return res.status(404).end();
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info({
|
logger.info({
|
||||||
event: 'token_request_start',
|
event: 'token_request_start',
|
||||||
code: code
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({
|
||||||
@@ -88,11 +87,10 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
|||||||
};
|
};
|
||||||
return res.json(token);
|
return res.json(token);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error({
|
logger.error({
|
||||||
event: 'token_request_failed',
|
event: 'token_request_failed',
|
||||||
reason: 'api_error',
|
reason: 'api_error',
|
||||||
error: e,
|
error: e,
|
||||||
code: code
|
|
||||||
});
|
});
|
||||||
return res.status(500).end();
|
return res.status(500).end();
|
||||||
}
|
}
|
||||||
|
|||||||
+50
-1
@@ -7,7 +7,7 @@ import {
|
|||||||
} from "@/types";
|
} from "@/types";
|
||||||
import { Api } from "@/esi-api";
|
import { Api } from "@/esi-api";
|
||||||
import { EXTRACTOR_TYPE_IDS, FACTORY_IDS, PI_SCHEMATICS } from "@/const";
|
import { EXTRACTOR_TYPE_IDS, FACTORY_IDS, PI_SCHEMATICS } from "@/const";
|
||||||
import { extractorsHaveExpired } from "./app/components/PlanetaryInteraction/timeColors";
|
import { extractorsHaveExpired } from "./app/components/PlanetaryInteraction/alerts";
|
||||||
|
|
||||||
export const getPlanets = async (character: AccessToken): Promise<Planet[]> => {
|
export const getPlanets = async (character: AccessToken): Promise<Planet[]> => {
|
||||||
const api = new Api();
|
const api = new Api();
|
||||||
@@ -22,10 +22,51 @@ export const getPlanets = async (character: AccessToken): Promise<Planet[]> => {
|
|||||||
return planets;
|
return planets;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
interface CachedPlanetData {
|
||||||
|
data: PlanetInfo;
|
||||||
|
timestamp: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const CACHE_DURATION_MS = 60_000; // 1 minute
|
||||||
|
const CACHE_STORAGE_KEY = "planet_cache";
|
||||||
|
|
||||||
|
const loadCacheFromStorage = (): Map<string, CachedPlanetData> => {
|
||||||
|
if (typeof window === "undefined") return new Map();
|
||||||
|
try {
|
||||||
|
const stored = localStorage.getItem(CACHE_STORAGE_KEY);
|
||||||
|
if (stored) {
|
||||||
|
const parsed = JSON.parse(stored);
|
||||||
|
return new Map(Object.entries(parsed));
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to load planet cache from localStorage:", error);
|
||||||
|
}
|
||||||
|
return new Map();
|
||||||
|
};
|
||||||
|
|
||||||
|
const saveCacheToStorage = (cache: Map<string, CachedPlanetData>) => {
|
||||||
|
if (typeof window === "undefined") return;
|
||||||
|
try {
|
||||||
|
const obj = Object.fromEntries(cache);
|
||||||
|
localStorage.setItem(CACHE_STORAGE_KEY, JSON.stringify(obj));
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to save planet cache to localStorage:", error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const planetCache = loadCacheFromStorage();
|
||||||
|
|
||||||
export const getPlanet = async (
|
export const getPlanet = async (
|
||||||
character: AccessToken,
|
character: AccessToken,
|
||||||
planet: Planet,
|
planet: Planet,
|
||||||
): Promise<PlanetInfo> => {
|
): Promise<PlanetInfo> => {
|
||||||
|
const cacheKey = `${character.character.characterId}-${planet.planet_id}`;
|
||||||
|
const cached = planetCache.get(cacheKey);
|
||||||
|
|
||||||
|
if (cached && Date.now() - cached.timestamp < CACHE_DURATION_MS) {
|
||||||
|
return cached.data;
|
||||||
|
}
|
||||||
|
|
||||||
const api = new Api();
|
const api = new Api();
|
||||||
const planetInfo = (
|
const planetInfo = (
|
||||||
await api.v3.getCharactersCharacterIdPlanetsPlanetId(
|
await api.v3.getCharactersCharacterIdPlanetsPlanetId(
|
||||||
@@ -36,6 +77,14 @@ export const getPlanet = async (
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
).data;
|
).data;
|
||||||
|
|
||||||
|
planetCache.set(cacheKey, {
|
||||||
|
data: planetInfo,
|
||||||
|
timestamp: Date.now(),
|
||||||
|
});
|
||||||
|
|
||||||
|
saveCacheToStorage(planetCache);
|
||||||
|
|
||||||
return planetInfo;
|
return planetInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+107
@@ -0,0 +1,107 @@
|
|||||||
|
import { AccessToken } from "./types";
|
||||||
|
|
||||||
|
const DB_NAME = "eve-pi-db";
|
||||||
|
const DB_VERSION = 1;
|
||||||
|
const STORE_NAME = "characters";
|
||||||
|
|
||||||
|
// Initialize IndexedDB
|
||||||
|
const initDB = (): Promise<IDBDatabase> => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const request = indexedDB.open(DB_NAME, DB_VERSION);
|
||||||
|
|
||||||
|
request.onerror = () => reject(request.error);
|
||||||
|
request.onsuccess = () => resolve(request.result);
|
||||||
|
|
||||||
|
request.onupgradeneeded = (event) => {
|
||||||
|
const db = (event.target as IDBOpenDBRequest).result;
|
||||||
|
if (!db.objectStoreNames.contains(STORE_NAME)) {
|
||||||
|
db.createObjectStore(STORE_NAME);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Save characters to IndexedDB
|
||||||
|
export const saveCharacters = async (
|
||||||
|
characters: AccessToken[]
|
||||||
|
): Promise<AccessToken[]> => {
|
||||||
|
try {
|
||||||
|
const db = await initDB();
|
||||||
|
const transaction = db.transaction([STORE_NAME], "readwrite");
|
||||||
|
const store = transaction.objectStore(STORE_NAME);
|
||||||
|
|
||||||
|
store.put(characters, "characters");
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
transaction.oncomplete = () => {
|
||||||
|
db.close();
|
||||||
|
resolve(characters);
|
||||||
|
};
|
||||||
|
transaction.onerror = () => {
|
||||||
|
db.close();
|
||||||
|
reject(transaction.error);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to save to IndexedDB:", error);
|
||||||
|
// Fallback: save minimal data to localStorage
|
||||||
|
try {
|
||||||
|
const minimalCharacters = characters.map((c) => ({
|
||||||
|
...c,
|
||||||
|
planets: [], // Strip planet data to reduce size
|
||||||
|
}));
|
||||||
|
localStorage.setItem("characters", JSON.stringify(minimalCharacters));
|
||||||
|
console.warn("Saved minimal character data to localStorage fallback");
|
||||||
|
} catch (storageError) {
|
||||||
|
console.error("Failed to save to localStorage fallback:", storageError);
|
||||||
|
}
|
||||||
|
return characters;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Load characters from IndexedDB
|
||||||
|
export const loadCharacters = async (): Promise<AccessToken[]> => {
|
||||||
|
try {
|
||||||
|
const db = await initDB();
|
||||||
|
const transaction = db.transaction([STORE_NAME], "readonly");
|
||||||
|
const store = transaction.objectStore(STORE_NAME);
|
||||||
|
const request = store.get("characters");
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
request.onsuccess = () => {
|
||||||
|
db.close();
|
||||||
|
const characters = request.result as AccessToken[] | undefined;
|
||||||
|
if (characters && characters.length > 0) {
|
||||||
|
resolve(characters);
|
||||||
|
} else {
|
||||||
|
// Try localStorage migration
|
||||||
|
resolve(migrateFromLocalStorage());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
request.onerror = () => {
|
||||||
|
db.close();
|
||||||
|
reject(request.error);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to load from IndexedDB:", error);
|
||||||
|
// Fallback to localStorage
|
||||||
|
return migrateFromLocalStorage();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Migrate data from localStorage to IndexedDB
|
||||||
|
const migrateFromLocalStorage = (): AccessToken[] => {
|
||||||
|
try {
|
||||||
|
const localStorageCharacters = localStorage.getItem("characters");
|
||||||
|
if (localStorageCharacters) {
|
||||||
|
const characterArray: AccessToken[] = JSON.parse(localStorageCharacters);
|
||||||
|
const filtered = characterArray.filter((c) => c.access_token && c.character);
|
||||||
|
// Don't delete from localStorage yet - keep as backup
|
||||||
|
return filtered;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to migrate from localStorage:", error);
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
};
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
import { Pin, PlanetWithInfo } from '../types';
|
||||||
|
|
||||||
|
export interface StorageContent {
|
||||||
|
type_id: number;
|
||||||
|
amount: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface StorageInfo {
|
||||||
|
pin_id: number;
|
||||||
|
type: string;
|
||||||
|
type_id: number;
|
||||||
|
capacity: number;
|
||||||
|
used: number;
|
||||||
|
fillRate: number;
|
||||||
|
value: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PlanetCalculations {
|
||||||
|
expired: boolean;
|
||||||
|
extractors: Pin[];
|
||||||
|
localProduction: Map<number, LocalProductionInfo>;
|
||||||
|
localImports: LocalImport[];
|
||||||
|
localExports: LocalExport[];
|
||||||
|
storageInfo: StorageInfo[];
|
||||||
|
extractorAverages: ExtractorAverage[];
|
||||||
|
hasLargeExtractorDifference: boolean;
|
||||||
|
importDepletionTimes: ImportDepletionTime[];
|
||||||
|
visibility: 'visible' | 'hidden';
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AlertState {
|
||||||
|
expired: boolean;
|
||||||
|
hasLowStorage: boolean;
|
||||||
|
hasLowImports: boolean;
|
||||||
|
hasLargeExtractorDifference: boolean;
|
||||||
|
hasLowExtractionRate: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ExtractorAverage {
|
||||||
|
typeId: number;
|
||||||
|
averagePerHour: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ImportDepletionTime {
|
||||||
|
typeId: number;
|
||||||
|
hoursUntilDepletion: number;
|
||||||
|
monthlyCost: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface LocalProductionInfo {
|
||||||
|
name: string;
|
||||||
|
cycle_time: number;
|
||||||
|
schematic_id: number;
|
||||||
|
inputs: SchematicInput[];
|
||||||
|
outputs: SchematicOutput[];
|
||||||
|
factoryCount: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface LocalImport {
|
||||||
|
type_id: number;
|
||||||
|
schematic_id: number;
|
||||||
|
quantity: number;
|
||||||
|
factoryCount: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface LocalExport {
|
||||||
|
type_id: number;
|
||||||
|
schematic_id: number;
|
||||||
|
quantity: number;
|
||||||
|
factoryCount: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SchematicInput {
|
||||||
|
schematic_id: number;
|
||||||
|
type_id: number;
|
||||||
|
quantity: number;
|
||||||
|
is_input: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SchematicOutput {
|
||||||
|
schematic_id: number;
|
||||||
|
type_id: number;
|
||||||
|
quantity: number;
|
||||||
|
is_input: number;
|
||||||
|
}
|
||||||
+4
-6
@@ -2,14 +2,12 @@ import pino from 'pino';
|
|||||||
|
|
||||||
const logger = pino({
|
const logger = pino({
|
||||||
level: process.env.LOG_LEVEL || 'info',
|
level: process.env.LOG_LEVEL || 'info',
|
||||||
transport: {
|
formatters: {
|
||||||
target: 'pino-pretty',
|
level: (label) => {
|
||||||
options: {
|
return { level: label };
|
||||||
colorize: true,
|
|
||||||
translateTime: 'SYS:standard',
|
|
||||||
ignore: 'pid,hostname',
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
timestamp: () => `,"time":"${new Date().toISOString()}"`,
|
||||||
base: {
|
base: {
|
||||||
env: process.env.NODE_ENV,
|
env: process.env.NODE_ENV,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user