예제 #1
0
    def combine(lines, increment):

        # we return a new PolyLine which is a composite (summed horizontally) of inputs
        composite = PolyLine()

        # find the range defined by the curves
        minY = None
        maxY = None
        for l in lines:
            minY = PolyLine.min(minY, l.min_y())
            maxY = PolyLine.max(maxY, l.max_y())

        # special case if the lines are already horizontal or None
        if minY == maxY:
            minSumX = None
            maxSumX = None
            for line in lines:
                minX = None
                maxX = None
                for point in line.points:
                    minX = PolyLine.min(minX, point.x)
                    maxX = PolyLine.max(maxX, point.x)
                minSumX = PolyLine.sum(minSumX, minX)
                maxSumX = PolyLine.sum(maxSumX, maxX)
            composite.add(Point(minSumX, minY))
            if minX != maxX:
                composite.add(Point(maxSumX, maxY))
            return composite

        # create an array of ys in equal increments, with highest first
        # this is assuming that price decreases with increase in demand (buyers!)
        # but seems to work with multiple suppliers?
        ys = sorted(np.linspace(minY, maxY, num=increment), reverse=True)
        # print ys
        # print minY, maxY

        # now find the cumulative x associated with each y in the array
        # starting with the highest y
        for y in ys:
            xt = None
            for line in lines:
                x = line.x(y, left=np.nan)
                # print x, y
                if x is not None:
                    xt = x if xt is None else xt + x
            composite.add(Point(xt, y))

        return composite
예제 #2
0
    def combine(lines, increment):

        # we return a new PolyLine which is a composite (summed horizontally) of inputs
        composite = PolyLine()

        # find the range defined by the curves
        minY = None
        maxY = None
        for l in lines:
            minY = PolyLine.min(minY, l.min_y())
            maxY = PolyLine.max(maxY, l.max_y())

        # special case if the lines are already horizontal or None
        if minY == maxY:
            minSumX = None
            maxSumX = None
            for line in lines:
                minX = None
                maxX = None
                for point in line.points:
                    minX = PolyLine.min(minX, point.x)
                    maxX = PolyLine.max(maxX, point.x)
                minSumX = PolyLine.sum(minSumX, minX)
                maxSumX = PolyLine.sum(maxSumX, maxX)
            composite.add(Point(minSumX, minY))
            if minX != maxX:
                composite.add(Point(maxSumX, maxY))
            return composite

        # create an array of ys in equal increments, with highest first
        # this is assuming that price decreases with increase in demand (buyers!)
        # but seems to work with multiple suppliers?
        ys = sorted(np.linspace(minY, maxY, num=increment), reverse=True)
        # print ys
        # print minY, maxY

        # now find the cumulative x associated with each y in the array
        # starting with the highest y
        for y in ys:
            xt = None
            for line in lines:
                x = line.x(y, left=np.nan)
                # print x, y
                if x is not None:
                    xt = x if xt is None else xt + x
            composite.add(Point(xt, y))

        return composite
예제 #3
0
def test_poly_line_max_second_none():
    max = PolyLine.max(1,None)
    assert max == 1
예제 #4
0
def test_poly_line_max_first_none():
    max = PolyLine.max(None,2)
    assert max == 2
예제 #5
0
def test_poly_line_max():
    max = PolyLine.max(1,2)
    assert max == 2
예제 #6
0
def test_poly_line_max_second_none():
    max = PolyLine.max(1, None)
    assert max == 1
예제 #7
0
def test_poly_line_max_first_none():
    max = PolyLine.max(None, 2)
    assert max == 2
예제 #8
0
def test_poly_line_max():
    max = PolyLine.max(1, 2)
    assert max == 2