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)
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)
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())
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)
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())
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)
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)