Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added include parent info option to Events query editor #38

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading