Class: Cosmos::TlmExtractorProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/cosmos/tools/tlm_extractor/tlm_extractor_processor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTlmExtractorProcessor

Returns a new instance of TlmExtractorProcessor.



20
21
22
# File 'lib/cosmos/tools/tlm_extractor/tlm_extractor_processor.rb', line 20

def initialize
  @packet_log_reader = System.default_packet_log_reader.new
end

Instance Attribute Details

#packet_log_readerObject

Returns the value of attribute packet_log_reader.



18
19
20
# File 'lib/cosmos/tools/tlm_extractor/tlm_extractor_processor.rb', line 18

def packet_log_reader
  @packet_log_reader
end

Instance Method Details

#process(input_filenames, configs, time_start = nil, time_end = nil) ⇒ Object

def process_batch



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/cosmos/tools/tlm_extractor/tlm_extractor_processor.rb', line 36

def process(input_filenames, configs, time_start = nil, time_end = nil)
  Cosmos.set_working_dir do
    # Set input filenames for each config and open the output file
    configs.each { |config| config.input_filenames = input_filenames; config.open_output_file }

    # Process each input file
    packet_count = 0
    input_filenames.each_with_index do |filename, input_file_index|
      file_size = File.size(filename).to_f
      yield input_file_index, packet_count, 0.0 if block_given?
      @packet_log_reader.each(filename, true, time_start, time_end) do |packet|
        configs.each { |config| config.process_packet(packet) }
        yield input_file_index, packet_count, (@packet_log_reader.bytes_read / file_size) if block_given? and packet_count % 100 == 0
        packet_count += 1
      end
      yield input_file_index, packet_count, 1.0 if block_given?
    end
  end # Cosmos.set_working_dir
ensure
  configs.each { |config| config.close_output_file }
end

#process_batch(batch_name, input_filenames, output_dir, output_extension, config_filenames, time_start = nil, time_end = nil, &block) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/cosmos/tools/tlm_extractor/tlm_extractor_processor.rb', line 24

def process_batch(batch_name, input_filenames, output_dir, output_extension, config_filenames, time_start = nil, time_end = nil, &block)
  configs = []
  config_filenames.each_with_index do |config_filename, config_file_index|
    configs << TlmExtractorConfig.new(config_filename)
    base = File.basename(config_filename)
    extension = File.extname(base)
    filename_no_extension = base[0..-(extension.length + 1)]
    configs[-1].output_filename = File.join(output_dir, batch_name.tr(' ', '_') + '_' + filename_no_extension.tr(' ', '_') + output_extension)
  end
  process(input_filenames, configs, time_start, time_end, &block)
end