Class: TripLeg
- Defined in:
- lib/dbr_models/trip_leg.rb,
lib/models/trip_leg.rb
Overview
This TripLeg is overriding the TripLeg model in fossil that usually would go to fos. It is pulling data from the mysql in memory database which is a copy of the fos trip leg table but with an added id column, and single ids for all foreign keys, so the associations are all rewritten to use the single primary key. The other methods are special methods for datamart trip_leg summary table
Class Method Summary collapse
- .fuel_data_by_fbo_keys(trip_legs, fbo_keys) ⇒ Object
- .fuel_passdown_data(start_date, end_date, fbo_keys) ⇒ Object
- .get_fuel_passdown_trip_legs(start_date, end_date) ⇒ Object
Instance Method Summary collapse
- #actual_arrival_date_time_base ⇒ Object
-
#actual_arrival_date_time_gmt ⇒ Object
Fixed to check if actual fields are populated, on older records these fields are not populated so we can’t use them.
- #actual_departure_date_time_base ⇒ Object
- #actual_land_date_time_gmt ⇒ Object
- #actual_takeoff_date_time_gmt ⇒ Object
- #actual_time_zone_change ⇒ Object
- #arrival_airport_zipcode ⇒ Object
-
#arrival_ap_id ⇒ Object
Datamart Methods.
- #arrival_diff_in_minutes ⇒ Object
- #arrival_fbo_is_primary ⇒ Object
- #arrival_fuel_cost ⇒ Object
- #arrival_fuel_expenses ⇒ Object
- #arrival_fuel_purchased_quantity ⇒ Object
- #arrival_icao_expanded ⇒ Object
- #arrival_icao_val ⇒ Object
-
#custom_statute_miles ⇒ Object
converts nautical miles to statute miles with fractional bit silly because its so similar in value to statute_miles.
- #delayed? ⇒ Boolean
- #depart_ap_id ⇒ Object
- #departed? ⇒ Boolean
- #departure_airport_zipcode ⇒ Object
- #departure_diff_in_minutes ⇒ Object
- #departure_fbo_is_primary ⇒ Object
- #departure_fuel_cost ⇒ Object
- #departure_fuel_expenses ⇒ Object
- #departure_fuel_purchased_quantity ⇒ Object
- #departure_icao_expanded ⇒ Object
-
#departure_icao_val ⇒ Object
This method guarantees an icao for a view that needs one.
- #ebt_time ⇒ Object
-
#fuel_expenses ⇒ Object
Fuel Expense Stuff.
- #is_charter? ⇒ Boolean
-
#is_completed_leg? ⇒ Boolean
Flight explorer is continually updating the land time for a flight, so its really not possible to tell if a flight is completed by checking that the arrival date or time is no longer 0/1440.
- #is_deadhead? ⇒ Boolean
- #is_flown? ⇒ Boolean
- #leg_class ⇒ Object
- #leg_status ⇒ Object
-
#passenger_list ⇒ Object
sort on lead_pax value to lead pax = 1 is first and the lead_pax values of 0 are all after.
- #pic ⇒ Object
- #pic_crew ⇒ Object
-
#pilot_code(type) ⇒ Object
get pic or sic or purser for this trip leg.
- #pilot_crew(type) ⇒ Object
- #sic ⇒ Object
- #sic_crew ⇒ Object
- #total_fuel_cost ⇒ Object
- #total_fuel_purchased_quantity ⇒ Object
- #total_trip_statute_miles ⇒ Object
- #verified? ⇒ Boolean
Class Method Details
.fuel_data_by_fbo_keys(trip_legs, fbo_keys) ⇒ Object
957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 |
# File 'lib/models/trip_leg.rb', line 957 def fuel_data_by_fbo_keys trip_legs, fbo_keys data = Hash.new { |hash, key| hash[key] = Array.new } trip_legs.each do |leg| leg.fuel_expenses.each do |expense| fbo_name = leg.send( "#{expense.type_string}_fbo__name" ) match = false fbo_keys.each do |key| if fbo_name.index(key) == 0 # fbo name can have suffix like A, B, SOUTH, EAST, etc. match = true break end end data[fbo_name].push( expense.fuel_passdown_hash ) if match end end data end |
.fuel_passdown_data(start_date, end_date, fbo_keys) ⇒ Object
942 943 944 945 |
# File 'lib/models/trip_leg.rb', line 942 def fuel_passdown_data start_date, end_date, fbo_keys trip_legs = TripLeg.get_fuel_passdown_trip_legs( start_date, end_date ) fuel_data_by_fbo_keys( trip_legs, fbo_keys ) end |
.get_fuel_passdown_trip_legs(start_date, end_date) ⇒ Object
947 948 949 950 951 952 953 954 955 |
# File 'lib/models/trip_leg.rb', line 947 def get_fuel_passdown_trip_legs start_date, end_date start_date = start_date.to_fos_days end_date = end_date.to_fos_days TripLeg.filter(:cancelled => 0, :status => [0,1,2]). filter(~{:'leg state' => 5}). filter({:'dept date act local' => start_date..end_date, :'depart date - local' => start_date..end_date}.sql_or). order(:depart_date_local).all end |
Instance Method Details
#actual_arrival_date_time_base ⇒ Object
727 728 729 |
# File 'lib/models/trip_leg.rb', line 727 def actual_arrival_date_time_base (actual_arrival_date_time_gmt.to_time.utc + (home_tz_gmt_offset/10).hours).to_datetime end |
#actual_arrival_date_time_gmt ⇒ Object
Fixed to check if actual fields are populated, on older records these fields are not populated so we can’t use them. Updated to calculated actual times based on dept datetime and block time actual. Jade Tucker 2/11/2011
675 676 677 678 679 680 681 682 |
# File 'lib/models/trip_leg.rb', line 675 def actual_arrival_date_time_gmt if arr_date_act_gmt != 0 then DateTime.from_fos_date_time(arr_date_act_gmt, arriv_time_act_gmt) else block_time_minutes = block_time_actual ? block_time_actual.minutes : 0 (actual_departure_date_time_gmt.to_time.utc + block_time_minutes).to_datetime end end |
#actual_departure_date_time_base ⇒ Object
720 721 722 |
# File 'lib/models/trip_leg.rb', line 720 def actual_departure_date_time_base (actual_departure_date_time_gmt.to_time.utc + (home_tz_gmt_offset/10).hours).to_datetime end |
#actual_land_date_time_gmt ⇒ Object
684 685 686 687 688 689 |
# File 'lib/models/trip_leg.rb', line 684 def actual_land_date_time_gmt time = land_time_act_gmt time -= 60*24 if land_time_act_gmt > arriv_time_act_gmt date = (arr_date_act_gmt > 0 ? arr_date_act_gmt : arrival_date_gmt) DateTime.from_fos_date_time(date, time) end |
#actual_takeoff_date_time_gmt ⇒ Object
664 665 666 667 668 |
# File 'lib/models/trip_leg.rb', line 664 def actual_takeoff_date_time_gmt time = t_o_time_act_gmt time += 60*24 if t_o_time_act_gmt < dept_time_act_gmt DateTime.from_fos_date_time(dept_date_act_gmt, time) end |
#actual_time_zone_change ⇒ Object
841 842 843 |
# File 'lib/models/trip_leg.rb', line 841 def actual_time_zone_change time_zone_change.to_f/10.0 end |
#arrival_airport_zipcode ⇒ Object
874 875 876 877 878 |
# File 'lib/models/trip_leg.rb', line 874 def arrival_airport_zipcode arrival_airport__city_state_zip and arrival_airport__city_state_zip.match(/(\d{5}-\d{4}$|\d{5})$/) and $1 end |
#arrival_ap_id ⇒ Object
Datamart Methods
852 853 854 |
# File 'lib/models/trip_leg.rb', line 852 def arrival_ap_id arrival_airport_id ? "#{arrival_ap_prefix}#{arrival_airport_id}" : "" end |
#arrival_diff_in_minutes ⇒ Object
884 885 886 |
# File 'lib/models/trip_leg.rb', line 884 def arrival_diff_in_minutes (leg_status == "VERI" or leg_status == "FLOG") ? ((actual_arrival_date_time_local - planned_arrival_date_time_local)*1440).to_i : nil end |
#arrival_fbo_is_primary ⇒ Object
860 861 862 |
# File 'lib/models/trip_leg.rb', line 860 def arrival_fbo_is_primary arrival_fbo__primary == 1 ? 'Yes' : 'No' end |
#arrival_fuel_cost ⇒ Object
919 920 921 |
# File 'lib/models/trip_leg.rb', line 919 def arrival_fuel_cost arrival_fuel_expenses.inject(0) { |sum, e| sum + e.fuel_cost } end |
#arrival_fuel_expenses ⇒ Object
911 912 913 |
# File 'lib/models/trip_leg.rb', line 911 def arrival_fuel_expenses fuel_expenses.select { |expense| expense.arrival_airport == 1 } end |
#arrival_fuel_purchased_quantity ⇒ Object
931 932 933 |
# File 'lib/models/trip_leg.rb', line 931 def arrival_fuel_purchased_quantity arrival_fuel_expenses.inject(0) { |sum, e| sum + e.quantity.to_i } end |
#arrival_icao_expanded ⇒ Object
833 834 835 |
# File 'lib/models/trip_leg.rb', line 833 def "#{arrival_icao_val} #{arrival_airport__name} #{arrival_airport__city} ,#{arrival_airport__state_abbreviation}" end |
#arrival_icao_val ⇒ Object
825 826 827 |
# File 'lib/models/trip_leg.rb', line 825 def arrival_icao_val arrival_icao == nil || arrival_icao.blank? ? arrival_ap_prefix + arrival_airport_id : arrival_icao end |
#custom_statute_miles ⇒ Object
converts nautical miles to statute miles with fractional bit silly because its so similar in value to statute_miles
846 847 848 849 |
# File 'lib/models/trip_leg.rb', line 846 def custom_statute_miles return 0 unless nautical_miles ((nautical_miles*1.150777*10).to_i)/10.0 end |
#delayed? ⇒ Boolean
787 788 789 |
# File 'lib/models/trip_leg.rb', line 787 def delayed? Time.now.utc > planned_departure_date_time_gmt and !departed? end |
#depart_ap_id ⇒ Object
856 857 858 |
# File 'lib/models/trip_leg.rb', line 856 def depart_ap_id depart_airport_id ? "#{depart_ap_prefix}#{depart_airport_id}" : "" end |
#departed? ⇒ Boolean
783 784 785 |
# File 'lib/models/trip_leg.rb', line 783 def departed? dept_date_act_gmt!=0 end |
#departure_airport_zipcode ⇒ Object
868 869 870 871 872 |
# File 'lib/models/trip_leg.rb', line 868 def departure_airport_zipcode departure_airport__city_state_zip and departure_airport__city_state_zip.match(/(\d{5}-\d{4}$|\d{5})$/) and $1 end |
#departure_diff_in_minutes ⇒ Object
880 881 882 |
# File 'lib/models/trip_leg.rb', line 880 def departure_diff_in_minutes (leg_status == "VERI" or leg_status == "FLOG") ? ((actual_departure_date_time_local - planned_departure_date_time_local)*1440).to_i : nil end |
#departure_fbo_is_primary ⇒ Object
864 865 866 |
# File 'lib/models/trip_leg.rb', line 864 def departure_fbo_is_primary departure_fbo__primary == 1 ? 'Yes' : 'No' end |
#departure_fuel_cost ⇒ Object
915 916 917 |
# File 'lib/models/trip_leg.rb', line 915 def departure_fuel_cost departure_fuel_expenses.inject(0) { |sum, e| sum + e.fuel_cost } end |
#departure_fuel_expenses ⇒ Object
907 908 909 |
# File 'lib/models/trip_leg.rb', line 907 def departure_fuel_expenses fuel_expenses.select { |expense| expense.arrival_airport == 0 } end |
#departure_fuel_purchased_quantity ⇒ Object
927 928 929 |
# File 'lib/models/trip_leg.rb', line 927 def departure_fuel_purchased_quantity departure_fuel_expenses.inject(0) { |sum, e| sum + e.quantity.to_i } end |
#departure_icao_expanded ⇒ Object
829 830 831 |
# File 'lib/models/trip_leg.rb', line 829 def "#{departure_icao_val} #{departure_airport__name} #{departure_airport__city} ,#{departure_airport__state_abbreviation}" end |
#departure_icao_val ⇒ Object
This method guarantees an icao for a view that needs one. If there is an icao, use it, otherwise make it from the prefix and airport_id .. which works as an icao, but beware, because these put together icao’s that you make are valid icao codes, but you can’t search the airport based it, since these airport rows don’t have an icao code at all, they only have the prefix and airport_id. whacky.
821 822 823 |
# File 'lib/models/trip_leg.rb', line 821 def departure_icao_val departure_icao == nil || departure_icao.blank? ? depart_ap_prefix + depart_airport_id : departure_icao end |
#ebt_time ⇒ Object
756 757 758 759 760 761 |
# File 'lib/models/trip_leg.rb', line 756 def ebt_time # subtracting the two datetimes yields a fraction of a day, so multiplying by minutes # in day ( 1440 ) to get total minutes difference. assumes flights not more than 24 hours. minutes_between = (planned_arrival_date_time_gmt - planned_departure_date_time_gmt) * 1440; DateTime.from_minutes(minutes_between) end |
#fuel_expenses ⇒ Object
Fuel Expense Stuff
903 904 905 |
# File 'lib/models/trip_leg.rb', line 903 def fuel_expenses flight_log_expenses.select{ |expense| expense.type == 1 } end |
#is_charter? ⇒ Boolean
791 792 793 |
# File 'lib/models/trip_leg.rb', line 791 def is_charter? [100, 11].include? leg_type_code end |
#is_completed_leg? ⇒ Boolean
Flight explorer is continually updating the land time for a flight, so its really not possible to tell if a flight is completed by checking that the arrival date or time is no longer 0/1440.
779 780 781 |
# File 'lib/models/trip_leg.rb', line 779 def is_completed_leg? (verified? or Time.now.utc > actual_arrival_date_time_gmt) and cancel_code == 0 end |
#is_deadhead? ⇒ Boolean
763 764 765 766 |
# File 'lib/models/trip_leg.rb', line 763 def is_deadhead? deadhead==1 or pax_count==0 # (status==1 or verify_date > 0) and (deadhead==1 or pax_count==0) and [107, 115, 108, 104].include? leg_type_code end |
#is_flown? ⇒ Boolean
772 773 774 |
# File 'lib/models/trip_leg.rb', line 772 def is_flown? ((verified? or flight_time_actual > 0) and cancel_code == 0) end |
#leg_class ⇒ Object
888 889 890 891 892 893 894 895 896 897 898 899 900 |
# File 'lib/models/trip_leg.rb', line 888 def leg_class my_class = case aircraft_type_id when 'C750' then 'C750' when 'CL30' then 'CL30' # when 'Managed' then 'Managed' #TODO There is no way to know if the plane is managed other than being given specific tail numbers when 'PRM1' then 'Premier' when 'BE35' then 'King Air' else 'NA' end my_class = 'NA' if (aircraft__owner_name =~ /xojet/i) == nil my_class end |
#leg_status ⇒ Object
805 806 807 808 809 810 811 812 813 814 815 |
# File 'lib/models/trip_leg.rb', line 805 def leg_status return "VERI" if verify_date > 0 or status == 1 return "FLOG" if flight_time_actual > 0 return "CANC" if cancel_code == 1 or [10,23].include? status case status.to_i when 21 then "MAINT" when 0 then "SCHED" when 20 then "SCHED" #really is "RESVD" else status end end |
#passenger_list ⇒ Object
sort on lead_pax value to lead pax = 1 is first and the lead_pax values of 0 are all after
796 797 798 799 800 801 802 803 |
# File 'lib/models/trip_leg.rb', line 796 def passenger_list return '' if trip__passengers.blank? or is_deadhead? trip__passengers.sort_by{|tp| -tp.lead_pax}.collect do |tp| if (leg_number >= tp.departure_leg_number and leg_number <= tp.arrival_leg_number) or tp.all_legs == 1 tp.name + (tp.lead_pax==1 ? " (lead pax)" : '' ) end end.compact.uniq.join(' : ') end |
#pic ⇒ Object
746 |
# File 'lib/models/trip_leg.rb', line 746 def pic; pilot_code(:pic); end |
#pic_crew ⇒ Object
753 |
# File 'lib/models/trip_leg.rb', line 753 def pic_crew; pilot_crew(:pic); end |
#pilot_code(type) ⇒ Object
get pic or sic or purser for this trip leg. type should be :pic or :sic or :pur
742 743 744 745 |
# File 'lib/models/trip_leg.rb', line 742 def pilot_code(type) crew_leg = pilot_crew(type) crew_leg ? crew_leg.crew : '' end |
#pilot_crew(type) ⇒ Object
749 750 751 752 |
# File 'lib/models/trip_leg.rb', line 749 def pilot_crew(type) return nil unless type crew_legs.find{|cl| cl.position_code_code == type.to_s.upcase } end |
#sic ⇒ Object
747 |
# File 'lib/models/trip_leg.rb', line 747 def sic; pilot_code(:sic); end |
#sic_crew ⇒ Object
754 |
# File 'lib/models/trip_leg.rb', line 754 def sic_crew; pilot_crew(:sic); end |
#total_fuel_cost ⇒ Object
923 924 925 |
# File 'lib/models/trip_leg.rb', line 923 def total_fuel_cost arrival_fuel_cost + departure_fuel_cost end |
#total_fuel_purchased_quantity ⇒ Object
935 936 937 |
# File 'lib/models/trip_leg.rb', line 935 def total_fuel_purchased_quantity departure_fuel_purchased_quantity + arrival_fuel_purchased_quantity end |
#total_trip_statute_miles ⇒ Object
837 838 839 |
# File 'lib/models/trip_leg.rb', line 837 def total_trip_statute_miles trip__total_statute_miles.to_f/10.0 end |
#verified? ⇒ Boolean
768 769 770 |
# File 'lib/models/trip_leg.rb', line 768 def verified? (status == 1 or verify_date > 0) end |