def send_response(self, res_type_info): """Presents nice recent statistics. It preloads data in the template for maximum responsiveness and interactively fetches data from the JSON API. """ # Preloads the data to save a complete request. resolution = self.request.params.get('resolution', 'hours') if resolution not in stats_framework.RESOLUTIONS: self.abort(404) duration = utils.get_request_as_int(self.request, 'duration', default=120, min_value=1, max_value=1000) now = utils.get_request_as_datetime(self.request, 'now') now = now or datetime.datetime.utcnow() description = res_type_info.DESCRIPTION.copy() description.update( stats_framework_gviz.get_description_key(resolution)) stats_data = stats_framework.get_stats(stats.STATS_HANDLER, resolution, now, duration, False) template_data = self.process_data(description, stats_data) template_data['duration'] = duration template_data['now'] = now template_data['resolution'] = resolution self.response.write( template.render(res_type_info.TEMPLATE, template_data))
def get_json(request, response, handler, resolution, description, order): """Returns the statistic data as a Google Visualization compatible reply. The return can be either JSON or JSONP, depending if the header 'X-DataSource-Auth' is set in the request. Note that this is not real JSON, as explained in developers.google.com/chart/interactive/docs/dev/implementing_data_source Exposes the data in the format described at https://developers.google.com/chart/interactive/docs/reference#dataparam and https://developers.google.com/chart/interactive/docs/querylanguage Arguments: - request: A webapp2.Request. - response: A webapp2.Response. - handler: A StatisticsFramework. - resolution: One of 'days', 'hours' or 'minutes'. - description: Dict describing the columns. - order: List describing the order to use for the columns. Raises: ValueError if a 400 should be returned. """ tqx_args = process_tqx(request.params.get('tqx', '')) duration = utils.get_request_as_int(request, 'duration', 120, 1, 256) now = utils.get_request_as_datetime(request, 'now') table = stats_framework.get_stats(handler, resolution, now, duration, True) return get_json_raw(request, response, table, description, order, tqx_args)
def send_response(self, res_type_info, resolution): if resolution not in stats_framework.RESOLUTIONS: self.abort(404) duration = utils.get_request_as_int(self.request, "duration", default=120, min_value=1, max_value=1000) now = utils.get_request_as_datetime(self.request, "now") description = res_type_info.DESCRIPTION.copy() description.update(stats_framework_gviz.get_description_key(resolution)) stats_data = stats_framework.get_stats(stats.STATS_HANDLER, resolution, now, duration, False) tqx_args = tqx_args = stats_framework_gviz.process_tqx(self.request.params.get("tqx", "")) try: stats_framework_gviz.get_json_raw( self.request, self.response, self.get_table(stats_data), description, res_type_info.ORDER, tqx_args ) except ValueError as e: self.abort(400, str(e))
def send_response(self, res_type_info): """Presents nice recent statistics. It preloads data in the template for maximum responsiveness and interactively fetches data from the JSON API. """ # Preloads the data to save a complete request. resolution = self.request.params.get("resolution", "hours") if resolution not in stats_framework.RESOLUTIONS: self.abort(404) duration = utils.get_request_as_int(self.request, "duration", default=120, min_value=1, max_value=1000) now = utils.get_request_as_datetime(self.request, "now") now = now or datetime.datetime.utcnow() description = res_type_info.DESCRIPTION.copy() description.update(stats_framework_gviz.get_description_key(resolution)) stats_data = stats_framework.get_stats(stats.STATS_HANDLER, resolution, now, duration, False) template_data = self.process_data(description, stats_data) template_data["duration"] = duration template_data["now"] = now template_data["resolution"] = resolution self.response.write(template.render(res_type_info.TEMPLATE, template_data))
def send_response(self, res_type_info, resolution): if resolution not in stats_framework.RESOLUTIONS: self.abort(404) duration = utils.get_request_as_int(self.request, 'duration', default=120, min_value=1, max_value=1000) now = utils.get_request_as_datetime(self.request, 'now') description = res_type_info.DESCRIPTION.copy() description.update( stats_framework_gviz.get_description_key(resolution)) stats_data = stats_framework.get_stats(stats.STATS_HANDLER, resolution, now, duration, False) tqx_args = tqx_args = stats_framework_gviz.process_tqx( self.request.params.get('tqx', '')) try: stats_framework_gviz.get_json_raw(self.request, self.response, self.get_table(stats_data), description, res_type_info.ORDER, tqx_args) except ValueError as e: self.abort(400, str(e))