Correct CSV and sqlite support for location group

Add CSV header and sqlite schema support for the newly added location group, along with the necessary functions in the starlink_grpc module to expose the field names and types for that group. This really should have gone in with the prior change.

Also, correct the order of the ping_latency and ping_loaded_latency groups in the CSV header, which was backwards. This would have resulted in an incorrect CSV header if both those groups were selected.
This commit is contained in:
sparky8512 2022-09-10 16:12:05 -07:00
parent 29699f0f59
commit 8650687f69
3 changed files with 42 additions and 17 deletions

View file

@ -46,7 +46,7 @@ import time
import dish_common import dish_common
import starlink_grpc import starlink_grpc
SCHEMA_VERSION = 3 SCHEMA_VERSION = 4
class Terminated(Exception): class Terminated(Exception):
@ -208,8 +208,10 @@ def ensure_schema(opts, conn, context):
def create_tables(conn, context, suffix): def create_tables(conn, context, suffix):
tables = {} tables = {}
name_groups = starlink_grpc.status_field_names(context=context) name_groups = (starlink_grpc.status_field_names(context=context) +
type_groups = starlink_grpc.status_field_types(context=context) (starlink_grpc.location_field_names(),))
type_groups = (starlink_grpc.status_field_types(context=context) +
(starlink_grpc.location_field_types(),))
tables["status"] = zip(name_groups, type_groups) tables["status"] = zip(name_groups, type_groups)
name_groups = starlink_grpc.history_stats_field_names() name_groups = starlink_grpc.history_stats_field_names()

View file

@ -128,18 +128,21 @@ def print_header(opts, print_file):
header.append(name) header.append(name)
if opts.status_mode: if opts.status_mode:
context = starlink_grpc.ChannelContext(target=opts.target) if opts.pure_status_mode:
try: context = starlink_grpc.ChannelContext(target=opts.target)
name_groups = starlink_grpc.status_field_names(context=context) try:
except starlink_grpc.GrpcError as e: name_groups = starlink_grpc.status_field_names(context=context)
dish_common.conn_error(opts, "Failure reflecting status field names: %s", str(e)) except starlink_grpc.GrpcError as e:
return 1 dish_common.conn_error(opts, "Failure reflecting status field names: %s", str(e))
if "status" in opts.mode: return 1
header_add(name_groups[0]) if "status" in opts.mode:
if "obstruction_detail" in opts.mode: header_add(name_groups[0])
header_add(name_groups[1]) if "obstruction_detail" in opts.mode:
if "alert_detail" in opts.mode: header_add(name_groups[1])
header_add(name_groups[2]) if "alert_detail" in opts.mode:
header_add(name_groups[2])
if "location" in opts.mode:
header_add(starlink_grpc.location_field_names())
if opts.bulk_mode: if opts.bulk_mode:
general, bulk = starlink_grpc.history_bulk_field_names() general, bulk = starlink_grpc.history_bulk_field_names()
@ -153,10 +156,10 @@ def print_header(opts, print_file):
header_add(ping) header_add(ping)
if "ping_run_length" in opts.mode: if "ping_run_length" in opts.mode:
header_add(runlen) header_add(runlen)
if "ping_loaded_latency" in opts.mode:
header_add(loaded)
if "ping_latency" in opts.mode: if "ping_latency" in opts.mode:
header_add(latency) header_add(latency)
if "ping_loaded_latency" in opts.mode:
header_add(loaded)
if "usage" in opts.mode: if "usage" in opts.mode:
header_add(usage) header_add(usage)

View file

@ -776,6 +776,26 @@ def status_data(
}, alerts }, alerts
def location_field_names():
"""Return the field names of the location data.
Returns:
A list with location data field names.
"""
return _field_names(LocationDict)
def location_field_types():
"""Return the field types of the location data.
Return the type classes for each field.
Returns:
A list with location data field types.
"""
return _field_types(LocationDict)
def get_location(context: Optional[ChannelContext] = None): def get_location(context: Optional[ChannelContext] = None):
"""Fetch location data and return it in grpc structure format. """Fetch location data and return it in grpc structure format.