formats stock row
432764
def __get_stock_row(self, stock: Stock, depth: int) -> str:
        
        assert isinstance(stock, Stock)

        view_model = AssetAllocationViewModel()

        view_model.depth = depth

        # Symbol
        view_model.name = stock.symbol

        # Current allocation
        view_model.curr_allocation = stock.curr_alloc

        # Value in base currency
        view_model.curr_value = stock.value_in_base_currency

        # Value in security's currency.
        view_model.curr_value_own_currency = stock.value
        view_model.own_currency = stock.currency

        return view_model
1062144
public function formatRow()
    {
        // execute CompleteLister row formating
        parent::formatRow();

        if (empty($this->columns)) {
            throw $this->exception('No columns defined for grid');
        }

        foreach ($this->columns as $field => $column) {
            if ((is_array($this->current_row) || $this->current_row instanceof ArrayAccess)
                && array_key_exists($field, $this->current_row)
            ) {
                $this->current_row[$field.'_original'] = $this->current_row[$field];
            }

            // if model field has listData structure, then get value instead of key
            if ($this->model && $f = $this->model->hasElement($field)) {
                $v = $this->current_row[$field];

                if ($this->model instanceof \atk4\data\Model) {
                    /** @type \atk4\data\Field $f */
                    if (isset($f->enum) && $values = $f->enum) {
                        $this->current_row[$field] = isset($f->ui['valueList'][$v])
                            ? $f->ui['valueList'][$v]
                            : $values[$v];
                    }
                } else {
                    /** @type Field $f */
                    if ($f->type() !== 'boolean' && $values = $f->listData()) {
                        $this->current_row[$field] = $values[$v];
                    }
                }
            }

            // process formatters
            $this->executeFormatters($field, $column, 'format_');

            // setting cell parameters (tdparam)
            $this->applyTDParams($field);
        }
    }
481472
def Cmd_display(self):
    
    re = "%(stock_no)s %(stock_name)s %(stock_date)s %(stock_price)s %(stock_range)s %(stock_range_per).2f%% %(RABC)s %(stock_vol)s" % {
        'stock_name': unicode(self.stock_name),
        'stock_no': unicode(self.stock_no),
        'stock_date': unicode(self.data_date[-1]),
        'stock_price': unicode(self.raw_data[-1]),
        'stock_range': unicode(self.stock_range[-1]),
        'stock_range_per': self.range_per,
        'stock_vol': self.stock_vol[-1]/1000,
        'RABC': self.RABC
      }
    return re
1137389
def output(self):
    #re = "{%(time)s} %(name)s %(stock_no)s %(c)s %(range)+.2f(%(pp)+.2f%%) %(value)s" % {
    '''
    
    '''
    if covstr(self.g['range']) > 0:
      css = "red"
    elif covstr(self.g['range']) < 0:
      css = "green"
    else:
      css = "gray"

    re = {
      'name': self.g['name'],
      'stock_no': self.g['no'],
      'time': self.g['time'],
      'open': self.g['open'],
      'h': self.g['h'],
      'l': self.g['l'],
      'c': self.g['c'],
      'max': self.g['max'],
      'min': self.g['min'],
      'range': covstr(self.g['range']),
      'ranges': self.g['ranges'],
      'value': self.g['value'],
      'pvalue': self.g['pvalue'],
      'pp': covstr(self.g['pp']),
      'top5buy': self.g['top5buy'],
      'top5sell': self.g['top5sell'],
      'crosspic': self.g['crosspic'],
      'css': css
    }
    return re
1285162
def columnise(rows, padding=2):
    """"""
    strs = []
    maxwidths = {}

    for row in rows:
        for i, e in enumerate(row):
            se = str(e)
            nse = len(se)
            w = maxwidths.get(i, -1)
            if nse > w:
                maxwidths[i] = nse

    for row in rows:
        s = ''
        for i, e in enumerate(row):
            se = str(e)
            if i < len(row) - 1:
                n = maxwidths[i] + padding - len(se)
                se += ' ' * n
            s += se
        strs.append(s)
    return strs
129912
def _build_simple_row(padded_cells, rowfmt):
    ""
    begin, sep, end = rowfmt
    return (begin + sep.join(padded_cells) + end).rstrip()
585764
def format_row(self, row, key, color):
        
        value = row[key]

        if isinstance(value, bool) or value is None:
            return '+' if value else ''

        if not isinstance(value, Number):
            return value

        # determine if integer value
        is_integer = float(value).is_integer()
        template = '{}' if is_integer else '{:' + self.floatfmt + '}'

        # if numeric, there could be a 'best' key
        key_best = key + '_best'
        if (key_best in row) and row[key_best]:
            template = color + template + Ansi.ENDC.value
        return template.format(value)
1325501
def _render_rows(self):
        
        _datas = getattr(self, '_datas', ())
        headers = getattr(self, 'headers', ())
        for index, row in enumerate(_datas):
            row_number = index + 2
            for col_num, value in enumerate(row):
                cell = self.worksheet.cell(row=row_number, column=col_num + 1)
                if value is not None:
                    cell.value = value
                else:
                    cell.value = ""
                if len(headers) > col_num:
                    header = headers[col_num]
                    format = get_cell_format(header)
                    if format is not None:
                        cell.number_format = format
75691
def process_row(cls, data, column_map):
        """"""
        row = {}
        for key,value in data.iteritems():
            if not value:
                value = '-'                
            elif isinstance(value, list):
                value = value[1]
            elif isinstance(value, dict):
                if 'type_name' in value:
                    if 'UnixTimeStamp' in value['type_name']:
                        value = datetime.datetime.utcfromtimestamp(value['epoch'])
                        if value == datetime.datetime(1970, 1, 1, 0, 0):
                            value = '-'

            # Assume the value is somehow well formed when we get here
            row[column_map[key]] = value
        return row
610840
private String getRowFormat(List<Integer> widths) {
    StringBuilder rowFormat = new StringBuilder(spaces(this.indentation));
    for (int i=0; i< widths.size(); i++) {
      rowFormat.append("%");
      rowFormat.append(this.flags != null ? this.flags.get(i) : "");
      rowFormat.append(widths.get(i).toString());
      rowFormat.append("s");
      rowFormat.append(spaces(this.delimiterWidth));
    }
    rowFormat.append("\n");

    return rowFormat.toString();
  }
135232
def as_text(self, max_rows=0, sep=" | "):
        """"""
        if not max_rows or max_rows > self.num_rows:
            max_rows = self.num_rows
        omitted = max(0, self.num_rows - max_rows)
        labels = self._columns.keys()
        fmts = self._get_column_formatters(max_rows, False)
        rows = [[fmt(label, label=True) for fmt, label in zip(fmts, labels)]]
        for row in itertools.islice(self.rows, max_rows):
            rows.append([f(v, label=False) for v, f in zip(row, fmts)])
        lines = [sep.join(row) for row in rows]
        if omitted:
            lines.append('... ({} rows omitted)'.format(omitted))
        return '\n'.join([line.rstrip() for line in lines])
981521
def parse_row(line_num, line, header, column_idx, prev_fields, options)
      fields = LineParser::parse(line, options[:in_format], options[:split_on])
      return nil,nil if fields.compact == []
      if options[:pad_fields] and fields.size < header.size
        fields += [''] * (header.size - fields.size) 
      end
      fields = Formatter::strip_quotes(fields) if @strip_quotes
      fields = Formatter::transform_row_ids(@transform_ids, fields) if @transform_ids
      fields = Filter::apply_column_filter(fields,column_idx) 
      return nil,nil if fields.compact == []
      rowname = fields[0]
      data_fields = fields[@first_column..-1]
      if data_fields.size > 0
        return nil,nil if not Validator::valid_row?(line_num, data_fields, prev_fields)
        return nil,nil if not Filter::numeric(@num_filter,data_fields,header)
        return nil,nil if not Filter::generic(@filter,data_fields,header)
        (rowname, data_fields) = Rewrite::rewrite(@rewrite,rowname,data_fields)
      end
      return rowname, data_fields
    end
539631
private void display(ResultSet rows) {

    final int width1 = 38;
    final int width2 = 12;
    final int width3 = 30;
    final int width4 = 21;

    String format = "%-" + width1 + "s%-" + width2 + "s%-" + width3 + "s%-" + width4 + "s%n";

    // headings
    System.out.printf(format, "sensor_id", "date", "timestamp", "value");

    // separators
    drawLine(width1, width2, width3, width4);

    // data
    for (Row row : rows) {

      System.out.printf(
          format,
          row.getUuid("sensor_id"),
          row.getLocalDate("date"),
          row.getInstant("timestamp"),
          row.getDouble("value"));
    }
  }
1077125
function doRow(dataType, key, data, expand, expandCell){
    return format(
		ROW
		, doRowStyle(dataType, expand)
		, dataType
		, doCellLabelStyle(expandCell)
		, key
		, doCellStyle(expandCell)
		, data
	);
}
735571
def render_row(row_index, widths)
      @pad + @page_data.each_with_index.map do |column, index|
        column[row_index].to_s.ljust(widths[index])
      end.join(" ")
    end
948940
function formatFromProps(arr, props) {
  const { columns } = props;
  const displayList = [];
  for (let i = 0; i < columns.length; i += 1) {
    if (colFlags.indexOf(columns[i]) !== -1) {
      displayList.push(arr[colFlags.indexOf(columns[i])]);
    }
    if (columns[i] === 'YMDW') {
      addDayOfWeek(displayList[i], props);
    }
    if (columns[i] === 'YMD') {
      addDayOfWeek(displayList[i], props, false);
    }
  }
  return displayList;
}
680839
def unpack_rsp(cls, rsp_pb):
        """"""
        if rsp_pb.retType != RET_OK:
            return RET_ERROR, rsp_pb.retMsg, None

        raw_position_list = rsp_pb.s2c.positionList

        position_list = [{
                             "code": merge_trd_mkt_stock_str(rsp_pb.s2c.header.trdMarket, position.code),
                             "stock_name": position.name,
                             "qty": position.qty,
                             "can_sell_qty": position.canSellQty,
                             "cost_price": position.costPrice if position.HasField('costPrice') else 0,
                             "cost_price_valid": 1 if position.HasField('costPrice') else 0,
                             "market_val": position.val,
                             "nominal_price": position.price,
                             "pl_ratio": 100 * position.plRatio if position.HasField('plRatio') else 0,
                             "pl_ratio_valid": 1 if position.HasField('plRatio') else 0,
                             "pl_val": position.plVal if position.HasField('plVal') else 0,
                             "pl_val_valid": 1 if position.HasField('plVal') else 0,
                             "today_buy_qty": position.td_buyQty if position.HasField('td_buyQty') else 0,
                             "today_buy_val": position.td_buyVal if position.HasField('td_buyVal') else 0,
                             "today_pl_val": position.td_plVal if position.HasField('td_plVal') else 0,
                             "today_sell_qty": position.td_sellQty if position.HasField('td_sellQty') else 0,
                             "today_sell_val": position.td_sellVal if position.HasField('td_sellVal') else 0,
                             "position_side": TRADE.REV_POSITION_SIDE_MAP[position.positionSide]
                                if position.positionSide in TRADE.REV_POSITION_SIDE_MAP else PositionSide.NONE,
                         } for position in raw_position_list]
        return RET_OK, "", position_list