Просмотр исходного кода

Update_BreakEven_Calculation

Updated the break-even calculation across both the frontend and backend to account for operational expenditures (OpEx).

        PURPOSE:
        To provide a more accurate and realistic timeline for return on investment (ROI). The previous calculation solely divided capital expenditure (CapEx) by daily profit. However, setting up production lines inherently requires a working capital buffer to operate for several days before yielding marketable outputs. By adding a 3-day buffer of operational costs (`cost_per_day`) to the numerator, users gain a precise visualization of their total required upfront investment relative to break-even time.

        IMPLEMENTATION DETAILS:
        - In `ts/roi.ts`: Modified the `breakEven` constant from `p.capex / p.profit_per_day` to `(p.capex + 3 * p.cost_per_day) / p.profit_per_day`.
        - In `roi.py`: Modified the `__lt__` (less than) magic method of the `Profit` dataclass. The backend JSON array uses this to automatically pre-sort the list of recipes by their break-even speed. It now applies the identical `(self.capex + 3 * self.cost_per_day) / self.profit_per_day` formula so that the frontend display remains correctly ordered.
        - Included hyper-documentation in both files detailing the inclusion of the 3-day working capital buffer.
Thomas Knott 2 недель назад
Родитель
Сommit
bfbc7de678
2 измененных файлов с 15 добавлено и 5 удалено
  1. 7 3
      roi.py
  2. 8 2
      ts/roi.ts

+ 7 - 3
roi.py

@@ -193,9 +193,13 @@ class Profit:
 	average_traded_7d: float
 
 	def __lt__(self, other: Profit) -> bool:
-		if (break_even := self.capex / self.profit_per_day) < 0:
+		# EXTREME DETAIL: The sorting logic for Profit instances determines the order items appear in the frontend.
+		# This has been updated to match the new frontend break-even calculation, which includes 3 days of operational
+		# expenses (cost_per_day) in the numerator along with capex. This ensures the JSON arrays generated by this script
+		# are inherently sorted by the new, more accurate break-even metric.
+		if (break_even := (self.capex + 3 * self.cost_per_day) / self.profit_per_day) < 0:
 			break_even = 10000 - self.profit_per_day
-		if (other_break_even := other.capex / other.profit_per_day) < 0:
+		if (other_break_even := (other.capex + 3 * other.cost_per_day) / other.profit_per_day) < 0:
 			other_break_even = 10000 - other.profit_per_day
 		return break_even < other_break_even
 
@@ -206,4 +210,4 @@ class MatPrice:
 	vwap_7d: float
 
 if __name__ == '__main__':
-	main()
+	main()

+ 8 - 2
ts/roi.ts

@@ -75,7 +75,13 @@ async function render() {
 			continue;
 		const tr = document.createElement('tr');
 		const profitPerArea = p.profit_per_day / p.area;
-		const breakEven = p.profit_per_day > 0 ? p.capex / p.profit_per_day : Infinity;
+		
+		// EXTREME DETAIL: The break-even calculation dictates how long it takes to recoup the initial investment.
+		// Previously, this only factored in raw Capital Expenditure (capex). It has been altered to include
+		// 3 days of Operational Expenditure (cost_per_day). This reflects the reality that running a production
+		// line requires an initial working capital buffer before the first batch of goods can be sold for profit.
+		const breakEven = p.profit_per_day > 0 ? (p.capex + 3 * p.cost_per_day) / p.profit_per_day : Infinity;
+		
 		tr.innerHTML = `
 			<td>${p.outputs.map(o => o.ticker).join(', ')}</td>
 			<td>${expertise[p.expertise]}</td>
@@ -154,4 +160,4 @@ interface Building {
 	building_type: 'INFRASTRUCTURE' | 'PLANETARY' | 'PRODUCTION';
 	building_ticker: string;
 	expertise: keyof typeof expertise;
-}
+}