|
@@ -20,21 +20,27 @@ document.querySelector('#fetch')!.addEventListener('click', async () => {
|
|
|
setupPopover();
|
|
setupPopover();
|
|
|
|
|
|
|
|
async function calculate(username: string, apiKey: string, supplyForDays: number): Promise<void> {
|
|
async function calculate(username: string, apiKey: string, supplyForDays: number): Promise<void> {
|
|
|
- const [prices, planets, warehouse, {bids, orders}] = await Promise.all([
|
|
|
|
|
|
|
+ const [prices, planets, avail, {bids, orders}] = await Promise.all([
|
|
|
getPrices(),
|
|
getPrices(),
|
|
|
getPlanets(username, apiKey),
|
|
getPlanets(username, apiKey),
|
|
|
warehouseInventory(username, apiKey),
|
|
warehouseInventory(username, apiKey),
|
|
|
getBids(username, apiKey)
|
|
getBids(username, apiKey)
|
|
|
]);
|
|
]);
|
|
|
const buy = new Map<string, number>();
|
|
const buy = new Map<string, number>();
|
|
|
- for (const planet of planets)
|
|
|
|
|
|
|
+ for (const planet of planets) {
|
|
|
for (const [mat, amount] of planet.supplyForDays(supplyForDays))
|
|
for (const [mat, amount] of planet.supplyForDays(supplyForDays))
|
|
|
buy.set(mat, (buy.get(mat) ?? 0) + amount);
|
|
buy.set(mat, (buy.get(mat) ?? 0) + amount);
|
|
|
|
|
+ for (const mat of planet.exporting) {
|
|
|
|
|
+ const planetExport = planet.inventory.get(mat);
|
|
|
|
|
+ if (planetExport)
|
|
|
|
|
+ avail.set(mat, (avail.get(mat) ?? 0) + planetExport);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// what's left to buy
|
|
// what's left to buy
|
|
|
const materials: Material[] = [];
|
|
const materials: Material[] = [];
|
|
|
for (const [mat, amount] of buy) {
|
|
for (const [mat, amount] of buy) {
|
|
|
- const remaining = Math.max(amount - (bids.get(mat) ?? 0) - (warehouse.get(mat) ?? 0), 0);
|
|
|
|
|
|
|
+ const remaining = Math.max(amount - (bids.get(mat) ?? 0) - (avail.get(mat) ?? 0), 0);
|
|
|
const price = prices.get(mat);
|
|
const price = prices.get(mat);
|
|
|
if (!price || price.Bid === null || price.Ask === null) {
|
|
if (!price || price.Bid === null || price.Ask === null) {
|
|
|
console.log(mat, 'has no bid/ask');
|
|
console.log(mat, 'has no bid/ask');
|
|
@@ -45,7 +51,7 @@ async function calculate(username: string, apiKey: string, supplyForDays: number
|
|
|
ticker: mat,
|
|
ticker: mat,
|
|
|
amount,
|
|
amount,
|
|
|
bids: bids.get(mat) ?? 0,
|
|
bids: bids.get(mat) ?? 0,
|
|
|
- warehouse: warehouse.get(mat) ?? 0,
|
|
|
|
|
|
|
+ have: avail.get(mat) ?? 0,
|
|
|
spread,
|
|
spread,
|
|
|
savings: spread * remaining,
|
|
savings: spread * remaining,
|
|
|
});
|
|
});
|
|
@@ -57,12 +63,12 @@ async function calculate(username: string, apiKey: string, supplyForDays: number
|
|
|
const format= new Intl.NumberFormat(undefined, {maximumFractionDigits: 0}).format;
|
|
const format= new Intl.NumberFormat(undefined, {maximumFractionDigits: 0}).format;
|
|
|
for (const m of materials) {
|
|
for (const m of materials) {
|
|
|
const tr = document.createElement('tr');
|
|
const tr = document.createElement('tr');
|
|
|
- const buyAmount = Math.max(m.amount - m.bids - m.warehouse, 0);
|
|
|
|
|
|
|
+ const buyAmount = Math.max(m.amount - m.bids - m.have, 0);
|
|
|
tr.innerHTML = `
|
|
tr.innerHTML = `
|
|
|
<td>${m.ticker}</td>
|
|
<td>${m.ticker}</td>
|
|
|
<td>${format(m.amount)}</td>
|
|
<td>${format(m.amount)}</td>
|
|
|
<td>${format(m.bids)}</td>
|
|
<td>${format(m.bids)}</td>
|
|
|
- <td>${format(m.warehouse)}</td>
|
|
|
|
|
|
|
+ <td>${format(m.have)}</td>
|
|
|
<td>${format(buyAmount)}</td>
|
|
<td>${format(buyAmount)}</td>
|
|
|
<td>${format(m.spread)}</td>
|
|
<td>${format(m.spread)}</td>
|
|
|
<td>${format(m.savings)}</td>
|
|
<td>${format(m.savings)}</td>
|
|
@@ -126,6 +132,7 @@ class Planet {
|
|
|
name: string;
|
|
name: string;
|
|
|
inventory: Map<string, number>;
|
|
inventory: Map<string, number>;
|
|
|
netConsumption: Amount[];
|
|
netConsumption: Amount[];
|
|
|
|
|
+ exporting: Set<string>; // producing more than consumption
|
|
|
|
|
|
|
|
constructor(fioBurn: FIOBurn) {
|
|
constructor(fioBurn: FIOBurn) {
|
|
|
this.name = fioBurn.PlanetName || fioBurn.PlanetNaturalId;
|
|
this.name = fioBurn.PlanetName || fioBurn.PlanetNaturalId;
|
|
@@ -149,6 +156,12 @@ class Planet {
|
|
|
c.netConsumption = net;
|
|
c.netConsumption = net;
|
|
|
this.netConsumption.push(c);
|
|
this.netConsumption.push(c);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ const consuming = new Set(this.netConsumption.map(item => item.MaterialTicker));
|
|
|
|
|
+ this.exporting = new Set<string>();
|
|
|
|
|
+ for (const item of fioBurn.OrderProduction)
|
|
|
|
|
+ if (!consuming.has(item.MaterialTicker))
|
|
|
|
|
+ this.exporting.add(item.MaterialTicker);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
supplyForDays(targetDays: number): Map<string, number> {
|
|
supplyForDays(targetDays: number): Map<string, number> {
|
|
@@ -169,7 +182,7 @@ interface Material {
|
|
|
ticker: string;
|
|
ticker: string;
|
|
|
amount: number;
|
|
amount: number;
|
|
|
bids: number;
|
|
bids: number;
|
|
|
- warehouse: number;
|
|
|
|
|
|
|
+ have: number;
|
|
|
spread: number;
|
|
spread: number;
|
|
|
savings: number;
|
|
savings: number;
|
|
|
}
|
|
}
|