Skip to content

Commit

Permalink
Improved station loading
Browse files Browse the repository at this point in the history
- Fixed how we load data age (some values were wrong),
- Improved performance,
  • Loading branch information
kfsone committed May 3, 2015
1 parent 77c0343 commit 112173b
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions tradedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1139,12 +1139,8 @@ def _loadStations(self):
stmt = """
SELECT station_id, system_id, name,
ls_from_star, market, blackmarket, shipyard,
max_pad_size, outfitting, rearm, refuel, repair,
COUNT(StationItem.item_id) AS itemCount,
JULIANDAY('now') - JULIANDAY(AVG(StationItem.modified))
max_pad_size, outfitting, rearm, refuel, repair
FROM Station
LEFT OUTER JOIN StationItem USING (station_id)
GROUP BY 1
"""
self.cur.execute(stmt)
stationByID = {}
Expand All @@ -1154,19 +1150,32 @@ def _loadStations(self):
ID, systemID, name,
lsFromStar, market, blackMarket, shipyard,
maxPadSize, outfitting, rearm, refuel, repair,
itemCount, dataAge
) in self.cur:
station = Station(
ID, systemByID[systemID], name,
lsFromStar, market, blackMarket, shipyard,
maxPadSize, outfitting, rearm, refuel, repair,
itemCount, dataAge
0, 0
)
if itemCount > 0:
self.tradingStationCount += 1
stationByID[ID] = station

tradingCount = 0
stmt = """
SELECT station_id,
COUNT(*) AS item_count,
AVG(JULIANDAY('now') - JULIANDAY(modified))
FROM StationItem
GROUP BY 1
HAVING item_count > 0
"""
for ID, itemCount, dataAge in self.cur.execute(stmt):
station = stationByID[ID]
station.itemCount = itemCount
station.dataAge = dataAge
tradingCount += 1

self.stationByID = stationByID
self.tradingStationCount = tradingCount
self.tdenv.DEBUG1("Loaded {:n} Stations", len(stationByID))
self.stellarGrid = None

Expand Down

0 comments on commit 112173b

Please sign in to comment.