Skip to content

Commit

Permalink
Functions to get average station trading prices
Browse files Browse the repository at this point in the history
  • Loading branch information
kfsone committed Jan 5, 2015
1 parent 0d1acf0 commit 4fb503b
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tradedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@ def __init__(self,
self.sqlFilename = str(self.sqlPath)
self.pricesFilename = str(self.pricesPath)

self.avgSelling, self.avgBuying = None, None

if load:
self.reloadCache()
self.load(
Expand Down Expand Up @@ -1235,6 +1237,42 @@ def lookupItem(self, name):
)


def getAverageSelling(self):
"""
Query the database for average selling prices of all items.
"""
if not self.avgSelling:
self.avgSelling = {
ID: int(cr)
for ID, cr in self.getDB().execute("""
SELECT Item.item_id, IFNULL(AVG(price), 0)
FROM Item
LEFT OUTER JOIN StationSelling
USING (item_id)
GROUP BY 1
""")
}
return self.avgSelling


def getAverageBuying(self):
"""
Query the database for average buying prices of all items.
"""
if not self.avgBuying:
self.avgBuying = {
ID: int(cr)
for ID, cr in self.getDB().execute("""
SELECT Item.item_id, IFNULL(AVG(price), 0)
FROM Item
LEFT OUTER JOIN StationBuying
USING (item_id)
GROUP BY 1
""")
}
return self.avgBuying


############################################################
# Rare Items

Expand Down

0 comments on commit 4fb503b

Please sign in to comment.