예제 #1
0
def render(results, cmdenv, tdb):
    mode = results.summary.mode
    singleMode = len(results.summary.queries) == 1
    maxStnLen = max_len(results.rows, key=lambda row: row.station.name())

    stnRowFmt = RowFormat()
    stnRowFmt.addColumn('Station', '<', maxStnLen,
            key=lambda row: row.station.name())
    if not singleMode:
        maxItmLen = max_len(results.rows, key=lambda row: row.item.name())
        stnRowFmt.addColumn(results.summary.mode, '<', maxItmLen,
                key=lambda row: row.item.name()
        )
    if mode is not SHIP_MODE or not singleMode:
        stnRowFmt.addColumn('Cost', '>', 10, 'n',
                key=lambda row: row.price)
    if mode is not SHIP_MODE:
        stnRowFmt.addColumn('Units', '>', 10,
                key=lambda row: '{:n}'.format(row.units) if row.units >= 0 else '?')

    if cmdenv.nearSystem:
        stnRowFmt.addColumn('DistLy', '>', 6, '.2f',
                key=lambda row: row.dist)

    if mode is not SHIP_MODE:
        stnRowFmt.addColumn('Age/days', '>', 7,
                key=lambda row: row.age)
    stnRowFmt.addColumn("StnLs", '>', 10,
            key=lambda row: row.station.distFromStar())
    stnRowFmt.addColumn('B/mkt', '>', 4,
            key=lambda row: TradeDB.marketStates[row.station.blackMarket])
    stnRowFmt.addColumn("Pad", '>', '3',
            key=lambda row: TradeDB.padSizes[row.station.maxPadSize])

    if not cmdenv.quiet:
        heading, underline = stnRowFmt.heading()
        print(heading, underline, sep='\n')

    for row in results.rows:
        print(stnRowFmt.format(row))

    if singleMode and cmdenv.detail:
        print("{:{lnl}} {:>10n}".format(
                "-- Ship Cost" if mode is SHIP_MODE else "-- Average",
                results.summary.avg,
                lnl=maxStnLen,
        ))
예제 #2
0
def render(results, cmdenv, tdb):
    from formatting import RowFormat, ColumnFormat, max_len

    longestNameLen = max_len(results.rows,
                             key=lambda row: row.item.name(cmdenv.detail))

    rowFmt = RowFormat()
    rowFmt.addColumn('Item',
                     '<',
                     longestNameLen,
                     key=lambda row: row.item.name(cmdenv.detail))
    rowFmt.addColumn('Profit', '>', 10, 'n', key=lambda row: row.gainCr)
    rowFmt.addColumn('Cost', '>', 10, 'n', key=lambda row: row.costCr)
    if cmdenv.detail > 1:
        rowFmt.addColumn('AvgCost',
                         '>',
                         10,
                         key=lambda row: tdb.avgSelling.get(row.item.ID, 0))
        rowFmt.addColumn('Buying',
                         '>',
                         10,
                         key=lambda row: row.costCr + row.gainCr)
        rowFmt.addColumn('AvgBuy',
                         '>',
                         10,
                         key=lambda row: tdb.avgBuying.get(row.item.ID, 0))

    if cmdenv.detail:
        rowFmt.addColumn('Supply',
                         '>',
                         10,
                         key=lambda row: '{:n}'.format(row.supply)
                         if row.supply >= 0 else '?')
        rowFmt.addColumn('Demand',
                         '>',
                         10,
                         key=lambda row: '{:n}'.format(row.demand)
                         if row.demand >= 0 else '?')
        rowFmt.addColumn('SrcAge',
                         '>',
                         8,
                         '.2f',
                         key=lambda row: (row.srcAge / 86400))
        rowFmt.addColumn('DstAge',
                         '>',
                         8,
                         '.2f',
                         key=lambda row: (row.dstAge / 86400))

    if not cmdenv.quiet:
        heading, underline = rowFmt.heading()
        print(heading, underline, sep='\n')

    for row in results.rows:
        print(rowFmt.format(row))
def render(results, cmdenv, tdb):
    if not results or not results.rows:
        raise CommandLineError("No ships available at {}".format(results.summary.station.name()))

    maxShipLen = max_len(results.rows, key=lambda row: row.ship.name())

    rowFmt = (
        RowFormat()
        .append(ColumnFormat("Ship", "<", maxShipLen, key=lambda row: row.ship.name()))
        .append(ColumnFormat("Cost", ">", 12, "n", key=lambda row: row.ship.cost))
    )

    if not cmdenv.quiet:
        heading, underline = rowFmt.heading()
        print(heading, underline, sep="\n")

    for row in results.rows:
        print(rowFmt.format(row))
예제 #4
0
def render(results, cmdenv, tdb):
    if not results or not results.rows:
        raise CommandLineError("No ships available at {}".format(
            results.summary.station.name()))

    maxShipLen = max_len(results.rows, key=lambda row: row.ship.name())

    rowFmt = RowFormat().append(
        ColumnFormat("Ship", '<', maxShipLen,
                     key=lambda row: row.ship.name())).append(
                         ColumnFormat("Cost",
                                      '>',
                                      12,
                                      'n',
                                      key=lambda row: row.ship.cost))

    if not cmdenv.quiet:
        heading, underline = rowFmt.heading()
        print(heading, underline, sep='\n')

    for row in results.rows:
        print(rowFmt.format(row))
예제 #5
0
def render(results, cmdenv, tdb):
    """
    If the "run" command returned a result set and we are running
    from the command line, this function will be called to generate
    the output of the command.
    """

    if not results.rows:
        raise CommandLineError("No items found.")

    # Calculate the longest station and rareitem name in our list.
    longestStnNameLen = max_len(results.rows,
                                key=lambda row: row.rare.station.name())
    longestRareNameLen = max_len(results.rows,
                                 key=lambda row: row.rare.name(cmdenv.detail))

    # Use the formatting system to describe what our
    # output rows are going to look at (see formatting.py)
    rowFmt = RowFormat()
    rowFmt.addColumn('Station',
                     '<',
                     longestStnNameLen,
                     key=lambda row: row.rare.station.name())
    rowFmt.addColumn('Rare',
                     '<',
                     longestRareNameLen,
                     key=lambda row: row.rare.name(cmdenv.detail))
    rowFmt.addColumn('Cost', '>', 10, 'n', key=lambda row: row.rare.costCr)
    rowFmt.addColumn('DistLy', '>', 6, '.2f', key=lambda row: row.dist)
    rowFmt.addColumn('Alloc', '>', 6, 'n', key=lambda row: row.rare.maxAlloc)
    rowFmt.addColumn('B/mkt',
                     '>',
                     4,
                     key=lambda row: TradeDB.marketStates[row.rare.illegal])
    rowFmt.addColumn("StnLs",
                     '>',
                     10,
                     key=lambda row: row.rare.station.distFromStar())
    rowFmt.addColumn(
        'B/mkt',
        '>',
        4,
        key=lambda row: TradeDB.marketStates[row.rare.station.blackMarket])
    rowFmt.addColumn(
        "Pad",
        '>',
        '3',
        key=lambda row: TradeDB.padSizes[row.rare.station.maxPadSize])
    rowFmt.addColumn(
        "Plt",
        '>',
        '3',
        key=lambda row: TradeDB.planetStates[row.rare.station.planetary])

    # Print a heading summary if the user didn't use '-q'
    if not cmdenv.quiet:
        heading, underline = rowFmt.heading()
        print(heading, underline, sep='\n')

    # Print out our results.
    for row in results.rows:
        print(rowFmt.format(row))
예제 #6
0
def render(results, cmdenv, tdb):
    system, station = results.summary.system, results.summary.station

    if cmdenv.detail:
        sysDetail = "(#{} @ {},{},{})".format(system.ID, system.posX,
                                              system.posY, system.posZ)
    else:
        sysDetail = "(#{})".format(system.ID)

    print("Station Data:")
    print("System....:", system.name(), sysDetail)
    print("Station...:", station.dbname, "(#{})".format(station.ID))

    if cmdenv.detail:
        siblings = ", ".join(stn.dbname for stn in system.stations
                             if stn is not station)
        if siblings:
            print("Also Here.:", siblings)

    ls = station.distFromStar()
    if cmdenv.detail and ls == '?':
        ls = '0 [unknown]'
    print("Stn/Ls....:", ls)

    def _detail(value, source):
        detail = source[value]
        if cmdenv.detail and detail == '?':
            detail += ' [unknown]'
        return detail

    print("Pad Size..:", _detail(station.maxPadSize, TradeDB.padSizes))
    print("Market....:", _detail(station.market, TradeDB.marketStates))
    print("B/Market..:", _detail(station.blackMarket, TradeDB.marketStates))
    print("Shipyard..:", _detail(station.shipyard, TradeDB.marketStates))
    print("Outfitting:", _detail(station.outfitting, TradeDB.marketStates))
    print("Rearm.....:", _detail(station.rearm, TradeDB.marketStates))
    print("Refuel....:", _detail(station.refuel, TradeDB.marketStates))
    print("Repair....:", _detail(station.repair, TradeDB.marketStates))
    print("Planetary.:", _detail(station.planetary, TradeDB.planetStates))
    print("Prices....:", station.itemCount or 'None')

    if station.itemCount == 0:
        return

    newest, oldest = tdb.query(
        """
            SELECT JULIANDAY('NOW') - JULIANDAY(MAX(si.modified)),
                   JULIANDAY('NOW') - JULIANDAY(MIN(si.modified))
              FROM StationItem si
             WHERE station_id = ?
    """, [station.ID]).fetchone()
    if newest or oldest:
        # less than a quarter hour difference? ignore?
        if abs(newest - oldest) < (1 / (24 * 4)):
            pricesAge = "{:.2f} days".format(oldest)
        else:
            pricesAge = "{:.2f}-{:.2f} days".format(newest, oldest)
    else:
        pricesAge = "[n/a]"

    print("Price Age.:", pricesAge)

    def makeBest(rows, explanation, alt, maxLen, starFn):
        if not rows:
            return "[n/a]"
        best = []
        for irow in rows:
            star = '*' if starFn(irow.price, irow.avgTrade) else ''
            best.append([irow, star])

        if not cmdenv.detail:
            return ', '.join(irow[0].item.name() + irow[1] for irow in best)

        bestText = "(" + explanation + ")"
        for irow in best:
            bestText += "\n    {:<{len}} @ {:7n}cr (Avg {} {:7n}cr)".format(
                irow[0].item.name(cmdenv.detail) + irow[1],
                irow[0].price,
                alt,
                irow[0].avgTrade,
                len=maxLen + 1,
            )
        return bestText

    longestNameLen = max(
        max_len(results.summary.selling,
                key=lambda row: row.item.name(cmdenv.detail)),
        max_len(results.summary.buying,
                key=lambda row: row.item.name(cmdenv.detail)),
    )
    print("Best Buy..:", makeBest(
            results.summary.selling, "Buy from this station", "Sell", longestNameLen,
            starFn=lambda price, avgCr: \
                price <= (avgCr * 0.9),
    ))
    print("Best Sale.:", makeBest(
            results.summary.buying, "Sell to this station", "Cost", longestNameLen,
            starFn=lambda price, avgCr: \
                price >= (avgCr * 1.1),
    ))
예제 #7
0
def render(results, cmdenv, tdb):
    mode = results.summary.mode
    singleMode = len(results.summary.queries) == 1
    maxStnLen = max_len(results.rows, key=lambda row: row.station.name())

    stnRowFmt = RowFormat()
    stnRowFmt.addColumn('Station',
                        '<',
                        maxStnLen,
                        key=lambda row: row.station.name())
    if not singleMode:
        maxItmLen = max_len(results.rows,
                            key=lambda row: row.item.name(cmdenv.detail))
        stnRowFmt.addColumn(results.summary.mode,
                            '<',
                            maxItmLen,
                            key=lambda row: row.item.name(cmdenv.detail))
    if mode is not SHIP_MODE or not singleMode:
        stnRowFmt.addColumn('Cost', '>', 10, 'n', key=lambda row: row.price)
    if mode is not SHIP_MODE:
        stnRowFmt.addColumn('Units',
                            '>',
                            10,
                            key=lambda row: '{:n}'.format(row.units)
                            if row.units >= 0 else '?')

    if cmdenv.nearSystem:
        stnRowFmt.addColumn('DistLy', '>', 6, '.2f', key=lambda row: row.dist)

    if mode is not SHIP_MODE:
        stnRowFmt.addColumn('Age/days', '>', 7, key=lambda row: row.age)
    stnRowFmt.addColumn("StnLs",
                        '>',
                        10,
                        key=lambda row: row.station.distFromStar())
    stnRowFmt.addColumn(
        'B/mkt',
        '>',
        4,
        key=lambda row: TradeDB.marketStates[row.station.blackMarket])
    stnRowFmt.addColumn(
        "Pad",
        '>',
        '3',
        key=lambda row: TradeDB.padSizes[row.station.maxPadSize])
    stnRowFmt.addColumn(
        "Plt",
        '>',
        '3',
        key=lambda row: TradeDB.planetStates[row.station.planetary])

    if not cmdenv.quiet:
        heading, underline = stnRowFmt.heading()
        print(heading, underline, sep='\n')

    for row in results.rows:
        print(stnRowFmt.format(row))

    if singleMode and cmdenv.detail:
        print("{:{lnl}} {:>10n}".format(
            "-- Ship Cost" if mode is SHIP_MODE else "-- Average",
            results.summary.avg,
            lnl=maxStnLen,
        ))
예제 #8
0
def render(results, cmdenv, tdb):
    if not results or not results.rows:
        raise TradeException("No systems found within {}ly of {}.".format(
            results.summary.ly, results.summary.near.name()))

    # Compare system names so we can tell
    maxSysLen = max_len(results.rows, key=lambda row: row.system.name())

    sysRowFmt = RowFormat().append(
        ColumnFormat("System",
                     '<',
                     maxSysLen,
                     key=lambda row: row.system.name())).append(
                         ColumnFormat("Dist",
                                      '>',
                                      '7',
                                      '.2f',
                                      key=lambda row: row.dist))

    showStations = cmdenv.detail
    if showStations:
        maxStnLen = max_len(chain.from_iterable(row.stations
                                                for row in results.rows),
                            key=lambda row: row.station.dbname)
        maxLsLen = max_len(chain.from_iterable(row.stations
                                               for row in results.rows),
                           key=lambda row: row.station.distFromStar())
        maxLsLen = max(maxLsLen, 5)
        stnRowFmt = RowFormat(prefix='  /  ').append(
                ColumnFormat("Station", '.<', maxStnLen + 2,
                    key=lambda row: row.station.dbname)
        ).append(
                ColumnFormat("StnLs", '>', maxLsLen,
                    key=lambda row: row.station.distFromStar())
        ).append(
                ColumnFormat("Age/days", '>', 7,
                        key=lambda row: row.age)
        ).append(
                ColumnFormat("Mkt", '>', '3',
                    key=lambda row: \
                        TradeDB.marketStates[row.station.market])
        ).append(
                ColumnFormat("BMk", '>', '3',
                    key=lambda row: \
                        TradeDB.marketStates[row.station.blackMarket])
        ).append(
                ColumnFormat("Shp", '>', '3',
                    key=lambda row: \
                        TradeDB.marketStates[row.station.shipyard])
        ).append(
                ColumnFormat("Out", '>', '3',
                    key=lambda row: \
                        TradeDB.marketStates[row.station.outfitting])
        ).append(
                ColumnFormat("Arm", '>', '3',
                    key=lambda row: \
                        TradeDB.marketStates[row.station.rearm])
        ).append(
                ColumnFormat("Ref", '>', '3',
                    key=lambda row: \
                        TradeDB.marketStates[row.station.refuel])
        ).append(
                ColumnFormat("Rep", '>', '3',
                    key=lambda row: \
                        TradeDB.marketStates[row.station.repair])
        ).append(
                ColumnFormat("Pad", '>', '3',
                    key=lambda row: \
                        TradeDB.padSizes[row.station.maxPadSize])
        ).append(
                ColumnFormat("Plt", '>', '3',
                    key=lambda row: \
                        TradeDB.planetStates[row.station.planetary])
        )
        if cmdenv.detail > 1:
            stnRowFmt.append(
                ColumnFormat("Itms",
                             ">",
                             4,
                             key=lambda row: row.station.itemCount))

    cmdenv.DEBUG0(
        "Systems within {ly:<5.2f}ly of {sys}.\n",
        sys=results.summary.near.name(),
        ly=results.summary.ly,
    )

    if not cmdenv.quiet:
        heading, underline = sysRowFmt.heading()
        if showStations:
            print(heading)
            heading, underline = stnRowFmt.heading()
        print(heading, underline, sep='\n')

    for row in results.rows:
        print(sysRowFmt.format(row))
        for stnRow in row.stations:
            print(stnRowFmt.format(stnRow))
예제 #9
0
def render(results, cmdenv, tdb):
    if not results or not results.rows:
        raise TradeException(
            "No systems found within {}ly of {}."
            .format(results.summary.ly, results.summary.near.name())
        )

    # Compare system names so we can tell
    maxSysLen = max_len(results.rows, key=lambda row: row.system.name())

    sysRowFmt = RowFormat().append(
        ColumnFormat("System", '<', maxSysLen,
                key=lambda row: row.system.name())
    ).append(
        ColumnFormat("Dist", '>', '7', '.2f',
                key=lambda row: row.dist)
    )

    showStations = cmdenv.detail
    if showStations:
        maxStnLen = max_len(
            chain.from_iterable(row.stations for row in results.rows),
            key=lambda row: row.station.dbname
        )
        maxLsLen = max_len(
            chain.from_iterable(row.stations for row in results.rows),
            key=lambda row: row.station.distFromStar()
        )
        maxLsLen = max(maxLsLen, 5)
        stnRowFmt = RowFormat(prefix='  /  ').append(
                ColumnFormat("Station", '.<', maxStnLen + 2,
                    key=lambda row: row.station.dbname)
        ).append(
                ColumnFormat("StnLs", '>', maxLsLen,
                    key=lambda row: row.station.distFromStar())
        ).append(
                ColumnFormat("Age/days", '>', 7,
                        key=lambda row: row.age)
        ).append(
                ColumnFormat("Mkt", '>', '3',
                    key=lambda row: \
                        TradeDB.marketStates[row.station.market])
        ).append(
                ColumnFormat("BMk", '>', '3',
                    key=lambda row: \
                        TradeDB.marketStates[row.station.blackMarket])
        ).append(
                ColumnFormat("Shp", '>', '3',
                    key=lambda row: \
                        TradeDB.marketStates[row.station.shipyard])
        ).append(
                ColumnFormat("Out", '>', '3',
                    key=lambda row: \
                        TradeDB.marketStates[row.station.outfitting])
        ).append(
                ColumnFormat("Arm", '>', '3',
                    key=lambda row: \
                        TradeDB.marketStates[row.station.rearm])
        ).append(
                ColumnFormat("Ref", '>', '3',
                    key=lambda row: \
                        TradeDB.marketStates[row.station.refuel])
        ).append(
                ColumnFormat("Rep", '>', '3',
                    key=lambda row: \
                        TradeDB.marketStates[row.station.repair])
        ).append(
                ColumnFormat("Pad", '>', '3',
                    key=lambda row: \
                        TradeDB.padSizes[row.station.maxPadSize])
        )
        if cmdenv.detail > 1:
            stnRowFmt.append(
                ColumnFormat("Itms", ">", 4,
                    key=lambda row: row.station.itemCount)
            )

    cmdenv.DEBUG0(
        "Systems within {ly:<5.2f}ly of {sys}.\n",
        sys=results.summary.near.name(),
        ly=results.summary.ly,
    )

    if not cmdenv.quiet:
        heading, underline = sysRowFmt.heading()
        if showStations:
            print(heading)
            heading, underline = stnRowFmt.heading()
        print(heading, underline, sep='\n')

    for row in results.rows:
        print(sysRowFmt.format(row))
        for stnRow in row.stations:
            print(stnRowFmt.format(stnRow))