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

roi: handle negative profit

raylu 2 өдөр өмнө
parent
commit
95c0bfcb63
2 өөрчлөгдсөн 5 нэмэгдсэн , 3 устгасан
  1. 4 2
      roi.py
  2. 1 1
      ts/roi.ts

+ 4 - 2
roi.py

@@ -149,8 +149,10 @@ class Profit:
 	average_traded_7d: float
 
 	def __lt__(self, other: Profit) -> bool:
-		break_even = self.capex / self.profit_per_day
-		other_break_even = other.capex / other.profit_per_day
+		if (break_even := self.capex / self.profit_per_day) < 0:
+			break_even = 1000 + break_even
+		if (other_break_even := other.capex / other.profit_per_day) < 0:
+			other_break_even = 1000 + other_break_even
 		return break_even < other_break_even
 
 if __name__ == '__main__':

+ 1 - 1
ts/roi.ts

@@ -9,7 +9,7 @@
 	for (const p of profits) {
 		const tr = document.createElement('tr');
 		const profit_per_area = p.profit_per_day / p.area;
-		const break_even = p.capex / p.profit_per_day;
+		const break_even = p.profit_per_day > 0 ? p.capex / p.profit_per_day : Infinity;
 		tr.innerHTML = `
 			<td>${p.output}</td>
 			<td>${p.expertise}</td>