Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: craigtaverner/geoptima.rb
base: 2196a8853a
...
head fork: craigtaverner/geoptima.rb
compare: ed1b65ecd2
Checking mergeability… Don't worry, you can still create the pull request.
  • 8 commits
  • 12 files changed
  • 0 commit comments
  • 1 contributor
View
10 Rakefile
@@ -16,8 +16,16 @@ task :clean_all do
system "git clean -df"
end
+desc "create the executables in bin"
+task :make_bin do
+ Dir.glob('examples/*.rb').each do |file|
+ bin = file.gsub(/\.rb/,'').gsub(/examples/,'bin')
+ puts "cp #{file} #{bin}"
+ end
+end
+
desc "create the gemspec"
-task :build do
+task :build => [:make_bin] do
system "gem build geoptima.gemspec"
end
View
10 bin/geoptima_file_time
@@ -1,10 +0,0 @@
-#!/usr/bin/env ruby
-
-require 'date'
-
-$root=DateTime.parse("1970-01-01 00:00:00")
-ARGV.each do |arg|
- base,seconds=arg.split(/_/)
- date = ($root + seconds.to_f/(60*60*24))
- puts "#{date}\t#{arg}"
-end
View
259 bin/show_geoptima
@@ -1,259 +0,0 @@
-#!/usr/bin/env ruby
-
-# useful if being run inside a source code checkout
-$: << 'lib'
-$: << '../lib'
-
-require 'date'
-require 'geoptima'
-
-Geoptima::assert_version("0.0.6")
-
-$debug=false
-
-$event_names=[]
-$files = []
-$print_limit = 10000
-
-def cw(val)
- val.nil? ? '' : "(#{val})"
-end
-
-while arg=ARGV.shift do
- if arg =~ /^\-(\w+)/
- $1.split(//).each do |aa|
- case aa
- when 'h'
- $help=true
- when 'd'
- $debug=true
- when 'p'
- $print=true
- when 'v'
- $verbose=true
- when 'x'
- $export=true
- when 's'
- $seperate=true
- when 'o'
- $export_stats=true
- when 'm'
- $map_headers=true
- when 'a'
- $combine_all=true
- when 'l'
- $more_headers=true
- when 'C'
- $chart_spec = ARGV.shift
- when 'E'
- $event_names += ARGV.shift.split(/[\,\;\:\.]+/)
- when 'T'
- $time_range = Range.new(*(ARGV.shift.split(/[\,]+/).map do |t|
- DateTime.parse t
- end))
- when 'L'
- $print_limit = ARGV.shift.to_i
- $print_limit = 10 if($print_limit<1)
- else
- puts "Unrecognized option: -#{aa}"
- end
- end
- else
- if File.exist? arg
- $files << arg
- else
- puts "No such file: #{arg}"
- end
- end
-end
-
-$help = true if($files.length < 1)
-if $help
- puts <<EOHELP
-Usage: ./showGeoptimaEvents.rb <-dvxEh> <-L limit> <-E types> <-T min,max> file <files>
- -d debug mode (output more context during processing) #{cw $debug}
- -p print mode (print out final results to console) #{cw $print}
- -v verbose mode (output extra information to console) #{cw $verbose}
- -x export IMEI specific CSV files for further processing #{cw $export}
- -o export field statistis #{cw $export_stats}
- -m map headers to classic NetView compatible version #{cw $map_headers}
- -l longer header list (phone and operator fields) #{cw $more_headers}
- -s seperate the export files by event type #{cw $seperate}
- -a combine all IMEI's into a single dataset #{cw $combine_all}
- -h show this help
- -C use specified chart specification file for stats and charts: #{$chart_spec}
- -E comma-seperated list of event types to show and export (default: all; current: #{$event_names.join(',')})
- -T time range to limit results to (default: all; current: #{$time_range})
- -L limit verbose output to specific number of lines #{cw $print_limit}
-EOHELP
- exit 0
-end
-
-$verbose = $verbose || $debug
-$datasets = Geoptima::Dataset.make_datasets($files, :locate => true, :time_range => $time_range, :combine_all => $combine_all)
-
-class Export
- attr_reader :files, :imei, :names, :headers
- def initialize(imei,names,dataset)
- imei = dataset.imsi if(imei.to_s.length < 1)
- @imei = imei
- @names = names
- if $export
- if $seperate
- @files = names.inject({}) do |a,name|
- a[name] = File.open("#{imei}_#{name}.csv",'w')
- a
- end
- else
- @files={nil => File.open("#{imei}.csv",'w')}
- end
- end
- @headers = names.inject({}) do |a,name|
- a[name] = dataset.header([name]).reject{|h| h === 'timeoffset'}
- a[name] = a[name].map{|h| "#{name}.#{h}"} unless($separate)
- puts "Created header for name #{name}: #{a[name].join(',')}" if($debug)
- a
- end
- @headers[nil] = @headers.values.flatten.sort
- files && files.each do |key,file|
- file.puts map_headers(base_headers+more_headers+header(key)).join("\t")
- end
- if $debug || $verbose
- @headers.each do |name,head|
- puts "Header[#{name}]: #{head.join(',')}"
- end
- end
- end
- def export_imei
- ($combine_all || $more_headers)
- end
- def base_headers
- ['Time','Event','Latitude','Longitude'] +
- (export_imei ? ['IMEI'] : [])
- end
- def more_headers
- $more_headers ?
- ['IMSI','MSISDN','MCC','MNC','LAC','CI','LAC-CI','RSSI','Platform','Model','OS','Operator'] :
- []
- end
- def base_fields(event)
- [event.time_key,event.name,event.latitude,event.longitude] +
- (export_imei ? [event.file.imei] : [])
- end
- def more_fields(event,dataset)
- more_headers.map do |h|
- case h
- when 'RSSI'
- dataset.recent(event,'signal.strength')
- when 'LAC'
- dataset.recent(event,'service.lac')
- when 'CI'
- dataset.recent(event,'service.cell_id')
- when 'LAC-CI'
- "#{dataset.recent(event,'service.lac')}-#{dataset.recent(event,'service.cell_id')}"
- when 'MCC'
- dataset[h] || dataset.recent(event,'service.mcc')
- when 'MNC'
- dataset[h] || dataset.recent(event,'service.mnc')
- when 'Operator'
- dataset['carrierName']
- when 'IMSI'
- dataset.imsi
- else
- dataset[h]
- end
- end
- end
- def get_field(event,name)
- h=(base_headers+more_headers).grep(/#{name}/)
- end
- def cap(array,sep="")
- array.map do |v|
- "#{v[0..0].upcase}#{v[1..-1]}"
- end.join(sep)
- end
- def map_headers(hnames)
- $map_headers && hnames.map do |h|
- case h
- when 'Time'
- 'time'
- when /gps\./
- cap(h.split(/[\._]/),'_').gsub(/gps/i,'GPS')
- when /^(call|signal|data|sms|mms|browser|neighbor)/i
- cap(h.split(/[\._]/),'_').gsub(/Neighbor/,'Neighbour').gsub(/mms/i,'MMS').gsub(/sms/,'SMS')
- when /\./
- cap(h.split(/[\._]/))
- else
- h
- end
- end || hnames
- end
- def export_stats(stats)
- File.open("#{imei}_stats.csv",'w') do |out|
- stats.keys.sort.each do |header|
- out.puts header
- values = stats[header].keys.sort
- out.puts values.join("\t")
- out.puts values.map{|v| stats[header][v]}.join("\t")
- out.puts
- end
- end
- end
- def header(name=nil)
- @headers[name]
- end
- def puts_to(line,name)
- name = nil unless($seperate)
- files[name].puts(line) if($export && files[name])
- end
- def puts_to_all(line)
- files && files.each do |key,file|
- file.puts line
- end
- end
- def close
- files && files.each do |key,file|
- file.close
- @files[key] = nil
- end
- end
-end
-
-def if_le
- $count ||= 0
- if $print
- if $count < $print_limit
- yield
- elsif $count == $print_limit
- puts " ... "
- end
- end
- $count += 1
-end
-
-puts "Found #{$datasets.length} IMEIs"
-$datasets.keys.sort.each do |imei|
- dataset = $datasets[imei]
- imsi = dataset.imsi
- events = dataset.sorted
- puts if($print)
- puts "Found #{dataset}"
- if events && ($print || $export)
- names = $event_names
- names = dataset.events_names if(names.length<1)
- export = Export.new(imei,names,dataset)
- export.export_stats(dataset.stats) if($export_stats)
- events.each do |event|
- names.each do |name|
- if event.name === name
- fields = export.header($seperate ? name : nil).map{|h| event[h]}
- b_fields = export.base_fields(event) + export.more_fields(event,dataset)
- export.puts_to "#{b_fields.join("\t")}\t#{fields.join("\t")}", name
- if_le{puts "#{b_fields.join("\t")}\t#{event.fields.inspect}"}
- end
- end
- end
- export.close
- end
-end
-
View
132 examples/csv_chart.rb
@@ -0,0 +1,132 @@
+#!/usr/bin/ruby
+
+# useful if being run inside a source code checkout
+$: << 'lib'
+$: << '../lib'
+
+require 'geoptima/chart'
+require 'geoptima/options'
+
+$files = Geoptima::Options.process_args
+
+class Stats
+ attr_reader :file, :imei, :headers, :stats, :data
+ def initialize(file,imei,fields)
+ @file = file
+ @imei = imei
+ @headers = fields
+ @stats = fields.map{|h| {}}
+ @data = fields.map{|h| []}
+ @numerical = fields.map{|h| true}
+ end
+ def add(field,index)
+ if field =~ /\w/
+ @numerical[index] &&= is_number?(field)
+ puts "\tField[#{index}]: #{field}" if($debug)
+ stats = @stats[index]
+ stats[field] ||= 0
+ stats[field] += 1
+ puts "\tField[#{index}]: #{field} => #{stats[field]}" if($debug)
+ @data[index] << field
+ end
+ end
+ def is_number?(field)
+ is_integer?(field) || is_float?(field)
+ end
+ def is_integer?(field)
+ field.to_i.to_s == field
+ end
+ def is_float?(field)
+ field.to_f.to_s == field
+ end
+ def length(index)
+ @stats[index].length
+ end
+ def diversity(index)
+ 100.0 * @stats[index].length.to_f / @data[index].length.to_f
+ end
+ def diverse?(index)
+ @stats[index].length>500 || diversity(index) > 40.0
+ end
+ def numerical?(index)
+ @numerical[index]
+ end
+end
+
+$stats = {}
+
+$files.each do |file|
+ lines = 0
+ imei = file.split(/[_\.]/)[0]
+ File.open(file).each do |line|
+ lines += 1
+ fields=line.chomp.split(/\t/)
+ if $stats[file]
+ puts "Processing line: #{line}" if($debug)
+ fields.each_with_index do |field,index|
+ $stats[file].add(field,index)
+ end
+ else
+ $stats[file] = Stats.new(file,imei,fields)
+ end
+ end
+end
+
+$stats.each do |file,stats|
+ stats.headers.each_with_index do |header,index|
+ puts "Charting #{header} with diversity #{stats.diversity(index)}"
+ case header
+ when 'signal.strength'
+ Geoptima::Chart.draw_line_chart(
+ stats.imei,
+ stats.data[0],
+ stats.data[index].map{|f| v=f.to_i; (v>-130 && v<0) ? v : nil},
+ :title => 'Signal Strength',
+ :maximum_value => -30,
+ :minimum_value => -130,
+ :width => 1024
+ ).write("Chart_#{stats.imei}_#{header}.png")
+
+ hist = stats.stats[index]
+ keys = hist.keys.sort{|a,b| a.to_i <=> b.to_i}
+ values = keys.map{|k| hist[k]}
+ Geoptima::Chart.draw_histogram_chart(
+ stats.imei, keys, values,
+ :title => 'Signal Strength Distribution',
+ :width => 1024
+ ).write("Chart_#{stats.imei}_#{header}_distribution.png")
+
+ when 'Event'
+ hist = stats.stats[index]
+ keys = hist.keys.sort{|a,b| a.to_i <=> b.to_i}
+ values = keys.map{|k| hist[k]}
+ Geoptima::Chart.draw_category_chart(
+ stats.imei, keys, values,
+ :title => "#{header} Distribution",
+ :width => 1024
+ ).write("Chart_#{stats.imei}_#{header}_distribution.png")
+
+ else
+ if stats.diverse?(index)
+ puts "Ingnoring high diversity field #{header}"
+ else
+ puts "Charting field: #{header} with length #{stats.length(index)} and diversity #{stats.diversity(index)}"
+ hist = stats.stats[index]
+ keys = hist.keys.sort{|a,b| a.to_i <=> b.to_i}
+ values = keys.map{|k| hist[k]}
+ args = [stats.imei, keys, values, {
+ :title => "#{header} Distribution",
+ :width => 1024}]
+ g = (stats.length(index) > 50) ?
+ Geoptima::Chart.draw_line_chart(*args) :
+ (stats.length(index) > 10 || stats.numerical?(index)) ?
+ Geoptima::Chart.draw_histogram_chart(*args) :
+ (stats.length(index) > 1) ?
+ Geoptima::Chart.draw_category_chart(*args) :
+ nil
+ g && g.write("Chart_#{stats.imei}_#{header}_distribution.png")
+ end
+ end
+ end
+end
+
View
126 examples/csv_stats.rb
@@ -0,0 +1,126 @@
+#!/usr/bin/env ruby
+
+# useful if being run inside a source code checkout
+$: << 'lib'
+$: << '../lib'
+
+require 'geoptima/options'
+
+$show_all = false
+
+$files = Geoptima::Options.process_args do |option|
+ option.a {$show_all = true}
+ option.o {$output_files = true}
+ option.u {$exclude_stats = true}
+ option.I {$include_props = ARGV.shift.split(/[\,\;]+/)}
+ option.O {$output_prefix = ARGV.shift}
+end
+
+$help = true if($files.length<0)
+if $help
+ puts <<EOHELP
+Usage: ./stats.rb <-dha> <-I include_props> files
+ -d debug mode #{cw $debug}
+ -h print this help #{cw $help}
+ -a show all values, not just discrete ones #{cw $show_all}
+ -o output the stats to files instead of the console #{cw $output_files}
+ -u exclude stats, showing only unique lists of values #{cw $exclude_stats}
+ -I only calculate statistics for named properties #{aw $include_props}
+ -O prefix output files with specific prefix #{aw $output_prefix}
+EOHELP
+ exit 0
+end
+
+$files.each do |file|
+ lines = 0
+ headers = nil
+ file_stats = nil
+ File.open(file).each do |line|
+ lines += 1
+ fields=line.chomp.split(/[\t\,]/)
+ if headers
+ puts "Processing line: #{line}" if($debug)
+ lac,ci=nil
+ fields.each_with_index do |field,index|
+ if $include_props.to_s=='' || $include_props.index(headers[index])
+ puts "\tField[#{index}]: #{field}" if($debug)
+ stats = file_stats[index]
+ stats[field] ||= 0
+ stats[field] += 1
+ puts "\tField[#{index}]: #{field} => #{stats[field]}" if($debug)
+ lac=field if(headers[index]=='LAC' || headers[index]=='service.lac')
+ ci=field if(headers[index]=='CI' || headers[index]=='service.cell_id')
+ #puts "\tSet LAC=#{lac}, CI=#{ci} based on header #{headers[index]}" if($debug)
+ end
+ end
+ puts "\tSet LAC=#{lac}, CI=#{ci}" if($debug)
+ if lac && ci
+ index = headers.length - 1
+ puts "\tAdding statistics for LAC=#{lac}, CI=#{ci} using additional header '#{headers[index]}'" if($debug)
+ stats = file_stats[index]
+ field="#{lac}-#{ci}"
+ stats[field] ||= 0
+ stats[field] += 1
+ puts "\tField[#{index}]: #{field} => #{stats[field]}" if($debug)
+ end
+ if $debug
+ headers.each_with_index do |header,index|
+ stats = file_stats[index]
+ values = stats.keys
+ puts "\nFound #{values.length} unique values for field[#{index}] '#{header}'"
+ end
+ end
+ else
+ headers = fields
+ headers << 'lac-ci'
+ file_stats = fields.map{|h| {}}
+ file_stats << {}
+ end
+ end
+
+ if headers
+ found=[]
+ empty=[]
+ headers.each_with_index do |header,index|
+ stats=file_stats[index]
+ found << [header,stats] if(stats.keys.length>0)
+ end
+ found.each do |ff|
+ header,stats=*ff
+ output = STDOUT
+ filename = ([$output_prefix,header,$exclude_stats ? "Values" : "Stats"]).compact.join('_')+".txt"
+ if $output_files
+ output = File.open(filename,'w')
+ end
+ values = stats.keys
+ perc = 100.0 * values.length.to_f / lines.to_f
+ puts "Found #{values.length} unique values for field '#{header}'"
+ if !$show_all && (values.length > 500)
+ puts "\tNot printing more values more diverse than 500"
+ elsif (!$show_all && (perc > 75))
+ puts "\tNot printing more values more diverse than #{perc}%"
+ else
+ output.puts header
+ values.sort.each do |value|
+ value_text = (value.to_s.length < 1) ? '<empty>' : value
+ if $exclude_stats
+ output.puts "\t#{value_text}"
+ else
+ output.puts "\t#{value_text}\t#{stats[value]}"
+ end
+ end
+ end
+ if $output_files
+ puts "\tSaved to #{filename}"
+ output.close
+ else
+ puts
+ end
+ end
+ else
+ puts "No headers found in file #{file}"
+ end
+
+end
+
+
View
59 examples/export_layer.rb
@@ -1,59 +0,0 @@
-#!/usr/bin/env jruby
-
-# useful if being run inside a source code checkout
-$: << 'lib'
-$: << '../lib'
-
-require 'rubygems'
-require 'neo4j/spatial'
-require 'neo4j/spatial/cmd'
-
-$zoom = 1.0
-$args = Neo4j::Spatial::Cmd.args
-
-if $list === 'layers'
- layers = Neo4j::Spatial::Layer.list
- puts "Have #{layers.length} existing layers in the database:"
- layers.each {|l| puts "\t#{l} (#{l.type_name})"}
- puts
- exit 0
-end
-
-if $help || $args.length < 1
- puts <<-eos
-
-usage: ./export_layer.rb <-D storage_path> <-F format> <-E dir> <-Z zoom> <-W width> <-H height> <-l> <-h> layer <layers>
- -D Use specified database location
- -F Use specified export format (png, shp)
- -E Use specified export directory path (default '.')
- -Z Zoom in by specified factor (eg. 3.0)
- -W Image width (default 600)
- -H Image height (default 400)
- -l List existing database layers first
- -h Display this help and exit
- The layer(s) should be pre-existing layers (including dynamic layers) in the database.
- Supported formats are 'shp' for ESRI Shapefile and 'png' for images.
-
-For example:
- ./export_layer.rb -D db -E exports -F png croatia.osm highway highway-residential natural-water
-
-This will export four previously defined layers to png format files in the 'exports' directory.
-
-eos
- exit
-end
-
-if $format.to_s.downcase === 'shp'
- $exporter = Neo4j::Spatial::SHPExporter.new :dir => $export
-else
- $exporter = Neo4j::Spatial::ImageExporter.new :dir => $export, :zoom => $zoom, :width => $width, :height => $height
-end
-
-puts "Exporting #{$args.length} layers to #{$exporter.format}"
-
-$args.each do |layer|
- l = Neo4j::Spatial::Layer.find layer
- puts "Exporting #{l} (#{l.type_name}) - #{l.index.layer_bounding_box}"
- $exporter.export l.name
- puts "Finished exporting #{l} (#{l.type_name}) of #{l.index.count} entries"
-end
View
6 examples/show_geoptima.rb
@@ -7,7 +7,7 @@
require 'date'
require 'geoptima'
-Geoptima::assert_version("0.0.6")
+Geoptima::assert_version("0.0.7")
$debug=false
@@ -15,10 +15,6 @@
$files = []
$print_limit = 10000
-def cw(val)
- val.nil? ? '' : "(#{val})"
-end
-
while arg=ARGV.shift do
if arg =~ /^\-(\w+)/
$1.split(//).each do |aa|
View
41 examples/stats.rb
@@ -1,41 +0,0 @@
-#!/usr/bin/env ruby
-
-$debug = false
-$lines = 0
-
-ARGF.each do |line|
- $lines += 1
- fields=line.chomp.split(/\t/)
- if $headers
- puts "Processing line: #{line}" if($debug)
- fields.each_with_index do |field,index|
- puts "\tField[#{index}]: #{field}" if($debug)
- stats = $stats[index]
- stats[field] ||= 0
- stats[field] += 1
- puts "\tField[#{index}]: #{field} => #{stats[field]}" if($debug)
- end
- else
- $headers = fields
- $stats = fields.map{|h| {}}
- end
-end
-
-$headers.each_with_index do |header,index|
- stats = $stats[index]
- values = stats.keys
- perc = 100.0 * values.length.to_f / $lines.to_f
- puts "\nFound #{values.length} unique values for field '#{header}'"
- if values.length > 500
- puts "\tNot printing more values more diverse than 500"
- elsif (perc > 75)
- puts "\tNot printing more values more diverse than #{perc}%"
- else
- puts header
- values.sort.each do |value|
- value_text = (value.to_s.length < 1) ? '<empty>' : value
- puts "\t#{value_text}\t#{stats[value]}"
- end
- end
-end
-
View
2  geoptima.gemspec
@@ -25,7 +25,7 @@ EOF
s.files = Dir.glob("{bin,lib,rdoc}/**/*").reject{|x| x=~/(tmp|target|test-data)/ || x=~/~$/} +
Dir.glob("examples/*rb") + Dir.glob("examples/sample*json") +
%w(README.rdoc CHANGELOG CONTRIBUTORS Gemfile geoptima.gemspec)
- s.executables = ['show_geoptima','geoptima_file_time']
+ s.executables = ['show_geoptima','geoptima_file_time','csv_chart','csv_stats']
s.extra_rdoc_files = %w( README.rdoc )
s.rdoc_options = ["--quiet", "--title", "Geoptima.rb", "--line-numbers", "--main", "README.rdoc", "--inline-source"]
View
1  lib/geoptima.rb
@@ -1,3 +1,4 @@
require 'geoptima/version.rb'
require 'geoptima/data.rb'
+require 'geoptima/options.rb'
View
60 lib/geoptima/data.rb
@@ -3,6 +3,20 @@
require 'rubygems'
require 'multi_json'
require 'date'
+if $use_dateperformance
+ begin
+ require 'date/performance'
+ require 'date/memoize'
+ class DateTime
+ def >(other) ; self - other > 0 ; end
+ def <(other) ; self - other < 0 ; end
+ def >=(other); self - other >= 0; end
+ def <=(other); self - other <= 0; end
+ end
+ rescue LoadError
+ puts "No date-performance gem installed, some features will run slower"
+ end
+end
#
# The Geoptima Module provides support for the Geoptima Client JSON file format
@@ -29,6 +43,26 @@ def self.[]=(key,value)
end
end
+ class DateRange
+ attr_reader :min, :max, :range
+ def initialize(min,max)
+ @min = min
+ @max = max
+ @range = Range.new(min,max)
+ end
+ if ENV['RUBY_VERSION'] =~ /1\.8/
+ puts "Defining Range.include? to wrap for 1.8"
+ def include?(time)
+ @range.include?(time)
+ end
+ else
+ puts "Defining Range.include? to perform inequality tests for 1.9"
+ def include?(time)
+ (time >= min) && (time <= @max)
+ end
+ end
+ end
+
# The Geoptima::Event class represents and individual record or event
class Event
KNOWN_HEADERS={
@@ -67,7 +101,7 @@ def utc
time.new_offset(0)
end
def time_key
- utc.strftime("%Y-%m-%d %H:%M:%S.%3N")
+ utc.strftime("%Y-%m-%d %H:%M:%S.%3N").gsub(/\.(\d{3})\d+/,'.\1')
end
def [](key)
@fields[key] || @fields[key.gsub(/#{name}\./,'')]
@@ -127,7 +161,7 @@ def [](key)
@fields[key] ||= subscriber[key] || subscriber[key.downcase]
end
def start
- @start ||= subscriber['start'] && DateTime.parse(subscriber['start'].gsub(/Asia\/Bangkok/,'GMT+7').gsub(/Mar 17 2044/,'Feb 14 2012'))
+ @start ||= subscriber['start'] && DateTime.parse(subscriber['start'].gsub(/Asia\/Bangkok/,'GMT+7'))#.gsub(/Mar 17 2044/,'Feb 14 2012'))
end
def valid?
start && start > Data.min_start && start < Data.max_start
@@ -216,7 +250,7 @@ def initialize(imei,options={})
@imei = imei
@data = []
@options = options
- @time_range = options[:time_range] || Range.new(Config[:min_datetime],Config[:max_datetime])
+ @time_range = options[:time_range] || DateRange.new(Config[:min_datetime],Config[:max_datetime])
@fields = {}
end
@@ -347,17 +381,30 @@ def merge_events
@sorted ||= {}
unless @sorted[nil]
event_hash = {}
+ puts "Creating sorted maps for #{self}" if($debug)
events_names.each do |name|
+ puts "Preparing maps for #{name}" if($debug)
@data.each do |data|
+ puts "Processing #{(e=data.events[name]) && e.length} events for #{name}" if($debug)
(events = data.events[name]) && events.each do |event|
+# t = event.time.to_i
+ puts "\t\tTesting #{event.time} inside #{@time_range}" if($debug)
+# if t < tmax
+# if event.time > @time_range.min
+# if (event.time >= @time_range.min) && (event.time < @time_range.max)
if @time_range.include?(event.time)
+# if @time_range.cover?(event.time)
+ puts "\t\t\tEvent at #{event.time} is inside #{@time_range}" if($debug)
key = "#{event.time_key} #{name}"
event_hash[key] = event
end
end
end
+ puts "After adding #{name} events, maps are #{event_hash.length} long" if($debug)
end
+ puts "Merging and sorting #{event_hash.keys.length} maps" if($debug)
@sorted[nil] = event_hash.keys.sort.map{|k| event_hash[k]}
+ puts "Sorted #{@sorted[nil].length} events" if($debug)
locate_events if(options[:locate])
end
@sorted
@@ -365,18 +412,21 @@ def merge_events
def locate_events
prev_gps = nil
+ count = 0
+ puts "Locating #{sorted.length} events" if($debug)
sorted.each do |event|
if event.name === 'gps'
event.locate(event)
prev_gps = event
elsif prev_gps
- event.locate_if_closer_than(prev_gps,60)
+ count += 1 if(event.locate_if_closer_than(prev_gps,60))
end
end
+ puts "Located #{count} / #{sorted.length} events" if($debug)
end
def to_s
- "IMEI:#{imei}, IMSI:#{imsis.join(',')}, Platform:#{platform}, Model:#{model}, OS:#{os}, Files:#{file_count}, Events:#{sorted.length}"
+ "IMEI:#{imei}, IMSI:#{imsis.join(',')}, Platform:#{platform}, Model:#{model}, OS:#{os}, Files:#{file_count}, Events:#{sorted && sorted.length}"
end
def self.make_datasets(files, options={})
View
2  lib/geoptima/version.rb
@@ -1,6 +1,6 @@
module Geoptima
- VERSION = "0.0.6"
+ VERSION = "0.0.7"
def self.version_as_int(ver)
base = 1

No commit comments for this range

Something went wrong with that request. Please try again.