Interface IPatterns
- Namespace
- Cratis.Chronicle.Patterns
- Assembly
- Cratis.Chronicle.dll
Defines a system for asking what usually happens, backed by the behavior patterns Chronicle mined from the event history of an event store.
public interface IPatterns
- Extension Methods
Methods
GetPatterns(PatternGroupingKey, FacetSet, PatternConfidence?, int, CancellationToken)
Get the patterns that apply to a context, most specific and most confident first.
Task<IEnumerable<BehaviorPattern>> GetPatterns(PatternGroupingKey groupingKey, FacetSet context, PatternConfidence? minimumConfidence = null, int maximumResults = 0, CancellationToken cancellationToken = default)
Parameters
groupingKeyPatternGroupingKeyThe scope to ask within - typically a user.
contextFacetSetThe context to match, which may constrain any subset of the facets.
minimumConfidencePatternConfidenceThe lowest PatternConfidence an answer may hold. Defaults to the server's configured threshold.
maximumResultsintThe largest number of answers to return. Defaults to the server's default.
cancellationTokenCancellationTokenOptional CancellationToken.
Returns
- Task<IEnumerable<BehaviorPattern>>
The matching patterns, empty when nothing clears the bar.
Remarks
An empty result is an answer, not a failure: it says this scope has no established behavior for this context. Nothing is invented to fill the gap, so a caller can treat "no patterns" as "do not claim to know".
GetPatternsAt(PatternGroupingKey, DateTimeOffset?, FacetSet?, PatternConfidence?, int, CancellationToken)
Get what a scope usually does at a moment, most likely first, at most one answer per action.
Task<IEnumerable<BehaviorPattern>> GetPatternsAt(PatternGroupingKey groupingKey, DateTimeOffset? moment = null, FacetSet? alsoConstraining = null, PatternConfidence? minimumConfidence = null, int maximumResults = 0, CancellationToken cancellationToken = default)
Parameters
groupingKeyPatternGroupingKeyThe scope to ask about - typically a user.
momentDateTimeOffset?The moment to ask about. Defaults to now.
alsoConstrainingFacetSetOptional further facets to narrow the question with.
minimumConfidencePatternConfidenceThe lowest PatternConfidence an answer may hold. Defaults to the server's configured threshold.
maximumResultsintThe largest number of answers to return. Defaults to the server's default.
cancellationTokenCancellationTokenOptional CancellationToken.
Returns
- Task<IEnumerable<BehaviorPattern>>
The matching patterns, empty when nothing clears the bar.
Remarks
The question an application actually has is "what does this person usually do right now", and this is that question. The day and the part of the day are read off the moment using the same rule the engine bucketed events with when it mined them, so the answer is about the slot the behavior was actually learned in.
Answers name what is done, through GetUsualActions(PatternGroupingKey, FacetSet, PatternConfidence?, int, CancellationToken). Pass alsoConstraining
to narrow the moment with more of the situation - the kind of thing being worked on, what caused the work.
An empty result is an answer, not a failure: this scope has no established behavior for this moment.
GetPatternsForScope(PatternGroupingKey, CancellationToken)
Get every pattern established for a scope.
Task<IEnumerable<BehaviorPattern>> GetPatternsForScope(PatternGroupingKey groupingKey, CancellationToken cancellationToken = default)
Parameters
groupingKeyPatternGroupingKeyThe scope to get for.
cancellationTokenCancellationTokenOptional CancellationToken.
Returns
- Task<IEnumerable<BehaviorPattern>>
Every BehaviorPattern held for the scope.
GetScopes(CancellationToken)
Get the scopes that have established patterns.
Task<IEnumerable<PatternGroupingKey>> GetScopes(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenOptional CancellationToken.
Returns
- Task<IEnumerable<PatternGroupingKey>>
The scopes holding patterns.
GetUsualActions(PatternGroupingKey, FacetSet, PatternConfidence?, int, CancellationToken)
Get what usually happens in a context, most likely first, at most one answer per action.
Task<IEnumerable<BehaviorPattern>> GetUsualActions(PatternGroupingKey groupingKey, FacetSet context, PatternConfidence? minimumConfidence = null, int maximumResults = 0, CancellationToken cancellationToken = default)
Parameters
groupingKeyPatternGroupingKeyThe scope to ask within - typically a user.
contextFacetSetThe context describing the situation, which may constrain any subset of the facets.
minimumConfidencePatternConfidenceThe lowest PatternConfidence an answer may hold. Defaults to the server's configured threshold.
maximumResultsintThe largest number of answers to return. Defaults to the server's default.
cancellationTokenCancellationTokenOptional CancellationToken.
Returns
- Task<IEnumerable<BehaviorPattern>>
The patterns naming what usually happens, empty when nothing clears the bar.
Remarks
Where GetPatterns(PatternGroupingKey, FacetSet, PatternConfidence?, int, CancellationToken) returns patterns that describe a situation, this returns the ones
that say what is done in it. Read the action off a result with
pattern.Facets.ValueOf(FacetName.CommandType), and its likelihood from Confidence - the chance
of that action given the context it was established in.
An empty result is an answer, not a failure: this scope has no established behavior for this context.