Beispiel #1
0
    def testMultiSeries(self):
        """
        Test suite for methods inherited from MultiSeries - bah...
        """

        # NB: the error message:
        #   java.lang.UnsupportedOperationException: Series type does not support this method.
        #   seriesType=class io.deephaven.db.plot.datasets.xy.XYDataSeriesTableArray
        #   method='@Override public  FigureImpl pointsVisible( java.lang.Boolean visible, java.lang.Object... keys )'

        # TODO: seriesNamingFunction(*args)?,pointColorByY(func, *keys)?
        # TODO: a ton of other call signatures for basically XYDataSeriesMethods

        figure = Plot.plot("Microsoft", self.table.where("Sym=`MSFT`"), "timestamp", "price")\
            .plot("Apple", self.table.where("Sym=`AAPL`"), "timestamp", "price")

        with self.subTest(msg="gradientVisible(boolean, *keys)"):
            figure = figure.gradientVisible(True, "Microsoft")
        with self.subTest(msg="lineColor(Paint/int/string, *keys)"):
            figure = figure.lineColor("RED", "Apple")
        with self.subTest(msg="lineStyle(LineStyle, *keys)"):
            figure = figure.lineStyle(Plot.lineStyle(4.0, 4.0), "Microsoft",
                                      "Apple")
        with self.subTest(msg="linesVisible(boolean, *keys)"):
            figure = figure.linesVisible(True, "Microsoft", "Apple")
        with self.subTest(msg="pointColor(Paint/int/string, *keys)"):
            figure = figure.pointColor("BLUE", "Microsoft", "Apple")
        with self.subTest(msg="pointLabel(object, *keys)"):
            figure = figure.pointLabel("label", "Microsoft", "Apple")
        with self.subTest(msg="pointLabelFormat(string, *keys)"):
            figure = figure.pointLabelFormat("{0}: ({1}, {2})", "Microsoft",
                                             "Apple")
        with self.subTest(msg="pointShape(string, *keys)"):
            figure = figure.pointShape("SQUARE", "Microsoft", "Apple")
        with self.subTest(msg="pointSize(double, *keys)"):
            figure = figure.pointSize(2.0, "Microsoft", "Apple")
        with self.subTest(msg="pointsVisible(boolean, *keys)"):
            figure = figure.pointsVisible(True, "Microsoft", "Apple")
        with self.subTest(msg="seriesColor(Paint/int/string, *keys)"):
            figure = figure.seriesColor(Plot.colorRGB(255, 0, 0), "Microsoft",
                                        "Apple")
        with self.subTest(msg="tool tips"):
            figure = figure.toolTipPattern("###,###.00", "Apple")\
                .xToolTipPattern("###,###.00", "Apple")\
                .yToolTipPattern("###,###.00", "Apple")
        with self.subTest(msg="group(int, *keys)"):
            figure = figure.group(0, "Microsoft", "Apple")
        del figure
Beispiel #2
0
    def testDataSeriesMethods(self):
        """
        Test suite for methods inherited from DataSeries
        """

        # TODO: pointColorByY(SerializableFunction)?, pointColorByY(Closure)?

        figure = Plot.plot("Microsoft", self.table.where("Sym=`MSFT`"),
                           "timestamp", "price")
        with self.subTest(msg="linesVisible(boolean)"):
            figure = figure.linesVisible(True)
        with self.subTest(msg="lineColor(Paint)"):
            figure = figure.lineColor(Plot.colorRGB(0.2, 1.0, 0.2))
        with self.subTest(msg="lineStyle(LineStyle)"):
            figure = figure.lineStyle(Plot.lineStyle(4, 4))
        with self.subTest(msg="pointsVisible(boolean)"):
            figure = figure.pointsVisible(True)
        with self.subTest(msg="pointSize(double)"):
            figure = figure.pointSize(2.0)
        with self.subTest(msg="pointLabel(object)"):
            figure = figure.pointLabel("label")
        with self.subTest(msg="pointLabelFormat(string)"):
            figure = figure.pointLabelFormat("{0}: ({1}, {2})")
        with self.subTest(msg="pointShape(string)"):
            figure = figure.pointShape("CIRCLE")
        with self.subTest(msg="seriesColor(Paint)"):
            figure = figure.seriesColor(Plot.colorRGB(0.1, 0.1, 0.1))
        with self.subTest(msg="pointColor(Paint)"):
            figure = figure.pointColor(Plot.colorRGB(1.0, 0.0, 0.0))
        with self.subTest(msg="gradientVisible(boolean)"):
            figure.gradientVisible(False)
        with self.subTest(msg="toolTipPattern(string)"):
            figure = figure.toolTipPattern("###,###.00")
        with self.subTest(msg="xToolTipPattern(string)"):
            figure = figure.xToolTipPattern("###,###.00")
        with self.subTest(msg="yToolTipPattern(string)"):
            figure = figure.yToolTipPattern("###,###.00")
        del figure
    .pointColor(Plot.colorRGB(255, 0, 0, 100))\
    .pointShape("up_triangle")\
    .chartTitle("AAPL vs MSFT (10-11am ET)")\
    .show()

# XY SERIES - SINGLE SERIES WITH PLOTSTYLE - STEP

t7 = db.t("LearnDeephaven", "StockTrades")\
    .where("Date=`2017-08-24`", "USym=`GOOG`")\
    .updateView("TimeBin=upperBin(Timestamp, 30 * MINUTE)")\
    .where("isBusinessTime(TimeBin)")

plotXYStep = Plot.plot("GOOG", t7.where("USym = `GOOG`")\
    .lastBy("TimeBin"), "TimeBin", "Last")\
    .plotStyle("Step")\
    .lineStyle(Plot.lineStyle(3))\
    .show()

# ERROR BAR on XY SERIES

# source the data
t_EB = db.t("LearnDeephaven", "StockTrades")\
    .where("Date = `2017-08-23`", "USym = `GOOG`")\
    .updateView("TimeBin=upperBin(Timestamp, 20 * MINUTE)")\
    .where("isBusinessTime(TimeBin)")

# calculate standard deviations for the upper and lower error values
t_EB_StdDev = t_EB.by(
    caf.AggCombo(caf.AggAvg("AvgPrice = Last"), caf.AggStd("StdPrice = Last")),
    "TimeBin")
pieChart = Plot.piePlot("Shares Traded", totalShares, "Sym", "SharesTraded")\
     .chartTitle("Total Shares")\
     .show()

#  ************* OPEN HIGH LOW CLOSE (OHLC) PLOTTING *************

#  OPEN HIGH LOW CLOSE (OHLC) - SINGLE SERIES

tOHLC = db.t("LearnDeephaven","EODTrades")\
     .where("Ticker=`AAPL`", "ImportDate=`2017-11-01`",
            "inRange(EODTimestamp, '2017-06-01T12:00 NY', '2017-07-31T12:00 NY')")

plotOHLC = Plot.ohlcPlot("AAPL", tOHLC, "EODTimestamp", "Open", "High", "Low", "Close")\
     .xBusinessTime()\
     .lineStyle(Plot.lineStyle(2))\
     .chartTitle("AAPL OHLC - June-July 2017")\
     .show()

#  OPEN HIGH LOW CLOSE (OHLC) - MULTIPLE SERIES WITH TWINX

t2OHLC = db.t("LearnDeephaven", "EODTrades").where(
    "Ticker in `AAPL`, `MSFT`", "ImportDate=`2017-11-01`",
    "inRange(EODTimestamp, '2017-06-01T12:00 NY', '2017-07-31T12:00 NY')")

plotOHLC2 = Plot.ohlcPlot("AAPL", t2OHLC.where("Ticker = `AAPL`"), "EODTimestamp", "Open", "High", "Low", "Close")\
     .lineStyle(Plot.lineStyle(2))\
     .twinX()\
     .ohlcPlot("MSFT", t2OHLC.where("Ticker = `MSFT`"),"EODTimestamp","Open","High","Low","Close")\
     .xBusinessTime()\
     .lineStyle(Plot.lineStyle(2))\
    def testLineStyle(self):
        """
        Test suite for line style construction
        """

        with self.subTest(msg="lineEndStyleNames()"):
            names = Plot.lineEndStyleNames()
            self.assertTrue(isinstance(names, list) and len(names) > 0)
            print("lineEndStyleNames() values {}".format(names))

        with self.subTest(msg="lineJoinStyleNames()"):
            names = Plot.lineJoinStyleNames()
            self.assertTrue(isinstance(names, list) and len(names) > 0)
            print("lineJoinStyleNames() values {}".format(names))

        endStyle, joinStyle = None, None
        with self.subTest(
                msg="lineEndStyle(string)"
        ):  # should be [BUTT, ROUND, SQUARE], not case sensitive
            endStyle = Plot.lineEndStyle("Butt")
        with self.subTest(msg="lineJoinStyle(string)"
                          ):  # should be [BEVEL, MITER, ROUND]
            joinStyle = Plot.lineJoinStyle("Bevel")

        with self.subTest(
                msg="lineStyle(double, lineEndStyle, lineJoinStyle, double...)"
        ):
            ls = Plot.lineStyle(4.0, endStyle, joinStyle, 3.0, 3.0)
        with self.subTest(msg="lineStyle(double, string, string, double...)"):
            ls = Plot.lineStyle(4.0, "butt", "bevel", 3.0, 3.0)
        with self.subTest(msg="lineStyle(double)"):
            ls = Plot.lineStyle(4.0)
        with self.subTest(msg="lineStyle(double, int[])"):
            ls = Plot.lineStyle(4.0, numpy.array([3, 3], dtype=numpy.int32))
        with self.subTest(msg="lineStyle(double, long[])"):
            ls = Plot.lineStyle(4.0, numpy.array([3, 3], dtype=numpy.int64))
        with self.subTest(msg="lineStyle(double, float[])"):
            ls = Plot.lineStyle(4.0, numpy.array([3, 3], dtype=numpy.float32))
        with self.subTest(msg="lineStyle(double, double[])"):
            ls = Plot.lineStyle(4.0, [3.0, 3.0])
        with self.subTest(msg="lineStyle(double...)"):
            ls = Plot.lineStyle(3.0, 3.0)

        with self.subTest(msg="lineStyle(string, string)"):
            ls = Plot.lineStyle("butt", "bevel")
        with self.subTest(msg="lineStyle()"):
            ls = Plot.lineStyle()
        with self.subTest(msg="lineStyle()"):
            ls = Plot.lineStyle()