本文整理汇总了Golang中github.com/skypies/flightdb/gae.FlightDB类的典型用法代码示例。如果您正苦于以下问题:Golang FlightDB类的具体用法?Golang FlightDB怎么用?Golang FlightDB使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FlightDB类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: idspecsToFlightV2s
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: idspecsToMapLines
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: decodetrackHandler
func decodetrackHandler(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
db := fdb.FlightDB{C: c}
icao := r.FormValue("icaoid")
callsign := strings.TrimSpace(r.FormValue("callsign"))
if icao == "" || callsign == "" {
http.Error(w, "need args {icaoid,callsign}", http.StatusInternalServerError)
return
}
if tracks, err := db.ReadTrackFragments(icao, callsign); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
} else {
var params = map[string]interface{}{
"Tracks": tracks,
"Callsign": callsign,
"Icao24": icao,
}
if err := templates.ExecuteTemplate(w, "fdb-decodetrack", params); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
}
示例4: addtrackHandler
func addtrackHandler(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
db := fdb.FlightDB{C: c}
icaoId := r.FormValue("icaoid")
callsign := strings.TrimSpace(r.FormValue("callsign"))
tStr := r.FormValue("track")
// Validate it works before persisting
t := ftype.Track{}
if err := t.Base64Decode(tStr); err != nil {
c.Errorf(" /mdb/addtrack: decode failed: %v", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
}
ftf := ftype.FrozenTrackFragment{
TrackBase64: tStr,
Callsign: callsign,
Icao24: icaoId,
}
if err := db.AddTrackFrgament(ftf); err != nil {
c.Errorf(" /mdb/addtrack: db.AddTrackFragment failed: %v", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
}
// 3. Routine to merge track fragments ? Extra credit ?
// c.Infof(" /mdb/addtrack: added %d points for [%s][%s]", len(t), icaoId, callsign)
w.Write([]byte(fmt.Sprintf("Added %d for %s\n", len(t), icaoId)))
}
示例5: skimmerReport
func skimmerReport(c appengine.Context, s, e time.Time, opt ReportOptions) ([]ReportRow, ReportMetadata, error) {
meta := ReportMetadata{}
fdb := fdb.FlightDB{C: c}
maybeMemcache(&fdb, e)
tags := []string{flightdb.KTagSERFR1}
if flights, err := fdb.LookupTimeRangeByTags(tags, s, e); err != nil {
return nil, nil, err
} else {
out := []ReportRow{}
for _, f := range flights {
t := f.BestTrack()
_, analysis := t.SkimsToSFO(opt.Skimmer_AltitudeTolerance, opt.Skimmer_MinDurationNM, 14.5, 50)
// Output one row per event, in a kind of hacky way
extras := fmt.Sprintf("&skim=1&alttol=%.0f&mindist=%.0f", opt.Skimmer_AltitudeTolerance,
opt.Skimmer_MinDurationNM)
for _, event := range analysis.Events {
row := SkimRow{Url: flight2Url(f) + template.HTML(extras), F: f, Source: t.LongSource(), A: analysis}
row.A.Events = []flightdb.SkimEvent{event}
out = append(out, row)
}
}
return out, meta, nil
}
}
示例6: brixxViolationReport
func brixxViolationReport(c appengine.Context, s, e time.Time, opt ReportOptions) ([]ReportRow, ReportMetadata, error) {
meta := ReportMetadata{}
fdb := fdb.FlightDB{C: c}
maybeMemcache(&fdb, e)
tags := []string{flightdb.KTagBRIXX}
if flights, err := fdb.LookupTimeRangeByTags(tags, s, e); err != nil {
return nil, nil, err
} else {
out := []ReportRow{}
// Hmm. Really need a better way to link 'violations in this report' to dots on the map
for _, f := range flights {
t := f.BestTrack()
for i, tp := range t {
if tp.Latlong.DistNM(sfo.KLatlongSJC) > 20 {
continue
}
if tp.AltitudeFeet < 5500 && tp.Latlong.Long < sfo.KFixes["YADUT"].Long {
row := BrixxRow{
Url: flight2Url(f),
F: f,
Source: t.LongSource(),
TP: &t[i],
}
out = append(out, row)
break
}
}
}
return out, meta, nil
}
}
示例7: jobTrackTimezoneHandler
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
}
示例8: jobV2adsbHandler
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
}
示例9: brixx1Report
func brixx1Report(c appengine.Context, s, e time.Time, opt ReportOptions) ([]ReportRow, ReportMetadata, error) {
meta := ReportMetadata{}
fdb := fdb.FlightDB{C: c}
maybeMemcache(&fdb, e)
tags := []string{flightdb.KTagBRIXX}
if flights, err := fdb.LookupTimeRangeByTags(tags, s, e); err != nil {
return nil, nil, err
} else {
out := []ReportRow{}
meta["[A] Total BRIXX flights "] = float64(len(flights))
for _, f := range flights {
hasAdsb := false
if _, exists := f.Tracks["ADSB"]; exists == true {
meta["[B] With data from "+f.Tracks["ADSB"].LongSource()]++
}
if t, exists := f.Tracks["FA"]; exists == true {
meta["[B] With data from "+f.Tracks["FA"].LongSource()]++
hasAdsb = t.IsFromADSB()
} else {
meta["[B] With data from "+f.Track.LongSource()]++
}
row := SERFR1Row{flight2Url(f), f, hasAdsb, false}
out = append(out, row)
}
return out, meta, nil
}
}
示例10: batchFlightScanHandler
// This enqueues tasks for each individual day, or flight
func batchFlightScanHandler(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
tags := []string{} //"ADSB"} // Maybe make this configurable ...
n := 0
str := ""
s, e, _ := widget.FormValueDateRange(r)
job := r.FormValue("job")
if job == "" {
http.Error(w, "Missing argument: &job=foo", http.StatusInternalServerError)
}
days := date.IntermediateMidnights(s.Add(-1*time.Second), e) // decrement start, to include it
for _, day := range days {
// Get the keys for all the flights on this day.
fdb := oldfgae.FlightDB{C: oldappengine.NewContext(r)}
dStart, dEnd := date.WindowForTime(day)
dEnd = dEnd.Add(-1 * time.Second)
keys, err := fdb.KeysInTimeRangeByTags(tags, dStart, dEnd)
if err != nil {
log.Errorf(c, "upgradeHandler: enqueue: %v", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
singleFlightUrl := "/backend/fdb-batch/flight"
for _, key := range keys {
str += fmt.Sprintf("Enqueing day=%s: %s?job=%s&key=%s\n",
day.Format("2006.01.02"), singleFlightUrl, job, key.Encode())
t := taskqueue.NewPOSTTask(singleFlightUrl, map[string][]string{
"date": {day.Format("2006.01.02")},
"key": {key.Encode()},
"job": {job},
})
if _, err := taskqueue.Add(c, t, "batch"); err != nil {
log.Errorf(c, "upgradeHandler: enqueue: %v", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
n++
}
}
log.Infof(c, "enqueued %d batch items for '%s'", n, job)
w.Header().Set("Content-Type", "text/plain")
w.Write([]byte(fmt.Sprintf("OK, batch, enqueued %d tasks for %s\n%s", n, job, str)))
}
示例11: formValueFlightByKey
// A super widget, for all the batch jobs
func formValueFlightByKey(r *http.Request) (*oldfdb.Flight, error) {
fdb := oldfgae.FlightDB{C: oldappengine.NewContext(r)}
key, err := olddatastore.DecodeKey(r.FormValue("key"))
if err != nil {
return nil, fmt.Errorf("fdb-batch: %v", err)
}
f, err := fdb.KeyToFlight(key)
if err != nil {
return nil, fmt.Errorf("fdb-batch: %v", err)
}
return f, nil
}
示例12: adsbClassbReport
func adsbClassbReport(c appengine.Context, s, e time.Time, opt ReportOptions) ([]ReportRow, ReportMetadata, error) {
fdb := fdb.FlightDB{C: c}
maybeMemcache(&fdb, e)
tags := []string{flightdb.KTagSERFR1}
if flights, err := fdb.LookupTimeRangeByTags(tags, s, e); err != nil {
return nil, nil, err
} else {
meta := ReportMetadata{}
rows := []ReportRow{}
for _, f := range flights {
row := ACBRow{F: f, Url: flight2Url(f)}
_, cbt := f.SFOClassB("FA", nil)
worst := cbt.FindWorstPoint()
row.FAViolation = (worst != nil)
if worst != nil {
row.FAAnalysis = worst.A
}
if f.HasTrack("ADSB") {
row.HadLocalTrack = true
_, cbt := f.SFOClassB("ADSB", nil)
worst := cbt.FindWorstPoint()
row.LocalViolation = (worst != nil)
if worst != nil {
row.LocalAnalysis = worst.A
}
}
if row.LocalViolation && !row.FAViolation {
row.FoundBonusViolation = true
}
if row.LocalViolation && row.FAViolation {
hFA := row.FAAnalysis.BelowBy
hLocal := row.LocalAnalysis.BelowBy
row.IncreasedViolationBy = hLocal - hFA
}
if row.LocalViolation || row.FAViolation {
rows = append(rows, row)
}
}
return rows, meta, nil
}
}
示例13: discrepReport
func discrepReport(c appengine.Context, s, e time.Time, opt ReportOptions) ([]ReportRow, ReportMetadata, error) {
meta := ReportMetadata{}
fdb := fdb.FlightDB{C: c}
maybeMemcache(&fdb, e)
tags := []string{flightdb.KTagSERFR1}
if flights, err := fdb.LookupTimeRangeByTags(tags, s, e); err != nil {
return nil, nil, err
} else {
out := []ReportRow{}
for _, f := range flights {
// If only one source has ADS-B, flag it
interest := false
if f.HasTrack("ADSB") && !f.HasTrack("FA:TA") {
interest = true
meta["Missing from FlightAware ADS-B"] += 1
}
if !f.HasTrack("ADSB") && f.HasTrack("FA:TA") {
interest = true
meta["Missing from local ADS-B"] += 1
}
// If both have ADS-B, look for missed violations
if f.HasTrack("ADSB") && f.HasTrack("FA:TA") {
if f.HasTag("ClassB:ADSB") && !f.HasTag("ClassB:FA") {
interest = true
meta["Bonus violations"] += 1
}
if !f.HasTag("ClassB:ADSB") && f.HasTag("ClassB:FA") {
interest = true
meta["Missed violations"] += 1
}
}
if !interest {
continue
}
row := SERFR1Row{flight2Url(f), f, false, false}
out = append(out, row)
}
return out, meta, nil
}
}
示例14: serfr1AtReport
func serfr1AtReport(c appengine.Context, s, e time.Time, opt ReportOptions) ([]ReportRow, ReportMetadata, error) {
meta := ReportMetadata{}
fdb := fdb.FlightDB{C: c}
maybeMemcache(&fdb, e)
tags := []string{flightdb.KTagSERFR1}
pos := sfo.KFixes[opt.Waypoint]
out := []ReportRow{}
iter := fdb.NewIter(fdb.QueryTimeRangeByTags(tags, s, e))
nSerfr1 := 0
for {
f, err := iter.NextWithErr()
if err != nil {
fdb.C.Errorf("serfr1AtReport iterator failed: %v", err)
return nil, nil, err
} else if f == nil {
break // We've hit EOF
}
nSerfr1++
if _, exists := f.Tracks["ADSB"]; exists == true {
meta["[B] with data from "+f.Tracks["ADSB"].LongSource()]++
}
if _, exists := f.Tracks["FA"]; exists == true {
meta["[B] with data from "+f.Tracks["FA"].LongSource()]++
} else {
meta["[B] with data from "+f.Track.LongSource()]++
}
if itp, err := f.BestTrack().PointOfClosestApproach(pos); err != nil {
c.Infof("Skipping flight %s: err=%v", f, err)
} else {
url := template.HTML(fmt.Sprintf("%s&waypoint=%s", flight2Url(*f), opt.Waypoint))
f.Tracks = nil // avoid running out of F1 RAM!
row := SERFR1AtRow{url, *f, itp}
out = append(out, row)
}
}
meta["[A] Total SERFR1 flights "] = float64(nSerfr1)
return out, meta, nil
}
示例15: serfr1Report
func serfr1Report(c appengine.Context, s, e time.Time, opt ReportOptions) ([]ReportRow, ReportMetadata, error) {
fdb := fdb.FlightDB{C: c}
maybeMemcache(&fdb, e)
meta := ReportMetadata{}
out := []ReportRow{}
idspecs := []string{}
reportFunc := func(f *flightdb.Flight) {
classBViolation := f.HasTag(flightdb.KTagReliableClassBViolation)
hasAdsb := false
if _, exists := f.Tracks["ADSB"]; exists == true {
meta["[B] with data from "+f.Tracks["ADSB"].LongSource()]++
idspecs = append(idspecs, fmt.Sprintf("%[email protected]%d", f.Id.ModeS, f.EnterUTC.Unix()))
}
if t, exists := f.Tracks["FA"]; exists == true {
meta["[B] with data from "+f.Tracks["FA"].LongSource()]++
hasAdsb = t.IsFromADSB()
} else {
meta["[B] with data from "+f.Track.LongSource()]++
}
fClone := f.ShallowCopy()
row := SERFR1Row{flight2Url(*fClone), *fClone, hasAdsb, classBViolation}
out = append(out, row)
}
tags := []string{flightdb.KTagSERFR1}
if err := fdb.IterWith(fdb.QueryTimeRangeByTags(tags, s, e), reportFunc); err != nil {
return nil, nil, err
}
approachUrl := fmt.Sprintf("http://ui-dot-serfr0-fdb.appspot.com/fdb/approach?idspec=%s",
strings.Join(idspecs, ","))
meta[fmt.Sprintf("[Z] %s", approachUrl)] = 1
meta["[A] Total SERFR1 flights "] = float64(len(out))
return out, meta, nil
}