Esempio n. 1
0
    def _build_report(self, name):
        import reports

        if name is None:
            name = self.get("reportname", None)
        params = self.reports.get(name, (None,))
        return reports.get_report(params)
Esempio n. 2
0
 def _build_report(self, name):
     import reports
     name = name or self.get("reportname", None)
     params = self.reports.get(name, (None, ))
     if type(params) is list:
         params = map(self._report_param_expand, params)
     else:
         params = self._report_param_expand(params)
     return reports.get_report(params)
Esempio n. 3
0
 def _build_report(self, name):
     import reports
     name = name or self.get("reportname", None)
     params = self.reports.get(name, (None,))
     if type(params) is list:
         params = map(self._report_param_expand, params)
     else:
         params = self._report_param_expand(params)
     return reports.get_report( params )
Esempio n. 4
0
 def _build_report(self, name):
     import reports
     if name is None:
         name = self.get("reportname", "default")
     params = self.reports.get(name, (None,))
     if type(params) is list:
         params = map(self._report_param_expand, params)
     else:
         params = self._report_param_expand(params)
     return reports.get_report( params )
Esempio n. 5
0
    def _build_report(self):
        import reports
        name = self.get("reportname", "default")
        params = self.reports.get(name, (None,))
        try:
            if (params[0]) is None:
                print "### no StandardReport defition ###"
                params = ('StandardReport', '$reportpath', 'text/html')
        except:
             params = ('StandardReport', '$reportpath', 'text/html')

        if type(params) is list:
            params = map(self._report_param_expand, params)
        else:
            params = self._report_param_expand(params)
        return reports.get_report( params )
Esempio n. 6
0
def report(report_id):
	report = report_util.get_report(report_id)
	if not report:
		abort(404)

	dates = report_util.get_dates()
	if not dates:
		abort(500)

	min_date = report.get('minDate')
	max_date = report.get('maxDate')
	date_pattern = report.get('datePattern')
	max_date_metric = report.get('maxDateMetric')

	# TODO: If a report doesn't explicitly have a min/max date,
	# but all of its metrics do, take the min/max of the metrics
	# and set that as the report's implicit min/max date.

	# Omit dates for which this report has no data.
	if max_date_metric:
		max_date = report_util.get_latest_date(max_date_metric)
	if min_date:
		dates = dates[:dates.index(min_date) + 1]
	if max_date:
		dates = dates[dates.index(max_date):]
	if date_pattern:
		date_pattern = re.compile(date_pattern)
		dates = [d for d in dates if date_pattern.match(d)]

	report['dates'] = dates
	report['lenses'] = report_util.get_lenses()

	start = request.args.get('start')
	end = request.args.get('end')

	# Canonicalize single-date formats.
	if end and not start:
		start, end = end, start

	# Canonicalize aliases.
	if start == 'latest':
		start = dates[0]
	elif start == 'earliest':
		start = dates[-1]
	if end == 'latest':
		end = dates[0]
	elif end == 'earliest':
		end = dates[-1]

	# This is longhand for the snapshot (histogram) view.
	if start == end:
		end = None

	# This is shorthand for the trends (timeseries) view.
	if not start and not end:
		# The default date range is 24 crawls (1 year).
		# May be shorter if the report's minimum date is more recent.
		start = dates[min(24, len(dates) - 1)]
		end = dates[0]

	if start and start not in dates:
		abort(400)
	if end and end not in dates:
		abort(400)

	viz = report_util.VizTypes.HISTOGRAM if (start and not end) else report_util.VizTypes.TIMESERIES

	if viz == report_util.VizTypes.TIMESERIES and report.get('timeseries') and not report.get('timeseries').get('enabled'):
		end = None
		viz = report_util.VizTypes.HISTOGRAM

		# The default for histograms should be the latest date.
		if not request.args.get('start'):
			start = dates[0]

	lens_id = get_lens_id(request)
	lens = report_util.get_lens(lens_id)
	if lens:
		report['lens'] = lens

	report['view'] = get_report_view(report, request)

	# Determine which metrics should be enabled for this report.
	for metric in report['metrics']:
		# Get a list of reports that also contain this metric.
		metric['similar_reports'] = report_util.get_similar_reports(metric['id'], report_id)

		# Mark the lens used for this metric, if applicable.
		if lens:
			metric['lens'] = lens

		metric[viz] = metric.get(viz, {})
		enabled = metric[viz].get('enabled', True)
		min_date = metric[viz].get('minDate', start)
		max_date = metric[viz].get('maxDate', end)

		# Disabled metrics should stay that way.
		if not enabled:
			continue

		# Disable the metric if it start/end is outside of the min/max window.
		enabled = start >= min_date
		if max_date and enabled:
			enabled = start <= max_date
		if end and enabled:
			enabled = end <= max_date

		metric[viz]['enabled'] = enabled


	if not request.script_root:
		request.script_root = url_for('report', report_id=report_id, _external=True)

	# Return as JSON if requested.
	if get_format(request) == 'json':
		return jsonify(status=200, report=report, start=start, end=end, viz=viz)

	return render_template('report/%s.html' % viz,
						   viz=viz,
						   reports=report_util.get_reports(),
						   report=report,
						   start=start,
						   end=end)
Esempio n. 7
0
    def section(self):
        return "<hr>\n"

    def page(self):
        return "<br><hr><br>\n"

    def initialize(self):
        return """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Final//EN">
<html>
  <head>
	<title>Test Results</title>
  </head>
<body>
"""

    def finalize(self):
        return "\n</body>\n</html>\n"


if __name__ == "__main__":
    # report = reports.get_report((None, "-", "text/html",))
    report = reports.get_report((None, "lla", "text/html"))
    report.initialize()
    report.info("Some self test info.")
    report.passed("Hello World")
    report.incomplete("Hello World")
    report.diagnostic("Hello World")
    report.passed("Hello World")
    report.passed("Hello World")
    report.finalize()
Esempio n. 8
0
                return "<p><span class=\"error\">%s: %s</span></p>\n" % (msgtype, escape(msg))

            else:
                return '<p>%s: %s</p>\n' % (msgtype, escape(msg))

	def text(self, text):
		return "<pre>%s</pre>\n" % (text,)

	def url(self, text, url):
		return '<p>%s: <a href="%s">%s</a></p>\n' % (text, url, url)

	def summary(self, text):
		sum = "<pre>%s</pre>\n" % (text,)
		sum =  sum.replace("PASSED", self._MSGTYPESUB["PASSED"])
		sum =  sum.replace("FAILED", self._MSGTYPESUB["FAILED"])
		return sum
	def section(self):
		return "<hr>\n"



if __name__ == "__main__":
	report = reports.get_report((None, "-", "text/html",))
	report.initialize()
	report.info("Some self test info.")
	report.passed("yippee!")
    report.error("ERROR\n2nd line\n")
	report.finalize()

# End of file
Esempio n. 9
0
 def _build_report(self, name):
     import reports
     if name is None:
         name = self.get("reportname", None)
     params = self.reports.get(name, (None, ))
     return reports.get_report(params)
Esempio n. 10
0
def report(report_id):
    report = reportutil.get_report(report_id)
    if not report:
        abort(404)

    dates = reportutil.get_dates()
    if not dates:
        abort(500)

    min_date = report.get('minDate')
    max_date = report.get('maxDate')

    # TODO: If a report doesn't explicitly have a min/max date,
    # but all of its metrics do, take the min/max of the metrics
    # and set that as the report's implicit min/max date.

    # Omit dates for which this report has no data.
    if min_date:
        dates = dates[:dates.index(min_date) + 1]
    if max_date:
        dates = dates[dates.index(max_date):]

    report['dates'] = dates

    start = request.args.get('start')
    end = request.args.get('end')

    # Canonicalize single-date formats.
    if end and not start:
        start, end = end, start

    # Canonicalize aliases.
    if start == 'latest':
        start = dates[0]
    elif start == 'earliest':
        start = dates[-1]
    if end == 'latest':
        end = dates[0]
    elif end == 'earliest':
        end = dates[-1]

    # This is longhand for the snapshot (histogram) view.
    if start == end:
        end = None

    # This is shorthand for the trends (timeseries) view.
    if not start and not end:
        # The default date range is 24 crawls (1 year).
        # May be shorter if the report's minimum date is more recent.
        start = dates[min(23, len(dates) - 1)]
        end = dates[0]

    if start and start not in dates:
        abort(400)
    if end and end not in dates:
        abort(400)

    viz = reportutil.VizTypes.HISTOGRAM if (
        start and not end) else reportutil.VizTypes.TIMESERIES

    if viz == reportutil.VizTypes.TIMESERIES and report.get(
            'timeseries') and not report.get('timeseries').get('enabled'):
        end = None
        viz = reportutil.VizTypes.HISTOGRAM

    # Determine which metrics should be enabled for this report.
    for metric in report['metrics']:
        # Get a list of reports that also contain this metric.
        metric['similar_reports'] = reportutil.get_similar_reports(
            metric['id'], report_id)

        metric[viz] = metric.get(viz, {})
        enabled = metric[viz].get('enabled', True)
        min_date = metric[viz].get('minDate', start)
        max_date = metric[viz].get('maxDate', end)

        # Disabled metrics should stay that way.
        if not enabled:
            continue

        # Disable the metric if it start/end is outside of the min/max window.
        enabled = start >= min_date
        if end and enabled:
            enabled = end <= max_date

        metric[viz]['enabled'] = enabled

    if not request.script_root:
        request.script_root = url_for('report',
                                      report_id=report_id,
                                      _external=True)

    return render_template('report/%s.html' % viz,
                           viz=viz,
                           reports=reportutil.get_reports(),
                           report=report,
                           start=start,
                           end=end)