Example #1
0
func playback2FlightIdentifier(r FlightPlaybackResponse, f *flightdb.FlightIdentifier) error {
	flight := r.Result.Response.Data.Flight
	id := flight.Identification
	if id.Number.Default != "" {
		if err := flightdb.ParseIATA(&f.Designator, id.Number.Default); err != nil {
			return err
		}
	}

	f.Origin, f.Destination = flight.Airport.Origin.Code.Iata, flight.Airport.Destination.Code.Iata

	// It would be preferable to find the scheduled date of departure for this; else we
	// misidentify those flights which get delayed past midnight.

	if flight.Track == nil || len(flight.Track) == 0 {
		return fmt.Errorf("playback2FightIdentifier: no track data, so no departure date!")
	}
	epoch := flight.Track[0].Timestamp
	f.DepartureDate = date.InPdt(time.Unix(int64(epoch), 0))

	if f.ForeignKeys == nil {
		f.ForeignKeys = map[string]string{}
	}
	f.ForeignKeys["fr24"] = id.Hex

	f.Registration = flight.Aircraft.Identification.Registration
	f.Callsign = id.Callsign // ?? Is this right ? If so, where is ICAO ??
	f.ModeS = flight.Aircraft.Identification.ModeS

	return nil
}
Example #2
0
func list2FlightIdentifier(v []interface{}, f *flightdb.FlightIdentifier) error {
	if iata := v[14].(string); iata != "" {
		if err := flightdb.ParseIATA(&f.Designator, iata); err != nil {
			return err
		}
	}
	// There is no ICAO data in here

	f.Origin, f.Destination = v[12].(string), v[13].(string)

	if f.ForeignKeys == nil {
		f.ForeignKeys = map[string]string{}
	}
	f.ForeignKeys["fr24"] = v[0].(string)

	f.Registration = v[10].(string)
	f.ModeS = v[1].(string)
	f.Callsign = v[17].(string)
	f.DepartureDate = time.Unix(int64(v[11].(float64)), 0) // This is kinda broken for long haul arrivals etc

	return nil
}