Pārlūkot izejas kodu

roi: building filter

raylu 3 dienas atpakaļ
vecāks
revīzija
8d13db9dab
3 mainītis faili ar 39 papildinājumiem un 2 dzēšanām
  1. 2 0
      roi.py
  2. 34 2
      ts/roi.ts
  3. 3 0
      www/roi.html

+ 2 - 0
roi.py

@@ -90,6 +90,7 @@ def calc_profit(recipe: Recipe, buildings: typing.Mapping[str, Building], hab_ar
 	) * runs_per_day / area
 	return Profit(outputs, recipe['recipe_name'],
 			expertise=building['expertise'],
+			building=building['building_ticker'],
 			profit_per_day=(profit_per_run * runs_per_day - worker_consumable_daily_cost),
 			area=area,
 			capex=capex,
@@ -176,6 +177,7 @@ class Profit:
 	outputs: typing.Collection[MatPrice]
 	recipe: str
 	expertise: str
+	building: str
 	profit_per_day: float
 	area: float
 	capex: float

+ 34 - 2
ts/roi.ts

@@ -10,6 +10,7 @@ async function getROI(cx: string) {
 
 const lowVolume = document.querySelector('input#low-volume') as HTMLInputElement;
 
+const cxSelect = document.querySelector('select#cx') as HTMLSelectElement;
 const expertise = {
 	AGRICULTURE: 'agri',
 	CHEMISTRY: 'chem',
@@ -28,7 +29,7 @@ for (const key of Object.keys(expertise)) {
 	option.textContent = key.replace('_', ' ').toLowerCase();
 	expertiseSelect.appendChild(option);
 }
-const cxSelect = document.querySelector('select#cx') as HTMLSelectElement;
+const buildingSelect = document.querySelector('select#building') as HTMLSelectElement;
 
 const formatDecimal = new Intl.NumberFormat(undefined,
 		{maximumFractionDigits: 2, maximumSignificantDigits: 6, roundingPriority: 'lessPrecision'}).format;
@@ -43,12 +44,35 @@ async function render() {
 		roiCache[cx] = getROI(cx);
 	const {lastModified, profits} = await roiCache[cx];
 
+	const buildingTickers = new Set(profits.map(p => p.building));
+	const buildings: {ticker: string, expertise: keyof typeof expertise}[] = Array.from(buildingTickers)
+			.map((building) => ({ticker: building, expertise: profits.find(p => p.building === building)!.expertise}))
+			.sort((a, b) => a.ticker.localeCompare(b.ticker));
+	let selectedBuilding = buildingSelect.value;
+	let buildingFound = false;
+	buildingSelect.innerHTML = '<option value="">(all)</option>';
+	for (const building of buildings)
+		if (expertiseSelect.value === '' || expertiseSelect.value === building.expertise) {
+			const option = document.createElement('option');
+			option.value = building.ticker;
+			option.textContent = building.ticker;
+			if (building.ticker === selectedBuilding) {
+				buildingFound = true;
+				option.selected = true;
+			}
+			buildingSelect.appendChild(option);
+		}
+	if (!buildingFound)
+		selectedBuilding = '';
+
 	for (const p of profits) {
 		const volumeRatio = p.output_per_day / p.average_traded_7d;
 		if (!lowVolume.checked && volumeRatio > 0.05)
 			continue;
 		if (expertiseSelect.value !== '' && p.expertise !== expertiseSelect.value)
 			continue;
+		if (selectedBuilding !== '' && p.building !== selectedBuilding)
+			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;
@@ -98,14 +122,16 @@ function formatMatPrices(matPrices: MatPrice[]): string {
 
 setupPopover();
 lowVolume.addEventListener('change', render);
-expertiseSelect.addEventListener('change', render);
 cxSelect.addEventListener('change', render);
+expertiseSelect.addEventListener('change', render);
+buildingSelect.addEventListener('change', render);
 render();
 
 interface Profit {
 	outputs: MatPrice[]
 	recipe: string
 	expertise: keyof typeof expertise
+	building: string
 	profit_per_day: number
 	area: number
 	capex: number
@@ -123,3 +149,9 @@ interface MatPrice {
 	amount: number
 	vwap_7d: number
 }
+
+interface Building {
+	building_type: 'INFRASTRUCTURE' | 'PLANETARY' | 'PRODUCTION';
+	building_ticker: string;
+	expertise: keyof typeof expertise;
+}

+ 3 - 0
www/roi.html

@@ -22,6 +22,9 @@
 			<label>expertise <select id="expertise">
 				<option value="">(all)</option>
 			</select></label>
+			<label>building <select id="building">
+				<option value="">(all)</option>
+			</select></label>
 		</form>
 		<table>
 			<thead>