/
util.go
53 lines (48 loc) · 1.15 KB
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package fields
import (
"github.com/aws/aws-sdk-go/service/iotsitewise"
"github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/grafana/iot-sitewise-datasource/pkg/util"
)
func FieldTypeForPropertyValue(property *iotsitewise.DescribeAssetPropertyOutput) data.FieldType {
dataType := util.GetPropertyDataType(property)
switch dataType {
case "BOOLEAN":
return data.FieldTypeBool
case "INTEGER":
return data.FieldTypeInt64
case "STRING":
return data.FieldTypeString
case "STRUCT":
return data.FieldTypeString
default:
return data.FieldTypeFloat64
}
}
// Map values from ???:
//
// https://docs.microsoft.com/en-us/rest/api/monitor/metrics/list#unit
//
// to
//
// https://github.com/grafana/grafana/blob/master/packages/grafana-data/src/valueFormats/categories.ts#L24
func ToGrafanaUnit(unit *string) string {
if unit == nil {
return ""
}
switch *unit {
case "Watts":
return "watt"
case "Kilowatts":
return "kwatt"
case "Count":
return "short" // this is used for integers
case "Percent":
return "percent"
case "Milliseconds":
return "ms"
case "Seconds":
return "s"
}
return *unit // this will become a suffix in the display
}