cosmos 4.2.3-java → 4.2.4-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/Manifest.txt +14 -1
  4. data/bin/dart_util +4 -0
  5. data/cosmos.gemspec +3 -2
  6. data/data/config/interface_modifiers.yaml +2 -1
  7. data/data/config/item_modifiers.yaml +1 -1
  8. data/data/config/parameter_modifiers.yaml +1 -1
  9. data/data/crc.txt +52 -45
  10. data/demo/config/data/crc.txt +6 -1
  11. data/demo/config/system/system.txt +1 -0
  12. data/demo/config/targets/DART/cmd_tlm/dart_cmds.txt +2 -0
  13. data/demo/config/targets/DART/cmd_tlm/dart_tlm.txt +40 -0
  14. data/demo/config/targets/DART/cmd_tlm_server.txt +6 -0
  15. data/demo/config/targets/DART/screens/status.txt +54 -0
  16. data/demo/config/targets/DART/target.txt +7 -0
  17. data/ext/cosmos/ext/structure/structure.c +16 -4
  18. data/lib/cosmos/dart/app/models/status.rb +2 -0
  19. data/lib/cosmos/dart/db/migrate/20180423205644_create_statuses.rb +22 -0
  20. data/lib/cosmos/dart/db/migrate/20180425211340_add_decom_state_index.rb +5 -0
  21. data/lib/cosmos/dart/db/migrate/20180509204705_remove_indexes.rb +29 -0
  22. data/lib/cosmos/dart/db/migrate/20180510160002_remove_timestamps_from_ples.rb +6 -0
  23. data/lib/cosmos/dart/db/migrate/20180511194944_add_packet_log_id_to_tables.rb +18 -0
  24. data/lib/cosmos/dart/db/schema.rb +15 -9
  25. data/lib/cosmos/dart/db/seeds.rb +8 -0
  26. data/lib/cosmos/dart/lib/dart_common.rb +5 -6
  27. data/lib/cosmos/dart/lib/dart_database_cleaner.rb +56 -5
  28. data/lib/cosmos/dart/lib/dart_decom_query.rb +108 -6
  29. data/lib/cosmos/dart/lib/dart_decommutator.rb +81 -22
  30. data/lib/cosmos/dart/lib/dart_importer.rb +44 -14
  31. data/lib/cosmos/dart/lib/dart_packet_log_writer.rb +73 -55
  32. data/lib/cosmos/dart/lib/dart_reducer_manager.rb +34 -3
  33. data/lib/cosmos/dart/lib/dart_reducer_worker_thread.rb +18 -7
  34. data/lib/cosmos/dart/processes/dart.rb +2 -1
  35. data/lib/cosmos/dart/processes/dart_decom_server.rb +2 -1
  36. data/lib/cosmos/dart/processes/dart_import.rb +1 -0
  37. data/lib/cosmos/dart/processes/dart_ingester.rb +1 -0
  38. data/lib/cosmos/dart/processes/dart_reducer.rb +1 -0
  39. data/lib/cosmos/dart/processes/dart_stream_server.rb +1 -0
  40. data/lib/cosmos/dart/processes/dart_util.rb +147 -0
  41. data/lib/cosmos/dart/processes/dart_worker.rb +1 -0
  42. data/lib/cosmos/dart/spec/dart/dart_database_cleaner_spec.rb +1 -1
  43. data/lib/cosmos/dart/spec/dart/dart_decom_query_spec.rb +1 -0
  44. data/lib/cosmos/dart/spec/dart/dart_decommutator_spec.rb +1 -0
  45. data/lib/cosmos/dart/spec/dart/dart_importer_spec.rb +1 -0
  46. data/lib/cosmos/dart/spec/dart/dart_packet_log_writer_spec.rb +39 -36
  47. data/lib/cosmos/dart/spec/dart/dart_reducer_manager_spec.rb +2 -1
  48. data/lib/cosmos/dart/spec/dart/dart_tcpip_server_interface_spec.rb +1 -2
  49. data/lib/cosmos/gui/widgets/dart_meta_frame.rb +13 -6
  50. data/lib/cosmos/interfaces.rb +1 -0
  51. data/lib/cosmos/interfaces/dart_status_interface.rb +91 -0
  52. data/lib/cosmos/interfaces/serial_interface.rb +5 -1
  53. data/lib/cosmos/io/json_drb.rb +7 -2
  54. data/lib/cosmos/io/json_drb_object.rb +11 -6
  55. data/lib/cosmos/io/json_rpc.rb +1 -0
  56. data/lib/cosmos/io/posix_serial_driver.rb +4 -2
  57. data/lib/cosmos/io/serial_driver.rb +8 -4
  58. data/lib/cosmos/io/win32_serial_driver.rb +4 -3
  59. data/lib/cosmos/packets/packet_config.rb +12 -2
  60. data/lib/cosmos/packets/structure_item.rb +1 -0
  61. data/lib/cosmos/script/extract.rb +4 -2
  62. data/lib/cosmos/streams/serial_stream.rb +10 -5
  63. data/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_config.rb +15 -15
  64. data/lib/cosmos/tools/cmd_tlm_server/gui/status_tab.rb +1 -1
  65. data/lib/cosmos/tools/table_manager/table_manager.rb +6 -4
  66. data/lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_dart_thread.rb +5 -4
  67. data/lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_logfile_thread.rb +1 -1
  68. data/lib/cosmos/top_level.rb +1 -1
  69. data/lib/cosmos/version.rb +4 -4
  70. data/spec/interfaces/serial_interface_spec.rb +13 -0
  71. data/spec/io/json_rpc_spec.rb +7 -0
  72. data/spec/io/win32_serial_driver_spec.rb +8 -0
  73. data/spec/packets/structure_item_spec.rb +6 -0
  74. data/spec/script/extract_spec.rb +5 -0
  75. data/spec/tools/cmd_tlm_server/cmd_tlm_server_config_spec.rb +10 -0
  76. metadata +17 -3
  77. data/lib/cosmos/dart/app/helpers/application_helper.rb +0 -2
@@ -0,0 +1,6 @@
1
+ # This is a segment of the main cmd_tlm_server.txt that will be used with
2
+ # AUTO_INTERFACE_TARGETS or INTERFACE_TARGET
3
+
4
+ INTERFACE DART_INT dart_status_interface.rb
5
+ TARGET DART
6
+ DONT_CONNECT
@@ -0,0 +1,54 @@
1
+ SCREEN AUTO AUTO 1.0 FIXED
2
+
3
+ VERTICAL
4
+
5
+ TITLE "DART Status"
6
+
7
+ HORIZONTAL
8
+ VERTICALBOX
9
+ SECTIONHEADER "Ingest Status"
10
+
11
+ LABELVALUE DART STATUS LAST_PLE_ID
12
+ LABELVALUE DART STATUS PLE_STATE_ERROR
13
+ LABELVALUE DART STATUS PLE_FIRST_TIME WITH_UNITS 22
14
+ LABELVALUE DART STATUS PLE_LAST_TIME WITH_UNITS 22
15
+ END
16
+
17
+ VERTICALBOX
18
+ SECTIONHEADER "Decom Status"
19
+
20
+ LABELVALUE DART STATUS PLE_STATE_NEED_DECOM
21
+ LABELVALUE DART STATUS DECOM_COUNT
22
+ LABELVALUE DART STATUS DECOM_ERROR_COUNT
23
+ LABELVALUE DART STATUS DECOM_MESSAGE_TIME WITH_UNITS 22
24
+ LABEL DECOM_MESSAGE:
25
+ VALUE DART STATUS DECOM_MESSAGE CONVERTED 50
26
+ END
27
+ END
28
+ HORIZONTAL
29
+ VERTICALBOX
30
+ SECTIONHEADER "Reduction Status"
31
+
32
+ LABELVALUE DART STATUS REDUCTION_COUNT
33
+ LABELVALUE DART STATUS REDUCTION_ERROR_COUNT
34
+ LABELVALUE DART STATUS REDUCTION_MESSAGE_TIME WITH_UNITS 22
35
+ LABEL REDUCTION_MESSAGE:
36
+ VALUE DART STATUS REDUCTION_MESSAGE CONVERTED 50
37
+ END
38
+
39
+ VERTICALBOX
40
+ SECTIONHEADER "Dart Database Status"
41
+
42
+ LABELVALUE DART STATUS DART_DATA_BYTES
43
+ LABELVALUE DART STATUS DART_LOGS_BYTES
44
+ LABELVALUE DART STATUS DART_DATABASE_BYTES
45
+ LABELVALUE DART STATUS DART_STATUS_SECONDS
46
+ END
47
+
48
+ END
49
+
50
+ VERTICALBOX
51
+ LABELVALUE DART STATUS RECEIVED_TIMEFORMATTED WITH_UNITS 22
52
+ END
53
+ END
54
+
@@ -0,0 +1,7 @@
1
+ # Ignored Parameters
2
+ # IGNORE_PARAMETER parameter_name
3
+ IGNORE_PARAMETER PACKET_ID
4
+
5
+ # Ignored Items
6
+ # IGNORE_ITEM item_name
7
+ IGNORE_ITEM PACKET_ID
@@ -46,6 +46,7 @@ static ID id_method_slice = 0;
46
46
  static ID id_method_reverse = 0;
47
47
  static ID id_method_Integer = 0;
48
48
  static ID id_method_Float = 0;
49
+ static ID id_method_kind_of = 0;
49
50
 
50
51
  static ID id_ivar_buffer = 0;
51
52
  static ID id_ivar_bit_offset = 0;
@@ -1186,15 +1187,25 @@ static VALUE read_item(int argc, VALUE* argv, VALUE self)
1186
1187
  * offset.
1187
1188
  */
1188
1189
  static VALUE structure_item_spaceship(VALUE self, VALUE other_item) {
1189
- int bit_offset = FIX2INT(rb_ivar_get(self, id_ivar_bit_offset));
1190
- int other_bit_offset = FIX2INT(rb_ivar_get(other_item, id_ivar_bit_offset));
1190
+ int bit_offset = 0;
1191
+ int other_bit_offset = 0;
1191
1192
  int bit_size = 0;
1192
1193
  int other_bit_size = 0;
1193
1194
  int create_index = 0;
1194
1195
  int other_create_index = 0;
1195
1196
  int have_create_index = 0;
1196
- volatile VALUE v_create_index = rb_ivar_get(self, id_ivar_create_index);
1197
- volatile VALUE v_other_create_index = rb_ivar_get(other_item, id_ivar_create_index);
1197
+ volatile VALUE v_create_index = Qnil;
1198
+ volatile VALUE v_other_create_index = Qnil;
1199
+
1200
+ if (!RTEST(rb_funcall(other_item, id_method_kind_of, 1, cStructureItem))) {
1201
+ return Qnil;
1202
+ }
1203
+
1204
+ bit_offset = FIX2INT(rb_ivar_get(self, id_ivar_bit_offset));
1205
+ other_bit_offset = FIX2INT(rb_ivar_get(other_item, id_ivar_bit_offset));
1206
+
1207
+ v_create_index = rb_ivar_get(self, id_ivar_create_index);
1208
+ v_other_create_index = rb_ivar_get(other_item, id_ivar_create_index);
1198
1209
  if (RTEST(v_create_index) && RTEST(v_other_create_index)) {
1199
1210
  create_index = FIX2INT(v_create_index);
1200
1211
  other_create_index = FIX2INT(v_other_create_index);
@@ -1373,6 +1384,7 @@ void Init_structure (void)
1373
1384
  id_method_reverse = rb_intern("reverse");
1374
1385
  id_method_Integer = rb_intern("Integer");
1375
1386
  id_method_Float = rb_intern("Float");
1387
+ id_method_kind_of = rb_intern("kind_of?");
1376
1388
 
1377
1389
  MIN_INT8 = INT2NUM(-128);
1378
1390
  MAX_INT8 = INT2NUM(127);
@@ -0,0 +1,2 @@
1
+ class Status < ApplicationRecord
2
+ end
@@ -0,0 +1,22 @@
1
+ class CreateStatuses < ActiveRecord::Migration[5.1]
2
+ def change
3
+ create_table :statuses do |t|
4
+ t.bigint :decom_count, :default => 0
5
+ t.bigint :decom_error_count, :default => 0
6
+ t.text :decom_message, :default => ""
7
+ t.datetime :decom_message_time
8
+
9
+ t.bigint :reduction_count, :default => 0
10
+ t.bigint :reduction_error_count, :default => 0
11
+ t.text :reduction_message, :default => ""
12
+ t.datetime :reduction_message_time
13
+
14
+ t.timestamps
15
+ end
16
+ status = Status.new
17
+ time = Time.utc(1970, 1, 1)
18
+ status.decom_message_time = time
19
+ status.reduction_message_time = time
20
+ status.save!
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ class AddDecomStateIndex < ActiveRecord::Migration[5.1]
2
+ def change
3
+ add_index :packet_log_entries, [:decom_state]
4
+ end
5
+ end
@@ -0,0 +1,29 @@
1
+ class RemoveIndexes < ActiveRecord::Migration[5.1]
2
+
3
+ def change
4
+ remove_index :packet_log_entries, :is_tlm
5
+ remove_index :packet_log_entries, :target_id
6
+ remove_index :packet_log_entries, :meta_id
7
+ remove_index :packet_log_entries, :ready
8
+ remove_index :packet_log_entries, :packet_id
9
+ remove_index :packet_log_entries, :packet_log_id
10
+
11
+ ActiveRecord::Base.connection.tables.each do |table|
12
+ # Since the decommutation tables are created dynamically we search
13
+ # through all the tables looking for tables named something like
14
+ # tXXX_YYY where XXX is the PacketConfig ID and YYY is the table index
15
+ if table.to_s =~ /^t(\d+)_(\d+)$/ # ASCII art? No! Regex!
16
+ packet_config_id = $1.to_i
17
+ table_index = $2.to_i
18
+
19
+ ["", "_m", "_h", "_d"].each do |modifier|
20
+ table_name = table + modifier
21
+ remove_index table_name, :meta_id
22
+ remove_index table_name, :reduced_id
23
+ remove_index table_name, :reduced_state
24
+ add_index table_name, :reduced_state, :where => "reduced_state < 2"
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,6 @@
1
+ class RemoveTimestampsFromPles < ActiveRecord::Migration[5.1]
2
+ def change
3
+ remove_column :packet_log_entries, :created_at
4
+ remove_column :packet_log_entries, :updated_at
5
+ end
6
+ end
@@ -0,0 +1,18 @@
1
+ class AddPacketLogIdToTables < ActiveRecord::Migration[5.1]
2
+ def change
3
+ ActiveRecord::Base.connection.tables.each do |table|
4
+ # Since the decommutation tables are created dynamically we search
5
+ # through all the tables looking for tables named something like
6
+ # tXXX_YYY where XXX is the PacketConfig ID and YYY is the table index
7
+ if table.to_s =~ /^t(\d+)_(\d+)$/ # ASCII art? No! Regex!
8
+ packet_config_id = $1.to_i
9
+ table_index = $2.to_i
10
+
11
+ ["", "_m", "_h", "_d"].each do |modifier|
12
+ table_name = table + modifier
13
+ add_column table_name, :packet_log_id, :integer
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -10,7 +10,7 @@
10
10
  #
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
13
- ActiveRecord::Schema.define(version: 20180116214338) do
13
+ ActiveRecord::Schema.define(version: 20180511194944) do
14
14
 
15
15
  # These are extensions that must be enabled in order to support this database
16
16
  enable_extension "plpgsql"
@@ -54,18 +54,11 @@ ActiveRecord::Schema.define(version: 20180116214338) do
54
54
  t.datetime "time", null: false
55
55
  t.integer "packet_log_id", null: false
56
56
  t.bigint "data_offset", null: false
57
- t.datetime "created_at", null: false
58
- t.datetime "updated_at", null: false
59
57
  t.bigint "meta_id"
60
58
  t.boolean "is_tlm", null: false
61
59
  t.integer "decom_state", default: 0
62
60
  t.boolean "ready", default: false
63
- t.index ["is_tlm"], name: "index_packet_log_entries_on_is_tlm"
64
- t.index ["meta_id"], name: "index_packet_log_entries_on_meta_id"
65
- t.index ["packet_id"], name: "index_packet_log_entries_on_packet_id"
66
- t.index ["packet_log_id"], name: "index_packet_log_entries_on_packet_log_id"
67
- t.index ["ready"], name: "index_packet_log_entries_on_ready"
68
- t.index ["target_id"], name: "index_packet_log_entries_on_target_id"
61
+ t.index ["decom_state"], name: "index_packet_log_entries_on_decom_state"
69
62
  t.index ["time"], name: "index_packet_log_entries_on_time"
70
63
  end
71
64
 
@@ -86,6 +79,19 @@ ActiveRecord::Schema.define(version: 20180116214338) do
86
79
  t.index ["target_id", "name", "is_tlm"], name: "index_packets_on_target_id_and_name_and_is_tlm", unique: true
87
80
  end
88
81
 
82
+ create_table "statuses", force: :cascade do |t|
83
+ t.bigint "decom_count", default: 0
84
+ t.bigint "decom_error_count", default: 0
85
+ t.text "decom_message", default: ""
86
+ t.datetime "decom_message_time"
87
+ t.bigint "reduction_count", default: 0
88
+ t.bigint "reduction_error_count", default: 0
89
+ t.text "reduction_message", default: ""
90
+ t.datetime "reduction_message_time"
91
+ t.datetime "created_at", null: false
92
+ t.datetime "updated_at", null: false
93
+ end
94
+
89
95
  create_table "system_configs", force: :cascade do |t|
90
96
  t.string "name", null: false
91
97
  t.datetime "created_at", null: false
@@ -5,3 +5,11 @@
5
5
  #
6
6
  # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
7
7
  # Character.create(name: 'Luke', movie: movies.first)
8
+ status = Status.first
9
+ unless status
10
+ status = Status.new
11
+ time = Time.utc(1970, 1, 1)
12
+ status.decom_message_time = time
13
+ status.reduction_message_time = time
14
+ status.save!
15
+ end
@@ -165,6 +165,7 @@ module DartCommon
165
165
  t.bigint :ple_id
166
166
  t.bigint :meta_id
167
167
  t.bigint :reduced_id
168
+ t.integer :packet_log_id
168
169
  t.integer :reduced_state, :default => 0
169
170
  table_data_types.each_with_index do |data_type, index|
170
171
  item_index = (table_index * MAX_COLUMNS_PER_TABLE) + index
@@ -183,9 +184,7 @@ module DartCommon
183
184
  end
184
185
  end
185
186
  t.index :time
186
- t.index :meta_id
187
- t.index :reduced_state
188
- t.index :reduced_id
187
+ t.index :reduced_state, :where => "reduced_state < 2"
189
188
  end
190
189
  create_reduction_table("t#{packet_config.id}_#{table_index}_h", table_data_types, table_index) # hour
191
190
  create_reduction_table("t#{packet_config.id}_#{table_index}_m", table_data_types, table_index) # month
@@ -524,6 +523,7 @@ module DartCommon
524
523
  # @param array_size [Integer, nil] Size of the array or nil if no array
525
524
  # @return [Symbol] Database type such as :integer, :bigint, :string, etc.
526
525
  def cosmos_data_type_to_db_type(data_type, bit_size, array_size)
526
+ return nil if data_type.nil? or bit_size.nil?
527
527
  db_type = nil
528
528
  case data_type
529
529
  when :INT
@@ -674,6 +674,7 @@ module DartCommon
674
674
  t.integer :num_samples
675
675
  t.bigint :meta_id
676
676
  t.bigint :reduced_id
677
+ t.integer :packet_log_id
677
678
  t.integer :reduced_state, :default => 0
678
679
  table_data_types.each_with_index do |data_type, index|
679
680
  item_index = (table_index * MAX_COLUMNS_PER_TABLE) + index
@@ -686,9 +687,7 @@ module DartCommon
686
687
  end
687
688
  end
688
689
  t.index :start_time
689
- t.index :meta_id
690
- t.index :reduced_state
691
- t.index :reduced_id
690
+ t.index :reduced_state, :where => "reduced_state < 2"
692
691
  end
693
692
  end
694
693
 
@@ -9,6 +9,7 @@
9
9
  # attribution addendums as found in the LICENSE.txt
10
10
 
11
11
  require 'dart_common'
12
+ require 'cosmos/packet_logs/packet_log_reader'
12
13
 
13
14
  class DartDatabaseCleaner
14
15
  include DartCommon
@@ -17,18 +18,68 @@ class DartDatabaseCleaner
17
18
  # if the DART packet logs were moved and force is false (default). This is
18
19
  # deliberate because force causes all the lost (or moved) files to be deleted
19
20
  # which forces them to be re-imported at their new location.
20
- def self.clean(force)
21
+ def self.clean(force, full = false)
21
22
  Cosmos::Logger::info("Starting database cleanup...")
22
23
  cleaner = DartDatabaseCleaner.new
23
24
  cleaner.clean_system_configs()
24
25
  cleaner.clean_packet_logs(force)
25
26
  cleaner.clean_packet_configs()
26
27
  cleaner.clean_packet_log_entries()
27
- cleaner.clean_decommutation_tables()
28
- cleaner.clean_reductions()
28
+ if full
29
+ cleaner.clean_decommutation_tables()
30
+ cleaner.clean_reductions()
31
+ end
29
32
  Cosmos::Logger::info("Database cleanup complete!")
30
33
  end
31
34
 
35
+ def remove_packet_log(filename)
36
+ filename = filename.gsub("\\", "/") # Fix slashes
37
+ filename = File.expand_path(filename, Cosmos::System.paths['DART_DATA']) # Make absolute path
38
+ if File.exists?(filename)
39
+ packet_log = PacketLog.where("filename = ?", filename).first
40
+ if packet_log
41
+ size = File.size(filename)
42
+ reader = Cosmos::PacketLogReader.new
43
+ reader.open(filename)
44
+ first_packet = nil
45
+ last_packet = nil
46
+ start_time = nil
47
+ end_time = nil
48
+ begin
49
+ first_packet = reader.first
50
+ last_packet = reader.last
51
+ start_time = first_packet.received_time
52
+ end_time = last_packet.received_time
53
+ rescue
54
+ if size == Cosmos::PacketLogReader::COSMOS2_HEADER_LENGTH or size == 0
55
+ Cosmos::Logger::error("File contains no packets: #{filename}")
56
+ else
57
+ Cosmos::Logger::error("Error analyzing file: #{filename}")
58
+ end
59
+ exit(1)
60
+ ensure
61
+ reader.close
62
+ end
63
+ num_deleted = PacketLogEntry.where("time >= ? and time <= ? and packet_log_id = ?", start_time - 1.minute, end_time + 1.minute, packet_log.id).delete_all
64
+ Cosmos::Logger::info("Removed #{num_deleted} PacketLogEntries")
65
+ each_decom_and_reduced_table() do |packet_config_id, table_index, decom_model, minute_model, hour_model, day_model|
66
+ num_deleted = 0
67
+ num_deleted += decom_model.where("time >= ? and time <= ? and packet_log_id = ?", start_time - 1.minute, end_time + 1.minute, packet_log.id).delete_all
68
+ num_deleted += minute_model.where("start_time >= ? and start_time <= ? and packet_log_id = ?", start_time - 1.minute, end_time + 2.minutes, packet_log.id).delete_all
69
+ num_deleted += hour_model.where("start_time >= ? and start_time <= ? and packet_log_id = ?", start_time - 1.minute, end_time + 1.hour + 1.minutes, packet_log.id).delete_all
70
+ num_deleted += day_model.where("start_time >= ? and start_time <= ? and packet_log_id = ?", start_time - 1.minute, end_time + 1.hour + 1.day, packet_log.id).delete_all
71
+ Cosmos::Logger::info("Deleted #{num_deleted} rows from #{decom_model.table_name} and reductions")
72
+ end
73
+ packet_log.delete
74
+ Cosmos::Logger::info("Packet Log Id #{packet_log.id} deleted")
75
+ else
76
+ Cosmos::Logger::error("File does not exist in database: #{filename}")
77
+ end
78
+ else
79
+ Cosmos::Logger::error("File does not exist: #{filename}")
80
+ end
81
+ end
82
+
32
83
  # Ensure we have all the System Configs locally on the DART machine
33
84
  def clean_system_configs
34
85
  Cosmos::Logger::info("Cleaning up SystemConfig...")
@@ -95,7 +146,7 @@ class DartDatabaseCleaner
95
146
  end
96
147
  rescue => err
97
148
  Cosmos::Logger::error("Error cleaning up packet config: #{packet_config.id}: #{err.formatted}")
98
- raise "Cleanup failure - Database requires manual correction"
149
+ raise $!, "Cleanup failure - Database requires manual correction: #{err.message}", $!.backtrace
99
150
  end
100
151
  end
101
152
  end
@@ -108,7 +159,7 @@ class DartDatabaseCleaner
108
159
  # outstanding entries which are not ready while packets are being received.
109
160
  # Note the normal shutdown process attempts to flush the log file and mark
110
161
  # all outstanding entries as ready so this would only happen during a crash.
111
- ples = PacketLogEntry.where("ready != true")
162
+ ples = PacketLogEntry.where("decom_state = 0 and ready != true")
112
163
  return unless ples.length > 0
113
164
  Cosmos::Logger::info("Removing unready packet log entries: #{ples.length}")
114
165
  ples.destroy_all
@@ -53,7 +53,7 @@ class DartDecomQuery
53
53
  # for other reduction values), and meta_id.
54
54
  def query(request)
55
55
  request_start_time = Time.now
56
- Cosmos::Logger.info("#{request_start_time.formatted}: QUERY: #{request}")
56
+ Cosmos::Logger.info("#{request_start_time.formatted}: query: #{request}")
57
57
 
58
58
  begin
59
59
  start_time_sec = request['start_time_sec']
@@ -136,7 +136,7 @@ class DartDecomQuery
136
136
  unless meta_ids.length > 0
137
137
  meta_filters = request['meta_filters']
138
138
  meta_filters ||= []
139
-
139
+
140
140
  if meta_filters.length > 0
141
141
  meta_ids = process_meta_filters(meta_filters, is_tlm, end_time)
142
142
  end
@@ -149,10 +149,10 @@ class DartDecomQuery
149
149
  offset = 0 if offset < 0
150
150
 
151
151
  return query_decom_reduced(
152
- item[0], item[1], item[2],
153
- value_type, is_tlm,
154
- start_time, end_time,
155
- reduction, reduction_modifier,
152
+ item[0], item[1], item[2],
153
+ value_type, is_tlm,
154
+ start_time, end_time,
155
+ reduction, reduction_modifier,
156
156
  item_name_modifier, limit, offset, meta_ids)
157
157
 
158
158
  rescue Exception => error
@@ -168,6 +168,8 @@ class DartDecomQuery
168
168
  # @param is_tlm true or false
169
169
  # @return [Array<String>] Array of item names
170
170
  def item_names(target_name, packet_name, is_tlm = true)
171
+ Cosmos::Logger.info("#{time.formatted}: item_names")
172
+
171
173
  target = Target.where("name = ?", target_name).first
172
174
  raise "Target #{target_name} not found" unless target
173
175
 
@@ -181,4 +183,104 @@ class DartDecomQuery
181
183
  return item_names
182
184
  end
183
185
 
186
+ # Returns status on the DART Database
187
+ def dart_status
188
+ start_time = Time.now
189
+ Cosmos::Logger.info("#{start_time.formatted}: dart_status")
190
+ result = {}
191
+ status = Status.first
192
+
193
+ # Ingest Status
194
+ # ---------------
195
+ # Last PacketLogEntry Id
196
+ last_ple = PacketLogEntry.select("id").last
197
+ if last_ple
198
+ result[:LAST_PLE_ID] = last_ple.id
199
+ else
200
+ result[:LAST_PLE_ID] = -1
201
+ end
202
+ # Num PacketLogEntries Needing Decom state = 0
203
+ result[:PLE_STATE_NEED_DECOM] = PacketLogEntry.where("decom_state = 0").count
204
+ # Num PacketLogEntries Errored - state >= 3
205
+ result[:PLE_STATE_ERROR] = PacketLogEntry.where("decom_state >= 3").count
206
+ # First Time in Database
207
+ sort_first_ple = PacketLogEntry.order("time ASC").select("time").first
208
+ if sort_first_ple
209
+ result[:PLE_FIRST_TIME_S] = sort_first_ple.time.tv_sec
210
+ result[:PLE_FIRST_TIME_US] = sort_first_ple.time.tv_usec
211
+ else
212
+ result[:PLE_FIRST_TIME_S] = 0
213
+ result[:PLE_FIRST_TIME_US] = 0
214
+ end
215
+ # Last Time in Database
216
+ sort_last_ple = PacketLogEntry.order("time DESC").select("time").first
217
+ if sort_last_ple
218
+ result[:PLE_LAST_TIME_S] = sort_last_ple.time.tv_sec
219
+ result[:PLE_LAST_TIME_US] = sort_last_ple.time.tv_usec
220
+ else
221
+ result[:PLE_LAST_TIME_S] = 0
222
+ result[:PLE_LAST_TIME_US] = 0
223
+ end
224
+
225
+ # Decom Status
226
+ # ---------------
227
+ # Decom Count
228
+ result[:DECOM_COUNT] = status.decom_count
229
+ # Decom Errors
230
+ result[:DECOM_ERROR_COUNT] = status.decom_error_count
231
+ # Decom Message
232
+ result[:DECOM_MESSAGE] = status.decom_message
233
+ # Decom Message Time
234
+ result[:DECOM_MESSAGE_TIME_S] = status.decom_message_time.tv_sec
235
+ result[:DECOM_MESSAGE_TIME_US] = status.decom_message_time.tv_usec
236
+
237
+ # Reduction Status
238
+ # ---------------
239
+ # Reduction Count
240
+ result[:REDUCTION_COUNT] = status.reduction_count
241
+ # Reduction Errors
242
+ result[:REDUCTION_ERROR_COUNT] = status.reduction_error_count
243
+ # Reduction Message
244
+ result[:REDUCTION_MESSAGE] = status.reduction_message
245
+ # Reduction Time
246
+ result[:REDUCTION_MESSAGE_TIME_S] = status.reduction_message_time.tv_sec
247
+ result[:REDUCTION_MESSAGE_TIME_US] = status.reduction_message_time.tv_usec
248
+
249
+ # Storage
250
+ # ---------------
251
+ Cosmos.set_working_dir do
252
+ # Size of outputs/dart/data folder
253
+ result[:DART_DATA_BYTES] = Dir.glob(File.join(Cosmos::System.paths['DART_DATA'], '**', '*')).map{ |f| File.size(f) }.inject(:+)
254
+ # Size of outputs/dart/logs folder
255
+ result[:DART_LOGS_BYTES] = Dir.glob(File.join(Cosmos::System.paths['DART_LOGS'], '**', '*')).map{ |f| File.size(f) }.inject(:+)
256
+ end
257
+ # Size of SQL Database
258
+ begin
259
+ result[:DART_DATABASE_BYTES] = ActiveRecord::Base.connection.execute("select pg_database_size('#{ActiveRecord::Base.connection_config[:database]}');")[0]['pg_database_size']
260
+ rescue
261
+ result[:DART_DATABASE_BYTES] = -1
262
+ end
263
+
264
+ end_time = Time.now
265
+ delta = end_time - start_time
266
+ result[:DART_STATUS_SECONDS] = delta
267
+
268
+ return result
269
+ end
270
+
271
+ def clear_errors
272
+ time = Time.now
273
+ Cosmos::Logger.info("#{time.formatted}: clear_errors")
274
+ status = Status.first
275
+ status.decom_error_count = 0
276
+ status.decom_message = ''
277
+ status.decom_message_time = time
278
+ status.reduction_error_count = 0
279
+ status.reduction_message = ''
280
+ status.reduction_message_time = time
281
+ status.save!
282
+
283
+ return nil
284
+ end
285
+
184
286
  end