fossil 0.5.40 → 0.5.41

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.40
1
+ 0.5.41
data/fossil.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{fossil}
8
- s.version = "0.5.40"
8
+ s.version = "0.5.41"
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-16}
12
+ s.date = %q{2011-03-17}
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 = [
@@ -12,7 +12,7 @@ class CityCost < Sequel::Model(:'city cost')
12
12
  self.kid_time = rand(65535)
13
13
  self.kid_comm = rand(255)
14
14
  self.kid_mult = rand(255)
15
- self.kid_user = rand(36**4).to_s(36)
15
+ self.kid_user = String.random_of_length(4)
16
16
  self.owner_kid_date = city_pair.kid_date
17
17
  self.owner_kid_time = city_pair.kid_time
18
18
  self.owner_kid_mult = city_pair.kid_mult
@@ -12,7 +12,7 @@ class CityPair < Sequel::Model(:'city pair')
12
12
  self.kid_time = rand(65535)
13
13
  self.kid_comm = rand(255)
14
14
  self.kid_mult = rand(255)
15
- self.kid_user = rand(36**4).to_s(36)
15
+ self.kid_user = String.random_of_length(4)
16
16
  end
17
17
 
18
18
  o_to_n :city_costs, :class=>:CityCost, :prefix=>'owner'
@@ -104,6 +104,10 @@ class FlightLogExpense < Sequel::Model(:'flight log expenses')
104
104
  arrival_airport == 0
105
105
  end
106
106
 
107
+ def type_string
108
+ is_departure_expense? ? "departure" : "arrival"
109
+ end
110
+
107
111
  def airport_fuel_lookup
108
112
  if !is_departure_expense? then
109
113
  ap_str = "ARRIVAL"
@@ -151,4 +155,29 @@ class FlightLogExpense < Sequel::Model(:'flight log expenses')
151
155
  end
152
156
  0.0
153
157
  end
158
+
159
+ def calculate_fuel_data
160
+ expense_type = expense_type_string
161
+ tl = trip_leg
162
+ vendor = tl.send("#{expense_type}_fuel_vendor__company_2")
163
+ vendor = tl.send("#{expense_type}_fuel_vendor__company_1") if !vendor or vendor == ""
164
+ vendor = tl.send("#{expense_type}_fuel_vendor__vendor_id") if !vendor or vendor == ""
165
+ airport = tl.send("#{expense_type}_icao_val")
166
+ fbo = tl.send("#{expense_type}_fbo__name")
167
+ aircraft = (tl.aircraft ? tl.tail_number : tl.aircraft_id)
168
+ leg_date = (tl.dept_date_act_local and tl.dept_date_act_local != 0 ? tl.dept_date_act_local : tl.depart_date_local)
169
+
170
+ {
171
+ :leg_date => leg_date,
172
+ :trip_number => tl.trip_number,
173
+ :leg_number => tl.leg_number,
174
+ :ac => aircraft,
175
+ :airport => airport,
176
+ :fbo => fbo,
177
+ :vendor => vendor,
178
+ :fuel_rate => expense.fuel_rate,
179
+ :fuel_quantity => expense.quantity,
180
+ :fuel_cost => expense.fuel_cost
181
+ }
182
+ end
154
183
  end
@@ -935,4 +935,45 @@ class TripLeg < Sequel::Model(:'trip legs')
935
935
  def total_fuel_purchased_quantity
936
936
  departure_fuel_purchased_quantity + arrival_fuel_purchased_quantity
937
937
  end
938
+
939
+
940
+ # Fuel Passdown Methods
941
+ class << self
942
+ def fuel_passdown_data start_date, end_date, fbo_keys
943
+ trip_legs = TripLeg.get_fuel_passdown_trip_legs( start_date, end_date )
944
+ fuel_data_by_fbo_keys( trip_legs, fbo_keys )
945
+ end
946
+
947
+ def get_fuel_passdown_trip_legs start_date, end_date
948
+ start_date = start_date.to_fos_days
949
+ end_date = end_date.to_fos_days
950
+ TripLeg.filter(:cancelled => 0, :status => [0,1,2]).
951
+ filter(~{:'leg state' => 5}).
952
+ filter({:'dept date act local' => start_date..end_date,
953
+ :'depart date - local' => start_date...end_date}.sql_or).limit(10).all
954
+ end
955
+
956
+ def fuel_data_by_fbo_keys trip_legs, fbo_keys
957
+ data = Hash.new
958
+ trip_legs.each do |leg|
959
+ leg.fuel_expenses.each do |expense|
960
+
961
+ expense_type = expense_type_string( expense )
962
+ fbo_name = leg.send( "#{expense_type}_fbo__name" )
963
+ p fbo_name
964
+ if fbo_keys.include?(fbo_name) then # is this an fbo we are looking for?
965
+ expense_hash = calculate_expense( expense, leg )
966
+
967
+ if data.has_key?(fbo_name)
968
+ data[fbo_name].push(expense_hash)
969
+ else
970
+ data[fbo_name] = [expense_hash]
971
+ end
972
+ end
973
+ end
974
+ end
975
+ data
976
+ end
977
+ protected :fuel_data_by_fbo_keys
978
+ end
938
979
  end
@@ -1,5 +1,19 @@
1
1
  require 'json'
2
2
 
3
+ class Array
4
+ def to_flat_file_row options = { :delimeter => ',', :enclosed_by => '' }
5
+ self.inject("") do |csv, item|
6
+ csv << "#{options[:enclosed_by]}#{item}#{options[:enclosed_by]}#{options[:delimeter]}"
7
+ end.chop
8
+ end
9
+ end
10
+
11
+ class String
12
+ def self.random_of_length length
13
+ length.times.inject("") {|str| str << (rand(26) + 97).chr }
14
+ end
15
+ end
16
+
3
17
  class Integer
4
18
  def as_cost
5
19
  self/100.0
@@ -62,4 +62,26 @@ describe Range do
62
62
  range = 1..1
63
63
  range.split_by_step(10).should == [1..1]
64
64
  end
65
+ end
66
+
67
+ describe Array do
68
+ describe "flat file conversions" do
69
+ before :all do
70
+ @array = ["one", "two","three"]
71
+ end
72
+
73
+ it "can do flat file string conversions with default values" do
74
+ @array.to_flat_file_row.should == "one,two,three"
75
+ end
76
+
77
+ it "can do flat file string conversions with options" do
78
+ @array.to_flat_file_row(:delimeter => '|', :enclosed_by => '"').should == %q{"one"|"two"|"three"}
79
+ end
80
+ end
81
+ end
82
+
83
+ describe String do
84
+ it "can generate a string of lower case characters of length" do
85
+ String.random_of_length(4).should match(/[a-z]{4}/)
86
+ end
65
87
  end
@@ -1,12 +1,12 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
- RSpec::Matchers.define :have_valid_kid_keys do |expected|
3
+ RSpec::Matchers.define :have_valid_kid_keys do
4
4
  match do |actual|
5
- actual.kid_date.to_s.should =~ /\d{1,5}/
6
- actual.kid_time.to_s.should =~ /\d{1,5}/
7
- actual.kid_user.should =~ /\w{1,4}/
8
- actual.kid_mult.to_s.should =~ /\d{1,3}/
9
- actual.kid_comm.to_s.should =~ /\d{1,3}/
5
+ actual.kid_date.to_s.should =~ /\A\d+\Z/
6
+ actual.kid_time.to_s.should =~ /\A\d+\Z/
7
+ actual.kid_user.should =~ /\A\w{4}\Z/
8
+ actual.kid_mult.to_s.should =~ /\A\d+\Z/
9
+ actual.kid_comm.to_s.should =~ /\A\d+\Z/
10
10
  end
11
11
  end
12
12
 
@@ -68,4 +68,9 @@ describe FlightLogExpense do
68
68
  end
69
69
  end
70
70
  end
71
+
72
+ it 'should give the type as a string' do
73
+ FlightLogExpense.new(:arrival_airport => 0).type_string.should == "departure"
74
+ FlightLogExpense.new(:arrival_airport => 1).type_string.should == "arrival"
75
+ end
71
76
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 5
8
- - 40
9
- version: 0.5.40
8
+ - 41
9
+ version: 0.5.41
10
10
  platform: ruby
11
11
  authors:
12
12
  - Daniel Sudol
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-16 00:00:00 -07:00
18
+ date: 2011-03-17 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency