stats_decorator.py 2.08 KB
Newer Older
1 2
import vidjil_utils

3
class StatDecorator(object):
4 5 6 7 8 9

    def __init__(self):
        pass

    def decorate(self, data):
        return data if data is not None else ""
Ryan Herbert's avatar
Ryan Herbert committed
10 11 12 13 14 15 16 17

class BooleanDecorator(StatDecorator):

    def __init__(self):
        super(BooleanDecorator, self).__init__()

    def decorate(self, data):
        if data:
18
            myclass = "icon-ok"
Ryan Herbert's avatar
Ryan Herbert committed
19
        else:
20
            myclass = "icon-cancel"
Ryan Herbert's avatar
Ryan Herbert committed
21 22 23 24 25 26 27 28 29
        return I(_class=myclass)

class BarDecorator(StatDecorator):

    def __init__(self):
        super(BarDecorator, self).__init__()

    def decorate(self, data):
        return DIV(SPAN(_style="width: %d%%" % data), _class="meter", _title="%d%%" % data)
30 31 32 33 34 35 36 37 38

class BarChartDecorator(StatDecorator):

    def __init__(self):
        super(BarChartDecorator, self).__init__()

    def decorate(self, data):
        bars = []
        for val in data:
39
            bar_span = SPAN(_style="height: %f%%; width: %f%%" % (val, (1.0/len(data))*100), _title="%f%%" % val, _class="bar")
40 41
            bars.append(bar_span)
        return DIV(*bars, _class="bar_chart")
42

43 44 45 46 47 48 49 50 51 52 53 54 55
class LabeledBarChartDecorator(BarChartDecorator):

    def __init__(self):
        super(LabeledBarChartDecorator, self).__init__()

    def decorate(self, data):
        bars = []
        for key in data:
            val = data[key]
            bar_span = SPAN(_style="height: %f%%; width: %f%%" % (val, (1.0/len(data))*100), _title="%s" % key, _class="bar")
            bars.append(bar_span)
        return DIV(*bars, _class="bar_chart")

56 57 58 59 60 61 62 63 64 65 66
class SetsDecorator(StatDecorator):

    def __init__(self):
        super(SetsDecorator, self).__init__()

    def decorate(self, data):
        ssets = []
        for sample_set in data:
            d = DIV("(%d) %s" % (sample_set['id'], sample_set['name']))
            ssets.append(d)
        return DIV(*ssets)
67 68 69 70 71 72 73 74 75

class LociListDecorator(StatDecorator):

    def __init__(self):
        super(LociListDecorator, self).__init__()

    def decorate(self, data):
        loci = []
        for locus in data:
76
            span = SPAN(locus, _class="stats_locus")
77 78
            loci.append(span)
        return DIV(*loci)