|
|
@@ -110,9 +110,8 @@ async function _render(apiKey: string, planet: string, usernames: string[], carg
|
|
|
const renderTarget = document.querySelector('#coop')!;
|
|
|
renderTarget.innerHTML = '';
|
|
|
|
|
|
- const [userStores, userWorkforces, rawMaterials]: [UserStorages[], UserWorkforces[], Material[]] = await Promise.all([
|
|
|
+ const [userStores, rawMaterials]: [UserStorages[], Material[]] = await Promise.all([
|
|
|
cachedFetchJSON(`https://api.punoted.net/v1/storages/?location=${planet}`, {headers: {'X-Data-Token': apiKey}}),
|
|
|
- cachedFetchJSON(`https://api.punoted.net/v1/workforce/?location=${planet}`, {headers: {'X-Data-Token': apiKey}}),
|
|
|
cachedFetchJSON('https://api.punoted.net/v1/materials/list'),
|
|
|
]);
|
|
|
|
|
|
@@ -133,19 +132,8 @@ async function _render(apiKey: string, planet: string, usernames: string[], carg
|
|
|
allStorages.set(userStorage.Username, items);
|
|
|
}
|
|
|
|
|
|
- const allWfNeeds = new Map<string, Map<string, number>>();
|
|
|
- for (const userWorkforce of userWorkforces) {
|
|
|
- const needs = new Map<string, number>();
|
|
|
- const wf = userWorkforce.Workforce[0];
|
|
|
- for (const workers of wf.Workforces)
|
|
|
- for (const need of workers.WorkforceNeeds)
|
|
|
- if (need.UnitsPerInterval > 0)
|
|
|
- needs.set(need.MaterialTicker, (needs.get(need.MaterialTicker) ?? 0) + need.UnitsPerInterval);
|
|
|
- allWfNeeds.set(userWorkforce.Username, needs);
|
|
|
- }
|
|
|
-
|
|
|
const userBurns = await Promise.all(usernames.map((username) => userBurn(apiKey, planet, username,
|
|
|
- allStorages.get(username), lastUpdates.get(username), allWfNeeds.get(username))));
|
|
|
+ allStorages.get(username), lastUpdates.get(username))));
|
|
|
|
|
|
const combinedBurn = new Map<string, Burn>();
|
|
|
for (const ub of userBurns) {
|
|
|
@@ -188,8 +176,8 @@ async function _render(apiKey: string, planet: string, usernames: string[], carg
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-async function userBurn(apiKey: string, planet: string, username: string, items?: Map<string, number>, lastUpdated?: number,
|
|
|
- wfNeeds?: Map<string, number>): Promise<{username: string, burn: Map<string, Burn>, html: string}> {
|
|
|
+async function userBurn(apiKey: string, planet: string, username: string, items?: Map<string, number>,
|
|
|
+ lastUpdated?: number): Promise<{username: string, burn: Map<string, Burn>, html: string}> {
|
|
|
const burns: Record<string, Burn[]> = await cachedFetchJSON(
|
|
|
`https://api.punoted.net/v1/production/user/burn?location=${planet}&username=${username}`,
|
|
|
{headers: {'X-Data-Token': apiKey}});
|
|
|
@@ -200,16 +188,6 @@ async function userBurn(apiKey: string, planet: string, username: string, items?
|
|
|
burnArray = Object.values(burns).at(0) ?? [];
|
|
|
|
|
|
const burn = new Map<string, Burn>(burnArray.map((b) => [b.MaterialTicker, b]));
|
|
|
- if (wfNeeds !== undefined)
|
|
|
- for (const [mat, amount] of wfNeeds.entries()) {
|
|
|
- const productionBurn = burn.get(mat);
|
|
|
- if (productionBurn === undefined)
|
|
|
- burn.set(mat, {MaterialTicker: mat, Production: 0, Consumption: amount, Net: -amount});
|
|
|
- else {
|
|
|
- productionBurn.Consumption += amount;
|
|
|
- productionBurn.Net -= amount;
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
const html = `<h2>${username}</h2>
|
|
|
last updated: ${lastUpdated ? new Date(lastUpdated).toLocaleString() : ''}
|
|
|
@@ -346,20 +324,6 @@ interface UserStorages {
|
|
|
Username: string
|
|
|
}
|
|
|
|
|
|
-interface UserWorkforces {
|
|
|
- Workforce: Array<{
|
|
|
- Type: 'FTL_FUEL_STORE' | 'SHIP_STORE' | 'STL_FUEL_STORE' | 'STORE' | 'WAREHOUSE_STORE'
|
|
|
- Workforces: Array<{
|
|
|
- WorkforceNeeds: Array<{
|
|
|
- MaterialTicker: string
|
|
|
- UnitsPerInterval: number
|
|
|
- }>
|
|
|
- }>
|
|
|
- LastUpdatedEpochMs: number
|
|
|
- }>
|
|
|
- Username: string
|
|
|
-}
|
|
|
-
|
|
|
interface Burn {
|
|
|
MaterialTicker: string
|
|
|
Production: number
|