Skip to content

Commit

Permalink
"buy" and "sell" --near now works in-system too
Browse files Browse the repository at this point in the history
  • Loading branch information
kfsone committed Dec 13, 2014
1 parent 35dd37b commit c656e7f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 30 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ TradeDangerous, Copyright (C) Oliver "kfsone" Smith, July 2014
==============================================================================

v6.2.1 [wip]
. (kfsone) "buy" and "sell" --near now checks the station/system too
. (kfsone) "buy" now shows average cost if you specify --detail (-v)
. (kfsone) "sell" now shows average value if you specify --detail (-v)
. (kfsone) Fixed item name matching (--avoid)
Expand Down
32 changes: 17 additions & 15 deletions commands/buy_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,28 @@ def run(results, cmdenv, tdb):
columns.append('0')

nearSystem = cmdenv.nearSystem
distances = dict()
if nearSystem:
maxLy = cmdenv.maxLyPer or tdb.maxSystemLinkLy
results.summary.near = nearSystem
results.summary.ly = maxLy

cmdenv.DEBUG0("Searching within {}ly of {}", maxLy, nearSystem.name())
systemRanges = {
system: dist
for system, dist in tdb.genSystemsInRange(
nearSystem,
maxLy,
includeSelf=True,
)
}
tables += (
" INNER JOIN StationLink AS sl"
" ON (sl.rhs_station_id = ss.station_id)"
)
columns.append('sl.dist')
constraints.append("(lhs_system_id = {})".format(
nearSystem.ID
))
constraints.append("(dist <= {})".format(
maxLy
))
else:
columns.append('0')
" INNER JOIN Station AS stn"
" ON (stn.station_id = ss.station_id)"
)
constraints.append("(stn.system_id IN ({}))".format(
",".join(['?'] * len(systemRanges))
))
bindValues += list(system.ID for system in systemRanges.keys())

whereClause = ' AND '.join(constraints)
stmt = """
Expand All @@ -133,12 +135,12 @@ def run(results, cmdenv, tdb):
cur = tdb.query(stmt, bindValues)

stationByID = tdb.stationByID
for (stationID, priceCr, stock, age, dist) in cur:
for (stationID, priceCr, stock, age) in cur:
row = ResultRow()
row.station = stationByID[stationID]
cmdenv.DEBUG2("{} {}cr {} units", row.station.name(), priceCr, stock)
if nearSystem:
row.dist = dist
row.dist = systemRanges[row.station.system]
row.price = priceCr
row.stock = stock
row.age = age
Expand Down
32 changes: 17 additions & 15 deletions commands/sell_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,28 @@ def run(results, cmdenv, tdb):
bindValues.append(cmdenv.quantity)

nearSystem = cmdenv.nearSystem
distances = dict()
if nearSystem:
maxLy = cmdenv.maxLyPer or tdb.maxSystemLinkLy
results.summary.near = nearSystem
results.summary.ly = maxLy

cmdenv.DEBUG0("Searching within {}ly of {}", maxLy, nearSystem.name())
systemRanges = {
system: dist
for system, dist in tdb.genSystemsInRange(
nearSystem,
maxLy,
includeSelf=True,
)
}
tables += (
" INNER JOIN StationLink AS sl"
" ON (sl.rhs_station_id = sb.station_id)"
)
columns.append('sl.dist')
constraints.append("(lhs_system_id = {})".format(
nearSystem.ID
))
constraints.append("(dist <= {})".format(
maxLy
))
else:
columns += [ '0' ]
" INNER JOIN Station AS stn"
" ON (stn.station_id = sb.station_id)"
)
constraints.append("(stn.system_id IN ({}))".format(
",".join(['?'] * len(systemRanges))
))
bindValues += list(system.ID for system in systemRanges.keys())

whereClause = ' AND '.join(constraints)
stmt = """
Expand All @@ -104,12 +106,12 @@ def run(results, cmdenv, tdb):
cur = tdb.query(stmt, bindValues)

stationByID = tdb.stationByID
for (stationID, priceCr, demand, dist) in cur:
for (stationID, priceCr, demand) in cur:
row = ResultRow()
row.station = stationByID[stationID]
cmdenv.DEBUG2("{} {}cr {} units", row.station.name(), priceCr, demand)
if nearSystem:
row.dist = dist
row.dist = systemRanges[row.station.system]
row.price = priceCr
row.demand = demand
results.rows.append(row)
Expand Down

0 comments on commit c656e7f

Please sign in to comment.