示例#1
0
def nonFrequencyPatternSearchTest(createTestFile=False):
    pattern = Pattern(
        SeqOperator(
            [QItem("AAPL", "a"),
             QItem("AMZN", "b"),
             QItem("LOCM", "c")]),
        AndFormula(
            GreaterThanFormula(
                IdentifierTerm("a", lambda x: x["Opening Price"]),
                IdentifierTerm("b", lambda x: x["Opening Price"])),
            GreaterThanFormula(
                IdentifierTerm("b", lambda x: x["Opening Price"]),
                IdentifierTerm("c", lambda x: x["Opening Price"]))),
        timedelta(minutes=5))
    runTest("nonFrequency", [pattern], createTestFile)
示例#2
0
def nonFrequencyTailoredPatternSearchTest(createTestFile=False):
    pattern = Pattern(
        SeqOperator(
            [QItem("DRIV", "a"),
             QItem("MSFT", "b"),
             QItem("CBRL", "c")]),
        AndFormula(
            GreaterThanFormula(
                IdentifierTerm("a", lambda x: x["Opening Price"]),
                IdentifierTerm("b", lambda x: x["Opening Price"])),
            GreaterThanFormula(
                IdentifierTerm("b", lambda x: x["Opening Price"]),
                IdentifierTerm("c", lambda x: x["Opening Price"]))),
        timedelta.max)
    runTest('nonFrequencyTailored1', [pattern], createTestFile,
            TrivialAlgorithm(), nasdaqEventStream)
示例#3
0
def arrivalRatesPatternSearchTest(createTestFile=False):
    pattern = Pattern(
        SeqOperator(
            [QItem("AAPL", "a"),
             QItem("AMZN", "b"),
             QItem("LOCM", "c")]),
        AndFormula(
            GreaterThanFormula(
                IdentifierTerm("a", lambda x: x["Opening Price"]),
                IdentifierTerm("b", lambda x: x["Opening Price"])),
            GreaterThanFormula(
                IdentifierTerm("b", lambda x: x["Opening Price"]),
                IdentifierTerm("c", lambda x: x["Opening Price"]))),
        timedelta(minutes=5))
    pattern.setAdditionalStatistics(StatisticsTypes.ARRIVAL_RATES,
                                    [0.0159, 0.0153, 0.0076])
    runTest("arrivalRates", [pattern], createTestFile,
            AscendingFrequencyAlgorithm())
示例#4
0
def frequencyTailoredPatternSearchTest(createTestFile=False):
    pattern = Pattern(
        SeqOperator(
            [QItem("DRIV", "a"),
             QItem("MSFT", "b"),
             QItem("CBRL", "c")]),
        AndFormula(
            GreaterThanFormula(
                IdentifierTerm("a", lambda x: x["Opening Price"]),
                IdentifierTerm("b", lambda x: x["Opening Price"])),
            GreaterThanFormula(
                IdentifierTerm("b", lambda x: x["Opening Price"]),
                IdentifierTerm("c", lambda x: x["Opening Price"]))),
        timedelta.max)
    frequencyDict = {"MSFT": 256, "DRIV": 257, "CBRL": 1}
    pattern.setAdditionalStatistics(StatisticsTypes.FREQUENCY_DICT,
                                    frequencyDict)
    runTest('frequencyTailored1', [pattern], createTestFile,
            AscendingFrequencyAlgorithm(), nasdaqEventStream)
示例#5
0
def frequencyPatternSearchTest(createTestFile=False):
    pattern = Pattern(
        SeqOperator(
            [QItem("AAPL", "a"),
             QItem("AMZN", "b"),
             QItem("LOCM", "c")]),
        AndFormula(
            GreaterThanFormula(
                IdentifierTerm("a", lambda x: x["Opening Price"]),
                IdentifierTerm("b", lambda x: x["Opening Price"])),
            GreaterThanFormula(
                IdentifierTerm("b", lambda x: x["Opening Price"]),
                IdentifierTerm("c", lambda x: x["Opening Price"]))),
        timedelta(minutes=5))
    pattern.setAdditionalStatistics(StatisticsTypes.FREQUENCY_DICT, {
        "AAPL": 460,
        "AMZN": 442,
        "LOCM": 219
    })
    runTest("frequency", [pattern], createTestFile,
            AscendingFrequencyAlgorithm())
示例#6
0
def simplePatternSearchTest(createTestFile=False):
    """
    PATTERN SEQ(AppleStockPriceUpdate a, AmazonStockPriceUpdate b, AvidStockPriceUpdate c)
    WHERE   a.OpeningPrice > b.OpeningPrice
        AND b.OpeningPrice > c.OpeningPrice
    WITHIN 5 minutes
    """
    pattern = Pattern(
        SeqOperator(
            [QItem("AAPL", "a"),
             QItem("AMZN", "b"),
             QItem("AVID", "c")]),
        AndFormula(
            GreaterThanFormula(
                IdentifierTerm("a", lambda x: x["Opening Price"]),
                IdentifierTerm("b", lambda x: x["Opening Price"])),
            GreaterThanFormula(
                IdentifierTerm("b", lambda x: x["Opening Price"]),
                IdentifierTerm("c", lambda x: x["Opening Price"]))),
        timedelta(minutes=5))
    runTest("simple", [pattern], createTestFile)
示例#7
0
def oneArgumentsearchTest(createTestFile=False):
    pattern = Pattern(
        SeqOperator([QItem("AAPL", "a")]),
        GreaterThanFormula(IdentifierTerm("a", lambda x: x["Opening Price"]),
                           AtomicTerm(135)), timedelta.max)
    runTest("one", [pattern], createTestFile)