Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
tKe committed Mar 30, 2015
2 parents e6a73d5 + 336a7fe commit be2af91
Show file tree
Hide file tree
Showing 7 changed files with 344 additions and 87 deletions.
5 changes: 5 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
TradeDangerous, Copyright (C) Oliver "kfsone" Smith, July 2014
==============================================================================

v6.16.1 Apr 01 2015 (In some parts of the world)
. (kfsone) "old" sub-command
- Added a "--route" option: which probably doesn't do what you think,
- Added a "--min-age" option: because old is the new new!

v6.16.0 Mar 29 2015
. (tKe) "run" command
- "--loop" option
Expand Down
44 changes: 44 additions & 0 deletions commands/olddata_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import itertools
import math
import sys

######################################################################
# Parser config
Expand Down Expand Up @@ -32,6 +33,15 @@
metavar='N.NN',
type=float,
),
ParseArgument('--route',
help='Sort to shortest path',
action='store_true',
),
ParseArgument('--min-age',
help='List data older than this number of days.',
type=float,
dest='minAge',
),
]

######################################################################
Expand Down Expand Up @@ -62,6 +72,12 @@ def run(results, cmdenv, tdb):
wheres = []
havings = []

if cmdenv.minAge:
wheres.append(
"(JULIANDAY('NOW') - JULIANDAY(si.modified) >= {})"
.format(cmdenv.minAge)
)

nearSys = cmdenv.nearSystem
if nearSys:
maxLy = cmdenv.maxLyPer or tdb.maxSystemLinkLy
Expand Down Expand Up @@ -141,6 +157,34 @@ def run(results, cmdenv, tdb):
row.dist = dist2 ** 0.5
results.rows.append(row)

if cmdenv.near:
results.rows.sort(key=lambda row: row.dist)

if cmdenv.route and len(results.rows) > 1:
def walk(startNode, dist):
rows = results.rows
startNode = rows[startNode]
openList = set(rows)
path = [startNode]
openList.remove(startNode)
while len(path) < len(rows):
lastNode = path[-1]
distFn = lastNode.station.system.distanceTo
nearest = min(openList, key=lambda row: distFn(row.station.system))
openList.remove(nearest)
path.append(nearest)
dist += distFn(nearest.station.system)
return (path, dist)
if cmdenv.near:
bestPath = walk(0, results.rows[0].dist)
else:
bestPath = (results.rows, float("inf"))
for i in range(len(results.rows)):
path = walk(i, 0)
if path[1] < bestPath[1]:
bestPath = path
results.rows[:] = bestPath[0]

return results

######################################################################
Expand Down
34 changes: 13 additions & 21 deletions commands/run_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,8 +739,11 @@ def validateRunArguments(tdb, cmdenv, calc):
if cmdenv.insurance >= (cmdenv.credits + arbitraryInsuranceBuffer):
raise CommandLineError("Insurance leaves no margin for trade")

if cmdenv.loop and cmdenv.unique:
raise CommandLineError("Cannot use --unique and --loop together")
if cmdenv.loop:
if cmdenv.unique:
raise CommandLineError("Cannot use --unique and --loop together")
if cmdenv.direct:
raise CommandLineError("Cannot use --direct and --loop together")

checkOrigins(tdb, cmdenv, calc)
checkDestinations(tdb, cmdenv, calc)
Expand Down Expand Up @@ -1020,7 +1023,9 @@ def run(results, cmdenv, tdb):
results.summary.exception = ""

pruneMod = cmdenv.pruneScores / 100
distancePruning = (cmdenv.destPlace or cmdenv.loop)
distancePruning = (cmdenv.destPlace and not cmdenv.direct) or (cmdenv.loop)
if distancePruning and not cmdenv.loop:
stopSystems = {stop.system for stop in stopStations}

loopRoutes = []
for hopNo in range(numHops):
Expand All @@ -1044,28 +1049,15 @@ def run(results, cmdenv, tdb):

if distancePruning:
remainingDistance = (numHops - hopNo) * maxHopDistLy
remainingDistanceSq = remainingDistance * remainingDistance

def canReachStopStation(r):
def routeStillHasAChance(r):
distanceFn = r.lastSystem.distanceTo
if cmdenv.loop:
stopSystems = {r.firstSystem}
else:
stopSystems = {stopStation.system
for stopStation in stopStations}
reachableSystems = [stopSystem
for stopSystem in stopSystems
if r.lastSystem.distToSq(stopSystem) <= remainingDistanceSq]
if len(reachableSystems):
if cmdenv.debug:
reachableSystems = [s.name() for s in reachableSystems]
cmdenv.DEBUG1("Route {} can still reach: {}", r.str(), ', '.join(reachableSystems))
return True
return distanceFn(r.firstSystem) <= remainingDistance
else:
cmdenv.DEBUG1("Route {} too far from all end stations", r.str())
return False
return any(stop for stop in stopSystems if distanceFn(stop) <= remainingDistance)

preCrop = len(routes)
routes[:] = [x for x in routes if canReachStopStation(x)]
routes[:] = [x for x in routes if routeStillHasAChance(x)]
pruned = preCrop - len(routes)
if pruned:
cmdenv.NOTE("Pruned {} origins too far from any end stations", pruned)
Expand Down
73 changes: 73 additions & 0 deletions data/ShipVendor.csv
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,16 @@ unq:[email protected]_id,unq:[email protected]_id,unq:[email protected]_id,mod
'BUNUVIVIA','Ellison Enterprise','Type 7','2015-03-04 19:50:35'
'BUNUVIVIA','Ellison Enterprise','Type 9','2015-03-04 19:50:35'
'BUNUVIVIA','Ellison Enterprise','Viper','2015-03-04 19:50:35'
'BV PHOENICIS','Aoki Dock','Adder','2015-03-29 20:30:28'
'BV PHOENICIS','Aoki Dock','Asp','2015-03-29 20:30:28'
'BV PHOENICIS','Aoki Dock','Cobra','2015-03-29 20:30:28'
'BV PHOENICIS','Aoki Dock','Eagle','2015-03-29 20:30:28'
'BV PHOENICIS','Aoki Dock','Hauler','2015-03-29 20:29:39'
'BV PHOENICIS','Aoki Dock','Sidewinder','2015-03-29 20:30:28'
'BV PHOENICIS','Aoki Dock','Type 6','2015-03-29 20:30:28'
'BV PHOENICIS','Aoki Dock','Type 7','2015-03-29 20:30:28'
'BV PHOENICIS','Aoki Dock','Type 9','2015-03-29 20:30:28'
'BV PHOENICIS','Aoki Dock','Viper','2015-03-29 20:30:28'
'CAERITIS','Bernoulli Vision','Adder','2015-03-27 03:25:17'
'CAERITIS','Bernoulli Vision','Cobra','2015-03-27 03:25:17'
'CAERITIS','Bernoulli Vision','Eagle','2015-03-27 03:25:17'
Expand Down Expand Up @@ -597,6 +607,16 @@ unq:[email protected]_id,unq:[email protected]_id,unq:[email protected]_id,mod
'GLIESE 563.1','Matteucci Ring','Type 6','2015-03-28 16:39:10'
'GLIESE 563.1','Matteucci Ring','Type 7','2015-03-28 16:39:03'
'GLIESE 563.1','Matteucci Ring','Type 9','2015-03-28 16:38:58'
'GLIESE 900.1','Barr Station','Adder','2015-03-29 11:00:18'
'GLIESE 900.1','Barr Station','Eagle','2015-03-29 11:00:18'
'GLIESE 900.1','Barr Station','Hauler','2015-03-29 11:00:18'
'GLIESE 900.1','Barr Station','Sidewinder','2015-03-29 10:59:53'
'GLIESE 900.1','Barr Station','Viper','2015-03-29 11:00:18'
'GLIESE 900.1','Leckie Gateway','Asp','2015-03-29 10:48:38'
'GLIESE 900.1','Leckie Gateway','Cobra','2015-03-29 10:48:38'
'GLIESE 900.1','Leckie Gateway','Sidewinder','2015-03-29 10:48:38'
'GLIESE 900.1','Leckie Gateway','Type 6','2015-03-29 10:48:38'
'GLIESE 900.1','Leckie Gateway','Type 9','2015-03-29 10:48:14'
'GLIESE 900.1','Lewitt Port','Cobra','2015-03-22 15:49:46'
'GLIESE 900.1','Lewitt Port','Eagle','2015-03-22 15:49:46'
'GLIESE 900.1','Lewitt Port','Sidewinder','2015-03-22 15:49:46'
Expand Down Expand Up @@ -833,6 +853,19 @@ unq:[email protected]_id,unq:[email protected]_id,unq:[email protected]_id,mod
'KANOS','Geston Ring','Type 7','2015-03-04 19:50:35'
'KANOS','Geston Ring','Type 9','2015-03-04 19:50:35'
'KANOS','Geston Ring','Viper','2015-03-04 19:50:35'
'KAUSAN','Lyulka Ring','Adder','2015-03-29 14:11:18'
'KAUSAN','Lyulka Ring','Asp','2015-03-29 14:11:03'
'KAUSAN','Lyulka Ring','Clipper','2015-03-29 14:11:44'
'KAUSAN','Lyulka Ring','Eagle','2015-03-29 14:10:51'
'KAUSAN','Lyulka Ring','Fer-de-Lance','2015-03-29 14:11:18'
'KAUSAN','Lyulka Ring','Hauler','2015-03-29 14:10:32'
'KAUSAN','Lyulka Ring','Python','2015-03-29 14:11:31'
'KAUSAN','Lyulka Ring','Sidewinder','2015-03-29 14:10:51'
'KAUSAN','Lyulka Ring','Type 6','2015-03-29 14:11:03'
'KAUSAN','Lyulka Ring','Type 7','2015-03-29 14:10:51'
'KAUSAN','Lyulka Ring','Type 9','2015-03-29 14:11:04'
'KAUSAN','Lyulka Ring','Viper','2015-03-29 14:11:31'
'KAUSAN','Lyulka Ring','Vulture','2015-03-29 14:11:18'
'KHAN GUBII','Alpers City','Adder','2015-03-04 19:50:35'
'KHAN GUBII','Alpers City','Anaconda','2015-03-04 19:50:35'
'KHAN GUBII','Alpers City','Asp','2015-03-04 19:50:35'
Expand Down Expand Up @@ -903,6 +936,17 @@ unq:[email protected]_id,unq:[email protected]_id,unq:[email protected]_id,mod
'LAKSAK','Stjepan Seljan Hub','Type 6','2015-03-20 07:24:20'
'LAKSAK','Stjepan Seljan Hub','Type 9','2015-03-20 07:24:20'
'LAKSAK','Stjepan Seljan Hub','Viper','2015-03-20 07:24:20'
'LAMPADE','Ashman Dock','Anaconda','2015-03-29 14:43:00'
'LAMPADE','Ashman Dock','Asp','2015-03-29 14:43:00'
'LAMPADE','Ashman Dock','Clipper','2015-03-29 14:43:00'
'LAMPADE','Ashman Dock','Cobra','2015-03-29 14:43:00'
'LAMPADE','Ashman Dock','Eagle','2015-03-29 14:43:00'
'LAMPADE','Ashman Dock','Hauler','2015-03-29 14:43:00'
'LAMPADE','Ashman Dock','Python','2015-03-29 14:43:00'
'LAMPADE','Ashman Dock','Sidewinder','2015-03-29 14:43:00'
'LAMPADE','Ashman Dock','Type 7','2015-03-29 14:43:00'
'LAMPADE','Ashman Dock','Viper','2015-03-29 14:42:03'
'LAMPADE','Ashman Dock','Vulture','2015-03-29 14:43:00'
'LAVE','Lave Station','Cobra','2015-03-27 20:35:28'
'LAVE','Lave Station','Eagle','2015-03-27 20:35:43'
'LAVE','Lave Station','Hauler','2015-03-27 20:35:43'
Expand Down Expand Up @@ -1230,6 +1274,12 @@ unq:[email protected]_id,unq:[email protected]_id,unq:[email protected]_id,mod
'LTT 9552','Reichelt Orbital','Type 6','2015-03-23 22:56:40'
'LTT 9552','Reichelt Orbital','Type 7','2015-03-23 22:56:40'
'LTT 9552','Reichelt Orbital','Type 9','2015-03-23 22:56:40'
'LTT 9863','Lynden-Bell Terminal','Asp','2015-03-29 20:58:38'
'LTT 9863','Lynden-Bell Terminal','Eagle','2015-03-29 20:58:38'
'LTT 9863','Lynden-Bell Terminal','Hauler','2015-03-29 20:58:10'
'LTT 9863','Lynden-Bell Terminal','Sidewinder','2015-03-29 20:58:38'
'LTT 9863','Lynden-Bell Terminal','Type 6','2015-03-29 20:58:38'
'LTT 9863','Lynden-Bell Terminal','Type 7','2015-03-29 20:58:38'
'LU VELORUM','Miletus Station','Anaconda','2015-03-04 19:50:35'
'LU VELORUM','Miletus Station','Asp','2015-03-04 19:50:35'
'LU VELORUM','Miletus Station','Cobra','2015-03-04 19:50:35'
Expand Down Expand Up @@ -1265,6 +1315,16 @@ unq:[email protected]_id,unq:[email protected]_id,unq:[email protected]_id,mod
'MAKULU','Hubble City','Viper','2015-03-28 20:45:33'
'MALINA','Kooi Resort','Sidewinder','2015-03-24 08:39:24'
'MALINA','Kooi Resort','Type 6','2015-03-24 08:39:24'
'MAORSI','Karachkina City','Asp','2015-03-29 19:24:18'
'MAORSI','Karachkina City','Clipper','2015-03-29 19:24:18'
'MAORSI','Karachkina City','Cobra','2015-03-29 19:24:19'
'MAORSI','Karachkina City','Hauler','2015-03-29 19:24:19'
'MAORSI','Karachkina City','Orca','2015-03-29 19:24:19'
'MAORSI','Karachkina City','Python','2015-03-29 19:24:19'
'MAORSI','Karachkina City','Sidewinder','2015-03-29 19:24:19'
'MAORSI','Karachkina City','Type 6','2015-03-29 19:24:20'
'MAORSI','Karachkina City','Type 7','2015-03-29 19:24:20'
'MAORSI','Karachkina City','Viper','2015-03-29 19:24:18'
'MBUTAS','Burkin Orbital','Asp','2015-03-21 09:57:04'
'MBUTAS','Burkin Orbital','Dropship','2015-03-21 09:57:04'
'MBUTAS','Burkin Orbital','Eagle','2015-03-21 09:57:04'
Expand Down Expand Up @@ -1368,6 +1428,19 @@ unq:[email protected]_id,unq:[email protected]_id,unq:[email protected]_id,mod
'NADUNINDA','Robson Mines','Hauler','2015-03-04 19:50:35'
'NADUNINDA','Robson Mines','Sidewinder','2015-03-04 19:50:35'
'NADUNINDA','Robson Mines','Type 7','2015-03-04 19:50:35'
'NAHUA','Fuller Vision','Asp','2015-03-29 19:23:15'
'NAHUA','Fuller Vision','Clipper','2015-03-29 19:23:15'
'NAHUA','Fuller Vision','Cobra','2015-03-29 19:23:16'
'NAHUA','Fuller Vision','Eagle','2015-03-29 19:23:16'
'NAHUA','Fuller Vision','Hauler','2015-03-29 19:23:16'
'NAHUA','Fuller Vision','Orca','2015-03-29 19:23:16'
'NAHUA','Fuller Vision','Python','2015-03-29 19:23:16'
'NAHUA','Fuller Vision','Sidewinder','2015-03-29 19:22:27'
'NAHUA','Fuller Vision','Type 6','2015-03-29 19:23:17'
'NAHUA','Fuller Vision','Type 7','2015-03-29 19:23:17'
'NAHUA','Fuller Vision','Type 9','2015-03-29 19:23:17'
'NAHUA','Fuller Vision','Viper','2015-03-29 19:23:17'
'NAHUA','Fuller Vision','Vulture','2015-03-29 19:23:18'
'NETO','Ising Vision','Adder','2015-03-04 19:50:35'
'NETO','Ising Vision','Anaconda','2015-03-04 19:50:35'
'NETO','Ising Vision','Asp','2015-03-04 19:50:35'
Expand Down
Loading

0 comments on commit be2af91

Please sign in to comment.