Class: Cosmos::TlmExtractor

Inherits:
QtTool show all
Defined in:
lib/cosmos/tools/tlm_extractor/tlm_extractor.rb

Overview

TlmExtractor class

This class implements the TlmExtractor. This application breaks a binary log of telemetry into a csv type file

Defined Under Namespace

Classes: MyListWidget

Constant Summary collapse

FORMATTING_OPTIONS =
%w(CONVERTED RAW FORMATTED WITH_UNITS)
DART_REDUCED_TYPE_OPTIONS =
%w(AVG MIN MAX STDDEV)
DART_REDUCTION_OPTIONS =
%w(NONE MINUTE HOUR DAY)

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from QtTool

#about, #closeEvent, #complete_initialize, config_path, create_default_options, graceful_kill, #initialize_help_menu, normalize_config_options, pre_window_new_hook, redirect_io, restore_io, #target_dirs_action

Constructor Details

#initialize(options) ⇒ TlmExtractor

Constructor



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/cosmos/tools/tlm_extractor/tlm_extractor.rb', line 74

def initialize(options)
  super(options) # MUST BE FIRST - All code before super is executed twice in RubyQt Based classes
  Cosmos.load_cosmos_icon("tlm_extractor.png")

  # Define instance variables
  @input_filenames = []
  @log_dir = System.paths['LOGS']
  @config_dir = File.join(Cosmos::USERPATH, 'config', 'tools', 'tlm_extractor', '')
  @cancel = false

  initialize_actions()
  initialize_menus()
  initialize_central_widget()
  complete_initialize()

  # Bring up slash screen for long duration tasks after creation
  Splash.execute(self) do |splash|
    # Configure CosmosConfig to interact with splash screen
    ConfigParser.splash = splash

    System.telemetry
    @search_box.completion_list = System.telemetry.all_item_strings(true, splash)
    # Always create the TlmExtractorConfig but note that it's optional to pass a config file
    @tlm_extractor_config = TlmExtractorConfig.new(options.config_file)
    @tlm_extractor_processor = TlmExtractorProcessor.new
    Qt.execute_in_main_thread(true) do
      @telemetry_chooser.update
      sync_config_to_gui()
    end

    # Unconfigure CosmosConfig to interact with splash screen
    ConfigParser.splash = nil
  end
end

Class Method Details

.post_options_parsed_hook(options) ⇒ Object

def initialize



455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
# File 'lib/cosmos/tools/tlm_extractor/tlm_extractor.rb', line 455

def self.post_options_parsed_hook(options)
  if options.input_files or options.dart
    normalize_config_options(options)
    
    # Process config file
    raise "Configuration File must be specified for command line processing" unless options.config_file

    # Process the input file(s)
    tlm_extractor_config = TlmExtractorConfig.new(options.config_file)
    tlm_extractor_processor = TlmExtractorProcessor.new
    unless options.output_file
      if options.input_files
        filename = options.input_files[0]
        extension = File.extname(filename)
        filename_no_extension = filename[0..-(extension.length + 1)]
        if tlm_extractor_config.delimiter.to_s.strip == ','
          filename = filename_no_extension << '.csv'
        else
          filename = filename_no_extension << '.txt'
        end
        options.output_file = File.join(System.paths['LOGS'], File.basename(filename))
      else
        options.output_file = File.join(System.paths['LOGS'], File.build_timestamped_filename(['tlmextractor']))
      end
    end

    tlm_extractor_config.output_filename = options.output_file
    if options.dart
      tlm_extractor_processor.process_dart([tlm_extractor_config])
    else
      tlm_extractor_processor.process(options.input_files, [tlm_extractor_config])
    end
    puts "Created #{options.output_file}"
    return false
  else
    return true
  end
end

.run(option_parser = nil, options = nil) ⇒ Object

Runs the application



495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
# File 'lib/cosmos/tools/tlm_extractor/tlm_extractor.rb', line 495

def self.run(option_parser = nil, options = nil)
  Cosmos.catch_fatal_exception do
    unless option_parser and options
      option_parser, options = create_default_options()
      options.width = 700
      options.height = 425
      options.auto_size = false
      options.restore_size = false # always render this the correct size
      options.title = "Telemetry Extractor"
      options.dart = false
      option_parser.separator "Telemetry Extractor Specific Options:"
      option_parser.on("-i", "--input FILE", "Process the specified input file") do |arg|
        options.input_files ||= []
        if arg[0..0] != '/' and arg[1..1] != ':'
          # Relative path to default of log folder
          arg = File.join(System.paths['LOGS'], arg)
        end
        options.input_files << arg
      end
      option_parser.on("-o", "--output FILE", "Output results to the specified file") do |arg|
        options.output_file = arg
      end
      option_parser.on("--dart", "Query Dart instead of files") do |arg|
        options.dart = true
      end
    end

    super(option_parser, options)
  end
end

Instance Method Details

#context_menu(point) ⇒ Object

def self.run



526
527
528
# File 'lib/cosmos/tools/tlm_extractor/tlm_extractor.rb', line 526

def context_menu(point)
  @item_menu.exec(@config_item_list.mapToGlobal(point))
end

#initialize_actionsObject



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/cosmos/tools/tlm_extractor/tlm_extractor.rb', line 109

def initialize_actions
  super()

  # File Menu Actions
  @open_config = Qt::Action.new('Open &Config', self)
  @open_config.statusTip = 'Open configuration file'
  @open_config.connect(SIGNAL('triggered()')) { handle_browse_button() }

  @save_config = Qt::Action.new('&Save Config', self)
  @save_config_keyseq = Qt::KeySequence.new('Ctrl+S')
  @save_config.shortcut = @save_config_keyseq
  @save_config.statusTip = 'Save current configuration'
  @save_config.connect(SIGNAL('triggered()')) { handle_save_button() }

  @file_options = Qt::Action.new('O&ptions', self)
  @file_options.statusTip = 'Open the options dialog'
  @file_options.connect(SIGNAL('triggered()')) { handle_options() }

  @analyze_log = Qt::Action.new('&Analyze Logs', self)
  @analyze_log.statusTip = 'Analyze log file packet counts'
  @analyze_log.connect(SIGNAL('triggered()')) { analyze_log_files() }

  # Mode Menu Actions
  @fill_down_check = Qt::Action.new('&Fill Down', self)
  @fill_down_check_keyseq = Qt::KeySequence.new('Ctrl+F')
  @fill_down_check.shortcut = @fill_down_check_keyseq
  @fill_down_check.statusTip = 'Fill Down'
  @fill_down_check.setCheckable(true)

  @matlab_header_check = Qt::Action.new('&Matlab Header', self)
  @matlab_header_check_keyseq = Qt::KeySequence.new('Ctrl+M')
  @matlab_header_check.shortcut = @matlab_header_check_keyseq
  @matlab_header_check.statusTip = 'Add a Matlab header to the output data'
  @matlab_header_check.setCheckable(true)

  @unique_only_check = Qt::Action.new('&Unique Only', self)
  @unique_only_check_keyseq = Qt::KeySequence.new('Ctrl+U')
  @unique_only_check.shortcut = @unique_only_check_keyseq
  @unique_only_check.statusTip = 'Only output rows where data has changed'
  @unique_only_check.setCheckable(true)

  @batch_mode_check = Qt::Action.new('&Batch Mode', self)
  @batch_mode_check_keyseq = Qt::KeySequence.new('Ctrl+B')
  @batch_mode_check.shortcut = @batch_mode_check_keyseq
  @batch_mode_check.statusTip = 'Process multiple config files with the same input files'
  @batch_mode_check.setCheckable(true)
  @batch_mode_check.connect(SIGNAL('triggered()')) { batch_mode_changed() }

  @normal_columns_check = Qt::Action.new('&Normal Columns', self)
  @normal_columns_check.statusTip = 'Normal Columns'
  @normal_columns_check.setCheckable(true)
  @normal_columns_check.setChecked(true)
  @normal_columns_check.connect(SIGNAL('triggered()')) { column_mode_changed() }

  @share_columns_check = Qt::Action.new('Share Columns (&All)', self)
  @share_columns_check.statusTip = 'Share columns for all items with the same name'
  @share_columns_check.setCheckable(true)
  @share_columns_check.connect(SIGNAL('triggered()')) { column_mode_changed() }

  @share_indiv_columns_check = Qt::Action.new('Share Columns (&Selected)', self)
  @share_indiv_columns_check.statusTip = 'Share columns for selected items with the same name'
  @share_indiv_columns_check.setCheckable(true)
  @share_indiv_columns_check.connect(SIGNAL('triggered()')) { column_mode_changed() }

  @full_column_names_check = Qt::Action.new('Full &Column Names', self)
  @full_column_names_check.statusTip = 'Use full item names in each column'
  @full_column_names_check.setCheckable(true)
  @full_column_names_check.connect(SIGNAL('triggered()')) { column_mode_changed() }

  # The column options are mutually exclusive so create an action group
  column_group = Qt::ActionGroup.new(self)
  column_group.addAction(@normal_columns_check)
  column_group.addAction(@share_columns_check)
  column_group.addAction(@share_indiv_columns_check)
  column_group.addAction(@full_column_names_check)

  @shared_columns = []
  @shared_columns_edit = Qt::Action.new('S&elect Shared Columns', self)
  @shared_columns_edit.statusTip = 'Select which columns are shared'
  @shared_columns_edit.setEnabled(false)
  @shared_columns_edit.connect(SIGNAL('triggered()')) { shared_columns_edit() }

  # Item Menu Actions
  @item_edit = Qt::Action.new('&Edit Items', self)
  @item_edit_keyseq = Qt::KeySequence.new('Ctrl+E')
  @item_edit.shortcut = @item_edit_keyseq
  @item_edit.statusTip = 'Options'
  @item_edit.connect(SIGNAL('triggered()')) { item_edit() }

  @item_delete = Qt::Action.new('&Delete Items', self)
  @item_delete.statusTip = 'Options'
  @item_delete.connect(SIGNAL('triggered()')) { item_delete() }
end

#initialize_central_widgetObject



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
# File 'lib/cosmos/tools/tlm_extractor/tlm_extractor.rb', line 238

def initialize_central_widget
  @resize_timer = Qt::Timer.new
  @resize_timer.connect(SIGNAL('timeout()')) { self.resize(self.width, self.minimumHeight) }

  # Create the central widget
  @central_widget = Qt::Widget.new
  setCentralWidget(@central_widget)

  @top_layout = Qt::VBoxLayout.new

  @config_box = Qt::GroupBox.new("Configuration")
  @config_box_layout = Qt::VBoxLayout.new
  @config_box.setLayout(@config_box_layout)
  @top_layout.addWidget(@config_box)

  # Configuration File Selector
  @config_layout = Qt::HBoxLayout.new
  @config_layout_label = Qt::Label.new('Configuration File:')
  @config_layout.addWidget(@config_layout_label)
  @config_field = Qt::LineEdit.new
  @config_field.setReadOnly(true)
  @config_layout.addWidget(@config_field)
  @save_button = Qt::PushButton.new('Save...')
  @config_layout.addWidget(@save_button)
  @save_button.connect(SIGNAL('clicked()')) { handle_save_button() }
  @browse_button = Qt::PushButton.new('Browse...')
  @config_layout.addWidget(@browse_button)
  @browse_button.connect(SIGNAL('clicked()')) { handle_browse_button() }
  @config_box_layout.addLayout(@config_layout)

  # Separator before editor
  @sep1 = Qt::Frame.new(@central_widget)
  @sep1.setFrameStyle(Qt::Frame::HLine | Qt::Frame::Sunken)
  @config_box_layout.addWidget(@sep1)

  # Configuration File Editor
  @config_item_list = MyListWidget.new(self)
  @config_item_list.setContextMenuPolicy(Qt::CustomContextMenu)
  @config_item_list.setDragDropMode(Qt::AbstractItemView::InternalMove)
  @config_item_list.setSelectionMode(Qt::AbstractItemView::ExtendedSelection)
  @config_item_list.setMinimumHeight(150)
  # Allow either double click or enter / return key to bring up the item editor
  @config_item_list.connect(SIGNAL('itemDoubleClicked(QListWidgetItem*)')) { item_list_editor() }
  @config_item_list.connect(SIGNAL('enterKeyPressed(int)')) { item_list_editor() }
  connect(@config_item_list, SIGNAL('customContextMenuRequested(const QPoint&)'), self, SLOT('context_menu(const QPoint&)'))
  @config_box_layout.addWidget(@config_item_list)

  # Telemetry Search
  @search_layout = Qt::HBoxLayout.new
  @search_box = FullTextSearchLineEdit.new(self)
  @search_add_item_button = Qt::PushButton.new('Add Item')
  @search_add_item_button.connect(SIGNAL('clicked()')) do
    split_tlm = @search_box.text.to_s.split(" ")
    if split_tlm.length == 3
      target_name = split_tlm[0].to_s.upcase
      packet_name = split_tlm[1].to_s.upcase
      item_name = split_tlm[2].to_s.upcase
      begin
        System.telemetry.packet_and_item(target_name, packet_name, item_name)
        add_item_callback(target_name, packet_name, item_name)
      rescue
        # Does not exist
      end
    end
  end
  @search_add_packet_button = Qt::PushButton.new('Add Packet')
  @search_add_packet_button.connect(SIGNAL('clicked()')) do
    split_tlm = @search_box.text.to_s.split(" ")
    if split_tlm.length >= 2
      target_name = split_tlm[0].to_s.upcase
      packet_name = split_tlm[1].to_s.upcase
      begin
        System.telemetry.packet(target_name, packet_name)
        add_packet_callback(target_name, packet_name)
      rescue
        # Does not exist
      end
    end
  end
  @search_add_target_button = Qt::PushButton.new('Add Target')
  @search_add_target_button.connect(SIGNAL('clicked()')) do
    split_tlm = @search_box.text.to_s.split(" ")
    if split_tlm.length >= 1
      target_name = split_tlm[0].to_s.upcase
      if System.telemetry.target_names.include?(target_name)
        add_target_callback(target_name)
      end
    end
  end
  @search_layout.addWidget(@search_box)
  @search_layout.addWidget(@search_add_item_button)
  @search_layout.addWidget(@search_add_packet_button)
  @search_layout.addWidget(@search_add_target_button)
  @config_box_layout.addLayout(@search_layout)

  # Telemetry Chooser
  tlm_chooser_layout = Qt::BoxLayout.new(Qt::Horizontal)
  add_target_button = Qt::PushButton.new('Add Target')
  add_target_button.connect(SIGNAL('clicked()')) do
    add_target_callback(@telemetry_chooser.target_name)
  end
  tlm_chooser_layout.addWidget(add_target_button)
  add_packet_button = Qt::PushButton.new('Add Packet')
  add_packet_button.connect(SIGNAL('clicked()')) do
    add_packet_callback(@telemetry_chooser.target_name, @telemetry_chooser.packet_name)
  end
  tlm_chooser_layout.addWidget(add_packet_button)
  @telemetry_chooser = TelemetryChooser.new(self, Qt::Horizontal, true, true, false, true)
  @telemetry_chooser.button_text = 'Add Item'
  @telemetry_chooser.select_button_callback = method(:add_item_callback)
  tlm_chooser_layout.addWidget(@telemetry_chooser)
  @config_box_layout.addLayout(tlm_chooser_layout)

  # Text Item Chooser
  @text_item_chooser = TextItemChooser.new(self)
  @text_item_chooser.button_callback = method(:add_text_item_callback)
  @config_box_layout.addWidget(@text_item_chooser)

  # Downsample
  @downsample_entry = FloatChooser.new(self, 'Downsample Seconds:', 0.0, 0.0, nil, 20, true)
  @config_box_layout.addWidget(@downsample_entry)

  # Batch Configuration
  @batch_config_box = Qt::GroupBox.new("Batch Configuration")
  @batch_config_layout = Qt::GridLayout.new
  @batch_config_layout.setColumnStretch(1, 1)
  @batch_config_box.setLayout(@batch_config_layout)
  @top_layout.addWidget(@batch_config_box)

  row = 0

  # Chooser for Log Files
  label = Qt::Label.new('Config Files:')
  @batch_config_layout.addWidget(label, row, 0)
  @batch_fill_widget = Qt::Widget.new
  @batch_fill_widget.setMinimumWidth(360)
  @batch_config_layout.addWidget(@batch_fill_widget, row, 1, 0, 3)
  @batch_browse_button = Qt::PushButton.new('Browse...')
  @batch_browse_button.connect(SIGNAL('clicked()')) { handle_batch_browse_button() }
  @batch_config_layout.addWidget(@batch_browse_button, row, 2)
  @batch_remove_button = Qt::PushButton.new('Remove')
  @batch_remove_button.connect(SIGNAL('clicked()')) { handle_batch_remove_button() }
  @batch_config_layout.addWidget(@batch_remove_button, row, 3)
  row += 1

  @batch_filenames_entry = Qt::ListWidget.new(self)
  @batch_filenames_entry.setSelectionMode(Qt::AbstractItemView::ExtendedSelection)
  @batch_filenames_entry.setSortingEnabled(true)
  @batch_filenames_entry.setMinimumHeight(90)
  @batch_config_layout.addWidget(@batch_filenames_entry, row, 0, 3, 4)
  row += 3

  # Batch Name
  @batch_name_label = Qt::Label.new('Batch Name:')
  @batch_config_layout.addWidget(@batch_name_label, row, 0)
  @batch_name_entry = Qt::LineEdit.new
  @batch_name_entry.setMinimumWidth(340)
  @batch_config_layout.addWidget(@batch_name_entry, row, 1, 1, 3)
  row += 1

  @batch_config_box.hide

  # Data Source Selection
  @data_source_layout = Qt::HBoxLayout.new()
  label = Qt::Label.new("Data Source: ")
  @data_source_layout.addWidget(label)
  @log_file_radio = Qt::RadioButton.new("Log File", self)
  @log_file_radio.setChecked(true)
  @log_file_radio.connect(SIGNAL('clicked()')) do
    @packet_log_frame.show_log_fields(true)
    @packet_log_frame.output_filename = ""
    @dart_meta_frame.hide
    @resize_timer.start(100)
  end
  @data_source_layout.addWidget(@log_file_radio)
  @dart_radio = Qt::RadioButton.new("DART Database", self)
  @dart_radio.connect(SIGNAL('clicked()')) do
    @packet_log_frame.show_log_fields(false)
    @packet_log_frame.output_filename = ""
    @dart_meta_frame.show
    @resize_timer.start(100)
  end
  @data_source_layout.addWidget(@dart_radio)
  @data_source_layout.addStretch()
  @top_layout.addLayout(@data_source_layout)

  # Packet Log Frame
  @packet_log_frame = PacketLogFrame.new(self, @log_dir, System.default_packet_log_reader.new(*System.default_packet_log_reader_params), @input_filenames, nil, true, true, true, Cosmos::TLM_FILE_PATTERN, Cosmos::TXT_FILE_PATTERN)
  @packet_log_frame.change_callback = method(:change_callback)
  @top_layout.addWidget(@packet_log_frame)

  @dart_meta_frame = DartMetaFrame.new(self)
  @dart_meta_frame.hide
  @top_layout.addWidget(@dart_meta_frame)

  # Process and Open Buttons
  @button_layout = Qt::HBoxLayout.new
  @process_button = Qt::PushButton.new('&Process')
  @process_button.connect(SIGNAL('clicked()')) { process() }
  @button_layout.addWidget(@process_button)

  @open_button = Qt::PushButton.new('&Open in Text Editor')
  @open_button.connect(SIGNAL('clicked()')) { open_button() }
  @open_button.setEnabled(false)
  @button_layout.addWidget(@open_button)

  if Kernel.is_windows?
    @open_excel_button = Qt::PushButton.new('&Open in Excel')
    @open_excel_button.connect(SIGNAL('clicked()')) { open_excel_button() }
    @open_excel_button.setEnabled(false)
    @button_layout.addWidget(@open_excel_button)
  end
  @top_layout.addLayout(@button_layout)

  @central_widget.setLayout(@top_layout)
end

#initialize_menusObject



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/cosmos/tools/tlm_extractor/tlm_extractor.rb', line 203

def initialize_menus
  # File Menu
  @file_menu = menuBar.addMenu('&File')
  @file_menu.addAction(@open_config)
  @file_menu.addAction(@save_config)
  @file_menu.addSeparator()
  @file_menu.addAction(@file_options)
  @file_menu.addAction(@analyze_log)
  @file_menu.addSeparator()
  @file_menu.addAction(@exit_action)

  # Mode Menu
  @mode_menu = menuBar.addMenu('&Mode')
  @mode_menu.addAction(@fill_down_check)
  @mode_menu.addAction(@matlab_header_check)
  @mode_menu.addAction(@unique_only_check)
  @mode_menu.addAction(@batch_mode_check)
  @mode_menu.addSeparator();
  @mode_menu.addAction(@normal_columns_check)
  @mode_menu.addAction(@share_columns_check)
  @mode_menu.addAction(@share_indiv_columns_check)
  @mode_menu.addAction(@full_column_names_check)
  @mode_menu.addSeparator();
  @mode_menu.addAction(@shared_columns_edit)

  # Item Menu
  @item_menu = menuBar.addMenu('&Item')
  @item_menu.addAction(@item_edit)
  @item_menu.addAction(@item_delete)

  # Help Menu
  @about_string = "COSMOS Telemetry Extractor allows processing of telemetry log files and breaking out specified items."
  initialize_help_menu()
end