Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

possible problem with wind direction

  • Loading branch information...
commit 6ae7940694fe2cacaa1ba30b49adff912c72a071 1 parent 3c29dbd
@petercutting authored
View
2  app/controllers/gearth_controller.rb
@@ -77,6 +77,8 @@ def route
# Igcfile.destroy_all( ["filename = ?",filename]) # forces data reload
@igcfile = Igcfile.get(path,Constants::PROC_VERSION.to_i)
+ @igcfile.import_file(path)
+
@windpoints = Windpoint.find(:all,:order => "seq_secs DESC",:conditions => {
:igcfile_id => @igcfile.id })
View
22 app/models/igcfile.rb
@@ -15,7 +15,7 @@ def after_initialize
def get_wind
- puts "get_wind "
+ #puts "get_wind "
@windpoints = Windpoint.find(:all,:order => "seq_secs DESC",:conditions => {
:igcfile_id => self.id })
@@ -25,7 +25,7 @@ def get_wind
avg_speed=0.0
#debugger
@windpoints.each {|wp|
- puts wp[:direction]
+ #print wp[:direction].to_s + " "
n=n+(wp[:speed] * Math.cos(wp[:direction]))
e=e+(wp[:speed] * Math.sin(wp[:direction]))
avg_speed = avg_speed + wp[:speed]
@@ -33,12 +33,18 @@ def get_wind
avg_speed = avg_speed / @windpoints.size
avg_direction = Math.atan2(e, n)
+
+ if avg_direction < 0
+ avg_direction = avg_direction + (2*Constants::PI)
+ end
+
puts "avg wind dir " + avg_direction.to_s[0,4] + " speed " + avg_speed.to_s[0,4]
self.update_attributes(:wind_direction => avg_direction, :wind_speed => avg_speed)
end
+ def Igcfile.get(path,proc_version)
puts
puts "Igcfile.get " + path + " " + proc_version.to_s
@@ -46,11 +52,11 @@ def Igcfile.get(path,proc_version)
begin
filename=path.split("/").last
-
+
#puts "Looking in DB for " + filename
@igcfile = Igcfile.find_by_filename!(filename) # ! enables a recordnotfound exception
- if @igcfile.proc_version.to_i < proc_version
+ if @igcfile.proc_version.to_i < proc_version
#puts "Old process version " + @igcfile.proc_version.to_s
raise ActiveRecord::RecordNotFound
end
@@ -66,9 +72,8 @@ def Igcfile.get(path,proc_version)
rescue Exception => ex
puts "Generic " + ex.message
end
-
- @igcfile.import_file(path)
+ if find_thermals==1
@igcfile.import_file(path)
Windpoint.find_thermals(@igcfile)
@igcfile.get_wind()
@@ -81,6 +86,11 @@ def Igcfile.get(path,proc_version)
def import_file(path)
puts 'import_file'
+
+ if not self.objects.empty?
+ puts "import_file, objects not empty, aborting"
+ return
+ end
save_obj=Hash.new
num_recs=1 # to prevent divide by zero
View
50 app/models/windpoint.rb
@@ -5,7 +5,7 @@ class Windpoint < ActiveRecord::Base
def Windpoint.find_thermals(igcfile)
puts "Windpoint.find_thermals "
-# delete old points
+ # delete old points
Windpoint.destroy_all( ["igcfile_id = ?",igcfile.id])
start_of_therm=0
@@ -54,25 +54,40 @@ def Windpoint.find_thermals(igcfile)
end
}
- lon1 = thermal_start[:malon]*Constants::RAD_PER_DEG
- lon2 = thermal_end[:malon]*Constants::RAD_PER_DEG
- lat1 = thermal_start[:malat]*Constants::RAD_PER_DEG
- lat2 = thermal_end[:malat]*Constants::RAD_PER_DEG
-
- d=(2*Math.asin(((Math.sin((lat1-lat2)/2))**2 + Math.cos(lat1)*Math.cos(lat2)*(Math.sin((lon1-lon2)/2))**2)**0.5)).abs
- if Math.sin(lon2-lon1)<0
- dir=Math.acos((Math.sin(lat2)-Math.sin(lat1)*Math.cos(d))/(Math.sin(d)*Math.cos(lat1)))
- else
- dir=2*Constants::PI-Math.acos((Math.sin(lat2)-Math.sin(lat1)*Math.cos(d))/(Math.sin(d)*Math.cos(lat1)))
- end
-
- speed = (d*Constants::RADIUS / (thermal_start[:seq_secs] - thermal_end[:seq_secs])).abs
- #climb = 0.0
climb = (thermal_end[:baro_alt] - thermal_start[:baro_alt]).to_f/(thermal_end[:seq_secs] - thermal_start[:seq_secs]).to_f
if climb > 0.2
- print climb.to_s[0,3] + " "
- w = Windpoint.new(:igcfile_id => igcfile.id,:speed => speed.to_i, :direction => dir, :climb => climb,
+
+ lon1 = thermal_start[:malon]*Constants::RAD_PER_DEG
+ lat1 = thermal_start[:malat]*Constants::RAD_PER_DEG
+ lon2 = thermal_end[:malon]*Constants::RAD_PER_DEG
+ lat2 = thermal_end[:malat]*Constants::RAD_PER_DEG
+
+# puts lon1.to_s + " " + lat1.to_s
+# puts lon2.to_s + " " + lat2.to_s
+# puts thermal_start[:baro_alt].to_s + " " + thermal_end[:baro_alt].to_s
+# puts thermal_start[:seq_secs].to_s + " " + thermal_end[:seq_secs].to_s
+
+# d=(2*Math.asin(((Math.sin((lat1-lat2)/2))**2 + Math.cos(lat1)*Math.cos(lat2)*(Math.sin((lon1-lon2)/2))**2)**0.5)).abs
+d=Math.acos(Math.sin(lat1)*Math.sin(lat2)+Math.cos(lat1)*Math.cos(lat2)*Math.cos(lon1-lon2))
+# puts
+ if Math.sin(lon2-lon1)<0
+ direction=Math.acos((Math.sin(lat2)-Math.sin(lat1)*Math.cos(d))/(Math.sin(d)*Math.cos(lat1)))
+ else
+ direction=2*Constants::PI-Math.acos((Math.sin(lat2)-Math.sin(lat1)*Math.cos(d))/(Math.sin(d)*Math.cos(lat1)))
+ end
+
+ speed = d*Constants::RADIUS / (thermal_end[:seq_secs] - thermal_start[:seq_secs])
+
+ puts (d*Constants::RADIUS).to_s + " " +
+ direction.to_s + " " +
+ climb.to_s[0,3] + " " +
+ thermal_start[:seq_secs].to_s + " " + thermal_end[:seq_secs].to_s + " " +
+ (thermal_end[:seq_secs] - thermal_start[:seq_secs]).to_s + " " +
+ direction.to_s[0,4] + " " + speed.to_s[0,4]
+
+
+ w = Windpoint.new(:igcfile_id => igcfile.id,:speed => speed, :direction => direction, :climb => climb,
:altitude => thermal_start[:baro_alt], :dlat => thermal_start[:malat],
:dlon => thermal_start[:malon], :seq_secs => thermal_start[:seq_secs],
:altitude2 => thermal_end[:baro_alt], :dlat2 => thermal_end[:malat],
@@ -90,6 +105,7 @@ def Windpoint.find_thermals(igcfile)
end
#
+ #puts " atan2(1,-1) " + Math.atan2(1,-1).to_s
puts ""
end
View
11 db/migrate/20110218135146_speed_to_float.rb
@@ -0,0 +1,11 @@
+class SpeedToFloat < ActiveRecord::Migration
+ def self.up
+ change_column :igcfiles, :wind_speed, :float
+ change_column :windpoints, :speed, :float
+ end
+
+ def self.down
+ change_column :igcfiles, :wind_speed, :int
+ change_column :windpoints, :speed, :int
+ end
+end
View
6 db/schema.rb
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20110217150710) do
+ActiveRecord::Schema.define(:version => 20110218135146) do
create_table "igcfiles", :force => true do |t|
t.string "filename"
@@ -18,7 +18,7 @@
t.datetime "updated_at"
t.string "path"
t.integer "proc_version"
- t.integer "wind_speed"
+ t.float "wind_speed"
end
add_index "igcfiles", ["filename"], :name => "index_igcfiles_on_filename", :unique => true
@@ -43,7 +43,7 @@
create_table "windpoints", :force => true do |t|
t.integer "igcfile_id"
t.float "direction"
- t.integer "speed"
+ t.float "speed"
t.integer "altitude"
t.integer "seq_secs"
t.float "dlon"
View
4 lib/constants.rb
@@ -1,6 +1,6 @@
class Constants
- PI = 3.14159 # PI/180
+ PI = 3.14159 #
RAD_PER_DEG = 0.0174532 # PI/180
RADIUS = 6371 * 1000
GRAV_CONST = 9.81
@@ -11,6 +11,6 @@ class Constants
IN_THERMAL = 2
LEAVE_THERMAL = 3
- PROC_VERSION = 35
+ PROC_VERSION = 39
end
View
61 lib/tasks/ligc3.rake
@@ -1,12 +1,16 @@
desc "Loads IGC files from specified directory (or .)"
-# rake ligc3[.]
-# rake ligc3[public/data]
-# rake ligc3["C:/Documents and Settings/Peter Cutting/My Documents/soaring/logs/IGC/RST/IGC_files_2009-09-30"]
-# rake ligc3[0,"C:/Documents and Settings/Peter Cutting/My Documents/soaring/logs/IGC/RST/test"]
-
-task :ligc3, [:proc_version,:dir] => :environment do |t, args|
-debugger
+# rake ligc3[.,0]
+# rake ligc3[public/data,0]
+# rake ligc3[public/data/NewFolder,0]
+# rake ligc3["C:\Documents and Settings/Peter Cutting/My Documents/soaring/logs",0]
+# rake ligc3["C:\Documents and Settings\cuttingp\My Documents\soaring\logs",0]
+# rake ligc3["C:\Documents and Settings\cuttingp\My Documents\soaring\logs",0]
+# rake ligc3["C:/Documents and Settings/Peter Cutting/My Documents/soaring/logs/IGC/RST/IGC_files_2009-09-30",0]
+# rake ligc3["C:/Documents and Settings/Peter Cutting/My Documents/soaring/logs/IGC/RST/test",0]
+
+task :ligc3, [:dir,:proc_version] => :environment do |t, args|
+ #debugger does not seem to work in rake tasks
args.with_defaults(:dir => "public/data")
args.with_defaults(:proc_version => 0)
@@ -17,42 +21,48 @@ debugger
#gem install activerecord-import -v 0.2.0
- puts File.dirname(__FILE__)
+ puts "script dir " + File.dirname(__FILE__)
#puts proc_version
# @dir="#{args.dir}"
# puts @dir
+# print "B "
+# $stdout.sync # only need to be done once
+# $stdout.flush
class Import
- def process_igcfiles(dir)
+ def process_igcfiles(dir,proc_version)
+
+ if proc_version == 0
+ proc_version = Igcfile.maximum('proc_version') + 1
+ end
+
puts 'directory is ' + dir
num_recs=0
-# Igcfile.destroy_all
-# Igcpoint.destroy_all
-# Windpoint.destroy_all
+ # Igcfile.destroy_all
+ # Igcpoint.destroy_all
+ # Windpoint.destroy_all
- WalkDirs(dir)
- #STDOUT.flush
+ WalkDirs(dir,proc_version)
end
- def WalkDirs(path)
+ def WalkDirs(path,proc_version)
+ puts "look in " + path
Find.find(path) do |entry|
if File.file?(entry) and entry.to_s.downcase.match('.igc$')
- #puts entry
- process_igcfile(entry)
+ process_igcfile(entry,proc_version)
end
end
end
- def process_igcfile(path)
+ def process_igcfile(path,proc_version)
filename=path.split("/").last
start = Time.now
- #puts "processing " + path
num_recs=1 # to prevent divide by zero
# begin
@@ -62,16 +72,8 @@ debugger
# end
#debugger
- @igcfile = Igcfile.get(path,Constants::PROC_VERSION.to_i)
-
- # puts "SAVING " + filename
- # igcfile = Igcfile.new( :filename => filename, :path => path)
- # igcfile.save
- #puts igcfile.inspect
- # objects=[]
- # objects = Igcfile.import(path)
- # Windpoint.find_thermals(igcfile,objects)
+ @igcfile = Igcfile.get(path,proc_version)
seconds = Time.now - start
# puts filename + ' ' + @objects.count.to_s + ' ' + (@objects.count/seconds).to_i.to_s
@@ -83,7 +85,8 @@ debugger
puts "Starting..."
import = Import.new
- import.process_igcfiles("#{args.dir}")
+ debugger
+ import.process_igcfiles("#{args.dir}","#{args.proc_version}".to_i)
end
View
2,527 public/data/NewFolder/38gc3rl4.igc
2,527 additions, 0 deletions not shown
View
5,143 public/data/NewFolder/38hc3rl1.iXgc
5,143 additions, 0 deletions not shown
View
6,355 public/data/NewFolder/38oc3rl1.iXgc
6,355 additions, 0 deletions not shown
Please sign in to comment.
Something went wrong with that request. Please try again.