Пример #1
0
func idspecsToFlightV2s(r *http.Request) ([]*newfdb.Flight, error) {
	c := oldappengine.NewContext(r)
	db := oldfgae.FlightDB{C: c}
	newFlights := []*newfdb.Flight{}

	idspecs, err := FormValueIdSpecs(r)
	if err != nil {
		return newFlights, err
	}

	for _, idspec := range idspecs {
		oldF, err := db.LookupById(idspec)
		if err != nil {
			return newFlights, err
		} else if oldF == nil {
			return newFlights, fmt.Errorf("flight '%s' not found", idspec)
		}
		newF, err := oldF.V2()
		if err != nil {
			return newFlights, err
		}
		newFlights = append(newFlights, newF)
	}

	return newFlights, nil
}
Пример #2
0
func idspecsToMapLines(r *http.Request) ([]newui.MapLine, error) {
	c := oldappengine.NewContext(r)
	db := oldfgae.FlightDB{C: c}

	lines := []newui.MapLine{}

	idspecs, err := FormValueIdSpecs(r)
	if err != nil {
		return lines, err
	}

	for _, idspec := range idspecs {
		oldF, err := db.LookupById(idspec)
		if err != nil {
			return lines, err
		} else if oldF == nil {
			return lines, fmt.Errorf("flight '%s' not found", idspec)
		}
		newF, err := oldF.V2()
		if err != nil {
			return lines, err
		}
		flightLines := newui.FlightToMapLines(newF)
		lines = append(lines, flightLines...)
	}

	return lines, nil
}
Пример #3
0
func lookupHandler(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	db := fdb.FlightDB{C: c}
	id := r.FormValue("id")

	if f, err2 := db.LookupById(id); err2 != nil {
		c.Errorf(" /mdb/lookup: %v", err2)
		http.Error(w, err2.Error(), http.StatusInternalServerError)

	} else if f == nil {
		http.Error(w, fmt.Sprintf("id=%s not found", id), http.StatusInternalServerError)

	} else {
		c.Infof("Tags: %v, Tracks: %v", f.TagList(), f.TrackList())
		_, classBTrack := f.SFOClassB("", nil)

		f.Analyse() // Repopulate the flight tags; useful when debugging new analysis stuff

		// Todo: collapse all these separate tracks down into the single point/line list thing
		fr24TrackJSVar := classBTrack.ToJSVar()

		// For Flightaware tracks
		//faClassBTrack := fdb.ClassBTrack{}
		faTrackJSVar := template.JS("{}")
		if _, exists := f.Tracks["FA"]; exists == true {
			_, faClassBTrack := f.SFOClassB("FA", nil)
			faTrackJSVar = faClassBTrack.ToJSVar()
			//fr24TrackJSVar = template.JS("{}")
		}

		// For ADS-B tracks !
		adsbTrackJSVar := template.JS("{}")
		if _, exists := f.Tracks["ADSB"]; exists == true {
			_, adsbClassBTrack := f.SFOClassB("ADSB", nil)
			adsbTrackJSVar = adsbClassBTrack.ToJSVar()
		}

		skimTrackJSVar := template.JS("{}")
		if r.FormValue("skim") != "" {
			alttol, _ := strconv.ParseFloat(r.FormValue("alttol"), 64)
			mindist, _ := strconv.ParseFloat(r.FormValue("mindist"), 64)
			skimTrack, _ := f.BestTrack().SkimsToSFO(alttol, mindist, 15.0, 40.0)
			skimTrackJSVar = skimTrack.ToJSVar()
			fr24TrackJSVar = template.JS("{}")
			faTrackJSVar = template.JS("{}")
			adsbTrackJSVar = template.JS("{}")
		}

		mapPoints := []MapPoint{}
		mapLines := []MapLine{}

		// &waypoint=EPICK
		if waypoint := r.FormValue("waypoint"); waypoint != "" {
			//pos := geo.Latlong{37.060312, -121.990814}
			pos := sfo.KFixes[waypoint]
			if itp, err := f.BestTrack().PointOfClosestApproach(pos); err != nil {
				c.Infof(" ** Error: %v", err)
			} else {
				mapPoints = append(mapPoints, MapPoint{Icon: "red", ITP: &itp})
				mapPoints = append(mapPoints, MapPoint{Pos: &itp.Ref, Text: "** Reference point"})
				mapLines = append(mapLines, MapLine{Line: &itp.Line, Color: "#ff8822"})
				mapLines = append(mapLines, MapLine{Line: &itp.Perp, Color: "#ff2288"})
			}
		}

		// &boxes=1
		if r.FormValue("boxes") != "" {
			if true {
				// fr24
				for _, box := range f.Track.AsContiguousBoxes() {
					mapLines = append(mapLines, LatlongTimeBoxToMapLines(box, "#118811")...)
				}
			}
			if t, exists := f.Tracks["FA"]; exists == true {
				for _, box := range t.AsContiguousBoxes() {
					mapLines = append(mapLines, LatlongTimeBoxToMapLines(box, "#1111aa")...)
				}
			}
			if t, exists := f.Tracks["ADSB"]; exists == true {
				for _, box := range t.AsContiguousBoxes() {
					mapLines = append(mapLines, LatlongTimeBoxToMapLines(box, "#aaaa11")...)
				}
			}
		}

		pointsStr := "{\n"
		for i, mp := range mapPoints {
			pointsStr += fmt.Sprintf("    %d: {%s},\n", i, mp.ToJSStr(""))
		}
		pointsJS := template.JS(pointsStr + "  }\n")
		linesStr := "{\n"
		for i, ml := range mapLines {
			linesStr += fmt.Sprintf("    %d: {%s},\n", i, ml.ToJSStr(""))
		}
		linesJS := template.JS(linesStr + "  }\n")

		box := sfo.KBoxSFO120K
		if r.FormValue("report") == "level" {
			box = sfo.KBoxPaloAlto20K
		} else if r.FormValue("report") == "stack" {
			box = sfo.KBoxSFO10K
		}

		var params = map[string]interface{}{
			"F":       f,
			"Legend":  f.Legend(),
			"Oneline": f.String(),
			"Text":    fmt.Sprintf("%#v", f.Id),
			"ClassB":  "",

			"MapsAPIKey":  kGoogleMapsAPIKey,
			"Center":      sfo.KLatlongSERFR1,
			"Zoom":        10,
			"CaptureArea": box,

			"MapsTrack":        fr24TrackJSVar,
			"FlightawareTrack": faTrackJSVar,
			"ADSBTrack":        adsbTrackJSVar,
			"SkimTrack":        skimTrackJSVar,

			"Points": pointsJS,
			"Lines":  linesJS,
		}

		templateName := "fdb-lookup"
		if r.FormValue("map") != "" {
			templateName = "fdb-lookup-map"
		}
		if err7 := templates.ExecuteTemplate(w, templateName, params); err7 != nil {
			http.Error(w, err7.Error(), http.StatusInternalServerError)
		}
	}
}