Эх сурвалжийг харах

supply: don't include warehouse inventory in cost

account for warehouse inventory when showing "total cost"
raylu 15 цаг өмнө
parent
commit
361204c475
2 өөрчлөгдсөн 17 нэмэгдсэн , 12 устгасан
  1. 1 11
      buy.py
  2. 16 1
      supply.py

+ 1 - 11
buy.py

@@ -24,17 +24,7 @@ def main() -> None:
 			buy[mat] += amount
 
 	# what we have
-	warehouses: typing.Sequence[market.Warehouse] = cache.get('https://rest.fnar.net/sites/warehouses/' + config.username,
-			headers={'Authorization': config.fio_api_key})
-	for warehouse in warehouses:
-		if warehouse['LocationNaturalId'] == 'HRT':
-			storage: market.Storage = cache.get(f'https://rest.fnar.net/storage/{config.username}/{warehouse["StoreId"]}',
-				headers={'Authorization': config.fio_api_key})
-			assert storage['Type'] == 'WAREHOUSE_STORE'
-			warehouse = {item['MaterialTicker']: item['MaterialAmount'] for item in storage['StorageItems']}
-			break
-	else:
-		raise Exception("couldn't find HRT warehouse")
+	warehouse = supply.warehouse_inventory()
 
 	# what we already are bidding for
 	orders: typing.Sequence[market.ExchangeOrder] = cache.get('https://rest.fnar.net/cxos/' + config.username,

+ 16 - 1
supply.py

@@ -83,6 +83,7 @@ def main() -> None:
 	raw_prices: typing.Mapping[str, market.RawPrice] = {p['MaterialTicker']: p
 			for p in cache.get('https://refined-prun.github.io/refined-prices/all.json') if p['ExchangeCode'] == 'IC1'}
 
+	warehouse = warehouse_inventory()
 	total_cost = 0
 	for planet in planets:
 		print('\n' + cyan(planet.name))
@@ -98,8 +99,11 @@ def main() -> None:
 					print(f' | {need:5.0f} (ignored)')
 				else:
 					cost = raw_prices[ticker]['Ask'] * need
-					total_cost += cost
 					print(f' | {need:5.0f} (${cost:6.0f})')
+					if have := warehouse.get(ticker, 0):
+						cost = raw_prices[ticker]['Ask'] * max(need - have, 0)
+						warehouse[ticker] = max(have - need, 0)
+					total_cost += cost
 			else:
 				print()
 	print(f'\ntotal cost: {total_cost:,}')
@@ -157,6 +161,17 @@ def shipping_used(materials: dict[str, Material], ignore: typing.Collection[str]
 		volume += amount * materials[ticker]['Volume']
 	return weight, volume
 
+def warehouse_inventory() -> dict[str, int]:
+	warehouses: typing.Sequence[market.Warehouse] = cache.get('https://rest.fnar.net/sites/warehouses/' + config.username,
+			headers={'Authorization': config.fio_api_key})
+	for warehouse in warehouses:
+		if warehouse['LocationNaturalId'] == 'HRT':
+			storage: market.Storage = cache.get(f'https://rest.fnar.net/storage/{config.username}/{warehouse["StoreId"]}',
+				headers={'Authorization': config.fio_api_key})
+			assert storage['Type'] == 'WAREHOUSE_STORE'
+			return {item['MaterialTicker']: item['MaterialAmount'] for item in storage['StorageItems']}
+	raise Exception("couldn't find HRT warehouse")
+
 def cyan(text: str) -> str:
 	return '\033[36m' + text + '\033[0m'