소스 검색

show traded for all recipes

raylu 1 개월 전
부모
커밋
7db17b3469
4개의 변경된 파일56개의 추가작업 그리고 41개의 파일을 삭제
  1. 24 18
      dist/main.js
  2. 0 0
      dist/main.js.map
  3. 1 2
      index.html
  4. 31 21
      src/main.ts

+ 24 - 18
dist/main.js

@@ -14,36 +14,42 @@ 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 fmt = new Intl.NumberFormat(undefined, { maximumFractionDigits: 2 });
-  const tbody = document.querySelector("tbody");
-  tbody.innerHTML = "";
+      priceMap.set(price.MaterialTicker, price);
+  const profits = [];
   for (const recipe of recipes) {
-    if (recipe.BuildingTicker !== "FRM")
-      continue;
     const runsPerDay = 1000 * 60 * 60 * 24 / recipe.TimeMs;
-    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);
+    if (recipe.Outputs.length !== 1) {
+      console.warn(`${recipe.RecipeName} doesn't have 1 output`);
+      continue;
+    }
+    const output = recipe.Outputs[0];
+    const outputPrice = priceMap.get(output.Ticker);
+    if (outputPrice === undefined)
+      throw new Error(`missing price for ${output.Ticker}`);
+    const revenuePerRun = output.Amount * outputPrice.PriceAverage;
     const costPerRun = recipe.Inputs.reduce((sum, input) => {
       const price = priceMap.get(input.Ticker);
       if (price === undefined)
         throw new Error(`missing price for ${input.Ticker}`);
-      return sum + price * input.Amount;
+      return sum + price.PriceAverage * input.Amount;
     }, 0);
+    const dailyProfit = (revenuePerRun - costPerRun) * runsPerDay;
+    profits.push({ recipeName: recipe.RecipeName, dailyProfit, traded: outputPrice.Traded });
+  }
+  profits.sort((a, b) => b.dailyProfit - a.dailyProfit);
+  const fmt = new Intl.NumberFormat(undefined, { maximumFractionDigits: 2 });
+  const tbody = document.querySelector("tbody");
+  tbody.innerHTML = "";
+  for (const profit of profits) {
     const row = document.createElement("tr");
     row.innerHTML = `
-			<td>${recipe.RecipeName}</td>
-			<td>${fmt.format(revenuePerRun * runsPerDay)}</td>
-			<td>${fmt.format(costPerRun * runsPerDay)}</td>
-			<td>${fmt.format((revenuePerRun - costPerRun) * runsPerDay)}</td>
+			<td>${profit.recipeName}</td>
+			<td>${fmt.format(profit.dailyProfit)}</td>
+			<td>${fmt.format(profit.traded)}</td>
 		`;
     tbody.appendChild(row);
   }
 }
 fetchData().then(render);
 
-//# debugId=E579798A6AFE522164756E2164756E21
+//# debugId=70C1D9063E5E875D64756E2164756E21

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
dist/main.js.map


+ 1 - 2
index.html

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

+ 31 - 21
src/main.ts

@@ -11,6 +11,13 @@ interface Price {
 	MaterialTicker: string;
 	ExchangeCode: string;
 	PriceAverage: number;
+	Traded: number;
+}
+
+interface RecipeProfit {
+	recipeName: string;
+	dailyProfit: number;
+	traded: number;
 }
 
 async function fetchData(): Promise<{recipes: Recipe[]; prices: Price[]}> {
@@ -26,40 +33,43 @@ async function fetchData(): Promise<{recipes: Recipe[]; prices: Price[]}> {
 }
 
 function render({recipes, prices}: {recipes: Recipe[], prices: Price[]}) {
-	const priceMap = new Map<string, number>();
+	const priceMap = new Map<string, Price>();
 	for (const price of prices)
 		if (price.ExchangeCode == 'PP7D_IC1')
-			priceMap.set(price.MaterialTicker, price.PriceAverage);
-
-	const fmt = new Intl.NumberFormat(undefined, {maximumFractionDigits: 2});
+			priceMap.set(price.MaterialTicker, price);
 
-	const tbody = document.querySelector('tbody') as HTMLTableSectionElement;
-	tbody.innerHTML = '';
+	const profits: RecipeProfit[] = []
 	for (const recipe of recipes) {
-		if (recipe.BuildingTicker !== 'FRM')
-			continue;
 		const runsPerDay = 1000 * 60 * 60 * 24 / recipe.TimeMs;
-
-		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);
-
+		if (recipe.Outputs.length !== 1) {
+			console.warn(`${recipe.RecipeName} doesn't have 1 output`);
+			continue;
+		}
+		const output = recipe.Outputs[0];
+		const outputPrice = priceMap.get(output.Ticker);
+		if (outputPrice === undefined)
+			throw new Error(`missing price for ${output.Ticker}`);
+		const revenuePerRun = output.Amount * outputPrice.PriceAverage;
 		const costPerRun = recipe.Inputs.reduce((sum, input) => {
 			const price = priceMap.get(input.Ticker);
 			if (price === undefined)
 				throw new Error(`missing price for ${input.Ticker}`);
-			return sum + price * input.Amount;
+			return sum + price.PriceAverage * input.Amount;
 		}, 0);
+		const dailyProfit = (revenuePerRun - costPerRun) * runsPerDay;
+		profits.push({ recipeName: recipe.RecipeName, dailyProfit, traded: outputPrice.Traded });
+	}
+	profits.sort((a, b) => b.dailyProfit - a.dailyProfit);
 
+	const fmt = new Intl.NumberFormat(undefined, {maximumFractionDigits: 2});
+	const tbody = document.querySelector('tbody') as HTMLTableSectionElement;
+	tbody.innerHTML = '';
+	for (const profit of profits) {
 		const row = document.createElement('tr');
 		row.innerHTML = `
-			<td>${recipe.RecipeName}</td>
-			<td>${fmt.format(revenuePerRun * runsPerDay)}</td>
-			<td>${fmt.format(costPerRun * runsPerDay)}</td>
-			<td>${fmt.format((revenuePerRun - costPerRun) * runsPerDay)}</td>
+			<td>${profit.recipeName}</td>
+			<td>${fmt.format(profit.dailyProfit)}</td>
+			<td>${fmt.format(profit.traded)}</td>
 		`;
 		tbody.appendChild(row);
 	}

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.