2
0

2 Коммитууд c0bb047b80 ... 3bfa524e0c

Эзэн SHA1 Мессеж Огноо
  raylu 3bfa524e0c junk: ignore materials in config 5 өдөр өмнө
  raylu 5cbbbdc24b HYR WCB production 5 өдөр өмнө
6 өөрчлөгдсөн 77 нэмэгдсэн , 4 устгасан
  1. 7 0
      config.py
  2. 7 1
      junk.py
  3. 2 2
      market.py
  4. 6 0
      pyproject.toml
  5. 1 1
      supply.py
  6. 54 0
      www/hyr_wcb.html

+ 7 - 0
config.py

@@ -10,6 +10,7 @@ class Config:
 	fio_rest_key: str
 	fio_api_key: str
 	punoted_api_key: str
+	junk: JunkConfig
 	market: MarketConfig
 	supply: dict[str, SupplyConfig]
 
@@ -18,6 +19,8 @@ class Config:
 			config = tomllib.load(f)
 		for k, v in config.items():
 			match k:
+				case 'junk':
+					v = JunkConfig(**v)
 				case 'market':
 					v = MarketConfig(**v)
 				case 'supply':
@@ -30,6 +33,10 @@ class Config:
 		else:
 			return SupplyConfig()
 
+@dataclasses.dataclass(eq=False, frozen=True, slots=True)
+class JunkConfig:
+	ignore_materials: typing.Sequence[str] = dataclasses.field(default_factory=list)
+
 @dataclasses.dataclass(eq=False, frozen=True, slots=True)
 class MarketConfig:
 	mm_items: typing.Mapping[str, int]

+ 7 - 1
junk.py

@@ -20,14 +20,20 @@ def main() -> None:
 	
 	supplies: list[tuple[float, str]] = []
 	for mat, amount in supply.warehouse_inventory().items():
+		if mat is None:
+			continue
 		if (consumption := total_consumption.get(mat)) is None:
 			supplies.append((float('inf'), mat))
 		else:
 			supplies.append((amount / consumption, mat))
 
 	supplies.sort(reverse=True)
+	ignored = frozenset(config.junk.ignore_materials)
 	for days, mat in supplies:
-		print(f'{mat}: {days:.2f} d')
+		if mat in ignored:
+			print(f'\033[90m{mat:3}: {days:.2f} d\033[0m')
+		else:
+			print(f'{mat:3}: {days:.2f} d')
 
 if __name__ == '__main__':
 	main()

+ 2 - 2
market.py

@@ -156,10 +156,10 @@ class Storage(typing.TypedDict):
 	StorageItems: typing.Sequence[StorageItem]
 	WeightLoad: float
 	VolumeLoad: float
-	Type: typing.Literal['STORE'] | typing.Literal['WAREHOUSE_STORE'] | typing.Literal['FTL_FUEL_STORE'] | typing.Literal['STL_FUEL_STORE'] |  typing.Literal['SHIP_STORE']
+	Type: typing.Literal['STORE', 'WAREHOUSE_STORE', 'FTL_FUEL_STORE', 'STL_FUEL_STORE', 'SHIP_STORE']
 
 class StorageItem(typing.TypedDict):
-	MaterialTicker: str
+	MaterialTicker: str | None # shipment blocks are None
 	MaterialAmount: int
 	Type: typing.Literal['INVENTORY', 'SHIPMENT']
 

+ 6 - 0
pyproject.toml

@@ -11,3 +11,9 @@ dependencies = [
 
 [dependency-groups]
 dev = ['workers-py', 'workers-runtime-sdk']
+
+[tool.ruff.lint]
+ignore = [
+	'I001', # unsorted-imports
+	'TRY002', # raise-vanilla-class
+]

+ 1 - 1
supply.py

@@ -193,7 +193,7 @@ def shipping_used(materials: typing.Mapping[str, Material], ignore: typing.Colle
 		volume += amount * materials[ticker]['Volume']
 	return weight, volume
 
-def warehouse_inventory() -> dict[str, int]:
+def warehouse_inventory() -> dict[str | None, int]:
 	warehouses: typing.Sequence[market.Warehouse] = cache.get('https://rest.fnar.net/sites/warehouses/' + config.username,
 			headers={'Authorization': config.fio_rest_key})
 	for warehouse in warehouses:

+ 54 - 0
www/hyr_wcb.html

@@ -0,0 +1,54 @@
+<!DOCTYPE html>
+<html>
+<head>
+	<meta charset="UTF-8">
+	<title>PrUn HYR WCB</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="hyr_wcb"></div>
+	</main>
+	<div id="popover" popover="hint"></div>
+	<script type="module">
+		import {setupProduction} from './production.js';
+		const blueprint = {
+			'FFC': 1,
+			'FSE': 1,
+			'HYR': 1,
+			'LFE': 1,
+			'MFE': 2,
+			'SFE': 2,
+			'WCB': 1,
+			'LFL': 1,
+			'MSL': 1,
+			'LHP': 71,
+			'SSC': 84,
+			'BR2': 1,
+			'CQM': 1,
+		};
+		const buy = new Set([
+			// definitely buy
+			'CTF', 'NV2',
+			'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', 5, document.querySelector('#hyr_wcb'));
+	</script>
+</body>
+</html>