raylu 2 mesiacov pred
rodič
commit
ae08d8b4bf
5 zmenil súbory, kde vykonal 43 pridanie a 13 odobranie
  1. 14 6
      dist/main.js
  2. 0 1
      dist/main.js.map
  3. 2 0
      index.html
  4. 17 5
      src/main.ts
  5. 10 1
      styles.css

+ 14 - 6
dist/main.js

@@ -15,27 +15,35 @@ function render({ recipes, prices }) {
   for (const price of prices)
     if (price.ExchangeCode == "PP7D_IC1")
       priceMap.set(price.MaterialTicker, price.PriceAverage);
+  const fmt = new Intl.NumberFormat(undefined, { maximumFractionDigits: 2 });
   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 revenuePerRun = recipe.Outputs.reduce((sum, output) => {
+      const price = priceMap.get(output.Ticker);
+      if (price === undefined)
+        throw new Error(`missing price for ${output.Ticker}`);
+      return sum + price * output.Amount;
+    }, 0);
+    const costPerRun = recipe.Inputs.reduce((sum, input) => {
       const price = priceMap.get(input.Ticker);
       if (price === undefined)
         throw new Error(`missing price for ${input.Ticker}`);
-      costPerRun += price * input.Amount;
-    }
+      return sum + price * input.Amount;
+    }, 0);
     const row = document.createElement("tr");
     row.innerHTML = `
 			<td>${recipe.RecipeName}</td>
-			<td>${(costPerRun * runsPerDay).toFixed(2)}</td>
+			<td>${fmt.format(revenuePerRun * runsPerDay)}</td>
+			<td>${fmt.format(costPerRun * runsPerDay)}</td>
+			<td>${fmt.format((revenuePerRun - costPerRun) * runsPerDay)}</td>
 		`;
     tbody.appendChild(row);
   }
 }
 fetchData().then(render);
 
-//# debugId=2420FEED6C51286B64756E2164756E21
+//# debugId=E579798A6AFE522164756E2164756E21

Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 0 - 1
dist/main.js.map


+ 2 - 0
index.html

@@ -12,7 +12,9 @@
 			<thead>
 				<tr>
 					<th>recipe</th>
+					<th>daily revenue</th>
 					<th>daily cost</th>
+					<th>daily profit</th>
 				</tr>
 			</thead>
 			<tbody></tbody>

+ 17 - 5
src/main.ts

@@ -31,23 +31,35 @@ function render({recipes, prices}: {recipes: Recipe[], prices: Price[]}) {
 		if (price.ExchangeCode == 'PP7D_IC1')
 			priceMap.set(price.MaterialTicker, price.PriceAverage);
 
+	const fmt = new Intl.NumberFormat(undefined, {maximumFractionDigits: 2});
+
 	const tbody = document.querySelector('tbody') as HTMLTableSectionElement;
 	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 revenuePerRun = recipe.Outputs.reduce((sum, output) => {
+			const price = priceMap.get(output.Ticker);
+			if (price === undefined)
+				throw new Error(`missing price for ${output.Ticker}`);
+			return sum + price * output.Amount;
+		}, 0);
+
+		const costPerRun = recipe.Inputs.reduce((sum, input) => {
 			const price = priceMap.get(input.Ticker);
 			if (price === undefined)
 				throw new Error(`missing price for ${input.Ticker}`);
-			costPerRun += price * input.Amount;
-		}
+			return sum + price * input.Amount;
+		}, 0);
+
 		const row = document.createElement('tr');
 		row.innerHTML = `
 			<td>${recipe.RecipeName}</td>
-			<td>${(costPerRun * runsPerDay).toFixed(2)}</td>
+			<td>${fmt.format(revenuePerRun * runsPerDay)}</td>
+			<td>${fmt.format(costPerRun * runsPerDay)}</td>
+			<td>${fmt.format((revenuePerRun - costPerRun) * runsPerDay)}</td>
 		`;
 		tbody.appendChild(row);
 	}

+ 10 - 1
styles.css

@@ -3,7 +3,8 @@
 }
 
 body {
-    font-family: sans-serif;
+    font-family: monospace;
+    font-size: 14pt;
     background-color: #000;
     color: #eee;
 }
@@ -14,3 +15,11 @@ main {
     padding: 1em;
     background: #111;
 }
+
+td {
+    text-align: right;
+    padding: 0.25em 1em;
+}
+td:first-child {
+    text-align: inherit;
+}

Niektoré súbory nie sú zobrazené, pretože je v týchto rozdielových dátach zmenené mnoho súborov