Esempio n. 1
0
    def detailchart(self, chartable):
        theme.reinitialize()

        min_y = 0
        max_y = 0
        capture = chartable.get('capture')
        for sortname, sortfn in self.sorts:
            data = capture[sortname]
            m = median(data)
            if m > max_y:
                max_y = m

        max_x = max(self.limits)
        min_x = min(self.limits)

        ipoints = 10.0

        x_interval = (max_x - min_x) / ipoints
        y_interval = (max_y - min_y) / ipoints

        xaxis = axis.X(label='Limit',
                       tic_interval = x_interval,
                       format='/4{}%d')
        yaxis = axis.Y(label='Seconds',
                       tic_interval = y_interval,
                       format='/4{}%0.3f')

        ar = area.T(
            x_range = (min_x, max_x),
            y_range = (min_y, max_y),
            x_axis  = xaxis,
            y_axis  = yaxis,
            legend =  legend.T(),
            )
        tb = text_box.T(loc=(140,90), text='Rlen\n%s' % chartable['rlen'])

        for sortname, sortfn in self.sorts:
            data = capture[sortname]
            linedata = [ (self.limits[x], data[x]) for x in range(len(data)) ]
            ar.add_plot(
                line_plot.T(label="%s" % sortname, data=linedata)
                )
        fd = open('detail-%s-%s.pdf' % (self.dbkey, chartable['rlen']), 'w')
        can = canvas.init(fd, 'pdf')
        ar.draw(can)
        tb.draw(can)
        can.close()
Esempio n. 2
0
    def comparisonchart(self, sortname1, sortname2):
        linedata = []
        test_total = 0
        test_wrong = 0

        for rlendata in self.main:
            rlen = rlendata['rlen']
            capture = rlendata['capture']
            values1 = capture[sortname1]
            values2 = capture[sortname2]
            doc_ratio = rlen / float(self.numdocs)
            cutoff = None
            wins = []

            #test = sortname1 == 'fwscan' and sortname2 in ('nbest', 'timsort')
            #test_fn = fwscan_wins
            test = sortname1 == 'nbest' and sortname2 == 'timsort'
            test_fn = nbest_ascending_wins

            for x in xrange(0, min(len(values1), len(values2))):
                t1 = values1[x]
                t2 = values2[x]
                limit = self.limits[x]
                limitratio = limit / float(self.numdocs)
                won = t1 < t2
                if won:
                    wins.append(limit)

                wrongmsg = "wrong %s? rlen %s, limit %s (%0.5f > %0.5f)%s"

                if test:
                    test_total += 1
                    curvewin = test_fn(limit, rlen, self.numdocs)
                    if won and (not curvewin):
                        extra = ''
                        if (t1 / t2) < .90:  # more than 10% difference
                            extra = " * (%0.2f)" % (t1 / t2)
                        print wrongmsg % ('curvelose', rlen, limit, t2, t1,
                                          extra)
                        test_wrong += 1
                    elif (not won) and curvewin:
                        extra = ''
                        if (t2 / t1) < .90:  # more than 10% difference
                            extra = " * (%0.2f)" % (t2 / t1)
                        print wrongmsg % ('curvewin', rlen, limit, t1, t2,
                                          extra)
                        test_wrong += 1

            for limit in wins:
                limitratio = limit / float(self.numdocs)
                linedata.append((doc_ratio, limitratio))

        if test:
            if test_total:
                test_right = test_total - test_wrong
                test_percent = test_right / float(test_total)
                print "test percentage %0.2f: (%s wrong out of %s)" % (
                    test_percent, test_wrong, test_total)

        comparename = 'compare-%s-%s-beats-%s' % (self.dbkey, sortname1,
                                                  sortname2)

        xaxis = axis.X(label='Doc Ratio (rlen//numdocs)',
                       tic_interval=.1,
                       format='/4{}%0.2f')
        yaxis = axis.Y(label='Limit Ratio (limit//numdocs)',
                       tic_interval=.1,
                       format='/4{}%0.2f')

        ar = area.T(
            x_range=(0, 1),
            y_range=(0, 1),
            x_axis=xaxis,
            y_axis=yaxis,
            legend=legend.T(),
        )

        ar.add_plot(
            line_plot.T(label="%s \nbeats \n%s" % (sortname1, sortname2),
                        data=linedata), )

        tb = text_box.T(loc=(140, 90), text='Numdocs\n%s' % self.numdocs)

        fd = open('%s.pdf' % comparename, 'w')
        can = canvas.init(fd, 'pdf')
        ar.draw(can)
        tb.draw(can)
        can.close()