Эх сурвалжийг харах

roi: show daily output/traded

raylu 3 өдөр өмнө
parent
commit
dd1fb0905e
4 өөрчлөгдсөн 29 нэмэгдсэн , 24 устгасан
  1. 8 12
      roi.py
  2. 12 7
      ts/roi.ts
  3. 4 3
      www/index.html
  4. 5 2
      www/style.css

+ 8 - 12
roi.py

@@ -26,7 +26,7 @@ def main() -> None:
 	for p in profits:
 		print(f'\033[53;1m{p.output:5} \033[53;32m{p.profit_per_area: 10,.0f} ', end='')
 		warnings = []
-		if p.low_volume:
+		if p.average_traded_7d < p.output_per_day * 20:
 			warnings.append('low volume')
 		if p.logistics_per_area > 1.5:
 			warnings.append('heavy logistics')
@@ -73,7 +73,8 @@ def calc_profit(recipe: Recipe, buildings: typing.Mapping[str, Building], materi
 			capex=capex,
 			cost_per_day=cost_per_day,
 			logistics_per_area=logistics_per_area,
-			low_volume=output_price.average_traded < output_per_day * 20)
+			output_per_day=output_per_day,
+			average_traded_7d=output_price.average_traded_7d)
 
 def building_daily_cost(building: Building, prices: typing.Mapping[str, Price]) -> float:
 	consumption = {
@@ -131,9 +132,9 @@ class RawPrice(typing.TypedDict):
 @dataclasses.dataclass(eq=False, frozen=True, slots=True)
 class Price:
 	vwap: float
-	average_traded: float
+	average_traded_7d: float
 
-@dataclasses.dataclass(eq=False, slots=True)
+@dataclasses.dataclass(eq=False, frozen=True, slots=True)
 class Profit:
 	output: str
 	recipe: str
@@ -142,16 +143,11 @@ class Profit:
 	capex: float
 	cost_per_day: float
 	logistics_per_area: float
-	low_volume: bool
-	score: float = dataclasses.field(init=False)
-
-	def __post_init__(self) -> None:
-		self.score = self.profit_per_area
-		if self.low_volume:
-			self.score *= 0.2
+	output_per_day: float
+	average_traded_7d: float
 
 	def __lt__(self, other: Profit) -> bool:
-		return self.score < other.score
+		return self.profit_per_area < other.profit_per_area
 
 if __name__ == '__main__':
 	main()

+ 12 - 7
ts/roi.ts

@@ -2,19 +2,23 @@
 	const response = await fetch('roi.json');
 	const profits: Profit[] = await response.json();
 
-	const format = new Intl.NumberFormat(undefined,
-			{maximumFractionDigits: 2, maximumSignificantDigits: 7, roundingPriority: 'lessPrecision'}).format;
+	const formatDecimal = new Intl.NumberFormat(undefined,
+			{maximumFractionDigits: 2, maximumSignificantDigits: 6, roundingPriority: 'lessPrecision'}).format;
+	const formatWhole = new Intl.NumberFormat(undefined, {maximumFractionDigits: 0}).format;
 	const tbody = document.querySelector('tbody')!;
 	for (const p of profits) {
 		const tr = document.createElement('tr');
 		tr.innerHTML = `
 			<td>${p.output}</td>
 			<td>${p.expertise}</td>
-			<td>${format(p.profit_per_area)}</td>
-			<td>${format(p.capex)}</td>
-			<td>${format(p.cost_per_day)}</td>
-			<td>${format(p.logistics_per_area)}</td>
+			<td>${formatDecimal(p.profit_per_area)}</td>
+			<td>${formatWhole(p.capex)}</td>
+			<td>${formatWhole(p.cost_per_day)}</td>
+			<td>${formatDecimal(p.logistics_per_area)}</td>
+			<td>${formatWhole(p.output_per_day)}<br>${formatWhole(p.average_traded_7d)}</td>
 		`;
+		const output = tr.querySelector('td')!;
+		output.title = p.recipe;
 		tbody.appendChild(tr);
 	}
 })();
@@ -27,5 +31,6 @@ interface Profit {
 	capex: number
 	cost_per_day: number
 	logistics_per_area: number
-	low_volume: boolean
+	output_per_day: number
+	average_traded_7d: number
 }

+ 4 - 3
www/index.html

@@ -13,12 +13,13 @@
 		<table>
 			<thead>
 				<tr>
-					<th>wrought product</th>
+					<th>wrought<br>product</th>
 					<th>expertise</th>
-					<th>daily profit/area</th>
+					<th>daily<br>profit/area</th>
 					<th>capex</th>
-					<th>daily opex</th>
+					<th>daily<br>opex</th>
 					<th>logistics</th>
+					<th>daily output<br>traded</th>
 				</tr>
 			</thead>
 			<tbody></tbody>

+ 5 - 2
www/style.css

@@ -31,8 +31,10 @@ main {
 	box-shadow: 0 0 5px #222;
 
 	table {
-		td, th {
-			padding: 0.25em 0.5em;
+		width: 100%;
+		border-collapse: collapse;
+		th {
+			white-space: no-wrap;
 		}
 		tbody {
 			td:nth-child(1),
@@ -43,6 +45,7 @@ main {
 			td {
 				font-family: monospace;
 				text-align: right;
+				border-top: 1px solid #222;
 			}
 		}
 	}