2 Commits effe8d75a6 ... 5ab5891458

Author SHA1 Message Date
  raylu 5ab5891458 gateways 2 weeks ago
  raylu 86cd2a2f5e buy: honor ignore_materials too 2 weeks ago
7 changed files with 113 additions and 40 deletions
  1. 1 1
      .gitignore
  2. 3 1
      buy.py
  3. 1 1
      package.json
  4. 16 34
      ts/production.ts
  5. 60 0
      www/gateways.html
  6. 31 2
      www/shipbuilding.html
  7. 1 1
      www/style.css

+ 1 - 1
.gitignore

@@ -6,6 +6,6 @@ uv.lock
 www/buy.js*
 www/ledger.js*
 www/mat.js*
+www/production.js*
 www/roi.js*
 www/roi_*.json
-www/shipbuilding.js*

+ 3 - 1
buy.py

@@ -82,8 +82,10 @@ def get_total_buy(days: int) -> typing.Mapping[str, int]:
 			headers={'Authorization': config.fio_api_key})]
 	buy: dict[str, int] = collections.defaultdict(int)
 	for planet in planets:
+		supply_config = config.supply_config(planet.name)
 		for mat, amount in planet.supply_for_days(days).items():
-			buy[mat] += amount
+			if mat not in supply_config.ignore_materials:
+				buy[mat] += amount
 	return buy
 
 def get_planet_exports_and_ship_storage() -> typing.Mapping[str, int]:

+ 1 - 1
package.json

@@ -2,7 +2,7 @@
 	"name": "prun-calc",
 	"version": "0",
 	"scripts": {
-		"build": "bun build ts/buy.ts ts/ledger.ts ts/mat.ts ts/roi.ts ts/shipbuilding.ts --outdir www --target browser --sourcemap=external",
+		"build": "bun build ts/buy.ts ts/ledger.ts ts/mat.ts ts/production.ts ts/roi.ts --outdir www --target browser --sourcemap=external",
 		"typecheck": "tsgo --noEmit",
 		"serve": "python3 -m http.server -d www 8000"
 	},

+ 16 - 34
ts/shipbuilding.ts → ts/production.ts

@@ -1,43 +1,27 @@
 import {cachedFetchJSON} from './cache';
 import {setupPopover} from './popover';
 
-const BUY = new Set([
-	// definitely buy
-	'C', 'FLX', 'H', 'H2O', 'HAL', 'HCP', 'HE', 'LST', 'MG', 'N', 'NA', 'NCS', 'NS', 'O', 'PE', 'PG', 'S', 'TCL', 'THF',
-	// maybe buy
-	'AIR', 'AU', 'BE', 'BRM', 'BOR', 'BTS', 'CU', 'FAN', 'FC', 'FE', 'HCC', 'HD', 'LDI', 'LI', 'MFK', 'MWF',
-	'REA', 'RG', 'RGO', 'ROM', 'SFK', 'SI', 'STL', 'TCO', 'TPU',
-	// import
-	'AAR', 'AWF', 'CAP', 'CF', 'RAD',
-	// skip
-	'LFE', 'LHP', 'MFE', 'SFE', 'SSC',
-])
-
-const blueprint = {
-	'FFC': 1,
-	'FSE': 1,
-	'LFE': 2,
-	'MFE': 2,
-	'RCT': 1,
-	'SFE': 1,
-	'LCB': 1,
-	'MFL': 1,
-	'MSL': 1,
-	'LHP': 94,
-	'SSC': 128,
-	'BR1': 1,
-	'CQM': 1,
-}
-
+let blueprint: Record<string, number>;
+let BUY: Set<string>;
+let renderTarget: Element;
+let cx: string;
 const apiKey = document.querySelector('#api-key') as HTMLInputElement;
-{
+
+export function setupProduction(bp: Record<string, number>, buy: Set<string>, cxCode: string, target: Element) {
+	blueprint = bp;
+	BUY = buy;
+	cx = cxCode;
+	renderTarget = target;
+
 	const storedApiKey = localStorage.getItem('punoted-api-key');
 	if (storedApiKey)
 		apiKey.value = storedApiKey;
+	document.querySelector('#fetch')!.addEventListener('click', render);
+
+	setupPopover();
+	render();
 }
-document.querySelector('#fetch')!.addEventListener('click', render);
 
-const renderTarget = document.querySelector('div#shipbuilding')!;
 async function render() {
 	const loader = document.querySelector('#loader') as HTMLElement;
 	loader.style.display = 'block';
@@ -50,8 +34,6 @@ async function render() {
 	}
 	loader.style.display = 'none';
 }
-setupPopover();
-render();
 
 async function _render() {
 	const [allPrices, recipes, buildingList, storage] = await Promise.all([
@@ -60,7 +42,7 @@ async function _render() {
 		cachedFetchJSON('https://api.prunplanner.org/data/buildings/') as Promise<Building[]>,
 		fetchStorage(),
 	]);
-	const prices = Object.fromEntries(allPrices.filter((price) => price.ExchangeCode === 'IC1')
+	const prices = Object.fromEntries(allPrices.filter((price) => price.ExchangeCode === cx)
 			.map((price) => [price.MaterialTicker, price]));
 	const buildings = Object.fromEntries(buildingList.map((b) => [b.building_ticker, b]));
 

+ 60 - 0
www/gateways.html

@@ -0,0 +1,60 @@
+<!DOCTYPE html>
+<html>
+<head>
+	<meta charset="UTF-8">
+	<title>PrUn gateways</title>
+	<link rel="stylesheet" type="text/css" href="style.css">
+	<link rel="icon" href="https://www.raylu.net/hammer-man.svg" />
+	<meta name="viewport" content="width=device-width, initial-scale=1">
+	<meta name="theme-color" content="#222">
+</head>
+<body>
+	<a href="/">← back</a>
+	<main class="production">
+		<form>
+			<label>PUNoted API key: <input type="password" size="30" id="api-key"></label>
+			<input type="button" value="fetch" id="fetch">
+		</form>
+		<section id="loader"></section>
+		<div id="gateways"></div>
+	</main>
+	<div id="popover" popover="hint"></div>
+	<script type="module">
+		import {setupProduction} from './production.js';
+		const blueprint = {
+			'SEA': 5000,
+			'LIT': 440,
+			'PSH': 2200,
+			'RSH': 600,
+			'TSH': 600,
+			'TRU': 4000,
+			'ABH': 400,
+			'ADE': 260,
+			'ASE': 360,
+			'ATA': 260,
+			'HSE': 160,
+			'LBH': 400,
+			'LDE': 160,
+			'LSE': 400,
+			'LTA': 80,
+			'RBH': 560,
+			'RDE': 200,
+			'RSE': 560,
+			'RTA': 200,
+			'ADS': 5,
+			'COM': 5,
+			'CBL': 240,
+			'SP': 8000,
+			'GWS': 10,
+			'SST': 1,
+			'SPT': 2600,
+			'TRS': 140,
+			'IMM': 5,
+		}
+		const buy = new Set([
+			'ADS', 'AMM', 'BBH', 'BSE', 'COM', 'GAL', 'HE', 'IMM', 'NE', 'O', 'SEA',
+		])
+		setupProduction(blueprint, buy, 'CI1', document.querySelector('#gateways'));
+	</script>
+</body>
+</html>

+ 31 - 2
www/shipbuilding.html

@@ -10,7 +10,7 @@
 </head>
 <body>
 	<a href="/">← back</a>
-	<main class="shipbuilding">
+	<main class="production">
 		<form>
 			<label>PUNoted API key: <input type="password" size="30" id="api-key"></label>
 			<input type="button" value="fetch" id="fetch">
@@ -19,6 +19,35 @@
 		<div id="shipbuilding"></div>
 	</main>
 	<div id="popover" popover="hint"></div>
-	<script src="shipbuilding.js"></script>
+	<script type="module">
+		import {setupProduction} from './production.js';
+		const blueprint = {
+			'FFC': 1,
+			'FSE': 1,
+			'LFE': 2,
+			'MFE': 2,
+			'RCT': 1,
+			'SFE': 1,
+			'LCB': 1,
+			'MFL': 1,
+			'MSL': 1,
+			'LHP': 94,
+			'SSC': 128,
+			'BR1': 1,
+			'CQM': 1,
+		};
+		const buy = new Set([
+			// definitely buy
+			'C', 'FLX', 'H', 'H2O', 'HAL', 'HCP', 'HE', 'LST', 'MG', 'N', 'NA', 'NCS', 'NS', 'O', 'PE', 'PG', 'S', 'TCL', 'THF',
+			// maybe buy
+			'AIR', 'AU', 'BE', 'BRM', 'BOR', 'BTS', 'CU', 'FAN', 'FC', 'FE', 'HCC', 'HD', 'LDI', 'LI', 'MFK', 'MWF',
+			'REA', 'RG', 'RGO', 'ROM', 'SFK', 'SI', 'STL', 'TCO', 'TPU',
+			// import
+			'AAR', 'AWF', 'CAP', 'CF', 'RAD',
+			// skip
+			'LFE', 'LHP', 'MFE', 'SFE', 'SSC',
+		])
+		setupProduction(blueprint, buy, 'IC1', document.querySelector('#shipbuilding'));
+	</script>
 </body>
 </html>

+ 1 - 1
www/style.css

@@ -157,7 +157,7 @@ main.ledger {
 	}
 }
 
-main.shipbuilding {
+main.production {
 	summary {
 		cursor: pointer;
 	}