raylu 1 тиждень тому
батько
коміт
05a4ac084a
2 змінених файлів з 33 додано та 28 видалено
  1. 0 28
      export_logistics.py
  2. 33 0
      junk.py

+ 0 - 28
export_logistics.py

@@ -1,28 +0,0 @@
-from __future__ import annotations
-
-import sys
-import typing
-
-import cache
-import supply
-
-def main() -> None:
-	(fio_burn,) = supply.get_fio_burn([sys.argv[1]])
-	planet = supply.Planet(fio_burn)
-
-	materials: typing.Mapping[str, supply.Material] = {mat['Ticker']: mat
-			for mat in cache.get('https://rest.fnar.net/material/allmaterials')}
-
-	total_weight = total_volume = 0.0
-	for mat in planet.exporting:
-		if amount := planet.inventory.get(mat):
-			weight = amount * materials[mat]['Weight']
-			volume = amount * materials[mat]['Volume']
-			print(f'{mat:3} {amount:5,} {weight:5.2f}t {volume:5.2f}m³')
-			total_weight += weight
-			total_volume += volume
-	
-	print(f'total {total_weight:.2f}t {total_volume:.2f}m³')
-
-if __name__ == '__main__':
-	main()

+ 33 - 0
junk.py

@@ -0,0 +1,33 @@
+from __future__ import annotations
+
+import collections
+import typing
+
+import cache
+from config import config
+import supply
+
+def main() -> None:
+	fio_burns: typing.Sequence[supply.FIOBurn] = cache.get('https://rest.fnar.net/fioweb/burn/user/' + config.username,
+			headers={'Authorization': config.fio_api_key})
+	planets = [supply.Planet(fio_burn) for fio_burn in fio_burns]
+
+	total_consumption: dict[str, float] = collections.defaultdict(float)
+	for planet in planets:
+		for mat, consumption in planet.net_consumption.items():
+			if consumption > 0:
+				total_consumption[mat] += consumption
+	
+	supplies: list[tuple[float, str]] = []
+	for mat, amount in supply.warehouse_inventory().items():
+		if (consumption := total_consumption.get(mat)) is None:
+			supplies.append((float('inf'), mat))
+		else:
+			supplies.append((amount / consumption, mat))
+
+	supplies.sort(reverse=True)
+	for days, mat in supplies:
+		print(f'{mat}: {days:.2f} d')
+
+if __name__ == '__main__':
+	main()