def format_floating_point_type(val, colormap, float_precision, decimal_sep=None, thousands_sep=None, **_): if math.isnan(val): bval = 'NaN' elif math.isinf(val): bval = 'Infinity' if val > 0 else '-Infinity' else: if thousands_sep: dpart, ipart = math.modf(val) bval = format_integer_with_thousands_sep(ipart, thousands_sep) dpart_str = ('%.*f' % (float_precision, math.fabs(dpart)))[2:].rstrip('0') if dpart_str: bval += '%s%s' % ('.' if not decimal_sep else decimal_sep, dpart_str) else: exponent = int(math.log10(abs(val))) if abs(val) > sys.float_info.epsilon else -sys.maxsize - 1 if -4 <= exponent < float_precision: # when this is true %g will not use scientific notation, # increasing precision should not change this decision # so we increase the precision to take into account the # digits to the left of the decimal point float_precision = float_precision + exponent + 1 bval = '%.*g' % (float_precision, val) if decimal_sep: bval = bval.replace('.', decimal_sep) return colorme(bval, colormap, 'float')
def format_by_type(cqltype, val, encoding, colormap=None, addcolor=False, nullval=None, date_time_format=None, float_precision=None): if nullval is None: nullval = default_null_placeholder if val is None: return colorme(nullval, colormap, 'error') if addcolor is False: colormap = empty_colormap elif colormap is None: colormap = default_colormap if date_time_format is None: date_time_format = DateTimeFormat() if float_precision is None: float_precision = default_float_precision return format_value(cqltype, val, encoding=encoding, colormap=colormap, date_time_format=date_time_format, float_precision=float_precision, nullval=nullval)
def format_field_value(v): if v is None: return colorme(nullval, colormap, 'error') return format_value(type(v), v, encoding=encoding, colormap=colormap, date_time_format=date_time_format, float_precision=float_precision, nullval=nullval, quote=True, decimal_sep=decimal_sep, thousands_sep=thousands_sep, boolean_styles=boolean_styles)
def format_field_value(v, t): if v is None: return colorme(nullval, colormap, 'error') return format_value(v, cqltype=t, encoding=encoding, colormap=colormap, date_time_format=date_time_format, float_precision=float_precision, nullval=nullval, quote=True, decimal_sep=decimal_sep, thousands_sep=thousands_sep, boolean_styles=boolean_styles)
def format_floating_point_type(val, colormap, float_precision, decimal_sep=None, thousands_sep=None, **_): if math.isnan(val): bval = 'NaN' elif math.isinf(val): bval = 'Infinity' if val > 0 else '-Infinity' else: if thousands_sep: dpart, ipart = math.modf(val) bval = format_integer_with_thousands_sep(ipart, thousands_sep) dpart_str = ('%.*f' % (float_precision, math.fabs(dpart)))[2:].rstrip('0') if dpart_str: bval += '%s%s' % ('.' if not decimal_sep else decimal_sep, dpart_str) else: exponent = int(math.log10(abs(val))) if abs( val) > sys.float_info.epsilon else -sys.maxsize - 1 if -4 <= exponent < float_precision: # when this is true %g will not use scientific notation, # increasing precision should not change this decision # so we increase the precision to take into account the # digits to the left of the decimal point float_precision = float_precision + exponent + 1 bval = '%.*g' % (float_precision, val) if decimal_sep: bval = bval.replace('.', decimal_sep) return colorme(bval, colormap, 'float')
def format_value_timestamp(val, colormap, date_time_format, quote=False, **_): bval = strftime(date_time_format.timestamp_format, calendar.timegm(val.utctimetuple()), timezone=date_time_format.timezone) if quote: bval = "'%s'" % bval return colorme(bval, colormap, 'timestamp')
def format_by_type(val, cqltype, encoding, colormap=None, addcolor=False, nullval=None, date_time_format=None, float_precision=None, decimal_sep=None, thousands_sep=None, boolean_styles=None): if nullval is None: nullval = default_null_placeholder if val is None: return colorme(nullval, colormap, 'error') if addcolor is False: colormap = empty_colormap elif colormap is None: colormap = default_colormap if date_time_format is None: date_time_format = DateTimeFormat() if float_precision is None: float_precision = default_float_precision return format_value(val, cqltype=cqltype, encoding=encoding, colormap=colormap, date_time_format=date_time_format, float_precision=float_precision, nullval=nullval, decimal_sep=decimal_sep, thousands_sep=thousands_sep, boolean_styles=boolean_styles)
def format_value_timestamp(val, colormap, date_time_format, quote=False, **_): tzless_dt = datetime_from_timestamp(calendar.timegm(val.utctimetuple())) \ + datetime.timedelta(microseconds=val.microsecond) bval = tzless_dt.replace(tzinfo=UTC()).strftime( date_time_format.timestamp_format) if quote: bval = "'%s'" % bval return colorme(bval, colormap, 'timestamp')
def format_value_timestamp(val, colormap, date_time_format, quote=False, **_): bval = strftime(date_time_format.timestamp_format, calendar.timegm(val.utctimetuple()), microseconds=val.microsecond, timezone=date_time_format.timezone) if quote: bval = "'%s'" % bval return colorme(bval, colormap, 'timestamp')
def format_field_value(v): if v is None: return colorme(nullval, colormap, 'error') return format_value(type(v), v, encoding=encoding, colormap=colormap, date_time_format=date_time_format, float_precision=float_precision, nullval=nullval, quote=True)
def format_value_timestamp(val, colormap, date_time_format, quote=False, **_): if isinstance(val, datetime.datetime): bval = strftime(date_time_format.timestamp_format, calendar.timegm(val.utctimetuple()), microseconds=val.microsecond, timezone=date_time_format.timezone) else: bval = str(val) if quote: bval = "'%s'" % bval return colorme(bval, colormap, 'timestamp')
def format_floating_point_type(val, colormap, float_precision, **_): if math.isnan(val): bval = 'NaN' elif math.isinf(val): bval = 'Infinity' if val > 0 else '-Infinity' else: exponent = int(math.log10(abs(val))) if abs(val) > sys.float_info.epsilon else -sys.maxsize - 1 if -4 <= exponent < float_precision: # when this is true %g will not use scientific notation, # increasing precision should not change this decision # so we increase the precision to take into account the # digits to the left of the decimal point float_precision = float_precision + exponent + 1 bval = '%.*g' % (float_precision, val) return colorme(bval, colormap, 'float')
def format_floating_point_type(val, colormap, float_precision, **_): if math.isnan(val): bval = 'NaN' elif math.isinf(val): bval = 'Infinity' if val > 0 else '-Infinity' else: exponent = int(math.log10(abs(val))) if abs(val) > sys.float_info.epsilon else -sys.maxint - 1 if -4 <= exponent < float_precision: # when this is true %g will not use scientific notation, # increasing precision should not change this decision # so we increase the precision to take into account the # digits to the left of the decimal point float_precision = float_precision + exponent + 1 bval = '%.*g' % (float_precision, val) return colorme(bval, colormap, 'float')
def format_python_formatted_type(val, colormap, color, quote=False): bval = str(val) if quote: bval = "'%s'" % bval return colorme(bval, colormap, color)
def format_value_blob(val, colormap, **_): bval = '0x' + binascii.hexlify(val) return colorme(bval, colormap, 'blob')
def format_integer_type(val, colormap, **_): # base-10 only for now; support others? bval = str(val) return colorme(bval, colormap, 'int')
def format_value_timestamp(val, colormap, time_format, quote=False, **_): bval = strftime(time_format, calendar.timegm(val.utctimetuple())) if quote: bval = "'%s'" % bval return colorme(bval, colormap, 'timestamp')
def format_integer_type(val, colormap, thousands_sep=None, **_): # base-10 only for now; support others? bval = format_integer_with_thousands_sep( val, thousands_sep) if thousands_sep else str(val) return colorme(bval, colormap, 'int')
def format_integer_type(val, colormap, thousands_sep=None, **_): # base-10 only for now; support others? bval = format_integer_with_thousands_sep(val, thousands_sep) if thousands_sep else str(val) return colorme(bval, colormap, 'int')