roi.ts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. import {setupPopover} from './popover';
  2. const roiCache: Record<string, Promise<{lastModified: Date, profits: Profit[]}>> = {};
  3. async function getROI(cx: string) {
  4. const response = await fetch(`/roi_${cx.toLowerCase()}.json`);
  5. const lastModified = new Date(response.headers.get('last-modified')!);
  6. const profits = await response.json();
  7. return {lastModified, profits};
  8. }
  9. type MetricType = 'vwap' | 'bid' | 'ask';
  10. const lowVolume = document.querySelector('input#low-volume') as HTMLInputElement;
  11. const cxSelect = document.querySelector('select#cx') as HTMLSelectElement;
  12. const expertise = {
  13. AGRICULTURE: 'agri',
  14. CHEMISTRY: 'chem',
  15. CONSTRUCTION: 'const',
  16. ELECTRONICS: 'elec',
  17. FOOD_INDUSTRIES: 'food ind',
  18. FUEL_REFINING: 'fuel',
  19. MANUFACTURING: 'mfg',
  20. METALLURGY: 'metal',
  21. RESOURCE_EXTRACTION: 'res ext',
  22. } as const;
  23. const expertiseSelect = document.querySelector('select#expertise') as HTMLSelectElement;
  24. for (const key of Object.keys(expertise)) {
  25. const option = document.createElement('option');
  26. option.value = key;
  27. option.textContent = key.replace('_', ' ').toLowerCase();
  28. expertiseSelect.appendChild(option);
  29. }
  30. const buildingSelect = document.querySelector('select#building') as HTMLSelectElement;
  31. const formatSigFig = new Intl.NumberFormat(undefined, {
  32. notation: 'compact',
  33. maximumSignificantDigits: 3,
  34. }).format;
  35. if (localStorage.getItem('roi-cx')) cxSelect.value = localStorage.getItem('roi-cx')!;
  36. if (localStorage.getItem('roi-expertise')) expertiseSelect.value = localStorage.getItem('roi-expertise')!;
  37. if (localStorage.getItem('roi-low-volume')) lowVolume.checked = localStorage.getItem('roi-low-volume') === 'true';
  38. let savedBuilding = localStorage.getItem('roi-building') || '';
  39. let storedSortKey = localStorage.getItem('roi-sort-key') as any;
  40. if (storedSortKey === 'logistics_per_base') storedSortKey = 'normalized_logistics_per_base';
  41. let currentSortKey: keyof ProfitWithMetrics | 'outputs' = storedSortKey || 'break_even';
  42. let currentSortAsc: boolean = localStorage.getItem('roi-sort-asc') !== 'false';
  43. let headersInitialized = false;
  44. let metricControlsInitialized = false;
  45. let capexMetric: MetricType = (localStorage.getItem('roi-capex-metric') as MetricType) || 'vwap';
  46. let opexMetric: MetricType = (localStorage.getItem('roi-opex-metric') as MetricType) || 'vwap';
  47. let revenueMetric: MetricType = (localStorage.getItem('roi-revenue-metric') as MetricType) || 'vwap';
  48. // EXTREME DETAIL: Changed state variables from numerical ints to strings to natively support
  49. // the 'omit' and 'dynamic' categorical values alongside the raw number options.
  50. let roundTripOption: string = localStorage.getItem('roi-round-trip') || '0';
  51. let showNegativeProfit: boolean = localStorage.getItem('roi-show-negative') !== 'false';
  52. let workingCapitalOption: string = localStorage.getItem('roi-working-capital-opt') || 'dynamic';
  53. let targetPermitOption: string = localStorage.getItem('roi-target-permit') || '2';
  54. async function render() {
  55. const tbody = document.querySelector('tbody')!;
  56. tbody.innerHTML = '';
  57. const cx = cxSelect.value;
  58. if (!roiCache[cx])
  59. roiCache[cx] = getROI(cx);
  60. const {lastModified, profits} = await roiCache[cx];
  61. if (!metricControlsInitialized) {
  62. const controls = document.createElement('div');
  63. controls.style.marginBottom = '15px';
  64. // EXTREME DETAIL: Converted Round Trip and Permit Number to distinct <select> dropdowns.
  65. // Injected `<option value="omit">Omit From Calculation</option>` at the top of all three.
  66. controls.innerHTML = `
  67. <label style="margin-right: 15px;">CapEx Price:
  68. <select id="capex-metric"><option value="vwap">VWAP</option><option value="bid">Bid</option><option value="ask">Ask</option></select>
  69. </label>
  70. <label style="margin-right: 15px;">OpEx Price:
  71. <select id="opex-metric"><option value="vwap">VWAP</option><option value="bid">Bid</option><option value="ask">Ask</option></select>
  72. </label>
  73. <label style="margin-right: 15px;">Revenue Price:
  74. <select id="revenue-metric"><option value="vwap">VWAP</option><option value="bid">Bid</option><option value="ask">Ask</option></select>
  75. </label>
  76. <label style="margin-right: 15px;">
  77. <input type="checkbox" id="show-negative"> Show Negative Profit
  78. </label>
  79. <label style="margin-right: 15px;">
  80. Round Trip (hrs):
  81. <select id="round-trip">
  82. <option value="omit">Omit From Calculation</option>
  83. <option value="0">0</option>
  84. <option value="2">2</option>
  85. <option value="4">4</option>
  86. <option value="8">8</option>
  87. <option value="12">12</option>
  88. <option value="24">24</option>
  89. <option value="48">48</option>
  90. <option value="72">72</option>
  91. <option value="168">168</option>
  92. </select>
  93. </label>
  94. <label style="margin-right: 15px;">
  95. Days OpEx:
  96. <select id="working-capital">
  97. <option value="omit">Omit From Calculation</option>
  98. <option value="dynamic">Max for Shipment (dynamic)</option>
  99. <option value="0">0</option>
  100. <option value="1">1</option>
  101. <option value="2">2</option>
  102. <option value="3">3</option>
  103. <option value="4">4</option>
  104. <option value="5">5</option>
  105. <option value="6">6</option>
  106. <option value="7">7</option>
  107. <option value="14">14</option>
  108. <option value="30">30</option>
  109. </select>
  110. </label>
  111. <label>
  112. Permit Number:
  113. <select id="target-permit">
  114. <option value="omit">Omit From Calculation</option>
  115. <option value="1">1</option>
  116. <option value="2">2</option>
  117. <option value="3">3</option>
  118. <option value="4">4</option>
  119. <option value="5">5</option>
  120. <option value="6">6</option>
  121. <option value="7">7</option>
  122. <option value="8">8</option>
  123. <option value="9">9</option>
  124. <option value="10">10</option>
  125. </select>
  126. </label>
  127. `;
  128. const table = document.querySelector('table');
  129. if (table) table.parentNode?.insertBefore(controls, table);
  130. (document.getElementById('capex-metric') as HTMLSelectElement).value = capexMetric;
  131. (document.getElementById('opex-metric') as HTMLSelectElement).value = opexMetric;
  132. (document.getElementById('revenue-metric') as HTMLSelectElement).value = revenueMetric;
  133. (document.getElementById('show-negative') as HTMLInputElement).checked = showNegativeProfit;
  134. (document.getElementById('round-trip') as HTMLSelectElement).value = roundTripOption;
  135. (document.getElementById('working-capital') as HTMLSelectElement).value = workingCapitalOption;
  136. (document.getElementById('target-permit') as HTMLSelectElement).value = targetPermitOption;
  137. document.getElementById('capex-metric')!.addEventListener('change', (e) => {
  138. capexMetric = (e.target as HTMLSelectElement).value as MetricType;
  139. render();
  140. });
  141. document.getElementById('opex-metric')!.addEventListener('change', (e) => {
  142. opexMetric = (e.target as HTMLSelectElement).value as MetricType;
  143. render();
  144. });
  145. document.getElementById('revenue-metric')!.addEventListener('change', (e) => {
  146. revenueMetric = (e.target as HTMLSelectElement).value as MetricType;
  147. render();
  148. });
  149. document.getElementById('show-negative')!.addEventListener('change', (e) => {
  150. showNegativeProfit = (e.target as HTMLInputElement).checked;
  151. render();
  152. });
  153. document.getElementById('round-trip')!.addEventListener('change', (e) => {
  154. roundTripOption = (e.target as HTMLSelectElement).value;
  155. render();
  156. });
  157. document.getElementById('working-capital')!.addEventListener('change', (e) => {
  158. workingCapitalOption = (e.target as HTMLSelectElement).value;
  159. render();
  160. });
  161. document.getElementById('target-permit')!.addEventListener('change', (e) => {
  162. targetPermitOption = (e.target as HTMLSelectElement).value;
  163. render();
  164. });
  165. metricControlsInitialized = true;
  166. }
  167. if (!headersInitialized) {
  168. const ths = document.querySelectorAll('th');
  169. const keys: (keyof ProfitWithMetrics | 'outputs')[] = [
  170. 'outputs', 'expertise', 'profit_per_base', 'break_even',
  171. 'capex_val', 'opex_val', 'normalized_logistics_per_base', 'market_capacity_base'
  172. ];
  173. ths.forEach((th, i) => {
  174. if (keys[i]) {
  175. th.style.cursor = 'pointer';
  176. th.title = '';
  177. if (keys[i] === 'profit_per_base') {
  178. th.textContent = 'Profit/Base';
  179. th.dataset.tooltip = 'Click to sort.\n\nDaily profit scaled to a full 500-area planetary base.\n(Percentiles rank 100.0% as the most desirable outcome, i.e., highest profit or lowest cost.)';
  180. } else if (keys[i] === 'capex_val') {
  181. th.textContent = 'CapEx/Base';
  182. th.dataset.tooltip = 'Click to sort.\n\nTotal capital expenditure scaled to a full 500-area planetary base.\nIncludes base construction, and optional Working Capital, HQ Upgrades, and Ship CapEx (use "Omit From Calculation" to exclude).';
  183. } else if (keys[i] === 'opex_val') {
  184. th.textContent = 'OpEx/Base';
  185. th.dataset.tooltip = 'Click to sort.\n\nDaily operational expenditure (input materials + worker consumables) scaled to a full 500-area planetary base.';
  186. } else if (keys[i] === 'normalized_logistics_per_base') {
  187. th.textContent = 'Logistics/Base';
  188. th.dataset.tooltip = 'Click to sort.\n\nDaily logistics bottleneck scaled to a full 500-area planetary base. The suffix indicates whether Weight (t) or Volume (m³) of Inputs (I) or Outputs (O) is the limiting bottleneck.\nSorts and percentiles are strictly normalized based on ship capacity limits (3000t or 1000m³).';
  189. } else if (keys[i] === 'market_capacity_base') {
  190. th.textContent = 'Market Cap (Bases)';
  191. th.dataset.tooltip = 'Click to sort.\n\nMarket Capacity: 7-day average traded volume ÷ daily output per base. Indicates how many full 500-area bases you can build before saturating the market.';
  192. } else if (keys[i] === 'break_even') {
  193. th.dataset.tooltip = 'Click to sort.\n\nBreak Even: CapEx ÷ daily profit. Note that CapEx dynamically includes optional logistics and HQ upgrades to accurately reflect operational readiness.';
  194. } else {
  195. th.dataset.tooltip = 'Click to sort.';
  196. }
  197. th.addEventListener('click', () => {
  198. if (currentSortKey === keys[i]) {
  199. currentSortAsc = !currentSortAsc;
  200. } else {
  201. currentSortKey = keys[i];
  202. currentSortAsc = keys[i] === 'break_even' ? true : false;
  203. }
  204. render();
  205. });
  206. }
  207. });
  208. headersInitialized = true;
  209. }
  210. const buildingTickers = new Set(profits.map(p => p.building));
  211. const buildings: {ticker: string, expertise: keyof typeof expertise}[] = Array.from(buildingTickers)
  212. .map((building) => ({ticker: building, expertise: profits.find(p => p.building === building)!.expertise}))
  213. .sort((a, b) => a.ticker.localeCompare(b.ticker));
  214. let selectedBuilding = buildingSelect.value || savedBuilding;
  215. let buildingFound = false;
  216. buildingSelect.innerHTML = '<option value="">(all)</option>';
  217. for (const building of buildings)
  218. if (expertiseSelect.value === '' || expertiseSelect.value === building.expertise) {
  219. const option = document.createElement('option');
  220. option.value = building.ticker;
  221. option.textContent = building.ticker;
  222. if (building.ticker === selectedBuilding) {
  223. buildingFound = true;
  224. option.selected = true;
  225. }
  226. buildingSelect.appendChild(option);
  227. }
  228. if (!buildingFound)
  229. selectedBuilding = '';
  230. savedBuilding = '';
  231. const filteredProfits = profits.filter(p => {
  232. const volumeRatio = p.output_per_day / p.average_traded_7d;
  233. if (!lowVolume.checked && volumeRatio > 0.05) return false;
  234. if (expertiseSelect.value !== '' && p.expertise !== expertiseSelect.value) return false;
  235. if (selectedBuilding !== '' && p.building !== selectedBuilding) return false;
  236. return true;
  237. });
  238. let profitsWithMetrics: ProfitWithMetrics[] = filteredProfits.map(p => {
  239. const bases = p.area / 500;
  240. const opex_val = p.opex[opexMetric] / bases;
  241. const revenue_val = p.revenue[revenueMetric] / bases;
  242. let capex_val = p.capex[capexMetric] / bases;
  243. // EXTREME DETAIL: Conditionally evaluate OpEx constraints based on the new dropdown selection.
  244. // If 'omit' is selected, activeWorkingCapitalDays remains 0, suppressing the cost completely.
  245. let activeWorkingCapitalDays = 0;
  246. if (workingCapitalOption !== 'omit') {
  247. if (workingCapitalOption === 'dynamic') {
  248. activeWorkingCapitalDays = p.normalized_logistics_per_base > 0
  249. ? 1 / p.normalized_logistics_per_base
  250. : 0;
  251. } else {
  252. activeWorkingCapitalDays = parseInt(workingCapitalOption, 10);
  253. }
  254. capex_val += (opex_val * activeWorkingCapitalDays);
  255. }
  256. // EXTREME DETAIL: Target permits safely bypassed if 'omit' is active.
  257. let hq_capex = 0;
  258. if (targetPermitOption !== 'omit') {
  259. const targetPermit = parseInt(targetPermitOption, 10);
  260. if (targetPermit >= 3) {
  261. const hqLevelStr = (targetPermit - 1).toString();
  262. if (p.hq_costs && p.hq_costs[hqLevelStr]) {
  263. hq_capex = p.hq_costs[hqLevelStr][capexMetric];
  264. capex_val += hq_capex;
  265. }
  266. }
  267. }
  268. // EXTREME DETAIL: Little's Law ship mathematics safely bypassed if 'omit' is active.
  269. let shipsNeeded = 0;
  270. let activeShipCapex = 0;
  271. if (roundTripOption !== 'omit') {
  272. const roundTripHours = parseInt(roundTripOption, 10);
  273. shipsNeeded = p.normalized_logistics_per_base * (roundTripHours / 24);
  274. activeShipCapex = shipsNeeded * 800_000;
  275. capex_val += activeShipCapex;
  276. }
  277. const profit_per_base = revenue_val - opex_val;
  278. const break_even = profit_per_base > 0 ? capex_val / profit_per_base : Infinity;
  279. return {
  280. ...p,
  281. capex_val,
  282. opex_val,
  283. revenue_val,
  284. profit_per_base,
  285. break_even,
  286. hq_capex,
  287. activeWorkingCapitalDays,
  288. activeShipCapex,
  289. shipsNeeded
  290. };
  291. });
  292. if (!showNegativeProfit) {
  293. profitsWithMetrics = profitsWithMetrics.filter(p => p.profit_per_base > 0);
  294. }
  295. const numSort = (a: number, b: number) => (a < b ? -1 : a > b ? 1 : 0);
  296. const arrProfit = profitsWithMetrics.map(p => p.profit_per_base).sort(numSort);
  297. const arrBreak = profitsWithMetrics.map(p => p.break_even).sort(numSort);
  298. const arrCapex = profitsWithMetrics.map(p => p.capex_val).sort(numSort);
  299. const arrOpex = profitsWithMetrics.map(p => p.opex_val).sort(numSort);
  300. const arrLog = profitsWithMetrics.map(p => p.normalized_logistics_per_base).sort(numSort);
  301. const arrCap = profitsWithMetrics.map(p => p.market_capacity_base).sort(numSort);
  302. profitsWithMetrics.sort((a, b) => {
  303. let valA: any = a[currentSortKey as keyof ProfitWithMetrics];
  304. let valB: any = b[currentSortKey as keyof ProfitWithMetrics];
  305. if (currentSortKey === 'outputs') {
  306. valA = a.outputs.map(o => o.ticker).join(', ');
  307. valB = b.outputs.map(o => o.ticker).join(', ');
  308. }
  309. if (valA < valB) return currentSortAsc ? -1 : 1;
  310. if (valA > valB) return currentSortAsc ? 1 : -1;
  311. return 0;
  312. });
  313. for (const p of profitsWithMetrics) {
  314. const tr = document.createElement('tr');
  315. const pctProfit = getPercentile(p.profit_per_base, arrProfit, false);
  316. const pctBreak = getPercentile(p.break_even, arrBreak, true);
  317. const pctCapex = getPercentile(p.capex_val, arrCapex, true);
  318. const pctOpex = getPercentile(p.opex_val, arrOpex, true);
  319. const pctLog = getPercentile(p.normalized_logistics_per_base, arrLog, true);
  320. const pctCap = getPercentile(p.market_capacity_base, arrCap, false);
  321. tr.innerHTML = `
  322. <td>${p.outputs.map(o => o.ticker).join(', ')}</td>
  323. <td>${expertise[p.expertise]}</td>
  324. <td style="color: ${color(p.profit_per_base, 0, 150000)}">${formatSigFig(p.profit_per_base)} <span style="font-size: 0.85em; opacity: 0.6;">(${pctProfit})</span></td>
  325. <td><span style="color: ${color(p.break_even, 30, 3)}">${formatSigFig(p.break_even)}</span>d <span style="font-size: 0.85em; opacity: 0.6;">(${pctBreak})</span></td>
  326. <td style="color: ${color(p.capex_val, 3_000_000, 400_000)}">${formatSigFig(p.capex_val)} <span style="font-size: 0.85em; opacity: 0.6;">(${pctCapex})</span></td>
  327. <td style="color: ${color(p.opex_val, 400_000, 10_000)}">${formatSigFig(p.opex_val)} <span style="font-size: 0.85em; opacity: 0.6;">(${pctOpex})</span></td>
  328. <td style="color: ${color(p.normalized_logistics_per_base, 1.0, 0.1)}">${formatSigFig(p.logistics_per_base)} ${p.logistics_bottleneck} <span style="font-size: 0.85em; opacity: 0.6;">(${pctLog})</span></td>
  329. <td style="color: ${color(p.market_capacity_base, 0.04, 1)}">${formatSigFig(p.market_capacity_base)} <span style="font-size: 0.85em; opacity: 0.6;">(${pctCap})</span></td>
  330. `;
  331. const output = tr.querySelector('td')!;
  332. output.dataset.tooltip = p.recipe;
  333. const profitCell = tr.querySelectorAll('td')[2];
  334. const runs_per_base = p.runs_per_day / (p.area / 500);
  335. profitCell.dataset.tooltip = formatMatPrices(p.outputs, revenueMetric, runs_per_base) + '\n\n' +
  336. formatMatPrices(p.input_costs, opexMetric, runs_per_base) + '\n' +
  337. '+ worker consumables\n\n' +
  338. `(${formatSigFig(p.revenue_val)} - ${formatSigFig(p.opex_val)}) = ${formatSigFig(p.profit_per_base)}`;
  339. // EXTREME DETAIL: Conditionally rendered the CapEx Tooltip breakdown.
  340. // If the user selected 'Omit From Calculation' for any parameter, that specific line
  341. // completely vanishes from the hover tooltip, confirming to the user that it was removed.
  342. const capexCell = tr.querySelectorAll('td')[4];
  343. capexCell.dataset.tooltip = `Base Construction: ${formatSigFig(p.capex[capexMetric] / (p.area / 500))}`;
  344. if (workingCapitalOption !== 'omit') {
  345. capexCell.dataset.tooltip += `\nWorking Capital (${formatSigFig(p.activeWorkingCapitalDays)} days): ${formatSigFig(p.opex_val * p.activeWorkingCapitalDays)}`;
  346. }
  347. if (targetPermitOption !== 'omit' && p.hq_capex > 0) {
  348. capexCell.dataset.tooltip += `\nHQ Upgrade (Permit ${targetPermitOption}): ${formatSigFig(p.hq_capex)}`;
  349. }
  350. if (roundTripOption !== 'omit') {
  351. capexCell.dataset.tooltip += `\nShip CapEx: ${formatSigFig(p.activeShipCapex)} (${formatSigFig(p.shipsNeeded)} ships)`;
  352. }
  353. const marketCell = tr.querySelectorAll('td')[7];
  354. marketCell.dataset.tooltip = `Market Capacity: ${formatSigFig(p.average_traded_7d)} traded/day ÷ ${formatSigFig(p.output_per_day / (p.area / 500))} produced/day/base = ${formatSigFig(p.market_capacity_base)} equivalent bases`;
  355. tbody.appendChild(tr);
  356. }
  357. document.getElementById('last-updated')!.textContent =
  358. `last updated: ${lastModified.toLocaleString(undefined, {dateStyle: 'full', timeStyle: 'long', hour12: false})}`;
  359. saveState();
  360. }
  361. function getPercentile(val: number, sortedArr: number[], invert: boolean = false): string {
  362. if (sortedArr.length < 2) return "100.0%";
  363. let less = 0;
  364. for (let i = 0; i < sortedArr.length; i++) {
  365. if (sortedArr[i] < val) less++;
  366. else break;
  367. }
  368. let decimal = less / (sortedArr.length - 1);
  369. if (invert) {
  370. decimal = 1.0 - decimal;
  371. }
  372. return (decimal * 100).toFixed(1) + "%";
  373. }
  374. function saveState() {
  375. localStorage.setItem('roi-cx', cxSelect.value);
  376. localStorage.setItem('roi-expertise', expertiseSelect.value);
  377. localStorage.setItem('roi-building', buildingSelect.value);
  378. localStorage.setItem('roi-low-volume', lowVolume.checked.toString());
  379. localStorage.setItem('roi-sort-key', currentSortKey);
  380. localStorage.setItem('roi-sort-asc', currentSortAsc.toString());
  381. localStorage.setItem('roi-capex-metric', capexMetric);
  382. localStorage.setItem('roi-opex-metric', opexMetric);
  383. localStorage.setItem('roi-revenue-metric', revenueMetric);
  384. localStorage.setItem('roi-show-negative', showNegativeProfit.toString());
  385. localStorage.setItem('roi-round-trip', roundTripOption);
  386. localStorage.setItem('roi-working-capital-opt', workingCapitalOption);
  387. localStorage.setItem('roi-target-permit', targetPermitOption);
  388. }
  389. function color(n: number, low: number, high: number): string {
  390. const scale = Math.min(Math.max((n - low) / (high - low), 0), 1);
  391. return `color-mix(in xyz, #0aa ${scale * 100}%, #f80)`;
  392. }
  393. function formatMatPrices(matPrices: MatPrice[], metric: MetricType, runs_per_day: number): string {
  394. return matPrices.map(({ticker, amount, vwap_7d, bid, ask}) => {
  395. const val = metric === 'vwap' ? vwap_7d : metric === 'bid' ? (bid ?? vwap_7d) : (ask ?? vwap_7d);
  396. const daily_amount = amount * runs_per_day;
  397. return `${ticker}: ${formatSigFig(daily_amount)} × ${formatSigFig(val)} = ${formatSigFig(daily_amount * val)}`;
  398. }).join('\n');
  399. }
  400. setupPopover();
  401. lowVolume.addEventListener('change', render);
  402. cxSelect.addEventListener('change', render);
  403. expertiseSelect.addEventListener('change', render);
  404. buildingSelect.addEventListener('change', render);
  405. render();
  406. interface Metrics {
  407. vwap: number;
  408. bid: number;
  409. ask: number;
  410. }
  411. interface Profit {
  412. outputs: MatPrice[]
  413. recipe: string
  414. expertise: keyof typeof expertise
  415. building: string
  416. area: number
  417. capex: Metrics
  418. opex: Metrics
  419. revenue: Metrics
  420. input_costs: MatPrice[]
  421. runs_per_day: number
  422. logistics_per_base: number
  423. normalized_logistics_per_base: number
  424. logistics_bottleneck: string
  425. output_per_day: number
  426. average_traded_7d: number
  427. market_capacity_base: number
  428. hq_costs: Record<string, Metrics>
  429. }
  430. interface ProfitWithMetrics extends Profit {
  431. capex_val: number;
  432. opex_val: number;
  433. revenue_val: number;
  434. profit_per_day: number;
  435. profit_per_base: number;
  436. break_even: number;
  437. hq_capex: number;
  438. activeWorkingCapitalDays: number;
  439. activeShipCapex: number;
  440. shipsNeeded: number;
  441. }
  442. interface MatPrice {
  443. ticker: string
  444. amount: number
  445. vwap_7d: number
  446. bid: number | null
  447. ask: number | null
  448. }
  449. interface Building {
  450. building_type: 'INFRASTRUCTURE' | 'PLANETARY' | 'PRODUCTION';
  451. building_ticker: string;
  452. expertise: keyof typeof expertise;
  453. }