Add price optimization option to multibuy
Doesn't work yet
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
|
||||
|
||||
import re
|
||||
from enum import Enum
|
||||
from enum import IntEnum, unique
|
||||
|
||||
from logbook import Logger
|
||||
|
||||
@@ -42,7 +42,8 @@ from service.port.shared import IPortUser, fetchItem, processing_notify
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class Options(Enum):
|
||||
@unique
|
||||
class Options(IntEnum):
|
||||
IMPLANTS = 1
|
||||
MUTATIONS = 2
|
||||
LOADED_CHARGES = 3
|
||||
|
||||
@@ -18,19 +18,24 @@
|
||||
# =============================================================================
|
||||
|
||||
|
||||
from enum import Enum
|
||||
from enum import IntEnum, unique
|
||||
|
||||
from service.price import Price as sPrc
|
||||
|
||||
|
||||
class Options(Enum):
|
||||
@unique
|
||||
class Options(IntEnum):
|
||||
IMPLANTS = 1
|
||||
CARGO = 2
|
||||
LOADED_CHARGES = 3
|
||||
OPTIMIZE_PRICES = 4
|
||||
|
||||
|
||||
MULTIBUY_OPTIONS = (
|
||||
(Options.LOADED_CHARGES.value, 'Loaded Charges', 'Export charges loaded into modules', True),
|
||||
(Options.IMPLANTS.value, 'Implants && Boosters', 'Export implants and boosters', False),
|
||||
(Options.CARGO.value, 'Cargo', 'Export cargo contents', True),
|
||||
(Options.OPTIMIZE_PRICES.value, 'Optimize Prices', 'Replace items by cheaper alternatives', False),
|
||||
)
|
||||
|
||||
|
||||
@@ -68,6 +73,14 @@ def exportMultiBuy(fit, options):
|
||||
for booster in fit.boosters:
|
||||
addItem(booster.item)
|
||||
|
||||
if options[Options.OPTIMIZE_PRICES.value]:
|
||||
|
||||
def cb(replacements):
|
||||
pass
|
||||
|
||||
priceSvc = sPrc.getInstance()
|
||||
priceSvc.findCheaperReplacements(itemCounts, cb)
|
||||
|
||||
exportLines = []
|
||||
exportLines.append(fit.ship.item.name)
|
||||
for item in sorted(itemCounts, key=lambda i: (i.group.category.name, i.group.name, i.name)):
|
||||
|
||||
@@ -146,35 +146,23 @@ class Price:
|
||||
|
||||
@classmethod
|
||||
def fitItemsList(cls, fit):
|
||||
return list(set(cls.fitItemIter(fit, includeShip=True)))
|
||||
return list(set(cls.fitItemIter(fit)))
|
||||
|
||||
@classmethod
|
||||
def fitObjectIter(cls, fit, includeShip=True):
|
||||
if includeShip:
|
||||
yield fit.ship
|
||||
def fitObjectIter(cls, fit):
|
||||
yield fit.ship
|
||||
|
||||
for mod in fit.modules:
|
||||
if not mod.isEmpty:
|
||||
yield mod
|
||||
|
||||
for drone in fit.drones:
|
||||
yield drone
|
||||
|
||||
for fighter in fit.fighters:
|
||||
yield fighter
|
||||
|
||||
for implant in fit.implants:
|
||||
yield implant
|
||||
|
||||
for booster in fit.boosters:
|
||||
yield booster
|
||||
|
||||
for cargo in fit.cargo:
|
||||
yield cargo
|
||||
for container in (fit.drones, fit.fighters, fit.implants, fit.boosters, fit.cargo):
|
||||
for obj in container:
|
||||
yield obj
|
||||
|
||||
@classmethod
|
||||
def fitItemIter(cls, fit, includeShip=True):
|
||||
for fitobj in cls.fitObjectIter(fit, includeShip=includeShip):
|
||||
def fitItemIter(cls, fit):
|
||||
for fitobj in cls.fitObjectIter(fit):
|
||||
yield fitobj.item
|
||||
charge = getattr(fitobj, 'charge', None)
|
||||
if charge:
|
||||
@@ -213,11 +201,11 @@ class Price:
|
||||
pyfalog.debug("Clearing Prices")
|
||||
db.clearPrices()
|
||||
|
||||
def findCheaperReplacements(self, callback, fit, includeBetter=False, fetchTimeout=10):
|
||||
def findCheaperReplacements(self, items, callback, includeBetter=False, fetchTimeout=10):
|
||||
sMkt = Market.getInstance()
|
||||
|
||||
potential = {} # All possible item replacements
|
||||
for item in self.fitItemIter(fit, includeShip=False):
|
||||
for item in items:
|
||||
if item in potential:
|
||||
continue
|
||||
itemRepls = sMkt.getReplacements(item, includeBetter=includeBetter)
|
||||
@@ -225,7 +213,7 @@ class Price:
|
||||
potential[item] = itemRepls
|
||||
itemsToFetch = {i for i in chain(potential.keys(), *potential.values())}
|
||||
|
||||
def cb():
|
||||
def cb(requests):
|
||||
# Decide what we are going to replace
|
||||
actual = {} # Items which should be replaced
|
||||
for replacee, replacers in potential.items():
|
||||
|
||||
Reference in New Issue
Block a user