Ejemplo n.º 1
0
def print_header(opts):
    header = ["datetimestamp_utc"]

    def header_add(names):
        for name in names:
            name, start, end = dish_common.BRACKETS_RE.match(name).group(
                1, 4, 5)
            if start:
                header.extend(name + "_" + str(x)
                              for x in range(int(start), int(end)))
            elif end:
                header.extend(name + "_" + str(x) for x in range(int(end)))
            else:
                header.append(name)

    if opts.satus_mode:
        context = starlink_grpc.ChannelContext(target=opts.target)
        try:
            name_groups = starlink_grpc.status_field_names(context=context)
        except starlink_grpc.GrpcError as e:
            dish_common.conn_error(
                opts, "Failure reflecting status field names: %s", str(e))
            return 1
        if "status" in opts.mode:
            header_add(name_groups[0])
        if "obstruction_detail" in opts.mode:
            header_add(name_groups[1])
        if "alert_detail" in opts.mode:
            header_add(name_groups[2])

    if opts.bulk_mode:
        general, bulk = starlink_grpc.history_bulk_field_names()
        header_add(general)
        header_add(bulk)

    if opts.history_stats_mode:
        groups = starlink_grpc.history_stats_field_names()
        general, ping, runlen, latency, loaded, usage = groups[0:6]
        header_add(general)
        if "ping_drop" in opts.mode:
            header_add(ping)
        if "ping_run_length" in opts.mode:
            header_add(runlen)
        if "ping_loaded_latency" in opts.mode:
            header_add(loaded)
        if "ping_latency" in opts.mode:
            header_add(latency)
        if "usage" in opts.mode:
            header_add(usage)

    print(",".join(header))
    return 0
def create_tables(conn, context, suffix):
    tables = {}
    name_groups = starlink_grpc.status_field_names(context=context)
    type_groups = starlink_grpc.status_field_types(context=context)
    tables["status"] = zip(name_groups, type_groups)

    name_groups = starlink_grpc.history_stats_field_names()
    type_groups = starlink_grpc.history_stats_field_types()
    tables["ping_stats"] = zip(name_groups[0:5], type_groups[0:5])
    tables["usage"] = ((name_groups[5], type_groups[5]), )

    name_groups = starlink_grpc.history_bulk_field_names()
    type_groups = starlink_grpc.history_bulk_field_types()
    tables["history"] = ((name_groups[1], type_groups[1]), (["counter"], [int
                                                                          ]))

    def sql_type(type_class):
        if issubclass(type_class, float):
            return "REAL"
        if issubclass(type_class, bool):
            # advisory only, stores as int:
            return "BOOLEAN"
        if issubclass(type_class, int):
            return "INTEGER"
        if issubclass(type_class, str):
            return "TEXT"
        raise TypeError

    column_info = {}
    cur = conn.cursor()
    for table, group_pairs in tables.items():
        column_names = ["time", "id"]
        columns = ['"time" INTEGER NOT NULL', '"id" TEXT NOT NULL']
        for name_group, type_group in group_pairs:
            for name_item, type_item in zip(name_group, type_group):
                name_item = dish_common.BRACKETS_RE.match(name_item).group(1)
                if name_item != "id":
                    columns.append('"{0}" {1}'.format(name_item,
                                                      sql_type(type_item)))
                    column_names.append(name_item)
        cur.execute('DROP TABLE IF EXISTS "{0}{1}"'.format(table, suffix))
        sql = 'CREATE TABLE "{0}{1}" ({2}, PRIMARY KEY("time","id"))'.format(
            table, suffix, ", ".join(columns))
        cur.execute(sql)
        column_info[table] = column_names
    cur.close()

    return column_info
Ejemplo n.º 3
0
def print_header(opts):
    header = ["datetimestamp_utc"]

    def header_add(names):
        for name in names:
            name, start, end = dish_common.BRACKETS_RE.match(name).group(1, 4, 5)
            if start:
                header.extend(name + "_" + str(x) for x in range(int(start), int(end)))
            elif end:
                header.extend(name + "_" + str(x) for x in range(int(end)))
            else:
                header.append(name)

    if opts.satus_mode:
        status_names, obstruct_names, alert_names = starlink_grpc.status_field_names()
        if "status" in opts.mode:
            header_add(status_names)
        if "obstruction_detail" in opts.mode:
            header_add(obstruct_names)
        if "alert_detail" in opts.mode:
            header_add(alert_names)

    if opts.bulk_mode:
        general, bulk = starlink_grpc.history_bulk_field_names()
        header_add(general)
        header_add(bulk)

    if opts.ping_mode:
        general, ping, runlen = starlink_grpc.history_ping_field_names()
        header_add(general)
        if "ping_drop" in opts.mode:
            header_add(ping)
        if "ping_run_length" in opts.mode:
            header_add(runlen)

    print(",".join(header))