require_relative '../lib/fossil' require 'logger' #require 'fossil_dbr' require 'pp' require 'active_record' class TripLegSummary < ActiveRecord::Base set_table_name :trip_leg_summary h = {"adapter"=>"mysql", "username"=>"flyos", "password"=>"flyos", "host"=>"localhost", "database"=>"flyos_fos_summary"} establish_connection h end p TripLegSummary.first old_summary_values= {:id=>"CTA-2-17-38922-1090", :trip_requester=>"Wayne,John", :pic=>"JS", :sic=>"RBB", :fuel_burned=>0, :fuel_vendor=>"None", :fueler_flags=>0, :fbo_flags=>Date.today } #class Sequel::Model::Associations::OneToManyAssociationReflection # # one_to_many associations can only have associated objects if none of # # the :keys options have a nil value. # def can_have_associated_objects?(obj) # !self[:primary_keys].any?{|k| obj.send(k).nil?} # end #end #h = {"adapter"=>"mysql", "username"=>"datamart", "password"=>"datap@ss", "host"=>"hrkdm.pcmt.local", "database"=>"dbr"} #DB = Sequel.fos_dbr(h) DB = Sequel.fos('flyos', :loggers=>[Logger.new($stdout)]) #DB.loggers=[Logger.new($stdout)]#File.expand_path("log/#{RAILS_ENV}.log"))] [TripLeg, Aircraft].each { |model| model.db = DB } #p [TripLeg.min(:kid_date),TripLeg.max(:kid_date)] #p [Date.from_fos_days(TripLeg.min(:kid_date)),Date.from_fos_days(TripLeg.max(:kid_date))] #p [Date.from_fos_days(TripLeg.min(:depart_date_local)),Date.from_fos_days(TripLeg.max(:depart_date_local))] #p Date.from_fos_days 38922 #DB = Sequel.fos('fosprod', :loggers=>[Logger.new($stdout)]) #DB = Sequel.fos('fos', :loggers=>[Logger.new($stdout)]) #DB = Sequel.fos('demo_company_fos_db')#, :loggers=>[Logger.new($stdout)]) #DB = Sequel.fos('flyos', :loggers=>[Logger.new($stdout)]) #[CityPair,CityCost].each {|model| model.db = DB} #p CityPair.first.city_costs #p CityPair.first.send('kid - user') #[TripLeg].each {|model| model.db = DB} #p TripLeg.filter(:trip_number=>45,:leg_number=>1).first.arrival_transport_comment #p Comment.filter(:kid_date=>38922,:kid_time=>1090,:kid_mult=>2,:kid_comm=>37).count #p Aircraft.all.collect &:aircraft_id #aircraft_ids = ["7RN", "45FM", "567T", "65PC", "67AS", "7NPN", "567Y", "89TY", "334D", "199J", "344D"] #aircraft_id = TripLeg.filter(:trip_number=>45,:leg_number=>1).first.aircraft_id #index = aircraft_ids.index(aircraft_id) #next_index = index == aircraft_ids.length-1 ? 0 : index + 1 #p aircraft_ids[next_index] #DB.run("UPDATE \"TRIP LEGS\" SET \"aircraft id\" = '#{aircraft_ids[next_index]}' WHERE (\"TRIP NUMBER\" = 45) AND (\"LEG NUMBER\" = 1)") #p DB.run("UPDATE \"TRIP LEGS\" SET \"NOTE\" = 'hi rob' WHERE (\"TRIP NUMBER\" = 45) AND (\"LEG NUMBER\" = 1)") #p TripLeg.filter(:trip_number=>45,:leg_number=>1).first.note #tl = TripLeg.filter(:trip_number=>45,:leg_number=>1).first #tl.note = "hi tob" #tl.save #[Vendor].each {|model| model.db = DB} #Aircraft.db = DB #p Aircraft.first #p [AirportFuel.min(:kid_date),AirportFuel.max(:kid_date)] #p [TripLeg.min(:dept_date_gmt),TripLeg.max(:dept_date_gmt)] #p [Date.from_fos_days(TripLeg.min(:dept_date_gmt)).to_s,Date.from_fos_days(TripLeg.max(:dept_date_gmt)).to_s] #p Vendor.count #p TripLeg.filter{kid_date > 40500}.limit(10).all.collect &:dep_fuel_vendor #p Passenger.filter(:kid_date=>38439, :kid_time=>1428, :kid_comm=>1, :kid_mult=>0).first #p Aircraft.filter(:kid_date=>39722).first.owner_name #p Aircraft.select(:kid_date,:owner_kid_date,:owner_kid_time).all.collect{|c| [c.kid_date,c.owner_kid_date,c.owner_kid_time] } #p Aircraft.select(:kid_date,:tail_number,:owner_name,:owner_kid_user,:owner_kid_comm,:owner_kid_mult,:owner_kid_date,:owner_kid_time).all.collect{|c| [c.kid_date,c.tail_number,c.owner_name,c.owner_kid_user,c.owner_kid_comm,c.owner_kid_mult,c.owner_kid_date,c.owner_kid_time] } #p Aircraft.select(:owner_name).all.collect(&:owner_name).uniq.sort #p Passenger.filter(:name.like('%CTA%')).first #p TripLeg.all.collect(&:aircraft__tail_number).uniq # #Aircraft.first.owner #p TripLeg.filter{flight_time_actual > 0 }.first.aft_time_view #p TripLeg.select(:cancel_code).distinct(:cancel_code) #p TripLeg.filter{ cancel_code >1 }.count #p TripLeg.first(:trip_number=>85868,:leg_number=>4).fill_hash( #p TripLeg.first(:trip_number=>87204,:leg_number=>2).fill_hash( # [:kid_date,:planned_departure_date_time_gmt,:status,:deadhead,:leg_type_code,:trip__trip_type_code] #) #pp TripLeg.first(:trip_number=>87204,:leg_number=>2).trip.values #p QuoteLeg.filter{kid_date > (Date.today-30)}.filter{block_time_actual > 0}.first.confirmation_number #p t.actual_departure_date_time_gmt.to_time #p t.actual_departure_date_time_gmt.to_time.utc #pp t.fill_hash( # [:actual_departure_date_time_gmt, # :actual_arrival_date_time_gmt, # :actual_departure_date_time_base, # :actual_arrival_date_time_base # ] #) #date = Date.today - 1 #p date #pp CrewDuty.find_crew_duty_in_time_range(date, date).collect{|v| [v.duty_start_time.to_s, v.duty_end_time.to_s, v.amended, v.amended_date, v.verified_date] } #[CrewDuty].each{|m| m.db=DB} #c = CrewDuty.filter(:kid_user=>'DEMO').first #c.update(:risk=>2) #[Personnel,ACQualification,Code].each{|m| m.db=DB} #p ACQualification.first #p Personnel.first(:employee_id=>'COXD').ac_qualifications.find{|ac| ac.aircraft_type_id='C750'} #ACQualification.filter(:aircraft_type_id=>'C750') #p per.ac_qualifications.first.aircraft_type_id # collect{|v| [v.aircraft_type_id, v.pilot_rating__code]} #[Personnel,Airport,TripLeg,AirportFbo].each{|m| m.db=DB} #p Personnel.first(:employee_name.like('%chmo%')) #[Trip,CrewLeg,TripLeg,Passenger,Aircraft,Airport,AirportFbo,CrewLeg,Code,Personnel,Comment].each{|m| m.db=DB} #p TripLeg.all.collect{ |t| [t.pic,t.sic,t.departure_fbo__name,t.arrival_fbo__name]} #t = Trip.filter(:trips__trip_number=>8).eager_graph(:trip_legs).all.first #p t #p AirportFbo[Sequel.fos_id_to_lookup_key("D-0-2-75-21071")] #p [:kid_user,:kid_mult,:kid_comm,:kid_date,:kid_time].zip(Sequel.fos_id_to_lookup_key("D-0-2-75-21071")) # def pk_list(prefix) # ['kid - user','kid - mult','kid - comm','kid - date','kid - time'].collect{|v| "#{prefix} #{v}" } # [:kid_user,:kid_mult,:kid_comm,:kid_date,:kid_time].collect{|v| "#{prefix} #{v.to_s}" } # end #p AirportFbo.filter(:icao=>'KSFO').count #DB.execute('Update "trip legs" set "lunch comment" = \'hi\' where "trip number" = 83100 and "leg number" = 3') #DB.execute('Update "trip legs" set "pax count" = 4 where "trip number" = 62 and "leg number" = 1 ') #tl = TripLeg.filter(:trip_number=>69012,:leg_number=>1).eager_graph(:fuel_expenses).all.first #tl = TripLeg.first #p tl.fuel_expenses #p tl.actual_arrival_date_time_gmt #date = TripLeg.filter(:arr_date_act_gmt=>0).filter{:verify_date >0}.order(:kid_date).last.kid_date # :arrival_date_gmt #p Date.from_fos_days(date).to_s #p TripLeg.filter(:arr_date_act_gmt=>0).count # :arrival_date_gmt #p TripLeg.count # :arrival_date_gmt #p tl.fos_id #p tl.pax_count #tl2 = TripLeg.filter(tl.pk_hash.soft_delete(:'kid - user')).filter(:kid_user.like("%#{tl.kid_user}%")).first #p tl.pk_hash #tl.update(:fs_hotel=>"dan lodge") #ku = tl.pk_hash.soft_delete(:'kid - user') #p ku #p tl.pk_hash.delete(:'kid - user') #fbo = Airport.filter(:icao=>tl.arrival_icao).eager_graph(:airport_fbos).all.first #tl.update(pk_list('fbo').zip(fbo.pk)) #p fbo.pk #p fbo.primary_key #tl.fbo_kid_user="D" #p tl.fill_hash(pk_list('fbo')) #pk_list('fbo').each_with_index do |k,i| # tl.send(k= fbo.pk[i] #end #p tl.fill_hash(pk_list('fbo')) # tl.arrival_icao #p fbo.pk #p fbos.collect{|f| [f.fos_id, f.name]} #p tl.arrival_fbo #p t.trip_legs.collect{|tl| [tl.fbo_kid_date,tl.fbo_kid_time,tl.fbo_kid_user,tl.fbo_kid_mult,tl.fbo_kid_comm]} #p Trip.filter(:trip_number=>8).first.trip_legs.size #p Personnel.filter(:crew_type=>1).all.collect &:employee_name #[Trip,CrewTrip,TripLeg,TripPassenger,Passenger,CrewLeg].each{|m| m.db=DB} #pp TripLeg.filter(:depart_date_key=>Date.today - 1).all.collect{|t| t.fill_hash [:pax_count,:pax_estimated,:passengers_actual] } #[Trip,TripLeg,Airport,AirportFbo,Aircraft,CrewLeg,Code,TripPassenger,Passenger,Personnel,Quote,Comment].each{|m| m.db=DB} #start_date = Date.parse('June 15 2010').to_fos_days #end_date = Date.parse('July 1 2010').to_fos_days #p TripLeg.filter{ kid_date > start_date}.count #tl = TripLeg.filter(:trip_number=>79174, :leg_number=>1 ).first #t = tl.trip #p t.kid_date #p tl.kid_date #p t.crew_trips.collect &:kid_date #p TripLeg.filter{ kid_date > end_date}.limit(10).all.collect{|tl| [tl.kid_date,(tl.trip.kid_date)]} #p TripLeg.filter{ kid_date > end_date}.limit(10).all.collect{|tl| [tl.status,tl.trip__passengers.collect(&:kid_date)] } #tl = TripLeg.filter((:kid_date + 0) > end_date,:status=>1 ).first #p tl.kid_date #p tl.trip.kid_date #p tl.trip.trip_passengers.collect &:kid_date #p Passenger.filter(:pax_is_a_requester=>1).count #now = Date.today.to_gm_time #from_datetime = now - 1.day + 1.minute #to_datetime = now #duty_periods = CrewDuty.find_crew_duty_in_time_range(from_datetime, to_datetime) #p duty_periods #p Trip.filter{ kid_date < start_date}.delete #p TripLeg.filter{ trips_kid_date < start_date}.delete #p TripPassenger.filter{ trip_kid_date < start_date}.delete #sql = <