Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions spec/filter/util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,35 @@ describe('haystack', () => {
)
).toEqual('id == @id')
})

it('returns a haystack filter without excluded tags', () => {
expect(
makeRelativeHaystackFilter(
new HDict({
id: HRef.make('id'),
dis: 'an equip',
equip: HMarker.make(),
his: HMarker.make(),
aux: HMarker.make(),
})
)
).toEqual('equip and dis == "an equip"')
})

it('returns a haystack filter without custom excluded tags', () => {
expect(
makeRelativeHaystackFilter(
new HDict({
id: HRef.make('id'),
dis: 'an equip',
equip: HMarker.make(),
customTag: HMarker.make(),
}),
{
excludeTags: ['customTag'],
}
)
).toEqual('equip and dis == "an equip"')
})
}) // makeRelativeHaystackFilter()
})
28 changes: 27 additions & 1 deletion src/filter/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@ import { valueIsKind } from '../core/HVal'
import { Kind } from '../core/Kind'
import { HFilterBuilder } from '../filter/HFilterBuilder'

/**
* Default list of tags to exclude from the relativization.
*/
export const RELATIVE_FILTER_EXCLUDED_TAGS = [
'aux',
'his',
'hisCollectCOV',
'hisCollectNA',
'hisTotalized',
'haystackPoint',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is not meant to be comprehensive, but since you have already added bacnetPoint and haystackPoint, why not adding modbusPoint too? We could probably cover 90% of the cases with these 3 connectors ;)

'bacnetPoint',
'axStatus',
'axAnnotated',
'demoPoint',
]

/**
* Relativization options.
*/
Expand All @@ -23,6 +39,11 @@ export interface RelativizeOptions {
* True (or undefined) if a point's kind should be used in the relativization.
*/
useKind?: boolean

/**
* List of tags to exclude from the relativization.
*/
excludeTags?: string[]
}

/**
Expand All @@ -37,12 +58,17 @@ export function makeRelativeHaystackFilter(
): string {
const useDisplayName = options?.useDisplayName ?? true
const useKind = options?.useKind ?? true
const excludeTags = options?.excludeTags ?? RELATIVE_FILTER_EXCLUDED_TAGS
const excludedTagSet = new Set(excludeTags)

const builder = new HFilterBuilder()

// Build the marker tags.
for (const { name, value } of record) {
if (valueIsKind<HMarker>(value, Kind.Marker)) {
if (
valueIsKind<HMarker>(value, Kind.Marker) &&
!excludedTagSet.has(name)
) {
if (!builder.isEmpty()) {
builder.and()
}
Expand Down