コード例 #1
0
def samePatternDifferentTimeStampsFullSharing(createTestFile=False):
    pattern1 = Pattern(
        SeqOperator(PrimitiveEventStructure("AAPL", "a"),
                    PrimitiveEventStructure("AMZN", "b"),
                    PrimitiveEventStructure("GOOG", "c")),
        AndCondition(
            GreaterThanEqCondition(Variable("a", lambda x: x["Peak Price"]),
                                   135),
            SmallerThanCondition(Variable("b", lambda x: x["Peak Price"]),
                                 Variable("c", lambda x: x["Peak Price"]))),
        timedelta(minutes=5))
    pattern2 = Pattern(
        SeqOperator(PrimitiveEventStructure("AAPL", "a"),
                    PrimitiveEventStructure("AMZN", "b"),
                    PrimitiveEventStructure("GOOG", "c")),
        AndCondition(
            GreaterThanEqCondition(Variable("a", lambda x: x["Peak Price"]),
                                   135),
            SmallerThanCondition(Variable("b", lambda x: x["Peak Price"]),
                                 Variable("c", lambda x: x["Peak Price"]))),
        timedelta(minutes=2))

    runMultiTest("DifferentTimeStampFullSharing", [pattern1, pattern2],
                 createTestFile,
                 subtree_sharing_eval_mechanism_params,
                 expected_file_name="DifferentTimeStamp")
コード例 #2
0
def sortedStorageBenchMarkTest(createTestFile=False):
    pattern = Pattern(
        AndOperator(PrimitiveEventStructure("DRIV", "a"),
                    PrimitiveEventStructure("MSFT", "b"),
                    PrimitiveEventStructure("CBRL", "c"),
                    PrimitiveEventStructure("MSFT", "m")),
        AndCondition(
            GreaterThanEqCondition(Variable("b", lambda x: x["Lowest Price"]),
                                   Variable("a", lambda x: x["Lowest Price"])),
            GreaterThanEqCondition(Variable("m", lambda x: x["Peak Price"]),
                                   Variable("c", lambda x: x["Peak Price"])),
            GreaterThanEqCondition(Variable("m", lambda x: x["Lowest Price"]),
                                   Variable("b", lambda x: x["Lowest Price"])),
        ),
        timedelta(minutes=360),
    )
    runBenchMark("sortedStorageBenchMark - unsorted storage", [pattern])
    storage_params = TreeStorageParameters(sort_storage=True,
                                           attributes_priorities={
                                               "a": 122,
                                               "b": 200,
                                               "c": 104,
                                               "m": 139
                                           })
    eval_params = TreeBasedEvaluationMechanismParameters(
        DEFAULT_TESTING_EVALUATION_MECHANISM_SETTINGS.tree_plan_params,
        storage_params)
    runBenchMark("sortedStorageBenchMark - sorted storage", [pattern],
                 eval_mechanism_params=eval_params)
コード例 #3
0
ファイル: StorageTests.py プロジェクト: salehbahoty/OpenCEP
def sortedStorageBenchMarkTest(createTestFile=False):
    pattern = Pattern(
        AndOperator(PrimitiveEventStructure("DRIV", "a"),
                    PrimitiveEventStructure("MSFT", "b"),
                    PrimitiveEventStructure("CBRL", "c"),
                    PrimitiveEventStructure("MSFT", "m")),
        AndCondition(
            GreaterThanEqCondition(Variable("b", lambda x: x["Lowest Price"]),
                                   Variable("a", lambda x: x["Lowest Price"])),
            GreaterThanEqCondition(Variable("m", lambda x: x["Peak Price"]),
                                   Variable("c", lambda x: x["Peak Price"])),
            GreaterThanEqCondition(Variable("m", lambda x: x["Lowest Price"]),
                                   Variable("b", lambda x: x["Lowest Price"])),
        ),
        timedelta(minutes=360),
    )
    runBenchMark("sortedStorageBenchMark - unsorted storage", [pattern])
    storage_params = TreeStorageParameters(sort_storage=True,
                                           attributes_priorities={
                                               "a": 122,
                                               "b": 200,
                                               "c": 104,
                                               "m": 139
                                           })
    eval_params = TreeBasedEvaluationMechanismParameters(
        optimizer_params=StatisticsDeviationAwareOptimizerParameters(
            tree_plan_params=TreePlanBuilderParameters()),
        storage_params=storage_params)

    runBenchMark("sortedStorageBenchMark - sorted storage", [pattern],
                 eval_mechanism_params=eval_params)
コード例 #4
0
def distinctPatterns(createTestFile=False):
    pattern1 = Pattern(
        SeqOperator(PrimitiveEventStructure("GOOG", "a"),
                    PrimitiveEventStructure("GOOG", "b"),
                    PrimitiveEventStructure("GOOG", "c")),
        AndCondition(
            SmallerThanCondition(Variable("a", lambda x: x["Peak Price"]),
                                 Variable("b", lambda x: x["Peak Price"])),
            SmallerThanCondition(Variable("b", lambda x: x["Peak Price"]),
                                 Variable("c", lambda x: x["Peak Price"]))),
        timedelta(minutes=3))
    pattern2 = Pattern(
        SeqOperator(PrimitiveEventStructure("AMZN", "x1"),
                    PrimitiveEventStructure("AMZN", "x2"),
                    PrimitiveEventStructure("AMZN", "x3")),
        AndCondition(
            SmallerThanEqCondition(Variable("x1", lambda x: x["Lowest Price"]),
                                   75),
            GreaterThanEqCondition(Variable("x2", lambda x: x["Peak Price"]),
                                   78),
            SmallerThanEqCondition(Variable("x3", lambda x: x["Lowest Price"]),
                                   Variable("x1",
                                            lambda x: x["Lowest Price"]))),
        timedelta(days=1))

    runMultiTest("BigMultiPattern", [pattern1, pattern2], createTestFile,
                 leaf_sharing_eval_mechanism_params)
コード例 #5
0
ファイル: MultiPattern_tests.py プロジェクト: ofriol/OpenCEP
def rootAndInner(createTestFile=False):
    #similar to leafIsRoot, but the time windows are different
    pattern1 = Pattern(
        SeqOperator(PrimitiveEventStructure("AAPL", "a")),
        GreaterThanEqCondition(Variable("a", lambda x: x["Peak Price"]), 135),
        timedelta(minutes=5))
    pattern2 = Pattern(
        SeqOperator(PrimitiveEventStructure("AAPL", "a"),
                    PrimitiveEventStructure("AMZN", "b"),
                    PrimitiveEventStructure("GOOG", "c")),
        AndCondition(
            GreaterThanEqCondition(Variable("a", lambda x: x["Peak Price"]),
                                   135),
            SmallerThanCondition(Variable("b", lambda x: x["Peak Price"]),
                                 Variable("c", lambda x: x["Peak Price"]))),
        timedelta(minutes=3))

    runMultiTest("RootAndInner", [pattern1, pattern2], createTestFile)
コード例 #6
0
ファイル: MultiPattern_tests.py プロジェクト: ofriol/OpenCEP
def samePatternDifferentTimeStamps(createTestFile=False):
    pattern1 = Pattern(
        SeqOperator(PrimitiveEventStructure("AAPL", "a"),
                    PrimitiveEventStructure("AMZN", "b"),
                    PrimitiveEventStructure("GOOG", "c")),
        AndCondition(
            GreaterThanEqCondition(Variable("a", lambda x: x["Peak Price"]),
                                   135),
            SmallerThanCondition(Variable("b", lambda x: x["Peak Price"]),
                                 Variable("c", lambda x: x["Peak Price"]))),
        timedelta(minutes=5))
    pattern2 = Pattern(
        SeqOperator(PrimitiveEventStructure("AAPL", "a"),
                    PrimitiveEventStructure("AMZN", "b"),
                    PrimitiveEventStructure("GOOG", "c")),
        AndCondition(
            GreaterThanEqCondition(Variable("a", lambda x: x["Peak Price"]),
                                   135),
            SmallerThanCondition(Variable("b", lambda x: x["Peak Price"]),
                                 Variable("c", lambda x: x["Peak Price"]))),
        timedelta(minutes=2))

    runMultiTest("DifferentTimeStamp", [pattern1, pattern2], createTestFile)
コード例 #7
0
def amazonInstablePatternSearchTest(createTestFile=False):
    """
    This pattern is looking for an in-stable day for Amazon.
    PATTERN SEQ(AmazonStockPriceUpdate x1, AmazonStockPriceUpdate x2, AmazonStockPriceUpdate x3)
    WHERE x1.LowestPrice <= 75 AND x2.PeakPrice >= 78 AND x3.LowestPrice <= x1.LowestPrice
    WITHIN 1 day
    """
    amazonInstablePattern = Pattern(
        SeqOperator(PrimitiveEventStructure("AMZN", "x1"), PrimitiveEventStructure("AMZN", "x2"), PrimitiveEventStructure("AMZN", "x3")),
        AndCondition(
                SmallerThanEqCondition(Variable("x1", lambda x: x["Lowest Price"]), 75),
                GreaterThanEqCondition(Variable("x2", lambda x: x["Peak Price"]), 78),
                BinaryCondition(Variable("x3", lambda x: x["Lowest Price"]),
                                Variable("x1", lambda x: x["Lowest Price"]),
                                relation_op=lambda x, y: x <= y)
        ),
        timedelta(days=1)
    )
    runTest('amazonInstable', [amazonInstablePattern], createTestFile)
コード例 #8
0
def amazonInstablePatternSearchTest(createTestFile=False,
                                    eval_mechanism_params=DEFAULT_TESTING_EVALUATION_MECHANISM_SETTINGS,
                                    test_name = "amazonInstable"):
    """
    This pattern is looking for an in-stable day for Amazon.
    PATTERN SEQ(AmazonStockPriceUpdate x1, AmazonStockPriceUpdate x2, AmazonStockPriceUpdate x3)
    WHERE x1.LowestPrice <= 75 AND x2.PeakPrice >= 78 AND x3.LowestPrice <= x1.LowestPrice
    WITHIN 1 day
    """
    amazonInstablePattern = Pattern(
        SeqOperator(PrimitiveEventStructure("AMZN", "x1"), PrimitiveEventStructure("AMZN", "x2"),
                    PrimitiveEventStructure("AMZN", "x3")),
        AndCondition(
            SmallerThanEqCondition(Variable("x1", lambda x: x["Lowest Price"]), 75),
            GreaterThanEqCondition(Variable("x2", lambda x: x["Peak Price"]), 78),
            BinaryCondition(Variable("x3", lambda x: x["Lowest Price"]),
                            Variable("x1", lambda x: x["Lowest Price"]),
                            relation_op=lambda x, y: x <= y)
        ),
        timedelta(days=1)
    )
    runTest(test_name, [amazonInstablePattern], createTestFile, eval_mechanism_params)