当前位置: 首页>>代码示例>>Golang>>正文


Golang FlightDB.CountTimeRangeByTags方法代码示例

本文整理汇总了Golang中github.com/skypies/flightdb/gae.FlightDB.CountTimeRangeByTags方法的典型用法代码示例。如果您正苦于以下问题:Golang FlightDB.CountTimeRangeByTags方法的具体用法?Golang FlightDB.CountTimeRangeByTags怎么用?Golang FlightDB.CountTimeRangeByTags使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/skypies/flightdb/gae.FlightDB的用法示例。


在下文中一共展示了FlightDB.CountTimeRangeByTags方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: classbReport

func classbReport(c appengine.Context, s, e time.Time, opt ReportOptions) ([]ReportRow, ReportMetadata, error) {
	fdb := fdb.FlightDB{C: c}
	maybeMemcache(&fdb, e)
	tags := []string{
		flightdb.KTagReliableClassBViolation,
		flightdb.KTagLocalADSBClassBViolation,
	}

	meta := ReportMetadata{}
	h := histogram.Histogram{} // Only use it for the stats
	rows := []ReportRow{}

	seen := map[string]bool{} // Because we do two passes, we might see same flight twice.

	metars, err := metar.FetchFromNOAA(urlfetch.Client(c), "KSFO",
		s.Add(-6*time.Hour), e.Add(6*time.Hour))
	if err != nil {
		return rows, meta, err
	}

	reportFunc := func(f *flightdb.Flight) {
		if _, exists := seen[f.UniqueIdentifier()]; exists {
			return
		} else {
			seen[f.UniqueIdentifier()] = true
		}

		bestTrack := "FA"
		if f.HasTag(flightdb.KTagLocalADSBClassBViolation) {
			bestTrack = "ADSB"
		}

		_, cbt := f.SFOClassB(bestTrack, metars)

		tmpRows := []ReportRow{}

		seq := 0
		for _, cbtp := range cbt {
			if cbtp.A.IsViolation() {
				fClone := f.ShallowCopy()
				tmpRows = append(tmpRows, CBRow{seq, flight2Url(*fClone), *fClone, cbtp.TP, cbtp.A})
				seq++
			}
		}

		if len(tmpRows) == 0 {
			return
		}

		worstCBRow := tmpRows[0].(CBRow)
		if seq > 0 {
			// Select the worst row
			n, belowBy := 0, 0.0
			for i, row := range tmpRows {
				if row.(CBRow).A.BelowBy > belowBy {
					n, belowBy = i, row.(CBRow).A.BelowBy
				}
			}
			worstCBRow = tmpRows[n].(CBRow)
			worstCBRow.Seq = 0 // fake this out for the webpage
		}

		if opt.ClassB_LocalDataOnly && !f.HasTag(flightdb.KTagLocalADSBClassBViolation) {
			meta["[C] -- Skippped; not local - "+worstCBRow.TP.LongSource()]++
		} else {
			meta["[C] -- Detected via "+worstCBRow.TP.LongSource()]++
			h.Add(histogram.ScalarVal(worstCBRow.A.BelowBy))

			if opt.ClassB_OnePerFlight {
				rows = append(rows, worstCBRow)
			} else {
				rows = append(rows, tmpRows...)
			}
		}
	}

	// Need to do multiple passes, because of tagA-or-tagB sillness
	// In each case, limit to SERFR1 flights
	for _, tag := range tags {
		theseTags := []string{tag, flightdb.KTagSERFR1}
		if err := fdb.IterWith(fdb.QueryTimeRangeByTags(theseTags, s, e), reportFunc); err != nil {
			return nil, nil, err
		}
	}

	if n, err := fdb.CountTimeRangeByTags([]string{flightdb.KTagSERFR1}, s, e); err != nil {
		return nil, nil, err
	} else {
		meta["[A] Total SERFR1 Flights"] = float64(n)
	}

	if stats, valid := h.Stats(); valid {
		meta["[B] Num violating flights"] = float64(stats.N)
		meta["[D] Mean violation below Class B floor"] = float64(int(stats.Mean))
		meta["[D] Stddev"] = float64(int(stats.Stddev))
	} else {
		meta["[B] Num violating flights"] = 0.0
	}

	return rows, meta, nil
//.........这里部分代码省略.........
开发者ID:hugoh,项目名称:complaints,代码行数:101,代码来源:reports.go


注:本文中的github.com/skypies/flightdb/gae.FlightDB.CountTimeRangeByTags方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。