2 커밋 a995682689 ... 8d13db9dab

작성자 SHA1 메시지 날짜
  raylu 8d13db9dab roi: building filter 4 주 전
  raylu a995682689 roi: building filter 4 주 전
1개의 변경된 파일13개의 추가작업 그리고 14개의 파일을 삭제
  1. 13 14
      ts/roi.ts

+ 13 - 14
ts/roi.ts

@@ -8,11 +8,6 @@ async function getROI(cx: string) {
 	return {lastModified, profits};
 }
 
-const buildingsPromise = fetch('https://api.prunplanner.org/data/buildings/')
-		.then((r) => r.json()).then((buildings: Building[]) =>
-			buildings.filter((b) => b.building_type === 'PRODUCTION')
-					.sort((a, b) => a.building_ticker.localeCompare(b.building_ticker)));
-
 const lowVolume = document.querySelector('input#low-volume') as HTMLInputElement;
 
 const cxSelect = document.querySelector('select#cx') as HTMLSelectElement;
@@ -44,15 +39,24 @@ async function render() {
 	const tbody = document.querySelector('tbody')!;
 	tbody.innerHTML = '';
 
+	const cx = cxSelect.value;
+	if (!roiCache[cx])
+		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 await buildingsPromise)
+	for (const building of buildings)
 		if (expertiseSelect.value === '' || expertiseSelect.value === building.expertise) {
 			const option = document.createElement('option');
-			option.value = building.building_ticker;
-			option.textContent = building.building_ticker;
-			if (building.building_ticker === selectedBuilding) {
+			option.value = building.ticker;
+			option.textContent = building.ticker;
+			if (building.ticker === selectedBuilding) {
 				buildingFound = true;
 				option.selected = true;
 			}
@@ -61,11 +65,6 @@ async function render() {
 	if (!buildingFound)
 		selectedBuilding = '';
 
-	const cx = cxSelect.value;
-	if (!roiCache[cx])
-		roiCache[cx] = getROI(cx);
-	const {lastModified, profits} = await roiCache[cx];
-
 	for (const p of profits) {
 		const volumeRatio = p.output_per_day / p.average_traded_7d;
 		if (!lowVolume.checked && volumeRatio > 0.05)