fossil 0.5.47 → 0.5.48

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.47
1
+ 0.5.48
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{fossil}
8
- s.version = "0.5.47"
8
+ s.version = "0.5.48"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Daniel Sudol", "Patrick Lardin"]
12
- s.date = %q{2011-03-23}
12
+ s.date = %q{2011-04-01}
13
13
  s.description = %q{Access FOS/betrieve db with this Sequel based orm wrapper}
14
14
  s.email = %q{dansudol@yahoo.com}
15
15
  s.extra_rdoc_files = [
@@ -7,18 +7,20 @@
7
7
  # The other methods are special methods for datamart trip_leg summary table
8
8
  #
9
9
  class TripLeg
10
- one_to_many :crew_legs, :class=>:CrewLeg, :key=>:trip_leg_id, :primary_key=>:id
11
- one_to_many :flight_log_expenses, :class=>:FlightLogExpense, :key=>:trip_leg_id, :primary_key=>:id
12
- many_to_one :trip, :class=>:Trip, :key=>:trips_id
13
- many_to_one :arrival_fbo, :class=>:AirportFbo, :key=>:fbo_id
14
- many_to_one :departure_fbo, :class=>:AirportFbo, :key=>:fueler_id
15
- many_to_one :trip_requester, :class=>:Passenger, :key=>:requester_id
16
- many_to_one :leg_requestor, :class=>:Passenger, :key=>:leg_req_id
17
- many_to_one :departure_catering_comment, :class=>:Comment, :key=>:departure_catering_comment_id
18
- many_to_one :arrival_catering_comment, :class=>:Comment, :key=>:arrival_catering_comment_id
19
- many_to_one :departure_transport_comment, :class=>:Comment, :key=>:departure_transport_comment_id
20
- many_to_one :arrival_transport_comment, :class=>:Comment, :key=>:arrival_transport_comment_id
21
- many_to_one :departure_general_comment, :class=>:Comment, :key=>:departure_general_comment_id
22
- many_to_one :arrival_general_comment, :class=>:Comment, :key=>:arrival_general_comment_id
23
- many_to_one :crew_transport_comment, :class=>:Comment, :key=>:crew_transport_comment_id
10
+ one_to_many :crew_legs, :class=>:CrewLeg, :key=>:trip_leg_id, :primary_key=>:id
11
+ one_to_many :flight_log_expenses, :class=>:FlightLogExpense, :key=>:trip_leg_id, :primary_key=>:id
12
+ many_to_one :trip, :class=>:Trip, :key=>:trips_id
13
+ many_to_one :arrival_fbo, :class=>:AirportFbo, :key=>:fbo_id
14
+ many_to_one :departure_fbo, :class=>:AirportFbo, :key=>:fueler_id
15
+ many_to_one :trip_requester, :class=>:Passenger, :key=>:requester_id
16
+ many_to_one :leg_requestor, :class=>:Passenger, :key=>:leg_req_id
17
+ many_to_one :departure_catering_comment, :class=>:Comment, :key=>:departure_catering_comment_id
18
+ many_to_one :arrival_catering_comment, :class=>:Comment, :key=>:arrival_catering_comment_id
19
+ many_to_one :departure_transport_comment, :class=>:Comment, :key=>:departure_transport_comment_id
20
+ many_to_one :arrival_transport_comment, :class=>:Comment, :key=>:arrival_transport_comment_id
21
+ many_to_one :departure_general_comment, :class=>:Comment, :key=>:departure_general_comment_id
22
+ many_to_one :arrival_general_comment, :class=>:Comment, :key=>:arrival_general_comment_id
23
+ many_to_one :crew_transport_comment, :class=>:Comment, :key=>:crew_transport_comment_id
24
+ many_to_one :arrival_airport, :class=>:Airport, :key=>:arrival_airport_id, :primary_key => :airport_id
25
+ many_to_one :departure_airport, :class=>:Airport, :key=>:depart_airport_id, :primary_key => :airport_id
24
26
  end
@@ -63,7 +63,7 @@ class FlightLogExpense < Sequel::Model(:'flight log expenses')
63
63
  column_alias :pay_method, :'pay method'
64
64
  column_alias :percent_markup, :'percent markup'
65
65
  column_alias :problem, :'problem'
66
- column_alias :quantity, :'quantity'
66
+ column_alias :quantity, :'quantity', :type => :integer
67
67
  column_alias :quantity_tenths, :'quantity tenths'
68
68
  column_alias :receipt, :'receipt'
69
69
  column_alias :receipt_number, :'receipt number'
@@ -83,7 +83,7 @@ class FlightLogExpense < Sequel::Model(:'flight log expenses')
83
83
  column_alias :trip_leg_kid_mult, :'trip leg kid - mult'
84
84
  column_alias :trip_leg_kid_time, :'trip leg kid - time'
85
85
  column_alias :trip_leg_kid_user, :'trip leg kid - user'
86
- column_alias :type, :'type'
86
+ column_alias :type, :'type', :type => :integer
87
87
  column_alias :unit, :'unit'
88
88
  column_alias :unit_cost, :'unit cost'
89
89
  column_alias :vendor_id, :'vendor id'
@@ -950,35 +950,25 @@ class TripLeg < Sequel::Model(:'trip legs')
950
950
  TripLeg.filter(:cancelled => 0, :status => [0,1,2]).
951
951
  filter(~{:'leg state' => 5}).
952
952
  filter({:'dept date act local' => start_date..end_date,
953
- :'depart date - local' => start_date...end_date}.sql_or).all
954
- # eager_graph(:flight_log_expenses => :vendor).
955
- # eager_graph(:departure_fbo).
956
- # eager_graph(:arrival_fbo).
957
- # select_fields(:self => [:dept_date_act_local, :depart_date_local, :trip_number, :leg_number,
958
- # :departure_icao, :depart_ap_prefix, :depart_airport_id, :arrival_icao,
959
- # :arrival_airport_id, :arrival_ap_prefix, :aircraft_id],
960
- # :flight_log_expenses__vendor => [:company_2, :company_1, :vendor_id],
961
- # :flight_log_expenses => [:*],
962
- # :departure_fbo => [:name],
963
- # :arrival_fbo => [:name]).all
953
+ :'depart date - local' => start_date..end_date}.sql_or).
954
+ order(:depart_date_local).all
964
955
  end
965
956
 
966
957
  def fuel_data_by_fbo_keys trip_legs, fbo_keys
967
- data = Hash.new
958
+ data = Hash.new { |hash, key| hash[key] = Array.new }
968
959
  trip_legs.each do |leg|
969
960
  leg.fuel_expenses.each do |expense|
970
961
 
971
962
  fbo_name = leg.send( "#{expense.type_string}_fbo__name" )
972
-
973
- if fbo_keys.include?(fbo_name) then # is this an fbo we are looking for?
974
- expense_hash = expense.fuel_passdown_hash
975
-
976
- if data.has_key?(fbo_name)
977
- data[fbo_name].push(expense_hash)
978
- else
979
- data[fbo_name] = [expense_hash]
963
+ match = false
964
+ fbo_keys.each do |key|
965
+ if fbo_name.index(key) == 0 # fbo name can have suffix like A, B, SOUTH, EAST, etc.
966
+ match = true
967
+ break
980
968
  end
981
969
  end
970
+
971
+ data[fbo_name].push( expense.fuel_passdown_hash ) if match
982
972
  end
983
973
  end
984
974
  data
@@ -16,7 +16,7 @@ end
16
16
 
17
17
  class Integer
18
18
  def as_cost
19
- self/100.0
19
+ self / 100.0
20
20
  end
21
21
 
22
22
  def in_hundredths
@@ -8,7 +8,7 @@ describe FlightLogExpense do
8
8
  @fe = FlightLogExpense.new(:type => 1)
9
9
  end
10
10
 
11
- describe 'fuel cost' do
11
+ describe '#fuel_cost' do
12
12
 
13
13
  it 'should not have a cost if it doesnt have a quantity' do
14
14
  @fe.quantity = 0
@@ -24,7 +24,7 @@ describe FlightLogExpense do
24
24
  end
25
25
  end
26
26
 
27
- describe 'fuel rate' do
27
+ describe '#fuel_rate' do
28
28
 
29
29
  it 'should not have a rate if the airport fuel pricing cannnot be determined' do
30
30
  @fe.quantity = 100
@@ -35,7 +35,7 @@ describe FlightLogExpense do
35
35
 
36
36
  describe 'different fuel tiers' do
37
37
 
38
- before :each do
38
+ before do
39
39
  airport_fuel = {
40
40
  :"qty 1"=>1, :"cost 1"=>393,
41
41
  :"qty 2"=>1000, :"cost 2"=>373,
@@ -67,6 +67,62 @@ describe FlightLogExpense do
67
67
  end
68
68
  end
69
69
  end
70
+
71
+ describe '#fuel_passdown_hash' do
72
+
73
+ before :each do
74
+ atlantic_fbo = AirportFbo.new( :name => "ATLANTIC AVIATION SERVIC" )
75
+ signature_fbo = AirportFbo.new( :name => "SIGNATURE FLIGHT SUPPORT" )
76
+
77
+ @trip_leg = TripLeg.new( :trip_number => 12345, :leg_number => 1, :aircraft_id => "C750",
78
+ :departure_icao => "KSFO", :arrival_icao => "KTEB",
79
+ :departure_fbo => signature_fbo, :arrival_fbo => atlantic_fbo,
80
+ :dept_date_act_local => 40123, :depart_date_local => 40124 )
81
+
82
+ @vendor = Vendor.new( :company_2 => "Landmark Aviation", :company_1 => "Landmark", :vendor_id => "LMAR" )
83
+
84
+ stub(@fe).trip_leg { @trip_leg }
85
+ stub(@fe).vendor { @vendor }
86
+ stub(@fe).fuel_rate { 4.12 }
87
+ @fe.quantity = 1234
88
+ @fe.arrival_airport = 0
89
+
90
+ @expected = {
91
+ :leg_date => 40123,
92
+ :trip_number => 12345,
93
+ :leg_number => 1,
94
+ :ac => "C750",
95
+ :airport => "KTEB",
96
+ :fbo => "ATLANTIC AVIATION SERVIC",
97
+ :vendor => "Landmark Aviation",
98
+ :fuel_rate => 4.12,
99
+ :fuel_quantity => 1234,
100
+ :fuel_cost => 5084.08
101
+ }
102
+ end
103
+
104
+ it 'should use arrival attributes if the expense is arrival' do
105
+ @fe.arrival_airport = 1
106
+ @fe.fuel_passdown_hash.should == @expected
107
+ end
108
+
109
+ it 'should use departure attributes if the expense is departure' do
110
+ @expected[:fbo] = "SIGNATURE FLIGHT SUPPORT"
111
+ @expected[:airport] = "KSFO"
112
+ @fe.fuel_passdown_hash.should == @expected
113
+ end
114
+
115
+ it 'should use vendor company_1 if company_2 is blank or nil' do
116
+ @vendor.company_2 = ""
117
+ @fe.fuel_passdown_hash[:vendor].should == "Landmark"
118
+ end
119
+
120
+ it 'should use vendor vendor_id if company_2 and company_1 are blank or nil' do
121
+ @vendor.company_2 = ""
122
+ @vendor.company_1 = ""
123
+ @fe.fuel_passdown_hash[:vendor].should == "LMAR"
124
+ end
125
+ end
70
126
  end
71
127
 
72
128
  it 'should give the type as a string' do
@@ -5,7 +5,6 @@ describe TripLeg do
5
5
  describe "leg_status" do
6
6
  it "shows maint status" do
7
7
  trip_leg = TripLeg.new(:cancel_code=>0, :status=>21, :flight_time_actual=>0, :verify_date=>0)
8
- trip_leg.status= 21
9
8
  trip_leg.leg_status.should == "MAINT"
10
9
  end
11
10
  end
@@ -353,7 +352,7 @@ describe TripLeg do
353
352
  @tl.total_fuel_cost.should == 200.0
354
353
  end
355
354
  end
356
-
355
+
357
356
  describe 'arrival fuel quantity' do
358
357
 
359
358
  it 'should not have a quantity if there are no fuel flight log expenses' do
@@ -370,7 +369,7 @@ describe TripLeg do
370
369
 
371
370
  it 'should not have a quantity if the fuel flight log expense is not arrival' do
372
371
  fe = FlightLogExpense.new(:type => 1, :arrival_airport => 0)
373
- fe.quantity = 300
372
+ fe.quantity = 300
374
373
  stub(@tl).fuel_expenses { [fe] }
375
374
 
376
375
  @tl.arrival_fuel_purchased_quantity.should == 0
@@ -401,7 +400,7 @@ describe TripLeg do
401
400
  @tl.arrival_fuel_purchased_quantity.should == 700.0
402
401
  end
403
402
  end
404
-
403
+
405
404
  describe 'departure fuel quantity' do
406
405
 
407
406
  it 'should not have a quantity if there are no fuel flight log expenses' do
@@ -418,7 +417,7 @@ describe TripLeg do
418
417
 
419
418
  it 'should not have a quantity if the fuel flight log expense is not departure' do
420
419
  fe = FlightLogExpense.new(:type => 1, :arrival_airport => 1)
421
- fe.quantity = 300
420
+ fe.quantity = 300
422
421
  stub(@tl).fuel_expenses { [fe] }
423
422
 
424
423
  @tl.departure_fuel_purchased_quantity.should == 0
@@ -449,7 +448,7 @@ describe TripLeg do
449
448
  @tl.departure_fuel_purchased_quantity.should == 700.0
450
449
  end
451
450
  end
452
-
451
+
453
452
  describe 'total fuel quantities' do
454
453
  it 'should not have a total quantity if there are no fuel flight log expenses' do
455
454
  stub(@tl).departure_fuel_purchased_quantity { 0 }
@@ -480,4 +479,60 @@ describe TripLeg do
480
479
  end
481
480
  end
482
481
  end
482
+
483
+ describe 'Fuel Passdown' do
484
+ describe '#fuel_passdown_data' do
485
+ it 'should take start_date end_date and fbo_keys and return the fuel expense data trip legs in the range' do
486
+ start_date = Date.new
487
+ end_date = Date.new + 1.days
488
+ fbo_keys = ["ATLANTIC AVIATION SERVICE"]
489
+ trip_legs = []
490
+ fuel_data = {}
491
+ mock(TripLeg).get_fuel_passdown_trip_legs( start_date, end_date ) { trip_legs }
492
+ mock(TripLeg).fuel_data_by_fbo_keys( trip_legs, fbo_keys ) { fuel_data }
493
+
494
+ TripLeg.fuel_passdown_data(start_date, end_date, fbo_keys).should == fuel_data
495
+ end
496
+ end
497
+
498
+ describe '#fuel_data_by_fbo_keys' do
499
+ before do
500
+ @fuel_data_hash1 = {}
501
+ @fuel_data_hash2 = {}
502
+
503
+ atlantic_fbo = AirportFbo.new( :name => "ATLANTIC AVIATION SERVIC" )
504
+ landmark_fbo = AirportFbo.new( :name => "LANDMARK AVIATION" )
505
+ signature_fbo = AirportFbo.new( :name => "SIGNATURE FLIGHT SUPPORT" )
506
+ no_match_fbo = AirportFbo.new( :name => "NOT MATCHING" )
507
+
508
+ flight_log_expense1 = FlightLogExpense.new( :arrival_airport => 0, :type => 1 )
509
+ stub( flight_log_expense1 ).fuel_passdown_hash { @fuel_data_hash1 }
510
+
511
+ flight_log_expense2 = FlightLogExpense.new( :arrival_airport => 1, :type => 1 )
512
+ stub( flight_log_expense2 ).fuel_passdown_hash { @fuel_data_hash2 }
513
+
514
+ flight_log_expense3 = FlightLogExpense.new( :arrival_airport => 0, :type => 1 )
515
+
516
+ leg1 = TripLeg.new( :departure_fbo => landmark_fbo, :arrival_fbo => atlantic_fbo )
517
+ stub( leg1 ).flight_log_expenses { [ flight_log_expense1 ] }
518
+
519
+ leg2 = TripLeg.new( :departure_fbo => landmark_fbo, :arrival_fbo => signature_fbo )
520
+ stub( leg2 ).flight_log_expenses { [ flight_log_expense2 ] }
521
+
522
+ leg3 = TripLeg.new( :departure_fbo => no_match_fbo, :arrival_fbo => no_match_fbo )
523
+ stub( leg3 ).flight_log_expenses { [ flight_log_expense3 ] }
524
+
525
+ @trip_legs = [ leg1, leg2, leg3 ]
526
+ end
527
+
528
+ it 'should return a hash of fuel data hashes grouped by fbo names' do
529
+ fbo_keys = [ "LANDMARK AVIATION", "SIGNATURE FLIGHT SUPPORT" ]
530
+ results = TripLeg.send( :fuel_data_by_fbo_keys, @trip_legs, fbo_keys )
531
+
532
+ results.should == { "LANDMARK AVIATION" => [ @fuel_data_hash1 ],
533
+ "SIGNATURE FLIGHT SUPPORT" => [ @fuel_data_hash2 ]
534
+ }
535
+ end
536
+ end
537
+ end
483
538
  end
@@ -5,15 +5,27 @@ describe "FOS Licensing" do
5
5
  before :all do
6
6
  # set_fos_db([TripLeg, FlightLogExpense, Vendor, AirportFbo])
7
7
  # set_dbr_db([TripLeg, FlightLogExpense, Aircraft, Vendor, AirportFbo])
8
- db = Sequel.fos_dbr(:username => 'datamart', :password => 'datap@ss', :adapter => 'mysql', :host => 'hrkdm', :database => 'dbr')
9
- db.loggers=[Logger.new($stdout)]
10
- [TripLeg, FlightLogExpense, Aircraft, Vendor, AirportFbo, AirportFuel].each { |m| m.db = db }
8
+ # db = Sequel.fos_dbr(:username => 'datamart', :password => 'datap@ss', :adapter => 'mysql', :host => 'hrkdm', :database => 'dbr')
9
+ # db.loggers=[Logger.new($stdout)]
10
+ # [TripLeg, FlightLogExpense, Aircraft, Vendor, AirportFbo, AirportFuel].each { |m| m.db = db }
11
11
  end
12
12
 
13
- it "puts the lotion on the skin" do
14
- legs = TripLeg.fuel_passdown_data(Date.parse('2011-02-06'), Date.parse('2011-02-06'), ["SIGNATURE FLIGHT SUPPORT"])
15
- p "BLAH BLAH BLAH"
16
- pp legs
13
+ it "pass a block to include?" do
14
+ fbos = ["ATLANTIC AVIATION SERVIC", "SIGNATURE FLIGHT SUPPORT", "LANDMARK AVIATION"]
15
+ search = "LANDMARK AVIATION EAST"
16
+
17
+ result = nil
18
+ fbos.each do |fbo|
19
+ result = fbo and break if search.match(/^#{fbo}.*/)
20
+ end
21
+
22
+ p result
23
+ end
24
+
25
+ # it "puts the lotion on the skin" do
26
+ # legs = TripLeg.fuel_passdown_data(Date.parse('2011-02-06'), Date.parse('2011-02-06'), ["SIGNATURE FLIGHT SUPPORT"])
27
+ # p "BLAH BLAH BLAH"
28
+ # pp legs
17
29
 
18
30
  # l = TripLeg.filter(:'trip number' => 68562, :'leg number' => 1).eager_graph(:flight_log_expenses => :vendor).all.first
19
31
  # p "BLAH BLAH BLAH BLAH"
@@ -23,7 +35,7 @@ describe "FOS Licensing" do
23
35
  # tl = TripLeg.filter(:trip_number=>68562, :leg_number =>1).first
24
36
  # tl = TripLeg.filter(:trip_number => 68562, :leg_number => 1).eager_graph(:fuel_expenses).select_fields(:self => [:trip_number, :leg_number], :fuel_expenses => [:type]).all
25
37
  # tl = TripLeg.filter(:trip_number => 68562, :leg_number => 1).eager_graph(:aircraft).select_fields(:self => [:trip_number, :leg_number], :aircraft => [:tail_number]).all
26
- end
38
+ # end
27
39
 
28
40
  # it "gets the user licensing information" do
29
41
  # print UserInformation.select(:users_initials, :mobile_access).sql
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: fossil
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.5.47
5
+ version: 0.5.48
6
6
  platform: ruby
7
7
  authors:
8
8
  - Daniel Sudol
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-03-23 00:00:00 -07:00
14
+ date: 2011-04-01 00:00:00 -07:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency