Exemple #1
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))
}