Skip to content

Commit

Permalink
Added --reverse option to rares command
Browse files Browse the repository at this point in the history
  • Loading branch information
kfsone committed Jan 1, 2015
1 parent 8ecb5df commit d40ac56
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 4 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ Work In Progress:
. (kfsone) "NOTE" now indicates a line that can be hidden using "-q",
. (kfsone) Deleted/Deprecated keys in .csv files are now warnings with "-i",
. (kfsone) command names can now be partial, e.g. "loc" for "local",
"ra", "rar" or "rare" for "rares"
"ra", "rar" or "rare" for "rares"
. (kfsone) Show stationLS and pad size in rares display
. (kfsone) Added "--stations" option to "nav" command to show station details,
. (kfsone) Added "--reverse" to "rares" command, to make it easier to find
far away alternatives:
$ trade.py rare --near neto --ly 160 --reverse --limit 10

v6.4.0 Jan 01 2015
. (kfsone) Added "rare" sub-command,
Expand Down
15 changes: 14 additions & 1 deletion commands/rares_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
help='Maximum distance to search.',
metavar='LY',
type=float,
default=42,
default=180,
dest='maxLyPer',
),
ParseArgument('--limit',
Expand All @@ -34,6 +34,12 @@
default=False,
dest='sortByPrice',
),
ParseArgument('--reverse', '-r',
help='Reverse the list.',
action='store_true',
default=False,
dest='sortByPrice',
),
]

######################################################################
Expand All @@ -60,6 +66,10 @@ def run(results, cmdenv, tdb):
row.dist = math.sqrt(dist)
results.rows.append(row)

if not results:
print("No matches found.")
return None

if cmdenv.sortByPrice:
results.rows.sort(key=lambda row: row.dist)
results.rows.sort(key=lambda row: row.rare.costCr, reverse=True)
Expand All @@ -68,6 +78,9 @@ def run(results, cmdenv, tdb):
results.rows.sort(key=lambda row: row.rare.costCr, reverse=True)
results.rows.sort(key=lambda row: row.dist)

if cmdenv.reverse:
results.rows.reverse()

limit = cmdenv.limit or 0
if limit > 0:
results.rows = results.rows[:limit]
Expand Down

0 comments on commit d40ac56

Please sign in to comment.