Ejemplo n.º 1
0
func jobV2adsbHandler(r *http.Request, f *oldfdb.Flight) (string, error) {
	c := appengine.NewContext(r)
	str := ""

	if f.HasTrack("ADSB") {
		return "", nil
	} // Already has one

	err, deb := f.GetV2ADSBTrack(urlfetch.Client(c))
	str += fmt.Sprintf("*getv2ADSB [%v]:-\n", err, deb)
	if err != nil {
		return str, err
	}

	if !f.HasTrack("ADSB") {
		return "", nil
	} // Didn't find one

	f.Analyse() // Retrigger Class-B stuff

	db := oldfgae.FlightDB{C: oldappengine.NewContext(r)}
	if err := db.UpdateFlight(*f); err != nil {
		log.Errorf(c, "Persist Flight %s: %v", f, err)
		return str, err
	}
	log.Infof(c, "Updated flight %s", f)
	str += fmt.Sprintf("--\nFlight was updated\n")

	return str, nil
}
Ejemplo n.º 2
0
func jobTrackTimezoneHandler(r *http.Request, f *oldfdb.Flight) (string, error) {
	c := appengine.NewContext(r)

	defaultTP := f.Track.ClosestTrackpoint(sfo.KFixes["EPICK"])
	adsbTP := f.Tracks["ADSB"].ClosestTrackpoint(sfo.KFixes["EPICK"])
	trackTimeDelta := defaultTP.TimestampUTC.Sub(adsbTP.TimestampUTC)

	str := fmt.Sprintf("OK, looked up %s\n Default: %s\n ADSB   : %s\n delta: %s\n",
		f, defaultTP, adsbTP, trackTimeDelta)

	if trackTimeDelta < -4*time.Hour || trackTimeDelta > 4*time.Hour {
		str += fmt.Sprintf("* recoding\n* before: %s\n", f.Tracks["ADSB"])

		for i, _ := range f.Tracks["ADSB"] {
			f.Tracks["ADSB"][i].TimestampUTC = f.Tracks["ADSB"][i].TimestampUTC.Add(time.Hour * -8)
		}
		str += fmt.Sprintf("* after : %s\n", f.Tracks["ADSB"])

		db := oldfgae.FlightDB{C: oldappengine.NewContext(r)}
		if err := db.UpdateFlight(*f); err != nil {
			log.Errorf(c, "Persist Flight %s: %v", f, err)
			return str, err
		}
		log.Infof(c, "Updated flight %s", f)
		str += fmt.Sprintf("--\nFlight was updated\n")

	} else {
		log.Debugf(c, "Skipped flight %s, delta=%s", f, trackTimeDelta)
		str += "--\nFlight was OK, left untouched\n"
	}

	return str, nil
}
Ejemplo n.º 3
0
func jobOceanicTagHandler(r *http.Request, f *oldfdb.Flight) (string, error) {
	c := appengine.NewContext(r)
	str := ""

	if f.HasTag("OCEANIC") {
		return "", nil
	}
	if !f.IsOceanic() {
		return "", nil
	}

	// It's oceanic, but missing a tag ... update
	f.Tags[oldfdb.KTagOceanic] = true

	db := oldfgae.FlightDB{C: oldappengine.NewContext(r)}
	if err := db.UpdateFlight(*f); err != nil {
		log.Errorf(c, "Persist Flight %s: %v", f, err)
		return str, err
	}
	log.Infof(c, "Updated flight %s", f)
	str += fmt.Sprintf("--\nFlight was updated\n")

	return str, nil
}
Ejemplo n.º 4
0
func debugHandler(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	db := fdb.FlightDB{C: c}
	id := r.FormValue("id")
	blob, f, err := db.GetBlobById(id)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	} else if blob == nil {
		http.Error(w, fmt.Sprintf("id=%s not found", id), http.StatusInternalServerError)
		return
	}

	blob.Flight = []byte{} // Zero this out

	s, e := f.Track.TimesInBox(sfo.KBoxSFO120K)
	log := blob.GestationLog
	blob.GestationLog = ""

	str := fmt.Sprintf("OK\n* Flight found: %s\n* Tracks: %q\n", f, f.TrackList())
	str += fmt.Sprintf("* Points in default track: %d\n", len(f.Track))
	str += fmt.Sprintf("* Default's start/end: %s, %s\n", s, e)
	str += fmt.Sprintf("\n** Gestation log:-\n%s\n", log)
	str += fmt.Sprintf("** Blob:-\n* Id=%s, Icao24=%s\n* Enter/Leave: %s -> %s\n* Tags: %v\n",
		blob.Id, blob.Icao24, blob.EnterUTC, blob.LeaveUTC, blob.Tags)

	v2URL := f.GetV2JsonUrl()
	str += "\n* V2 URL: " + v2URL + "\n"

	str += "\n**** Tracks Before\n\n"
	str += fmt.Sprintf("** %s [DEFAULT]\n", f.Track)
	for name, t := range f.Tracks {
		str += fmt.Sprintf("** %s %s\n", name, t)
	}

	err, deb := f.GetV2ADSBTrack(urlfetch.Client(c))
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	str += "\n***\n" + deb

	str += "\n**** Tracks After\n\n"
	str += fmt.Sprintf("** %s [DEFAULT]\n", f.Track)
	for name, t := range f.Tracks {
		str += fmt.Sprintf("** %s %s\n", name, t)
	}

	str += "--\nPersisting ...\n"

	if err := db.UpdateFlight(*f); err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	/*

		consistent,debug := f.TracksAreConsistentDebug()
		str += fmt.Sprintf("\n** Track consistency (%v)\n\n%s\n", consistent, debug)

		//str += "\n** Default track\n"
		//for _,tp := range f.Track { str += fmt.Sprintf(" * %s\n", tp) }
	*/

	w.Header().Set("Content-Type", "text/plain")
	w.Write([]byte(str))
}