from datetime import datetime

B_TO_G = 1073741824.0
B_TO_M = 1048576.0
B_TO_K = 1024.0


def format_time(value, date_format='%Y-%m-%d %H:%M:%S'):
    dt = datetime.fromtimestamp(int(value))
    return dt.strftime(date_format)


def format_size(value):
    tmp = value / B_TO_G
    if tmp < 1.0:
        tmp = value / B_TO_M
        if tmp < 1.0:
            tmp = value / B_TO_K
            return "%s K" % round(tmp, 2)
        return "%s M" % round(tmp, 2)
    return "%s G" % round(tmp, 2)

@@ -22,16 +22,64 @@
 datetime
+%0Afrom tools import socket_families, socket_types
 %0A%0AB_TO_G
@@ -519,24 +519,285 @@
  %22%25s G%22 %25 round(tmp, 2)%0A
+%0A%0Adef socket_family(value):%0A    return socket_families%5Bvalue%5D%0A%0A%0Adef socket_type(value):%0A    return socket_types%5Bvalue%5D%0A%0A%0Adef format_addr_port(value):%0A    if value:%0A        result = value%5B0%5D + ':' + str(value%5B1%5D)%0A    else:%0A        result = ''%0A%0A    return result%0A

格式化地址、socket family、socket type 的过滤器