Skip to content

Commit

Permalink
Updated series name
Browse files Browse the repository at this point in the history
  • Loading branch information
coderReview committed Apr 5, 2024
1 parent 085ff47 commit 834ef62
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
18 changes: 4 additions & 14 deletions pkg/plugin/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ func convertItemsToDataFrame(processedQuery *PiProcessedQuery, d *Datasource, Su
webID := processedQuery.WebID
includeMetaData := processedQuery.UseUnit
digitalStates := processedQuery.DigitalStates
lenElements := len(processedQuery.Elements)
noDataReplace := processedQuery.getSummaryNoDataReplace()

digitalStateValues := make([]string, 0)
Expand All @@ -371,24 +370,15 @@ func convertItemsToDataFrame(processedQuery *PiProcessedQuery, d *Datasource, Su
}

// get frame name
frameName := getDataLabel(d.isUsingNewFormat(), processedQuery, d.getPointTypeForWebID(webID), SummaryType)
dataFrameName := frameName["name"]
frameLabel := getDataLabels(d.isUsingNewFormat(), processedQuery, d.getPointTypeForWebID(webID), SummaryType)
dataFrameName := frameLabel["name"]

var labels map[string]string
var digitalState = d.getDigitalStateForWebID(webID)

var frame *data.Frame

if lenElements > 1 {
frame = data.NewFrame(processedQuery.Elements[lenElements-2] + "." + processedQuery.Elements[lenElements-1])
} else if lenElements > 0 {
frame = data.NewFrame(processedQuery.Elements[lenElements-1])
} else {
frame = data.NewFrame(dataFrameName)
}

frame := data.NewFrame(processedQuery.TargetPath)
if d.isUsingNewFormat() {
labels = frameName
labels = frameLabel
}

backend.Logger.Debug("Convert", "frame", dataFrameName, "labels", labels, "type", sliceType.Elem().String())
Expand Down
11 changes: 6 additions & 5 deletions pkg/plugin/timeseries_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (d *Datasource) processQuery(query backend.DataQuery, datasourceUID string)
IsPIPoint: PiQuery.Pi.IsPiPoint,
Streamable: PiQuery.isStreamable() && *d.dataSourceOptions.UseExperimental && *d.dataSourceOptions.UseStreaming,
FullTargetPath: fullTargetPath,
Elements: strings.Split(targetBasePath, `\`),
TargetPath: targetBasePath,
UseUnit: UseUnits,
DigitalStates: DigitalStates,
Display: PiQuery.Pi.Display,
Expand Down Expand Up @@ -320,7 +320,7 @@ func (q *PIWebAPIQuery) isSummary() bool {
return *q.Summary.Basis != "" && len(*q.Summary.Types) > 0
}

func getDataLabel(useNewFormat bool, q *PiProcessedQuery, pointType string, summaryLabel string) map[string]string {
func getDataLabels(useNewFormat bool, q *PiProcessedQuery, pointType string, summaryLabel string) map[string]string {
var frameLabel map[string]string
summaryNewFormat := ""

Expand All @@ -336,7 +336,7 @@ func getDataLabel(useNewFormat bool, q *PiProcessedQuery, pointType string, summ
targetParts := strings.Split(q.FullTargetPath, `\`)
frameLabel = map[string]string{
"element": targetParts[0],
"name": targetParts[len(targetParts)-1],
"name": q.Label,
"type": pointType + summaryNewFormat,
}
} else {
Expand All @@ -346,14 +346,15 @@ func getDataLabel(useNewFormat bool, q *PiProcessedQuery, pointType string, summ
labelParts := strings.SplitN(targetParts[len(targetParts)-1], "|", 2)
frameLabel = map[string]string{
"element": labelParts[0],
"name": labelParts[1],
"name": q.Label,
"type": pointType + summaryNewFormat,
}
}
} else {
// Old format returns just the tag/attribute name
frameLabel = map[string]string{
"name": q.Label + summaryLabel,
"element": q.TargetPath,
"name": q.Label + summaryLabel,
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/timeseries_query_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ type PiProcessedQuery struct {
Error error
Index int
Resource string
Elements []string
TargetPath string
Regex *Regex `json:"Regex"`
Summary *QuerySummary `json:"Summary"`
}
Expand Down

0 comments on commit 834ef62

Please sign in to comment.