Skip to content

Commit

Permalink
Added include parent info option to Events query editor
Browse files Browse the repository at this point in the history
  • Loading branch information
vereecw committed Dec 6, 2024
1 parent b2545a0 commit 92dd5dc
Show file tree
Hide file tree
Showing 7 changed files with 272 additions and 86 deletions.
38 changes: 27 additions & 11 deletions pkg/datasource/event_query_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ func (ds *HistorianDataSource) handleEventQuery(ctx context.Context, eventQuery
return nil, err
}

allEventTypes, err := ds.API.GetEventTypes(ctx, "")
if err != nil {
return nil, err
}

if len(assets) == 0 || len(eventTypes) == 0 {
return data.Frames{}, nil
}
Expand All @@ -48,10 +53,19 @@ func (ds *HistorianDataSource) handleEventQuery(ctx context.Context, eventQuery
return nil, err
}

eventTypeProperties := []schemas.EventTypeProperty{}
// get all unique event types from the events
eventTypeUUIDs := map[uuid.UUID]struct{}{}
for i := range events {
eventTypeUUIDs[events[i].EventTypeUUID] = struct{}{}
if events[i].Parent != nil {
eventTypeUUIDs[events[i].Parent.EventTypeUUID] = struct{}{}
}
}

var eventTypeProperties []schemas.EventTypeProperty
if util.CheckMinimumVersion(historianInfo, "6.4.0") {
eventTypeQuery := url.Values{}
for i, eventTypeUUID := range slices.Collect(maps.Keys(eventTypes)) {
for i, eventTypeUUID := range slices.Collect(maps.Keys(eventTypeUUIDs)) {
eventTypeQuery.Add(fmt.Sprintf("EventTypeUUIDs[%d]", i), eventTypeUUID.String())
}
eventTypeQuery.Add("Types[0]", eventQuery.Type)
Expand All @@ -60,16 +74,10 @@ func (ds *HistorianDataSource) handleEventQuery(ctx context.Context, eventQuery
return nil, err
}
} else {
allEventTypeProperties, err := ds.API.GetEventTypeProperties(ctx, "")
eventTypeProperties, err = ds.API.GetEventTypeProperties(ctx, "")
if err != nil {
return nil, err
}

for _, eventTypeProperty := range allEventTypeProperties {
if _, ok := eventTypes[eventTypeProperty.EventTypeUUID]; ok {
eventTypeProperties = append(eventTypeProperties, eventTypeProperty)
}
}
}

selectedPropertiesSet := map[string]struct{}{}
Expand Down Expand Up @@ -99,12 +107,20 @@ func (ds *HistorianDataSource) handleEventQuery(ctx context.Context, eventQuery
}
}

eventTypePropertiesByEventType := map[uuid.UUID][]schemas.EventTypeProperty{}
for _, eventTypeProperty := range eventTypeProperties {
if _, ok := eventTypePropertiesByEventType[eventTypeProperty.EventTypeUUID]; !ok {
eventTypePropertiesByEventType[eventTypeProperty.EventTypeUUID] = []schemas.EventTypeProperty{}
}
eventTypePropertiesByEventType[eventTypeProperty.EventTypeUUID] = append(eventTypePropertiesByEventType[eventTypeProperty.EventTypeUUID], eventTypeProperty)
}

switch eventQuery.Type {
case string(schemas.EventTypePropertyTypeSimple):
assetPropertyFieldTypes := getAssetPropertyFieldTypes(eventAssetPropertyFrames)
return EventQueryResultToDataFrame(slices.Collect(maps.Values(assets)), events, slices.Collect(maps.Values(eventTypes)), eventTypeProperties, selectedPropertiesSet, assetPropertyFieldTypes, eventAssetPropertyFrames)
return EventQueryResultToDataFrame(eventQuery.IncludeParentInfo, slices.Collect(maps.Values(assets)), events, allEventTypes, eventTypeProperties, selectedPropertiesSet, assetPropertyFieldTypes, eventAssetPropertyFrames)
case string(schemas.EventTypePropertyTypePeriodic):
return EventQueryResultToTrendDataFrame(slices.Collect(maps.Values(assets)), events, slices.Collect(maps.Values(eventTypes)), eventTypeProperties, selectedPropertiesSet, eventAssetPropertyFrames)
return EventQueryResultToTrendDataFrame(eventQuery.IncludeParentInfo, slices.Collect(maps.Values(assets)), events, util.ByUUID(allEventTypes), eventTypePropertiesByEventType, selectedPropertiesSet, eventAssetPropertyFrames)
default:
return nil, fmt.Errorf("unsupported event query type %s", eventQuery.Type)
}
Expand Down
Loading

0 comments on commit 92dd5dc

Please sign in to comment.