This version of the module is deprecated: Withdrawn: published under the wrong account. This project does not belong to JSJ222. Do not use this package.
Bounded event-time complex event pattern detection for MoonBit
Dependencies
moon add JSJ222/mooncep@0.1.0import {
"JSJ222/mooncep" @cep,
}fn main raise {
let pattern = @cep.Pattern::new("login-signal", [
@cep.Stage::new("failures", @cep.Kind("failed"), min=3, max=3),
@cep.Stage::new("success", @cep.Kind("success")),
], 300000L, after_match=@cep.SkipPastLast)
let engine = @cep.Engine::new([pattern])
for (id, kind, time) in [
("f1", "failed", 1000L), ("f2", "failed", 2000L),
("f3", "failed", 3000L), ("s1", "success", 4000L),
] {
ignore(engine.push(@cep.Event::new(id, "user/7", time, kind)))
}
let batch = engine.advance_watermark(4000L)
assert_eq(batch.matches().length(), 1)
println(@cep.match_to_json(batch.matches()[0]).stringify())
}moon run --target native examples/security
moon run --target native examples/orders
moon run --target native examples/equipment
moon run --target native examples/funnel
moon run --target native --release examples/performance| Example | Complete input-to-output scenario |
|---|---|
| Security | Three failed logins followed by success for the same account produce captured evidence. |
| Orders | A persisted session is restored; unpaid orders are confirmed after their deadline, while payment at the deadline cancels absence. |
| Equipment | Out-of-order alarms, a rising field comparison and recovery produce a typed operational record. |
| Funnel | An optional coupon stage and multiple purchases demonstrate preview, branching and result telemetry. |
moon run --target native cmd/mooncep -- validate examples/files/program.json
moon run --target native cmd/mooncep -- run examples/files/program.json examples/files/events.ndjson
moon run --target native cmd/mooncep -- inspect SESSION.json
moon run --target native cmd/mooncep -- restore SESSION.json EVENTS.ndjsonmoon check --target all --deny-warn
moon build --target all --deny-warn
moon test --target all --deny-warn
moon fmt --check
moon info
git diff --exit-code
python scripts/verify_repository.pypub(all) suberror CepError {
Invalid(path~ : String, reason~ : String)
Resource(resource~ : String, limit~ : Int)
LateEvent(time~ : Int64, watermark~ : Int64)
WatermarkRegression(previous~ : Int64, requested~ : Int64)
} derive(Debug)pub struct CommandReader {
partial : String
line : Int
closed : Bool
max_line : Int
max_commands : Int
}pub(all) enum Condition {
Always
Kind(String)
Has(String)
Compare(String, Comparison, Value)
FieldCompare(String, Comparison, String)
CaptureCompare(String, Comparison, String, String)
CaptureCount(String, Comparison, Int)
TextPrefix(String, String)
TextContains(String, String)
All(Array[Condition])
Any(Array[Condition])
Not(Condition)
} derive(Eq, Debug)pub struct DetectionMetrics {
series : Map[String, DetectionSeries]
max_series : Int
by_key : Bool
batches : Int64
processed : Int64
work : Int64
}pub(all) struct DetectionSeries {
pattern : String
key : String?
matches : Int64
absence_matches : Int64
timeouts : Int64
shortest_duration : Int64?
longest_duration : Int64?
mean_duration : Double?
}pub struct Inspection {
watermark : Int64
occurrence : Int64
buffered : Int
active : Int
partitions : Array[PartitionStatus]
patterns : Array[PatternStatus]
}pub struct Monitor {
reader : CommandReader
session : Session
accepted_events : Int64
advances : Int64
matches : Int64
timeouts : Int64
work : Int64
}pub(all) struct MonitorStats {
accepted_events : Int64
advances : Int64
matches : Int64
timeouts : Int64
work : Int64
buffered_events : Int
active_states : Int
pending_text_units : Int
}pub(all) struct PartitionStatus {
key : String
buffered : Int
active : Int
earliest_event : Int64?
latest_event : Int64?
earliest_deadline : Int64?
}pub struct Pattern {
id : String
stages : Array[Stage]
within : Int64
after_match : AfterMatch
absence : Condition?
}pub(all) struct PatternAnalysis {
minimum_captures : Int
maximum_captures : Int
nullable_stages : Int
variable_stages : Int
repeated_stages : Int
strict_stages : Int
skip_any_stages : Int
guarded_stages : Int
has_absence : Bool
branching_risk : BranchingRisk
} derive(Eq, Debug)pub(all) struct PatternStatus {
pattern : String
active : Int
awaiting_absence : Int
earliest_deadline : Int64?
}pub(all) enum Projection {
EntityKey
PatternName
StartTime
EndTime
Duration
AbsenceMatch
CaptureSize(String)
FirstField(String, String)
LastField(String, String)
TotalInteger(String, String)
TotalDecimal(String, String)
MinimumField(String, String)
MaximumField(String, String)
AverageDecimal(String, String)
} derive(Eq, Debug)pub struct Stage {
name : String
condition : Condition
min : Int
max : Int
contiguity : Contiguity
forbidden : Condition?
}pub(all) struct StageDiagnostic {
stage : String
positive : Evaluation
forbidden : Evaluation?
minimum : Int
maximum : Int
}Install
Download zipBounded event-time complex event pattern detection for MoonBit
Dependencies