You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.4 KiB
47 lines
1.4 KiB
package common_models
|
|
|
|
import "time"
|
|
|
|
type EsVbRaw struct {
|
|
isFloat bool //是否拍扁
|
|
StructId int `json:"structId"`
|
|
IotaDeviceName string `json:"iota_device_name"`
|
|
Param map[string]any `json:"param"`
|
|
Data map[string]any `json:"data"`
|
|
CollectTime time.Time `json:"collect_time"`
|
|
IotaDevice string `json:"iota_device"`
|
|
CreateTime time.Time `json:"create_time"`
|
|
}
|
|
|
|
// FlatMapDynamicVib 振动数据打散
|
|
func (the *EsVbRaw) FlatMapDynamicVib() []EsVbRaw {
|
|
var EsVbRaws []EsVbRaw
|
|
if !the.isFloat {
|
|
onceMill := 0.0 //毫秒间隔
|
|
if sampleFreqObj, ok := the.Param["sampleFreq"]; ok {
|
|
if sampleFreq, ok := sampleFreqObj.(float64); ok {
|
|
onceMill = 1000 / sampleFreq
|
|
}
|
|
}
|
|
if rawsObj, ok := the.Data["raw"]; ok {
|
|
if raws, ok := rawsObj.([]float64); ok {
|
|
for i, raw := range raws {
|
|
onceTime := the.CollectTime.Add(time.Duration(onceMill*float64(i)) * time.Millisecond)
|
|
esVbRaw := EsVbRaw{
|
|
isFloat: true,
|
|
StructId: the.StructId,
|
|
IotaDeviceName: the.IotaDeviceName,
|
|
Param: the.Param,
|
|
Data: map[string]any{"physicalvalue": raw},
|
|
CollectTime: onceTime,
|
|
IotaDevice: the.IotaDevice,
|
|
CreateTime: the.CreateTime,
|
|
}
|
|
EsVbRaws = append(EsVbRaws, esVbRaw)
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
return EsVbRaws
|
|
}
|
|
|