def results(r, **attr):
    '\n        Custom Method to show the Scale of Results\n    '

    def NBSP():
        return XML('&nbsp;')
    rheader = problem_rheader(r)
    response.view = 'delphi/results.html'
    empty = dict(rheader=rheader, num_voted=0, chart='', table_color='', grids='', summary='')
    problem = r.record
    if problem:
        vtable = s3db.delphi_vote
        query = (vtable.problem_id == problem.id)
        votes = db(query).select(vtable.solution_id, vtable.rank, vtable.created_by)
    else:
        votes = None
    if (not votes):
        return empty
    stable = s3db.delphi_solution
    query = (stable.problem_id == problem.id)
    solutions = db(query).select(stable.id, stable.name, stable.problem_id, stable.changes)
    if (not solutions):
        return empty
    arrayF = {}
    arrayP = {}
    arrayX = {}
    arrayP2 = {}
    arrayU = {}
    for solution in solutions:
        s1 = solution.id
        for sol_2 in solutions:
            s2 = sol_2.id
            if (s1 == s2):
                arrayF[(s1, s2)] = None
                arrayP[(s1, s2)] = None
                arrayX[(s1, s2)] = None
                arrayP2[(s1, s2)] = None
                arrayU[(s1, s2)] = None
                continue
            arrayF[(s1, s2)] = 0
            arrayP[(s1, s2)] = 0.5
            arrayX[(s1, s2)] = 0
            arrayP2[(s1, s2)] = 0.5
            arrayU[(s1, s2)] = 0.5
    voters = []
    for vote in votes:
        voter = vote.created_by
        if (voter not in voters):
            voters.append(voter)
    num_voted = len(voters)
    for voter in voters:
        ranks = {}
        for vote in votes:
            if (vote.created_by != voter):
                continue
            ranks[vote.rank] = vote.solution_id
        for rank_1 in range(1, len(ranks)):
            for rank_2 in range((rank_1 + 1), (len(ranks) + 1)):
                arrayF[(ranks[rank_1], ranks[rank_2])] += 1
    grids = DIV()
    header = TR(TD())
    rows = TBODY()
    for solution in solutions:
        header.append(TH(solution.name))
        s1 = solution.id
        row = TR(TH(solution.name))
        for sol_2 in solutions:
            s2 = sol_2.id
            value = arrayF[(s2, s1)]
            if (value is None):
                row.append(TD('-'))
            else:
                row.append(TD(value))
        rows.append(row)
    output = TABLE(THEAD(header), rows, _class='delphi_wide')
    output = DIV(H4(T("Array F: # times that solution in column is preferred over it's partner in row")), output)
    grids.append(output)
    grids.append(NBSP())
    for solution in solutions:
        s1 = solution.id
        for sol_2 in solutions:
            s2 = sol_2.id
            if (s1 == s2):
                continue
            total = float((arrayF[(s1, s2)] + arrayF[(s2, s1)]))
            if total:
                proportion = (arrayF[(s2, s1)] / total)
            else:
                proportion = 0.5
            arrayP[(s2, s1)] = proportion
            if (proportion == 0.0):
                arrayX[(s2, s1)] = _getUnitNormalDeviation(0.01)
            elif (proportion == 1.0):
                arrayX[(s2, s1)] = _getUnitNormalDeviation(0.99)
            else:
                arrayX[(s2, s1)] = _getUnitNormalDeviation(proportion)
            novotes = (num_voted - total)
            if (proportion == 0.5):
                pass
            elif (proportion > 0.5):
                proportion = ((arrayF[(s2, s1)] - novotes) / num_voted)
            else:
                proportion = ((arrayF[(s2, s1)] + novotes) / num_voted)
            arrayP2[(s2, s1)] = proportion
            if (proportion == 0.0):
                arrayU[(s2, s1)] = _getUnitNormalDeviation(0.01)
            elif (proportion == 1.0):
                arrayU[(s2, s1)] = _getUnitNormalDeviation(0.99)
            else:
                arrayU[(s2, s1)] = _getUnitNormalDeviation(proportion)
    header = TR(TD())
    rows = TBODY()
    for solution in solutions:
        header.append(TH(solution.name))
        s1 = solution.id
        row = TR(TH(solution.name))
        for sol_2 in solutions:
            s2 = sol_2.id
            value = arrayP[(s2, s1)]
            if (value is None):
                row.append(TD('-'))
            else:
                row.append(TD(value))
        rows.append(row)
    output = TABLE(THEAD(header), rows, _class='delphi_wide')
    output = DIV(H4(T("Array P: proportion of times that solution in column is preferred over it's partner in row, assuming that pairs not ranked start at the level of indifference (0.5)")), output)
    grids.append(output)
    grids.append(NBSP())
    header = TR(TD())
    rows = TBODY()
    footer = TR(TH('Total'))
    footer2 = TR(TH('Scale'))
    totals = {}
    counts = {}
    for solution in solutions:
        s1 = solution.id
        totals[s1] = 0
        counts[s1] = 0
    for solution in solutions:
        header.append(TH(solution.name))
        s1 = solution.id
        row = TR(TH(solution.name))
        for sol_2 in solutions:
            s2 = sol_2.id
            value = arrayX[(s2, s1)]
            if (value is None):
                row.append(TD('-'))
            else:
                row.append(TD(value))
            if (value is not None):
                totals[s2] += value
                counts[s2] += 1
        rows.append(row)
    for solution in solutions:
        s1 = solution.id
        footer.append(TH(totals[s1]))
        if counts[s1]:
            solution.scale = (totals[s1] / counts[s1])
            footer2.append(TH(solution.scale))
        else:
            solution.scale = 0
            footer2.append(TH())
    output = TABLE(THEAD(header), rows, footer, footer2, _class='delphi_wide')
    output = DIV(H4(T('Array X: unit normal deviate')), output)
    grids.append(output)
    grids.append(NBSP())
    header = TR(TD())
    rows = TBODY()
    for solution in solutions:
        header.append(TH(solution.name))
        s1 = solution.id
        row = TR(TH(solution.name))
        for sol_2 in solutions:
            s2 = sol_2.id
            value = arrayP2[(s2, s1)]
            if (value is None):
                row.append(TD('-'))
            else:
                row.append(TD(value))
        rows.append(row)
    output = TABLE(THEAD(header), rows, _class='delphi_wide')
    output = DIV(H4(T("Array P2: proportion of times that solution in column is preferred over it's partner in row, assuming that non-votes move towards indifference")), output)
    grids.append(output)
    grids.append(NBSP())
    header = TR(TD())
    rows = TBODY()
    footer = TR(TH('Total'))
    footer2 = TR(TH('Scale'))
    totals = {}
    counts = {}
    for solution in solutions:
        s1 = solution.id
        totals[s1] = 0
        counts[s1] = 0
    for solution in solutions:
        header.append(TH(solution.name))
        s1 = solution.id
        row = TR(TH(solution.name))
        for sol_2 in solutions:
            s2 = sol_2.id
            value = arrayU[(s2, s1)]
            if (value is None):
                row.append(TD('-'))
            else:
                row.append(TD(value))
            if (value is not None):
                totals[s2] += value
                counts[s2] += 1
        rows.append(row)
    for solution in solutions:
        s1 = solution.id
        footer.append(TH(totals[s1]))
        if counts[s1]:
            solution.uncertainty = (totals[s1] / counts[s1])
            footer2.append(TH(solution.uncertainty))
        else:
            solution.uncertainty = 0
            footer2.append(TH())
    output = TABLE(THEAD(header), rows, footer, footer2, _class='delphi_wide')
    output = DIV(H4(T('Array U: unit normal deviate of the uncertainty value (assuming that all unvoted items return the probability towards indifference)')), output)
    grids.append(output)

    def scale(solution):
        return float(solution.scale)
    solutions = solutions.sort(scale, reverse=True)
    n = len(solutions)
    image = ''
    if image:
        from s3chart import S3Chart
        chart = S3Chart(9, 6)
        fig = chart.fig
        ax = fig.add_axes([0.35, 0.1, 0.6, 0.8])
        problem = r.record
        ax.set_title(problem.name)
        labels = []
        scales = []
        uncertainties = []
        for solution in solutions:
            labels.append(solution.name)
            scales.append(solution.scale)
            uncertainties.append(solution.uncertainty)
        from numpy import arange
        ind = arange(n)
        width = 0.35
        ax.set_yticks((ind + width))
        ax.set_yticklabels(labels)
        labels = ax.get_yticklabels()
        for label in labels:
            label.set_size(8)
        ax.set_xlabel('Scale')
        ax.xaxis.grid(True)
        rects1 = ax.barh(ind, scales, width, linewidth=0)
        rects2 = ax.barh((ind + width), uncertainties, width, linewidth=0, color='red')
        ax.legend((rects1[0], rects2[0]), ('Scale', 'Uncertainty'))
        image = chart.draw()
    classes = 5
    q = []
    qappend = q.append
    for i in range((classes - 1)):
        qappend(((1.0 / classes) * (i + 1)))
    values = [float(solution.scale) for solution in solutions]
    breaks = s3db.stats_quantile(values, q)
    breaks = list(breaks)
    values_min = min(values)
    values_max = max(values)
    breaks.insert(0, values_min)
    breaks.append(values_max)
    colours = ['edf8fb', 'b2e2e2', '66c2a4', '2ca25f', '006d2c']
    for solution in solutions:
        for i in range(classes):
            value = solution.scale
            if ((value >= breaks[i]) and (value <= breaks[(i + 1)])):
                solution.color = colours[i]
                break
    thead = THEAD(TR(TH(T('Solution Item'), _rowspan='2'), TH(T('Scale'), _rowspan='2'), TH(T('Uncertainty'), _rowspan='2'), TH(T('Activity Level'), _colspan='3')), TR(TH(T('Voted on')), TH(T('Times Changed')), TH(T('Comments'))))
    tbody = TBODY()
    for solution in solutions:
        rows = True
        tbody.append(TR(TD(solution.name), TD(solution.scale, _class='taright'), TD(solution.uncertainty, _class='taright'), TD(solution.votes(), _class='tacenter'), TD(solution.changes, _class='tacenter'), TD(solution.comments(), _class='tacenter'), _style=('background:#%s' % solution.color)))
    summary = TABLE(thead, tbody, _class='delphi_wide')
    s3.stylesheets.append('S3/delphi.css')
    return dict(rheader=rheader, num_voted=num_voted, chart=image, summary=summary, grids=grids)
Custom Method to show the Scale of Results
def results(r, **attr):
    '\n        \n    '

    def NBSP():
        return XML('&nbsp;')
    rheader = problem_rheader(r)
    response.view = 'delphi/results.html'
    empty = dict(rheader=rheader, num_voted=0, chart=, table_color=, grids=, summary=)
    problem = r.record
    if problem:
        vtable = s3db.delphi_vote
        query = (vtable.problem_id == problem.id)
        votes = db(query).select(vtable.solution_id, vtable.rank, vtable.created_by)
    else:
        votes = None
    if (not votes):
        return empty
    stable = s3db.delphi_solution
    query = (stable.problem_id == problem.id)
    solutions = db(query).select(stable.id, stable.name, stable.problem_id, stable.changes)
    if (not solutions):
        return empty
    arrayF = {}
    arrayP = {}
    arrayX = {}
    arrayP2 = {}
    arrayU = {}
    for solution in solutions:
        s1 = solution.id
        for sol_2 in solutions:
            s2 = sol_2.id
            if (s1 == s2):
                arrayF[(s1, s2)] = None
                arrayP[(s1, s2)] = None
                arrayX[(s1, s2)] = None
                arrayP2[(s1, s2)] = None
                arrayU[(s1, s2)] = None
                continue
            arrayF[(s1, s2)] = 0
            arrayP[(s1, s2)] = 0.5
            arrayX[(s1, s2)] = 0
            arrayP2[(s1, s2)] = 0.5
            arrayU[(s1, s2)] = 0.5
    voters = []
    for vote in votes:
        voter = vote.created_by
        if (voter not in voters):
            voters.append(voter)
    num_voted = len(voters)
    for voter in voters:
        ranks = {}
        for vote in votes:
            if (vote.created_by != voter):
                continue
            ranks[vote.rank] = vote.solution_id
        for rank_1 in range(1, len(ranks)):
            for rank_2 in range((rank_1 + 1), (len(ranks) + 1)):
                arrayF[(ranks[rank_1], ranks[rank_2])] += 1
    grids = DIV()
    header = TR(TD())
    rows = TBODY()
    for solution in solutions:
        header.append(TH(solution.name))
        s1 = solution.id
        row = TR(TH(solution.name))
        for sol_2 in solutions:
            s2 = sol_2.id
            value = arrayF[(s2, s1)]
            if (value is None):
                row.append(TD('-'))
            else:
                row.append(TD(value))
        rows.append(row)
    output = TABLE(THEAD(header), rows, _class='delphi_wide')
    output = DIV(H4(T("Array F: # times that solution in column is preferred over it's partner in row")), output)
    grids.append(output)
    grids.append(NBSP())
    for solution in solutions:
        s1 = solution.id
        for sol_2 in solutions:
            s2 = sol_2.id
            if (s1 == s2):
                continue
            total = float((arrayF[(s1, s2)] + arrayF[(s2, s1)]))
            if total:
                proportion = (arrayF[(s2, s1)] / total)
            else:
                proportion = 0.5
            arrayP[(s2, s1)] = proportion
            if (proportion == 0.0):
                arrayX[(s2, s1)] = _getUnitNormalDeviation(0.01)
            elif (proportion == 1.0):
                arrayX[(s2, s1)] = _getUnitNormalDeviation(0.99)
            else:
                arrayX[(s2, s1)] = _getUnitNormalDeviation(proportion)
            novotes = (num_voted - total)
            if (proportion == 0.5):
                pass
            elif (proportion > 0.5):
                proportion = ((arrayF[(s2, s1)] - novotes) / num_voted)
            else:
                proportion = ((arrayF[(s2, s1)] + novotes) / num_voted)
            arrayP2[(s2, s1)] = proportion
            if (proportion == 0.0):
                arrayU[(s2, s1)] = _getUnitNormalDeviation(0.01)
            elif (proportion == 1.0):
                arrayU[(s2, s1)] = _getUnitNormalDeviation(0.99)
            else:
                arrayU[(s2, s1)] = _getUnitNormalDeviation(proportion)
    header = TR(TD())
    rows = TBODY()
    for solution in solutions:
        header.append(TH(solution.name))
        s1 = solution.id
        row = TR(TH(solution.name))
        for sol_2 in solutions:
            s2 = sol_2.id
            value = arrayP[(s2, s1)]
            if (value is None):
                row.append(TD('-'))
            else:
                row.append(TD(value))
        rows.append(row)
    output = TABLE(THEAD(header), rows, _class='delphi_wide')
    output = DIV(H4(T("Array P: proportion of times that solution in column is preferred over it's partner in row, assuming that pairs not ranked start at the level of indifference (0.5)")), output)
    grids.append(output)
    grids.append(NBSP())
    header = TR(TD())
    rows = TBODY()
    footer = TR(TH('Total'))
    footer2 = TR(TH('Scale'))
    totals = {}
    counts = {}
    for solution in solutions:
        s1 = solution.id
        totals[s1] = 0
        counts[s1] = 0
    for solution in solutions:
        header.append(TH(solution.name))
        s1 = solution.id
        row = TR(TH(solution.name))
        for sol_2 in solutions:
            s2 = sol_2.id
            value = arrayX[(s2, s1)]
            if (value is None):
                row.append(TD('-'))
            else:
                row.append(TD(value))
            if (value is not None):
                totals[s2] += value
                counts[s2] += 1
        rows.append(row)
    for solution in solutions:
        s1 = solution.id
        footer.append(TH(totals[s1]))
        if counts[s1]:
            solution.scale = (totals[s1] / counts[s1])
            footer2.append(TH(solution.scale))
        else:
            solution.scale = 0
            footer2.append(TH())
    output = TABLE(THEAD(header), rows, footer, footer2, _class='delphi_wide')
    output = DIV(H4(T('Array X: unit normal deviate')), output)
    grids.append(output)
    grids.append(NBSP())
    header = TR(TD())
    rows = TBODY()
    for solution in solutions:
        header.append(TH(solution.name))
        s1 = solution.id
        row = TR(TH(solution.name))
        for sol_2 in solutions:
            s2 = sol_2.id
            value = arrayP2[(s2, s1)]
            if (value is None):
                row.append(TD('-'))
            else:
                row.append(TD(value))
        rows.append(row)
    output = TABLE(THEAD(header), rows, _class='delphi_wide')
    output = DIV(H4(T("Array P2: proportion of times that solution in column is preferred over it's partner in row, assuming that non-votes move towards indifference")), output)
    grids.append(output)
    grids.append(NBSP())
    header = TR(TD())
    rows = TBODY()
    footer = TR(TH('Total'))
    footer2 = TR(TH('Scale'))
    totals = {}
    counts = {}
    for solution in solutions:
        s1 = solution.id
        totals[s1] = 0
        counts[s1] = 0
    for solution in solutions:
        header.append(TH(solution.name))
        s1 = solution.id
        row = TR(TH(solution.name))
        for sol_2 in solutions:
            s2 = sol_2.id
            value = arrayU[(s2, s1)]
            if (value is None):
                row.append(TD('-'))
            else:
                row.append(TD(value))
            if (value is not None):
                totals[s2] += value
                counts[s2] += 1
        rows.append(row)
    for solution in solutions:
        s1 = solution.id
        footer.append(TH(totals[s1]))
        if counts[s1]:
            solution.uncertainty = (totals[s1] / counts[s1])
            footer2.append(TH(solution.uncertainty))
        else:
            solution.uncertainty = 0
            footer2.append(TH())
    output = TABLE(THEAD(header), rows, footer, footer2, _class='delphi_wide')
    output = DIV(H4(T('Array U: unit normal deviate of the uncertainty value (assuming that all unvoted items return the probability towards indifference)')), output)
    grids.append(output)

    def scale(solution):
        return float(solution.scale)
    solutions = solutions.sort(scale, reverse=True)
    n = len(solutions)
    image = 
    if image:
        from s3chart import S3Chart
        chart = S3Chart(9, 6)
        fig = chart.fig
        ax = fig.add_axes([0.35, 0.1, 0.6, 0.8])
        problem = r.record
        ax.set_title(problem.name)
        labels = []
        scales = []
        uncertainties = []
        for solution in solutions:
            labels.append(solution.name)
            scales.append(solution.scale)
            uncertainties.append(solution.uncertainty)
        from numpy import arange
        ind = arange(n)
        width = 0.35
        ax.set_yticks((ind + width))
        ax.set_yticklabels(labels)
        labels = ax.get_yticklabels()
        for label in labels:
            label.set_size(8)
        ax.set_xlabel('Scale')
        ax.xaxis.grid(True)
        rects1 = ax.barh(ind, scales, width, linewidth=0)
        rects2 = ax.barh((ind + width), uncertainties, width, linewidth=0, color='red')
        ax.legend((rects1[0], rects2[0]), ('Scale', 'Uncertainty'))
        image = chart.draw()
    classes = 5
    q = []
    qappend = q.append
    for i in range((classes - 1)):
        qappend(((1.0 / classes) * (i + 1)))
    values = [float(solution.scale) for solution in solutions]
    breaks = s3db.stats_quantile(values, q)
    breaks = list(breaks)
    values_min = min(values)
    values_max = max(values)
    breaks.insert(0, values_min)
    breaks.append(values_max)
    colours = ['edf8fb', 'b2e2e2', '66c2a4', '2ca25f', '006d2c']
    for solution in solutions:
        for i in range(classes):
            value = solution.scale
            if ((value >= breaks[i]) and (value <= breaks[(i + 1)])):
                solution.color = colours[i]
                break
    thead = THEAD(TR(TH(T('Solution Item'), _rowspan='2'), TH(T('Scale'), _rowspan='2'), TH(T('Uncertainty'), _rowspan='2'), TH(T('Activity Level'), _colspan='3')), TR(TH(T('Voted on')), TH(T('Times Changed')), TH(T('Comments'))))
    tbody = TBODY()
    for solution in solutions:
        rows = True
        tbody.append(TR(TD(solution.name), TD(solution.scale, _class='taright'), TD(solution.uncertainty, _class='taright'), TD(solution.votes(), _class='tacenter'), TD(solution.changes, _class='tacenter'), TD(solution.comments(), _class='tacenter'), _style=('background:#%s' % solution.color)))
    summary = TABLE(thead, tbody, _class='delphi_wide')
    s3.stylesheets.append('S3/delphi.css')
    return dict(rheader=rheader, num_voted=num_voted, chart=image, summary=summary, grids=grids)