소스 검색

shipbuilding: summarize buys

raylu 1 주 전
부모
커밋
6b64887099
1개의 변경된 파일14개의 추가작업 그리고 4개의 파일을 삭제
  1. 14 4
      shipbuilding.py

+ 14 - 4
shipbuilding.py

@@ -10,7 +10,9 @@ BUY = frozenset([
 	# definitely buy
 	'C', 'FLX', 'H', 'H2O', 'HAL', 'HCP', 'HE', 'LST', 'MG', 'N', 'NA', 'NCS', 'NS', 'O', 'PE', 'PG', 'S', 'TCL', 'THF',
 	# maybe buy
-	'AU', 'BRM', 'CU', 'FE', 'LI', 'RG', 'ROM', 'SI', 'TI',
+	'AIR', 'AU', 'BE', 'BRM', 'CU', 'FAN', 'FC', 'FE', 'HCC', 'HD', 'LDI', 'LI', 'MFK', 'MWF', 'REA', 'RG', 'RGO', 'ROM', 'SFK', 'SI', 'STL', 'TI', 'TPU',
+	# import
+	'AAR', 'AWF', 'CAP', 'CF',
 	# skip
 	'LFE', 'LHP', 'MFE', 'SFE', 'SSC',
 ])
@@ -36,9 +38,10 @@ def main() -> None:
 	recipes = recipe_for_mats()
 
 	production: dict[str, dict[str, float]] = collections.defaultdict(lambda: collections.defaultdict(float))
+	buy: dict[str, float] = collections.defaultdict(float)
 	cost = 0.0
 	for mat, amount in blueprint.items():
-		cost += analyze_mat(0, mat, amount, production, prices, recipes)
+		cost += analyze_mat(0, mat, amount, production, buy, prices, recipes)
 		print()
 	print(f'total cost: {cost:,}')
 
@@ -59,6 +62,11 @@ def main() -> None:
 					print(f' {amount:g}×\033[31m{mat}\033[0m', end='')
 			print()
 
+	print('buy')
+	for mat, amount in buy.items():
+		price = prices[mat]
+		print(f'{amount:g}×{mat}', price['Demand'])
+
 def recipe_for_mats() -> dict[str, roi.Recipe]:
 	all_recipes: list[roi.Recipe] = cache.get('https://api.prunplanner.org/data/recipes/', expiry=cache.ONE_DAY)
 	mat_recipes = collections.defaultdict(list) # all ways to make a mat
@@ -72,12 +80,13 @@ def recipe_for_mats() -> dict[str, roi.Recipe]:
 			mat_recipe[mat] = recipes[0]
 	return mat_recipe
 
-def analyze_mat(level: int, mat: str, amount: float, production: dict[str, dict[str, float]],
+def analyze_mat(level: int, mat: str, amount: float, production: dict[str, dict[str, float]], buy: dict[str, float],
 		prices: typing.Mapping[str, RawPrice], recipes: dict[str, roi.Recipe]) -> float:
 	price = prices[mat]
 	traded = price['AverageTraded30D'] or 0
 	if mat in BUY:
 		print('\t' * level + f'{amount:g}×{mat} buy: {price["Ask"]}, daily traded {traded:5.1f}')
+		buy[mat] += amount
 		assert price['Ask'] is not None
 		return price['Ask'] * amount
 	else:
@@ -96,7 +105,7 @@ def analyze_mat(level: int, mat: str, amount: float, production: dict[str, dict[
 			total_cost = 0.0
 			for input_mat in recipe['inputs']:
 				input_amount = input_mat['material_amount'] * amount / recipe['outputs'][0]['material_amount']
-				total_cost += analyze_mat(level + 1, input_mat['material_ticker'], input_amount, production, prices, recipes)
+				total_cost += analyze_mat(level + 1, input_mat['material_ticker'], input_amount, production, buy, prices, recipes)
 			print('\t' * level + f'\tcost: {total_cost:,.0f}')
 		return total_cost
 
@@ -106,6 +115,7 @@ class RawPrice(typing.TypedDict):
 	Ask: float | None
 	AverageTraded30D: float | None # averaged daily traded volume over last 30 days
 	Supply: int
+	Demand: int
 
 if __name__ == '__main__':
 	main()