def treemap_data(session, request): ''' Dumps data that represents the system state at some point in time. Currently it dumps the latest snapshot of the system for continuous metrics and data over the past x months for discontinous metrics. QueryDict params: cmp_type (str): The type of component for which child data is gathered. E.g if a subsystem is provided, the returned data is all data for the files in that subsystem. cmp_id (int): The component id. metric (str): A metric that must exist in the global METRICS dict. response_type (str): "application/json"|"text/csv" ''' metric = request.GET['metric'] cmp_type = request.GET['type'] cmp_id = request.GET.get('id') response_type = request.GET.get("response_type", "application/json") if metric not in METRICS.keys(): return HttpResponseNotFound("<h3>Metric not found</h3>") query = MetricsDb_TreemapData.get_query(session, metric, cmp_type, cmp_id) data = [views_utils.get_query_columns(query)] + query.all() return views_utils.dump_data(data, response_type, filename="treemap_data_" + metric)
def metric_descriptions(_): ''' Todo: Make the output csv compatible ''' # The frontend shifts the first row because it should be agnostic towards both csv and json output metrics = ["empty entry for csv"] for metric_name, data in METRICS.iteritems(): entry = {'metric': metric_name} entry.update(data) metrics.append(entry) return views_utils.dump_data(metrics, "application/json")
def lineview_data(session, request): ''' Dumps data that has accumulated over time. This data is best suited for chart like visualizations. QueryDict params: cmp_type (str): The type of component. "subsystem"|"file"|"function" cmp_id (int): The component id found in the database metric (str): A metric that must exist in the global METRICS dict. response_type (str): "application/json"|"text/csv" Args: request (django.http.HttpRequest) Returns: django.http.HttpResponse ''' cmp_type = request.GET['type'] cmp_id = request.GET['id'] metric = request.GET['metric'] response_type = request.GET.get("response_type", "application/json") if metric not in METRICS.keys(): return HttpResponseNotFound("<h3>Metric not found</h3>") db = settings.METRICSDB cmp_name = "" if cmp_type == "subsystem": cmp_name = session.query( Subsystem.subsystem).filter(Subsystem.id == cmp_id).scalar() data = db.get_changemetric_for_subsystem(session, cmp_id, metric) elif cmp_type == "file": cmp_name = session.query(File.file).filter(File.id == cmp_id).scalar() data = db.get_changemetric_for_file(session, cmp_id, metric) elif cmp_type == "function": cmp_name = session.query( Function.function).filter(Function.id == cmp_id).scalar() data = db.get_changemetric_for_function(session, cmp_id, metric) columns = [["date", "value"]] data = columns + views_utils.adapt_data(data) return views_utils.dump_data(data, response_type, filename=cmp_name + "_" + metric)
def lineview_data(session, request): ''' Dumps data that has accumulated over time. This data is best suited for chart like visualizations. QueryDict params: cmp_type (str): The type of component. "subsystem"|"file"|"function" cmp_id (int): The component id found in the database metric (str): A metric that must exist in the global METRICS dict. response_type (str): "application/json"|"text/csv" Args: request (django.http.HttpRequest) Returns: django.http.HttpResponse ''' cmp_type = request.GET['type'] cmp_id = request.GET['id'] metric = request.GET['metric'] response_type = request.GET.get("response_type", "application/json") if metric not in METRICS.keys(): return HttpResponseNotFound("<h3>Metric not found</h3>") db = settings.METRICSDB cmp_name = "" if cmp_type == "subsystem": cmp_name = session.query(Subsystem.subsystem).filter(Subsystem.id == cmp_id).scalar() data = db.get_changemetric_for_subsystem(session, cmp_id, metric) elif cmp_type == "file": cmp_name = session.query(File.file).filter(File.id == cmp_id).scalar() data = db.get_changemetric_for_file(session, cmp_id, metric) elif cmp_type == "function": cmp_name = session.query(Function.function).filter(Function.id == cmp_id).scalar() data = db.get_changemetric_for_function(session, cmp_id, metric) columns = [["date", "value"]] data = columns + views_utils.adapt_data(data) return views_utils.dump_data(data, response_type, filename=cmp_name + "_" + metric)