63 lines
1.3 KiB
Go
63 lines
1.3 KiB
Go
package data
|
|
|
|
import (
|
|
"datart/data/influx"
|
|
"datart/data/postgres"
|
|
"strings"
|
|
|
|
"github.com/redis/go-redis/v9"
|
|
)
|
|
|
|
func GenPhasorFields(channel string) []string {
|
|
fields := make([]string, 0, 3)
|
|
|
|
switch {
|
|
case strings.HasPrefix(channel, postgres.ChannelYCPrefix):
|
|
|
|
fieldPrefix := strings.ToLower(channel)
|
|
fields = append(fields,
|
|
fieldPrefix+influx.FieldSuffixAMP,
|
|
fieldPrefix+influx.FieldSuffixPA,
|
|
fieldPrefix+influx.FieldSuffixRMS)
|
|
|
|
case strings.HasPrefix(channel, postgres.ChannelYXPrefix):
|
|
|
|
fields = append(fields, strings.ToLower(channel))
|
|
|
|
case strings.HasPrefix(channel, postgres.ChannelUPrefix):
|
|
|
|
fieldUPrefix := strings.ToLower(channel)
|
|
fields = append(fields,
|
|
fieldUPrefix+influx.FieldSuffixAMP,
|
|
fieldUPrefix+influx.FieldSuffixPA,
|
|
fieldUPrefix+influx.FieldSuffixRMS)
|
|
|
|
case channel == postgres.ChannelP,
|
|
channel == postgres.ChannelQ,
|
|
channel == postgres.ChannelS,
|
|
channel == postgres.ChannelPF,
|
|
channel == postgres.ChannelF,
|
|
channel == postgres.ChannelDF:
|
|
|
|
fields = append(fields, strings.ToLower(channel))
|
|
}
|
|
|
|
return fields
|
|
}
|
|
|
|
type zUnit struct {
|
|
Key string
|
|
Members []redis.Z
|
|
}
|
|
|
|
func convertTVsToMenmbers(tvs []influx.TV) []redis.Z {
|
|
members := make([]redis.Z, len(tvs))
|
|
|
|
for i, tv := range tvs {
|
|
members[i].Member = tv.Time
|
|
members[i].Score = tv.Value
|
|
}
|
|
|
|
return members
|
|
}
|