Exemplo n.º 1
0
// Handler of /api/1/pings/{origin}/hours GET requests to retrieve the average
// `transfer_time_ms` for a specific `origin`, aggregated by hours.
func HandlerGetAvgPerHour(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	origin := vars["origin"]
	avgCollection := connector.GetAveragePerHour(origin)

	utils_json.WriteAverages(w, avgCollection)
}
Exemplo n.º 2
0
// Handler of /api/2/pings/{origin}/{time} GET requests to retrieve the average
// `transfer_time_ms` for a specific `origin`, aggregated by hours. The first
// date is {time + 1 day} if way is set to "next" or {time - 1 day} if way is
// set to "prev".
func HandlerGetAvgPerHourDayShift(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	origin := vars["origin"]
	start, err := time.Parse("2006-01-02 15:04:05 +0000 UTC", vars["time"])
	way := vars["way"]
	avgCollection := utils_json.NewAvgCollection(0)

	if err == nil {
		if way == "prev" {
			start = start.AddDate(0, 0, -1)
			avgCollection = connector.GetAverages(origin, start, time.Hour, 24)
		} else if way == "next" {
			start = start.AddDate(0, 0, +1)
			avgCollection = connector.GetAverages(origin, start, time.Hour, 24)
		}
	}

	utils_json.WriteAverages(w, avgCollection)
}