lucas
2 months ago
9 changed files with 245 additions and 121 deletions
@ -0,0 +1,6 @@ |
|||
package models |
|||
|
|||
const ( |
|||
RawTypeVib = "vib" |
|||
RawTypeDiag = "diag" |
|||
) |
@ -0,0 +1,107 @@ |
|||
package models |
|||
|
|||
import ( |
|||
"time" |
|||
) |
|||
|
|||
type DeviceData struct { |
|||
DeviceId string |
|||
Name string |
|||
ThingId string |
|||
StructId int |
|||
TaskId string |
|||
AcqTime time.Time |
|||
RealTime time.Time |
|||
ErrCode int |
|||
Raw map[string]any |
|||
RawUnit map[string]string |
|||
DeviceInfo DeviceInfo |
|||
DimensionId string |
|||
//数据类型 常见有 comm="" ,RawTypeVib="vib"
|
|||
DataType string |
|||
} |
|||
|
|||
func (d *DeviceData) GetVibrationData() VibrationData { |
|||
vibData := VibrationData{} |
|||
if d.DataType == RawTypeVib { |
|||
if v, ok := d.Raw["filterFreq"]; ok { |
|||
if vv, ok := v.(float64); ok { |
|||
vibData.FilterFreq = vv |
|||
} |
|||
} |
|||
|
|||
if v, ok := d.Raw["sampleFreq"]; ok { |
|||
if vv, ok := v.(float64); ok { |
|||
vibData.SampleFreq = vv |
|||
} |
|||
} |
|||
|
|||
if v, ok := d.Raw["gainAmplifier"]; ok { |
|||
if vv, ok := v.(float64); ok { |
|||
vibData.GainAmplifier = byte(vv) |
|||
} |
|||
} |
|||
|
|||
if v, ok := d.Raw["version"]; ok { |
|||
if vv, ok := v.(float64); ok { |
|||
vibData.Version = byte(vv) |
|||
} |
|||
} |
|||
|
|||
if v, ok := d.Raw["triggerType"]; ok { |
|||
if vv, ok := v.(float64); ok { |
|||
vibData.TriggerType = byte(vv) |
|||
} |
|||
} |
|||
|
|||
if v, ok := d.Raw["physicalvalue"]; ok { |
|||
|
|||
if vSlice, ok := v.([]any); ok { |
|||
for _, vObj := range vSlice { |
|||
if vv, ok := vObj.(float64); ok { |
|||
vibData.Data = append(vibData.Data, vv) |
|||
} |
|||
} |
|||
|
|||
} |
|||
|
|||
//去直流
|
|||
if len(vibData.Data) > 0 { |
|||
avg := func(dataArray []float64) float64 { |
|||
sum := 0.0 |
|||
for _, f := range dataArray { |
|||
sum += f |
|||
} |
|||
return sum / float64(len(dataArray)) |
|||
}(vibData.Data) //common_calc.GetAvg(vibData.Data)
|
|||
|
|||
for i := 0; i < len(vibData.Data); i++ { |
|||
vibData.Data[i] = vibData.Data[i] - avg |
|||
} |
|||
} |
|||
} |
|||
|
|||
} |
|||
return vibData |
|||
} |
|||
|
|||
// VibrationData 振动数据
|
|||
type VibrationData struct { |
|||
Version byte |
|||
SampleFreq float64 |
|||
FilterFreq float64 |
|||
GainAmplifier byte |
|||
TriggerType byte |
|||
Data []float64 // 原始波形数据
|
|||
Unit string |
|||
} |
|||
|
|||
func (v *VibrationData) FormatParams() map[string]any { |
|||
return map[string]any{ |
|||
"sampleFreq": v.SampleFreq, |
|||
"version": v.Version, |
|||
"filterFreq": v.FilterFreq, |
|||
"gainAmplifier": v.GainAmplifier, |
|||
"triggerType": v.TriggerType, |
|||
} |
|||
} |
Loading…
Reference in new issue