def METHOD_NAME(report_id):
    if request.base_url[-1] == "/":
        return redirect("/reports/%s" % (report_id)), 301
    METHOD_NAME = report_util.get_report(report_id)
    if not METHOD_NAME:
        abort(404)
    report_url = report_util.get_report(report_id).get("url")
    if report_url:
        return redirect(report_url), 302
    dates = report_util.get_dates()
    if not dates:  # pragma: no cover
        abort(500)
    min_date = METHOD_NAME.get("minDate")
    max_date = METHOD_NAME.get("maxDate")
    date_pattern = METHOD_NAME.get("datePattern")
    max_date_metric = METHOD_NAME.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) :]  # noqa: E203
    if date_pattern:
        date_pattern = re.compile(date_pattern)
        dates = [d for d in dates if date_pattern.match(d)]
    METHOD_NAME["dates"] = dates
    METHOD_NAME["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 72 crawls (3 years).
        # May be shorter if the report's minimum date is more recent.
        start = dates[min(72, 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 METHOD_NAME.get("timeseries")
        and not METHOD_NAME.get("timeseries").get("enabled")
    ):  # pragma: no cover
        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:
        METHOD_NAME["lens"] = lens
    METHOD_NAME["view"] = get_report_view(METHOD_NAME, request)
    # Determine which metrics should be enabled for this report.
    for metric in METHOD_NAME["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
    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, METHOD_NAME=METHOD_NAME, start=start, end=end, viz=viz)
    return render_template(
        "report/%s.html" % viz,
        viz=viz,
        script_root=script_root,
        reports=report_util.get_reports(),
        METHOD_NAME=METHOD_NAME,
        start=start,
        end=end,
    )