First draft of price fetching code, as well as a bugfix fixing fitting calculations being done twice
This commit is contained in:
@@ -86,7 +86,7 @@ class Fit(object):
|
||||
eos.db.commit()
|
||||
fit.clear()
|
||||
fit.calculateModifiedAttributes()
|
||||
return fit
|
||||
return True
|
||||
|
||||
def removeModule(self, fitID, position):
|
||||
fit = eos.db.getFit(fitID)
|
||||
@@ -94,11 +94,11 @@ class Fit(object):
|
||||
eos.db.commit()
|
||||
fit.clear()
|
||||
fit.calculateModifiedAttributes()
|
||||
return fit
|
||||
return True
|
||||
|
||||
def addDrone(self, fitID, itemID):
|
||||
if fitID == None:
|
||||
return
|
||||
return False
|
||||
|
||||
fit = eos.db.getFit(fitID)
|
||||
item = eos.db.getItem(itemID, eager=("attributes", "group.category"))
|
||||
@@ -112,8 +112,9 @@ class Fit(object):
|
||||
eos.db.commit()
|
||||
fit.clear()
|
||||
fit.calculateModifiedAttributes()
|
||||
|
||||
return fit
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def removeDrone(self, fitID, i):
|
||||
fit = eos.db.getFit(fitID)
|
||||
@@ -128,7 +129,7 @@ class Fit(object):
|
||||
eos.db.commit()
|
||||
fit.clear()
|
||||
fit.calculateModifiedAttributes()
|
||||
return fit
|
||||
return True
|
||||
|
||||
def toggleDrone(self, fitID, i):
|
||||
fit = eos.db.getFit(fitID)
|
||||
@@ -141,4 +142,4 @@ class Fit(object):
|
||||
eos.db.commit()
|
||||
fit.clear()
|
||||
fit.calculateModifiedAttributes()
|
||||
return fit
|
||||
return True
|
||||
|
||||
@@ -19,6 +19,46 @@
|
||||
|
||||
import eos.db
|
||||
import eos.types
|
||||
import wx
|
||||
import collections
|
||||
import threading
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
|
||||
class PriceWorkerThread(threading.Thread):
|
||||
def run(self):
|
||||
self.cv = threading.Condition()
|
||||
self.updateRequests = collections.deque()
|
||||
self.scheduled = set()
|
||||
self.processUpdates()
|
||||
|
||||
def processUpdates(self):
|
||||
updateRequests = self.updateRequests
|
||||
cv = self.cv
|
||||
|
||||
while True:
|
||||
cv.acquire()
|
||||
|
||||
while len(updateRequests) == 0:
|
||||
cv.wait()
|
||||
|
||||
# Grab our data and rerelease the lock
|
||||
callback, requests = self.updateRequests.popleft()
|
||||
self.scheduled.clear()
|
||||
cv.release()
|
||||
|
||||
# Grab prices, this is the time-consuming part
|
||||
if len(requests) > 0:
|
||||
eos.types.Price.fetchPrices(*requests)
|
||||
|
||||
callback()
|
||||
|
||||
|
||||
def trigger(self, prices, callbacks):
|
||||
self.cv.acquire()
|
||||
self.updateRequests.append((callbacks, prices))
|
||||
self.scheduled.update(prices)
|
||||
self.cv.notify()
|
||||
self.cv.release()
|
||||
|
||||
class Market():
|
||||
instance = None
|
||||
@@ -39,6 +79,10 @@ class Market():
|
||||
|
||||
def __init__(self):
|
||||
self.activeMetas = set()
|
||||
self.priceCache = {}
|
||||
self.workerThread = PriceWorkerThread()
|
||||
self.workerThread.daemon = True
|
||||
self.workerThread.start()
|
||||
|
||||
def getChildren(self, id):
|
||||
"""
|
||||
@@ -162,3 +206,36 @@ class Market():
|
||||
l.append((var.ID, var.name, var.icon.iconFile if var.icon else ""))
|
||||
|
||||
return l
|
||||
|
||||
def getPrices(self, typeIDs, callback):
|
||||
fetch = set()
|
||||
all = []
|
||||
new = []
|
||||
for typeID in typeIDs:
|
||||
price = self.priceCache.get(typeID)
|
||||
if price is None:
|
||||
try:
|
||||
price = eos.db.getPrice(typeID)
|
||||
except NoResultFound:
|
||||
price = eos.types.Price(typeID)
|
||||
new.append(price)
|
||||
|
||||
self.priceCache[typeID] = price
|
||||
|
||||
all.append(price)
|
||||
if not price.isValid and not price in self.workerThread.scheduled:
|
||||
fetch.add(price)
|
||||
|
||||
def dbAdd():
|
||||
for price in new:
|
||||
eos.db.saveddata_session.add(price)
|
||||
eos.db.saveddata_session.commit()
|
||||
eos.db.saveddata_session.flush()
|
||||
|
||||
def cb():
|
||||
wx.CallAfter(callback, all)
|
||||
wx.CallAfter(dbAdd)
|
||||
|
||||
print map(lambda p: p.typeID, fetch)
|
||||
print map(lambda p: p.typeID, new)
|
||||
self.workerThread.trigger(fetch, cb)
|
||||
|
||||
2
eos
2
eos
Submodule eos updated: e7818890ac...c61a2e9e8d
@@ -49,8 +49,10 @@ class DroneView(d.Display):
|
||||
def addItem(self, event):
|
||||
cFit = controller.Fit.getInstance()
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
cFit.addDrone(fitID, event.itemID)
|
||||
wx.PostEvent(self.mainFrame, fv.FitChanged(fitID=fitID))
|
||||
trigger = cFit.addDrone(fitID, event.itemID)
|
||||
if trigger:
|
||||
wx.PostEvent(self.mainFrame, fv.FitChanged(fitID=fitID))
|
||||
|
||||
event.Skip()
|
||||
|
||||
def removeItem(self, event):
|
||||
|
||||
@@ -45,6 +45,7 @@ class FittingView(d.Display):
|
||||
|
||||
#Gets called from the fitMultiSwitch when it decides its time
|
||||
def changeFit(self, fitID):
|
||||
print "c"
|
||||
self.activeFitID = fitID
|
||||
if fitID == None:
|
||||
self.Hide()
|
||||
@@ -54,6 +55,7 @@ class FittingView(d.Display):
|
||||
wx.PostEvent(self.mainFrame, FitChanged(fitID=fitID))
|
||||
|
||||
def appendItem(self, itemID):
|
||||
print "a"
|
||||
fitID = self.activeFitID
|
||||
if fitID != None:
|
||||
cFit = controller.Fit.getInstance()
|
||||
@@ -61,6 +63,7 @@ class FittingView(d.Display):
|
||||
wx.PostEvent(self.mainFrame, FitChanged(fitID=fitID))
|
||||
|
||||
def removeItem(self, event):
|
||||
print "i"
|
||||
row, _ = self.HitTest(event.Position)
|
||||
if row != -1:
|
||||
cFit = controller.Fit.getInstance()
|
||||
|
||||
@@ -106,6 +106,7 @@ class MultiSwitch(wx.Notebook):
|
||||
self.SetPageImage(tab, self.imageList.Add(bitmap))
|
||||
|
||||
def pageChanged(self, event):
|
||||
print "p"
|
||||
selection = event.Selection
|
||||
page = self.GetPage(selection)
|
||||
if hasattr(page, "type") and page.type == "fit":
|
||||
@@ -153,6 +154,7 @@ class MultiSwitch(wx.Notebook):
|
||||
event.Skip()
|
||||
|
||||
def itemSelected(self, event):
|
||||
print "s"
|
||||
selected = self.GetSelection()
|
||||
page = self.GetPage(selected)
|
||||
if page.type == "fit":
|
||||
|
||||
@@ -32,6 +32,7 @@ class StatsPane(wx.Panel):
|
||||
"capacitorViewFull", "targetingmiscViewFull", "priceViewFull"]
|
||||
|
||||
def fitChanged(self, event):
|
||||
print "f"
|
||||
cFit = controller.Fit.getInstance()
|
||||
fit = cFit.getFit(event.fitID)
|
||||
for view in self.views:
|
||||
@@ -45,8 +46,8 @@ class StatsPane(wx.Panel):
|
||||
# Force font size 8
|
||||
standardFont = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
|
||||
standardFont.SetPointSize(8)
|
||||
self.SetFont(standardFont)
|
||||
|
||||
self.SetFont(standardFont)
|
||||
|
||||
mainSizer = wx.BoxSizer(wx.VERTICAL)
|
||||
self.SetSizer(mainSizer)
|
||||
|
||||
@@ -61,7 +62,7 @@ class StatsPane(wx.Panel):
|
||||
|
||||
view.populatePanel(contentPanel, headerPanel)
|
||||
tp.SetLabel(view.getHeaderText(None))
|
||||
|
||||
|
||||
view.refreshPanel(None)
|
||||
|
||||
mainSizer.Add(tp, 0, wx.EXPAND | wx.LEFT, 3)
|
||||
|
||||
Reference in New Issue
Block a user