本文整理汇总了Golang中github.com/skypies/complaints/complaintdb.ComplaintDB.QueryInSpanByEmailAddress方法的典型用法代码示例。如果您正苦于以下问题:Golang ComplaintDB.QueryInSpanByEmailAddress方法的具体用法?Golang ComplaintDB.QueryInSpanByEmailAddress怎么用?Golang ComplaintDB.QueryInSpanByEmailAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/skypies/complaints/complaintdb.ComplaintDB
的用法示例。
在下文中一共展示了ComplaintDB.QueryInSpanByEmailAddress方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: personalReportHandler
func personalReportHandler(w http.ResponseWriter, r *http.Request) {
session := sessions.Get(r)
if session.Values["email"] == nil {
http.Error(w, "session was empty; no cookie ?", http.StatusInternalServerError)
return
}
email := session.Values["email"].(string)
if r.FormValue("date") == "" {
var params = map[string]interface{}{
"Yesterday": date.NowInPdt().AddDate(0, 0, -1),
}
if err := templates.ExecuteTemplate(w, "personal-report-form", params); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
return
}
start, end, _ := widget.FormValueDateRange(r)
ctx := appengine.Timeout(appengine.NewContext(r), 60*time.Second)
cdb := complaintdb.ComplaintDB{C: ctx}
w.Header().Set("Content-Type", "text/plain")
// w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", "sc.txt"))
fmt.Fprintf(w, "Personal disturbances report for <%s>:\n From [%s]\n To [%s]\n",
email, start, end)
complaintStrings := []string{}
var countsByHour [24]int
countsByDate := map[string]int{}
countsByAirline := map[string]int{}
iter := cdb.NewIter(cdb.QueryInSpanByEmailAddress(start, end, email))
n := 0
for {
c := iter.Next()
if c == nil {
break
}
str := fmt.Sprintf("Time: %s, Loudness:%d, Speedbrakes:%v, Flight:%6.6s, Notes:%s",
c.Timestamp.Format("2006.01.02 15:04:05"), c.Loudness, c.HeardSpeedbreaks,
c.AircraftOverhead.FlightNumber, c.Description)
n++
complaintStrings = append(complaintStrings, str)
countsByHour[c.Timestamp.Hour()]++
countsByDate[c.Timestamp.Format("2006.01.02")]++
if airline := c.AircraftOverhead.IATAAirlineCode(); airline != "" {
countsByAirline[airline]++
}
}
fmt.Fprintf(w, "\nTotal number of disturbance reports, over %d days: %d\n",
len(countsByDate), n)
fmt.Fprintf(w, "\nDisturbance reports, counted by Airline (where known):\n")
for _, k := range keysByIntValDesc(countsByAirline) {
fmt.Fprintf(w, " %s: % 4d\n", k, countsByAirline[k])
}
fmt.Fprintf(w, "\nDisturbance reports, counted by date:\n")
for _, k := range keysByKeyAsc(countsByDate) {
fmt.Fprintf(w, " %s: % 4d\n", k, countsByDate[k])
}
fmt.Fprintf(w, "\nDisturbance reports, counted by hour of day (across all dates):\n")
for i, n := range countsByHour {
fmt.Fprintf(w, " %02d: % 4d\n", i, n)
}
fmt.Fprintf(w, "\nFull dump of all disturbance reports:\n\n")
for _, s := range complaintStrings {
fmt.Fprint(w, s+"\n")
}
}