func getMostRecentHistory( currentTime time.Time, trailk *context.Context, ctx appengine.Context, keyTool *key.Tool) *history { h := &history{} summaries := summary.NewSummaries(trailk, ctx, keyTool) h.Report24Hours = getSummaryReport( "DEFAULT_24_HOURS", "Source", currentTime, summaries) h.Report48Hours = getSummaryReport( "DEFAULT_48_HOURS", "Source", currentTime, summaries) h.Report30Days = getSummaryReport( "DEFAULT_30_DAYS", "Source", currentTime, summaries) h.Report60Days = getSummaryReport( "DEFAULT_60_DAYS", "Source", currentTime, summaries) h.Reference30Days = getSummaryReport( "DEFAULT_30_DAYS", "Reference", currentTime, summaries) h.CurrentTime = currentTime return h }
func Update(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) trailk := context.NewContext() keyTool := key.NewTool(c) fetcher := urlfetch.NewURLFetcher(c) subjects := source.NewSubjects(trailk, c, keyTool, "Source") subjectRefers := source.NewSubjects(trailk, c, keyTool, "Reference") bm := benchmark.NewBenchmark( fetcher, config.Benchmark_Repeat, config.Benchmark_Delay, config.Benchmark_ConnectionTimeoutMax, config.Benchmark_ConnectionTimeoutMin, config.Benchmark_ConnectionTimeoutIncreaseFactor) summaries := summary.NewSummaries(trailk, c, keyTool) summary.Defaults(summaries) // Build defaults if needed // Test reference first to warmup benchmark.NewBenchmarks(bm).Resulter(func(s *benchmarkcommon.Summary) { for _, sum := range summaries.Select("Reference").All() { segErr := sum.Update(s.Max(), s.Min(), s.Average(), s.Timeout()) if segErr != nil { c.Errorf("Reference frame updating: %v", segErr) continue } } }).Errorer(func(e error) { c.Errorf(e.Error()) }).RunAll(subjectRefers) benchmark.NewBenchmarks(bm).Resulter(func(s *benchmarkcommon.Summary) { for _, sum := range summaries.Select("Source").All() { segErr := sum.Update(s.Max(), s.Min(), s.Average(), s.Timeout()) if segErr != nil { c.Errorf("Source segment updating: %v", segErr) continue } } }).Errorer(func(e error) { c.Errorf(e.Error()) }).RunAll(subjects) w.WriteHeader(http.StatusOK) }
func Index(w http.ResponseWriter, r *http.Request) { // Check if we need to display 404 here if r.URL.Path != "/" { NotFoundError(w, r) return } c := appengine.NewContext(r) trailk := context.NewContext() keyTool := key.NewTool(c) s := summary.NewSummaries(trailk, c, keyTool) cached := memcache.NewMemcache(c) page, err := cached.Get(INDEX_MEMCACHE_KEY, 24*time.Hour, func() ([]byte, error) { currentTime := trailk.Time().Now() sumData := &summaryData{ Report30Days: getSummaryReports("DEFAULT_30_DAYS", "Source", currentTime, s), Report24Hours: getSummaryReports("DEFAULT_24_HOURS", "Source", currentTime, s), Dists: s.Select("Source").Distribution().All(), DistsRef: s.Select("Reference").Distribution().All(), } buf, tplErr := template.Render("landing", sumData) if tplErr != nil { return []byte(""), tplErr } return buf.Bytes(), nil }) if err != nil { switch err { default: controller.ServerError(http.StatusInternalServerError, w, err) } return } w.Header().Set("Content-Type", "text/html; charset=utf-8") w.WriteHeader(http.StatusOK) w.Write(page) }