Class BehaviorPattern

Namespace
Cratis.Chronicle.Concepts.Patterns
Assembly
Cratis.Chronicle.dll

Represents a recurring combination of facets that survived the support and confidence thresholds.

public record BehaviorPattern : IEquatable<BehaviorPattern>
Inheritance
BehaviorPattern
Implements
Inherited Members
Extension Methods

Remarks

Only surviving patterns are persisted, so storage scales with distinct recurring behavior rather than with event volume - a store that appends millions of events but sees a few hundred recurring behaviors holds a few hundred rows here.

Constructors

BehaviorPattern(BehaviorPattern)

protected BehaviorPattern(BehaviorPattern original)

Parameters

original BehaviorPattern

BehaviorPattern(PatternGroupingKey, FacetSet, PatternOccurrences, PatternConfidence, PatternSupport, PatternWeight, DateTimeOffset, DateTimeOffset)

Represents a recurring combination of facets that survived the support and confidence thresholds.

public BehaviorPattern(PatternGroupingKey GroupingKey, FacetSet Facets, PatternOccurrences Occurrences, PatternConfidence Confidence, PatternSupport Support, PatternWeight Weight, DateTimeOffset FirstSeen, DateTimeOffset LastSeen)

Parameters

GroupingKey PatternGroupingKey

The scope the pattern belongs to.

Facets FacetSet

The FacetSet the pattern is expressed in.

Occurrences PatternOccurrences

How many times the pattern has been observed.

Confidence PatternConfidence

How often the pattern holds when its context is present.

Support PatternSupport

The share of all observed events the pattern was seen in.

Weight PatternWeight

The recency-weighted strength of the pattern.

FirstSeen DateTimeOffset

When the pattern was first observed.

LastSeen DateTimeOffset

When the pattern was last observed.

Remarks

Only surviving patterns are persisted, so storage scales with distinct recurring behavior rather than with event volume - a store that appends millions of events but sees a few hundred recurring behaviors holds a few hundred rows here.

Properties

Action

Gets the action the pattern names, or Unspecified when it is pure context.

public FacetValue Action { get; }

Property Value

FacetValue

Confidence

How often the pattern holds when its context is present.

public PatternConfidence Confidence { get; init; }

Property Value

PatternConfidence

ContextSpecificity

Gets how much of an asked context the pattern's own context uses - the number of context facets it constrains.

public int ContextSpecificity { get; }

Property Value

int

Remarks

The specificity of an answer, as opposed to Specificity. Two patterns naming the same action differ by how much of the question they were conditioned on, and the action facet they share tells them apart in neither direction.

EqualityContract

protected virtual Type EqualityContract { get; }

Property Value

Type

Facets

The FacetSet the pattern is expressed in.

public FacetSet Facets { get; init; }

Property Value

FacetSet

FirstSeen

When the pattern was first observed.

public DateTimeOffset FirstSeen { get; init; }

Property Value

DateTimeOffset

GroupingKey

The scope the pattern belongs to.

public PatternGroupingKey GroupingKey { get; init; }

Property Value

PatternGroupingKey

LastSeen

When the pattern was last observed.

public DateTimeOffset LastSeen { get; init; }

Property Value

DateTimeOffset

Occurrences

How many times the pattern has been observed.

public PatternOccurrences Occurrences { get; init; }

Property Value

PatternOccurrences

Specificity

Gets how specific the pattern is - the number of facets it constrains.

public int Specificity { get; }

Property Value

int

Support

The share of all observed events the pattern was seen in.

public PatternSupport Support { get; init; }

Property Value

PatternSupport

Weight

The recency-weighted strength of the pattern.

public PatternWeight Weight { get; init; }

Property Value

PatternWeight

Methods

AnswersFor(FacetSet)

Check whether the pattern answers what usually happens in a context.

public bool AnswersFor(FacetSet context)

Parameters

context FacetSet

The FacetSet describing the situation being asked about.

Returns

bool

True when the pattern names an action and was established in a context the asked one covers, false when not.

Remarks

The action facet is excluded from the comparison on purpose. A caller asking what somebody usually does on a Monday morning cannot name the command in the question - naming it is what they are asking for - so requiring the whole pattern to be a subset of the question excludes exactly the patterns that answer it.

An answer must also use some of the question. A pattern established in no context at all - "half of what this person ever does is post ledger entries" - is a subset of every context there is, so without this it answers every question identically, including questions about moments the scope has never worked. That would make "nothing is established here" unsayable for anyone with a dominant action, which is the one answer this whole surface exists to be able to give honestly. When the caller names nothing, though, the general behavior is precisely what they asked for, and it is returned.

Deconstruct(out PatternGroupingKey, out FacetSet, out PatternOccurrences, out PatternConfidence, out PatternSupport, out PatternWeight, out DateTimeOffset, out DateTimeOffset)

public void Deconstruct(out PatternGroupingKey GroupingKey, out FacetSet Facets, out PatternOccurrences Occurrences, out PatternConfidence Confidence, out PatternSupport Support, out PatternWeight Weight, out DateTimeOffset FirstSeen, out DateTimeOffset LastSeen)

Parameters

GroupingKey PatternGroupingKey
Facets FacetSet
Occurrences PatternOccurrences
Confidence PatternConfidence
Support PatternSupport
Weight PatternWeight
FirstSeen DateTimeOffset
LastSeen DateTimeOffset

Equals(BehaviorPattern?)

public virtual bool Equals(BehaviorPattern? other)

Parameters

other BehaviorPattern

Returns

bool

Equals(object?)

public override bool Equals(object? obj)

Parameters

obj object

Returns

bool

GetHashCode()

public override int GetHashCode()

Returns

int

Matches(FacetSet)

Check whether the pattern applies to a context.

public bool Matches(FacetSet context)

Parameters

context FacetSet

The FacetSet describing the context, which may constrain more facets than the pattern does.

Returns

bool

True when every facet the pattern constrains is present with the same value in the context, false when not.

Remarks

This is the question "does this established pattern describe the situation I am in" - the one worth asking about an action that already happened. It can never return a pattern naming an action the caller did not name, because such a pattern is not a subset of what was asked. Use AnswersFor(FacetSet) for the question that has an action as its answer.

PrintMembers(StringBuilder)

protected virtual bool PrintMembers(StringBuilder builder)

Parameters

builder StringBuilder

Returns

bool

ToString()

public override string ToString()

Returns

string

Operators

operator ==(BehaviorPattern?, BehaviorPattern?)

public static bool operator ==(BehaviorPattern? left, BehaviorPattern? right)

Parameters

left BehaviorPattern
right BehaviorPattern

Returns

bool

operator !=(BehaviorPattern?, BehaviorPattern?)

public static bool operator !=(BehaviorPattern? left, BehaviorPattern? right)

Parameters

left BehaviorPattern
right BehaviorPattern

Returns

bool