Module: Argos::Ascii
Class Method Summary collapse
-
.argos?(filename) ⇒ Boolean
Argos ASCII file?.
-
.factory(type) ⇒ Argos::Ds Argos::Diag
Factory for Argos::Ds / Argos::Diag.
-
.source(argos) ⇒ Hash
Source fingerprint of Argos file (sha1 hash, segment and document counts, etc.).
-
.type(filename) ⇒ String
Detect Argos ASCII filetype (“ds” or “diag” or nil).
Instance Method Summary collapse
Class Method Details
.argos?(filename) ⇒ Boolean
Argos ASCII file?
33 34 35 36 37 38 39 40 |
# File 'lib/argos/ascii.rb', line 33 def self.argos?(filename) case type(filename) when "ds", "diag" true else false end end |
.factory(type) ⇒ Argos::Ds Argos::Diag
Factory for Argos::Ds / Argos::Diag
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/argos/ascii.rb', line 47 def self.factory(type) # Auto-detect file format if not "ds" or "diag" if not ["ds","diag"].include? type if argos? type type = self.type(type) end end case type when "ds" Ds.new when "diag" Diag.new else raise ArgumentError, "Unknown Argos type: #{type}" end end |
.source(argos) ⇒ Hash
Source fingerprint of Argos file (sha1 hash, segment and document counts, etc.)
70 71 72 73 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 108 109 110 111 112 113 114 |
# File 'lib/argos/ascii.rb', line 70 def self.source(argos) argos.parse(argos.filename) latitude_mean = longitude_mean = nil if argos.latitudes.any? latitude_mean = (argos.latitudes.inject{ |sum, latitude| sum + latitude } / argos.latitudes.size).round(3) end if argos.longitudes.any? longitude_mean = (argos.longitudes.inject{ |sum, longitude| sum + longitude } / argos.latitudes.size).round(3) end source = { id: argos.source, technology: "argos", collection: "tracking", type: argos.type, programs: argos.programs, platforms: argos.platforms, start: argos.start, stop: argos.stop, north: argos.latitudes.max, east: argos.longitudes.max, south: argos.latitudes.min, west: argos.longitudes.min, latitude_mean: latitude_mean, longitude_mean: longitude_mean, file: "file://"+argos.filename, bytes: argos.filesize, modified: argos.updated.utc.iso8601, messages: argos..size, filter: argos.filtername.nil? ? argos.filter : argos.filtername, size: argos.size, parser: Argos.library_version } if argos.multiplicates.any? source[:multiplicates] = argos.multiplicates.map {|a| a[:id]} end if argos.errors.any? source[:errors] = argos.errors end source end |
.type(filename) ⇒ String
Detect Argos ASCII filetype (“ds” or “diag” or nil)
“ds”|“diag”
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/argos/ascii.rb', line 9 def self.type filename if File.file? filename # Avoid invalid byte sequence in UTF-8 (ArgumentError) firstline = File.open(filename, :encoding => "iso-8859-1") {|f| f.readline} else firstline = filename end case firstline when Argos::Ds::START_REGEX, Argos::Ds::START_REGEX_LEGACY "ds" when Argos::Diag::START_REGEX "diag" when "", nil raise ArgumentError, "Not a file or empty string: #{filename}" else nil end end |
Instance Method Details
#latitudes ⇒ Object
117 118 119 |
# File 'lib/argos/ascii.rb', line 117 def latitudes select {|a| a.key? :latitude and a[:latitude].is_a? Float }.map {|a| a[:latitude]}.sort end |
#longitudes ⇒ Object
121 122 123 |
# File 'lib/argos/ascii.rb', line 121 def longitudes select {|a| a.key? :longitude and a[:longitude].is_a? Float }.map {|a| a[:longitude]}.sort end |
#platforms ⇒ Object
125 126 127 |
# File 'lib/argos/ascii.rb', line 125 def platforms map {|a| a[:platform]}.uniq.sort end |
#programs ⇒ Object
129 130 131 |
# File 'lib/argos/ascii.rb', line 129 def programs map {|a| a[:program]}.uniq.sort end |