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


Golang ComplaintDB.GetComplaintsInSpan方法代码示例

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


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

示例1: serfr1ComplaintsReport

func serfr1ComplaintsReport(c appengine.Context, s, e time.Time, opt ReportOptions) ([]ReportRow, ReportMetadata, error) {
	fdb := fdb.FlightDB{C: c}
	maybeMemcache(&fdb, e)
	cdb := complaintdb.ComplaintDB{C: c, Memcache: true}
	meta := ReportMetadata{}

	memKey := fmt.Sprintf("serfr1complaintsreport:%s:%d-%d", s.Unix(), e.Unix())

	if rows, meta, err := reportFromMemcache(c, memKey); err == nil {
		return rows, meta, err
	}

	if complaints, err := cdb.GetComplaintsInSpan(s, e); err != nil {
		return nil, nil, err

	} else {
		meta["[B] Total disturbance reports"] = float64(len(complaints))

		nFlights := 0
		nFpC := map[string]int{} // num flights per carrier
		nCpC := map[string]int{} // num complaints per carrier

		// Aggregate complaints per flightnumber (as seen from complaints)
		nC, nSB, nWC := map[string]int{}, map[string]int{}, map[string]int{}
		for _, comp := range complaints {
			if k := comp.AircraftOverhead.FlightNumber; k != "" {
				nC[k] += 1
				nWC[k] += comp.Loudness
				if comp.HeardSpeedbreaks {
					nSB[k] += 1
					nWC[k] += 4
				}
			}
		}

		rows := []SCRow{}
		reportFunc := func(f *flightdb.Flight) {
			nFlights++

			carrier := f.Id.Designator.IATAAirlineDesignator
			if carrier != "" {
				nFpC[carrier] += 1
			}

			if k := f.Id.Designator.String(); k != "" {
				if carrier != "" {
					nCpC[carrier] += nC[k]
				}
				fClone := f.ShallowCopy()
				scRow := SCRow{
					NumComplaints:      nC[k],
					NumSpeedbrakes:     nSB[k],
					WeightedComplaints: nWC[k],
					F:                  *fClone,
				}
				rows = append(rows, scRow)
				meta["[B] SERFR1 disturbance reports"] += float64(nC[k])
			}
		}

		tags := []string{flightdb.KTagSERFR1}
		if err := fdb.IterWith(fdb.QueryTimeRangeByTags(tags, s, e), reportFunc); err != nil {
			return nil, nil, err
		}

		meta["[A] Total flights we saw on SERFR1"] += float64(nFlights)
		meta["[C] Average number of reports per overflight"] =
			float64(int64(float64(len(complaints)) / float64(nFlights)))

		sort.Sort(SCRowByNumComplaints(rows))
		out := []ReportRow{}
		for _, r := range rows {
			out = append(out, r)
		}

		bestCarrier, worstCarrier := "", ""
		bestScore, worstScore := 999, -1
		for carrier, nFlights := range nFpC {
			if nFlights < 3 {
				continue
			}
			cPerFlight := nCpC[carrier] / nFlights
			if cPerFlight < bestScore {
				bestCarrier, bestScore = carrier, cPerFlight
			}
			if cPerFlight > worstScore {
				worstCarrier, worstScore = carrier, cPerFlight
			}
		}

		meta["[D] Worst airline (average reports per overflight) - "+worstCarrier] = float64(worstScore)
		meta["[E] Best airline (average reports per overflight) - "+bestCarrier] = float64(bestScore)

		// reportToMemcache(c, out, meta, memKey)
		return out, meta, nil
	}
}
开发者ID:hugoh,项目名称:complaints,代码行数:97,代码来源:reports.go


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