| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- // src/main.ts
- async function fetchData() {
- const [recipesResponse, exchangesResponse] = await Promise.all([
- fetch("https://api.prunplanner.org/data/recipes"),
- fetch("https://api.prunplanner.org/data/exchanges")
- ]);
- const [recipes, prices] = await Promise.all([
- recipesResponse.json(),
- exchangesResponse.json()
- ]);
- return { recipes, prices };
- }
- function render({ recipes, prices }) {
- const priceMap = new Map;
- for (const price of prices)
- if (price.ExchangeCode == "PP7D_IC1")
- priceMap.set(price.MaterialTicker, price.PriceAverage);
- const tbody = document.querySelector("tbody");
- tbody.innerHTML = "";
- for (const recipe of recipes) {
- if (recipe.BuildingTicker !== "FRM")
- continue;
- const runsPerDay = 1000 * 60 * 60 * 24 / recipe.TimeMs;
- let costPerRun = 0;
- for (const input of recipe.Inputs) {
- const price = priceMap.get(input.Ticker);
- if (price === undefined)
- throw new Error(`missing price for ${input.Ticker}`);
- costPerRun += price * input.Amount;
- }
- const row = document.createElement("tr");
- row.innerHTML = `
- <td>${recipe.RecipeName}</td>
- <td>${(costPerRun * runsPerDay).toFixed(2)}</td>
- `;
- tbody.appendChild(row);
- }
- }
- fetchData().then(render);
- //# debugId=2420FEED6C51286B64756E2164756E21
|