Class: Cosmos::DataObject

Inherits:
Object show all
Defined in:
lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb

Overview

Represents a data object in a tabbed plots definition Designed for use as a base class for custom data objects

Direct Known Subclasses

LinegraphDataObject, XyDataObject

Constant Summary collapse

COLOR_LIST =

List of colors to use

%w(blue red green darkorange gold purple hotpink lime cornflowerblue brown coral crimson indigo tan lightblue cyan peru)
DEFAULT_ARRAY_SIZE =

Used to create large arrays to prevent memory thrashing with large objects

100000
PRUNE_HYSTERISIS_PERCENTAGE =

Percent of max seconds saved to achieve hystersis on pruning to reduce memory thrashing

0.10

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDataObject

Returns a new instance of DataObject.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 54

def initialize
  @plot = nil
  @max_points_saved = nil
  @prune_hysterisis = nil
  # Start this value at the max float so any x_value will be less than it
  @first_x_value = Float::MAX
  @error = nil
  @assigned_color = nil
  @color = COLOR_LIST[0]

  # Type is classname without DataObject
  @data_object_type = self.class.to_s[0..-11].upcase
  @data_object_type = @data_object_type.split("::")[-1] # remove Cosmos:: if necessary
end

Instance Attribute Details

#assigned_colorObject

Assigned Color of the line (string or nil for auto color choice)



48
49
50
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 48

def assigned_color
  @assigned_color
end

#colorObject

Color currently being used to draw the line (string)



45
46
47
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 45

def color
  @color
end

#data_object_typeObject

Type of data object (string)



39
40
41
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 39

def data_object_type
  @data_object_type
end

#errorObject

Error associated with this data_object (Exception)



42
43
44
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 42

def error
  @error
end

#first_x_valueObject

This value is the first x value for this data object since reset() was called. It is stored here so it can be retrieved even after x values have been pruned.



52
53
54
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 52

def first_x_value
  @first_x_value
end

#max_points_savedObject

Max number of data points saved (integer)



36
37
38
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 36

def max_points_saved
  @max_points_saved
end

#nameObject

Returns the name of this data object



165
166
167
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 165

def name
  'Unknown'
end

#plotObject

Plot holding this data object (subclass of Plot)



30
31
32
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 30

def plot
  @plot
end

Instance Method Details

#configuration_stringObject

Returns the configuration lines used to create this data object



70
71
72
73
74
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 70

def configuration_string
  string  = "    DATA_OBJECT #{@data_object_type}\n"
  string << "      COLOR #{@assigned_color}\n" if @assigned_color
  string
end

#copyObject

Creates a copy of the data object with settings but without data



141
142
143
144
145
146
147
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 141

def copy
  data_object = self.class.new
  data_object.assigned_color = @assigned_color.clone if @assigned_color
  data_object.color = @color.clone
  data_object.max_points_saved = @max_points_saved
  data_object
end

#edit(editted_data_object) ⇒ Object

Edits the data object by updating its settings from another data object



150
151
152
153
154
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 150

def edit(editted_data_object)
  @assigned_color = editted_data_object.assigned_color
  @color = editted_data_object.color
  self.max_points_saved = editted_data_object.max_points_saved
end

#edit_safe?(edited_data_object) ⇒ Boolean

Indicates if the changes made to the data object are safe to perform without reseting its data

Parameters:

  • edited_data_object (DataObject)

    The data object which was edited

Returns:

  • (Boolean)


160
161
162
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 160

def edit_safe?(edited_data_object)
  true
end

#exportObject

Exports the data object’s data as an array of arrays. Each inner array is a column of the output.



136
137
138
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 136

def export
  raise "export must be defined by class #{self.class}"
end

#handle_keyword(parser, keyword, parameters) ⇒ Object

Handles data object specific keywords



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 77

def handle_keyword(parser, keyword, parameters)
  case keyword
  when 'COLOR'
    # Expect 1 parameter
    parser.verify_num_parameters(1, 1, "COLOR <Color Name>")
    @assigned_color = parameters[0].downcase
    @color = @assigned_color
  else
    raise ArgumentError, "Unknown keyword received by #{self.class}: #{keyword}"
  end
end

#handle_process_exception(error, telemetry_point) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 104

def handle_process_exception(error, telemetry_point)
  raise error if error.class == NoMemoryError
  reset()
  @plot.redraw_needed = true
  @error = error
  if error.is_a? TypeError
    @error = FatalError.new("Telemetry point #{telemetry_point} could not be displayed. This is most likely due to this telemetry point being a String which can't be represented on the graph. Remove the point from the list of telemetry items to cause this exception to go away.\n\n#{error}")
  else
    @exceptions_reported ||= []
    unless @exceptions_reported.include?(error.message)
      @exceptions_reported << error.message
      Cosmos.write_exception_file(error)
    end
  end
end

Supplies text that should be appended to the popup string on mousing over the specified x value



129
130
131
132
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 129

def popup_modifier(x_value)
  # The default class returns an empty value
  return ""
end

#process_packet(packet, count) ⇒ Object

Processes a packet associated with this data object

Parameters:

  • packet (Packet)

    The packet to process

  • count (Integer)

    Count which increments for each packet received by the higher level process



100
101
102
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 100

def process_packet(packet, count)
  raise "process_packet must be defined by class #{self.class}"
end

#processed_packetsObject

Returns the packets processed by this data object as an array of

target_name, packet_name

pairs



91
92
93
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 91

def processed_packets
  raise "processed_packets must be defined by class #{self.class}"
end

#prune_to_max_points_saved(force_prune = false) ⇒ Object

Prunes data to max_points_saved

Parameters:

  • force_prune (Boolean) (defaults to: false)

    Whether to prune no matter if the PRUNE_HYSTERISIS_PERCENTAGE is met. Set to true if the max_points_saved is changed to ensure the total is within the new limit.



186
187
188
189
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 186

def prune_to_max_points_saved(force_prune = false)
  # Must be implemented by subclasses
  return nil
end

#resetObject

Resets the data object’s data (everything that is not configuration)



121
122
123
124
125
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 121

def reset
  @error = nil
  # Reset this value at the max float so any x_value will be less than it
  @first_x_value = Float::MAX
end