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.
42 lines
13 KiB
42 lines
13 KiB
1 month ago
|
package et_calc
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"gitea.anxinyun.cn/container/common_models"
|
||
|
"log"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
//var processDataStrWSD_noFormula = `{"DeviceData":{"DeviceId":"ed0f1d94-49a9-415b-9336-f965a2b0a985","Name":"温湿度传感器m1","ThingId":"5da9aa1b-05b7-4943-be57-dedb34f7a1bd","StructId":3,"TaskId":"0e1c7d3d-257d-4763-a335-198aef0fc625","AcqTime":"2024-03-20T04:20:48.000125336+08:00","RealTime":"2024-03-20T04:20:48.000251942+08:00","ErrCode":0,"Raw":{"Temp":27.9,"humidy":13.5},"DeviceInfo":{"id":"ed0f1d94-49a9-415b-9336-f965a2b0a985","name":"温湿度传感器m1","structure":{"thingId":"5da9aa1b-05b7-4943-be57-dedb34f7a1bd","id":3,"name":"添加边坡","type":"边坡","orgId":1,"latitude":0,"longitude":0},"device_meta":{"id":"d5bf6f22-3d7a-4ab0-9043-1020e9516bcc","name":"温湿度传感器","model":"FS-BDS-WSD","properties":[],"capabilities":[{"capabilityCategoryId":3,"id":"d2add1b3-b21c-420b-82a4-e0c55ee3a019","name":"采集","properties":[{"category":"Output","name":"Temp","showName":"温度","unit":"℃"},{"category":"Output","name":"humidy","showName":"湿度","unit":"%"}]}]}},"DimensionId":"76c75371-bb9a-4f71-a25d-58adf7938296"},"StationInfo":[{"Id":197,"Name":"温湿度测点1","Structure":3,"ThingId":"5da9aa1b-05b7-4943-be57-dedb34f7a1bd","StructName":"","FactorId":2,"ManualData":false,"Formula":0,"ParamsValue":null,"FactorName":"","ProtoCode":"1002","Devices":[{"formula_id":0,"params":{},"iota_device_id":"ed0f1d94-49a9-415b-9336-f965a2b0a985","iota_device_serial":0}],"Labels":"{}","CombineInfo":"","ThemeData":{"RawData":null,"ThemeData":null}},{"Id":200,"Name":"温湿度传感器m1-2","Structure":3,"ThingId":"5da9aa1b-05b7-4943-be57-dedb34f7a1bd","StructName":"","FactorId":2,"ManualData":false,"Formula":0,"ParamsValue":null,"FactorName":"","ProtoCode":"1002","Devices":[{"formula_id":0,"params":{},"iota_device_id":"ed0f1d94-49a9-415b-9336-f965a2b0a985","iota_device_serial":0}],"Labels":"{}","CombineInfo":"","ThemeData":{"RawData":null,"ThemeData":null}}]}`
|
||
|
//var processDataStrYB_Formula303 = `{"DeviceData":{"DeviceId":"c5eb15d8-6a3e-4a0e-8cca-59bf1d06465b","Name":"GXGS16-2","ThingId":"8e3eec71-c924-47fd-ac8b-2f28c49ad4e9","StructId":1,"TaskId":"ad6a62f1-0af7-4c53-80dd-c1d7833cdf38","AcqTime":"2024-01-16T09:40:02.921+08:00","RealTime":"0001-01-01T00:00:00Z","ErrCode":0,"Raw":{"frequency":32906,"physicalvalue":-10,"waterlevel":-10},"DeviceInfo":{"id":"c5eb15d8-6a3e-4a0e-8cca-59bf1d06465b","name":"GXGS16-2","structure":{"thingId":"8e3eec71-c924-47fd-ac8b-2f28c49ad4e9","id":1,"name":"东江大桥","type":"桥梁","orgId":1,"latitude":0,"longitude":0},"device_meta":{"id":"13ee1f91-04cc-48af-820e-ffc0ed179b6c","name":"表面式应变计","model":"FS-BM50","properties":[{"category":"Constant","name":"sensortype","showName":"传感器类型","unit":""},{"category":"Constant","name":"protocolcode","showName":"协议号","unit":""},{"category":"Constant","name":"deviceType","showName":"设备类型","unit":""},{"category":"Constant","name":"range","showName":"量程","unit":"με"}],"capabilities":[{"capabilityCategoryId":3,"id":"5d3b0ddc-308b-4ad6-93cd-7aefd34b600f","name":"RTU","properties":[{"category":"Output","name":"frequency","showName":"频率","unit":"Hz"},{"category":"Output","name":"temperature","showName":"温度","unit":"℃"},{"category":"Output","name":"physicalvalue","showName":"微应变","unit":"με"},{"category":"Output","name":"am","showName":"幅值","unit":"mv"}]},{"capabilityCategoryId":3,"id":"77becc38-82f7-4612-83e2-10e0ebf5e6e3","name":"采集","properties":[{"category":"Output","name":"frequency","showName":"频率","unit":"Hz"},{"category":"Output","name":"temperature","showName":"温度","unit":"℃"},{"category":"Output","name":"physicalvalue","showName":"微应变","unit":"με"},{"category":"Output","name":"am","showName":"幅值","unit":"mv"}]},{"capabilityCategoryId":3,"id":"99a6c9c1-0f57-45bc-a1ff-e98a56faef46","name":"云采集","properties":[{"category":"Output","name":"am","showName":"幅值","unit":"mV"},{"category":"Output","name":"frequency","showName":"频率","unit":"Hz"},{"category":"Output","name":"physicalvalue","showName":"微应变","unit":"με"},{"category":"Output","name":"temperature","showName":"温度","unit":"℃"}]},{"capabilityCategoryId":3,"id":"4bd4c44c-2dca-4de3-9e9e-39b2bebc57a5","name":"微功耗","properties":[{"category":"Output","name":"frequency","showName":"频率","unit":"Hz"},{"category":"Output","name":"physicalvalue","showName":"微应变","unit":"με"},{"category":"Output","name":"am","showName":"幅值","unit":"mV"},{"category":"Output","name":"temperature","showName":"温度","unit":"℃"}]}]}},"DimensionId":"a460675c-fb42-4f9e-80b9-d50b51597618"},"StationInfo":[{"Id":106,"Name":"DJ-RSG-G08-001-02","Structure":1,"ThingId":"8e3eec71-c924-47fd-ac8b-2f28c49ad4e9","StructName":"","FactorId":11,"ManualData":false,"Formula":0,"ParamsValue":null,"FactorName":"","ProtoCode":"3001","Devices":[{"formula_id":303,"params":{"Ti":178,"To":20,"k":1.2},"iota_device_id":"c5eb15d8-6a3e-4a0e-8cca-59bf1d06465b","iota_device_serial":0}],"Labels":"{}","CombineInfo":"","ThemeData":{"RawData":null,"ThemeData":null}}]}`
|
||
|
|
||
|
var processDataStrWSD_noFormula = `
|
||
|
{"DeviceData":{"DeviceId":"ed0f1d94-49a9-415b-9336-f965a2b0a985","Name":"温湿度传感器m1","ThingId":"5da9aa1b-05b7-4943-be57-dedb34f7a1bd","StructId":3,"TaskId":"0e1c7d3d-257d-4763-a335-198aef0fc625","AcqTime":"2024-03-20T04:20:48.000125336+08:00","RealTime":"2024-03-20T04:20:48.000251942+08:00","ErrCode":0,"Raw":{"Temp":27.9,"humidy":13.5},"RawUnit":{"Temp":"℃","humidy":"%"},"DeviceInfo":{"id":"ed0f1d94-49a9-415b-9336-f965a2b0a985","name":"温湿度传感器m1","structure":{"thingId":"5da9aa1b-05b7-4943-be57-dedb34f7a1bd","id":3,"name":"添加边坡","type":"边坡","orgId":1,"latitude":0,"longitude":0},"device_meta":{"id":"d5bf6f22-3d7a-4ab0-9043-1020e9516bcc","name":"温湿度传感器","model":"FS-BDS-WSD","properties":[],"capabilities":[{"capabilityCategoryId":3,"id":"d2add1b3-b21c-420b-82a4-e0c55ee3a019","name":"采集","properties":[{"category":"Output","name":"Temp","showName":"温度","unit":"℃"},{"category":"Output","name":"humidy","showName":"湿度","unit":"%"}]}]}},"DimensionId":"76c75371-bb9a-4f71-a25d-58adf7938296","DataType":""},"Stations":[{"Info":{"id":197,"name":"温湿度测点1","structure":3,"thingId":"5da9aa1b-05b7-4943-be57-dedb34f7a1bd","struct_name":"添加边坡","factor":2,"manual_data":false,"formula":0,"params_value":null,"Factor":{"id":2,"name":"环境温湿度","protoCode":"1002","protoName":"温湿度","items":[{"id":3,"name":"温度","field_name":"temperature","unit_name":"℃","precision":0},{"id":4,"name":"湿度","field_name":"humidity","unit_name":"%RH","precision":0}],"units":{"humidity":"%RH","temperature":"℃"}},"proto":"1002","Proto":{"code":"1002","name":"温湿度","items":[{"id":3,"name":"温度","field_name":"temperature","unit_name":"℃","precision":0},{"id":4,"name":"湿度","field_name":"humidity","unit_name":"%RH","precision":0}]},"Devices":[{"formula_id":0,"params":{},"iota_device_id":"ed0f1d94-49a9-415b-9336-f965a2b0a985","iota_device_serial":0,"FormulaInfo":{"id":0,"expression":"","params":null,"ioFields":{"input":null,"output":null},"type":""},"DeviceFactorProto":{"formula":0,"field_val":{"Temp":"temperature","humidy":"humidity"},"FieldValUnitK":null}}],"Labels":"{}","CombineInfo":""},"Data":{"DeviceCalcData":null,"ThemeData":null,"CollectTime":"0001-01-01T00:00:00Z","AlarmLevel":0},"Threshold":{"Items":[{"item":3,"field_name":"temperature","name":"温度","level":1,"lower":20,"upper":100000,"begin":null,"end":null},{"item":3,"field_name":"temperature","name":"温度","level":2,"lower":10,"upper":20,"begin":null,"end":null},{"item":4,"field_name":"humidity","name":"湿度","level":1,"lower":6,"upper":16,"begin":null,"end":null}]}}]}`
|
||
|
var processDataStrYB_Formula303 = `
|
||
|
{"DeviceData":{"DeviceId":"c5eb15d8-6a3e-4a0e-8cca-59bf1d06465b","Name":"GXGS16-2","ThingId":"8e3eec71-c924-47fd-ac8b-2f28c49ad4e9","StructId":1,"TaskId":"ad6a62f1-0af7-4c53-80dd-c1d7833cdf38","AcqTime":"2024-01-16T09:40:02.921+08:00","RealTime":"0001-01-01T00:00:00Z","ErrCode":0,"Raw":{"frequency":32906,"physicalvalue":-10,"waterlevel":-10},"RawUnit":{"am":"mv","frequency":"Hz","physicalvalue":"με","temperature":"℃"},"DeviceInfo":{"id":"c5eb15d8-6a3e-4a0e-8cca-59bf1d06465b","name":"GXGS16-2","structure":{"thingId":"8e3eec71-c924-47fd-ac8b-2f28c49ad4e9","id":1,"name":"东江大桥","type":"桥梁","orgId":1,"latitude":0,"longitude":0},"device_meta":{"id":"13ee1f91-04cc-48af-820e-ffc0ed179b6c","name":"表面式应变计","model":"FS-BM50","properties":[{"category":"Constant","name":"sensortype","showName":"传感器类型","unit":""},{"category":"Constant","name":"protocolcode","showName":"协议号","unit":""},{"category":"Constant","name":"deviceType","showName":"设备类型","unit":""},{"category":"Constant","name":"range","showName":"量程","unit":"με"}],"capabilities":[{"capabilityCategoryId":3,"id":"5d3b0ddc-308b-4ad6-93cd-7aefd34b600f","name":"RTU","properties":[{"category":"Output","name":"frequency","showName":"频率","unit":"Hz"},{"category":"Output","name":"temperature","showName":"温度","unit":"℃"},{"category":"Output","name":"physicalvalue","showName":"微应变","unit":"με"},{"category":"Output","name":"am","showName":"幅值","unit":"mv"}]},{"capabilityCategoryId":3,"id":"77becc38-82f7-4612-83e2-10e0ebf5e6e3","name":"采集","properties":[{"category":"Output","name":"frequency","showName":"频率","unit":"Hz"},{"category":"Output","name":"temperature","showName":"温度","unit":"℃"},{"category":"Output","name":"physicalvalue","showName":"微应变","unit":"με"},{"category":"Output","name":"am","showName":"幅值","unit":"mv"}]},{"capabilityCategoryId":3,"id":"99a6c9c1-0f57-45bc-a1ff-e98a56faef46","name":"云采集","properties":[{"category":"Output","name":"am","showName":"幅值","unit":"mV"},{"category":"Output","name":"frequency","showName":"频率","unit":"Hz"},{"category":"Output","name":"physicalvalue","showName":"微应变","unit":"με"},{"category":"Output","name":"temperature","showName":"温度","unit":"℃"}]},{"capabilityCategoryId":3,"id":"4bd4c44c-2dca-4de3-9e9e-39b2bebc57a5","name":"微功耗","properties":[{"category":"Output","name":"frequency","showName":"频率","unit":"Hz"},{"category":"Output","name":"physicalvalue","showName":"微应变","unit":"με"},{"category":"Output","name":"am","showName":"幅值","unit":"mV"},{"category":"Output","name":"temperature","showName":"温度","unit":"℃"}]}]}},"DimensionId":"a460675c-fb42-4f9e-80b9-d50b51597618","DataType":""},"Stations":[{"Info":{"id":106,"name":"DJ-RSG-G08-001-02","structure":1,"thingId":"8e3eec71-c924-47fd-ac8b-2f28c49ad4e9","struct_name":"东江大桥","factor":11,"manual_data":false,"formula":0,"params_value":null,"Factor":{"id":11,"name":"结构应变","protoCode":"3001","protoName":"应变","items":[{"id":39,"name":"应变","field_name":"strain","unit_name":"με","precision":0}],"units":{"strain":"με"}},"proto":"3001","Proto":{"code":"3001","name":"应变","items":[{"id":39,"name":"应变","field_name":"strain","unit_name":"με","precision":0}]},"Devices":[{"formula_id":303,"params":{"Ti":178,"To":20,"k":1.2},"iota_device_id":"c5eb15d8-6a3e-4a0e-8cca-59bf1d06465b","iota_device_serial":0,"FormulaInfo":{"id":303,"expression":"y=x-k*(Ti-To)","params":[{"name":"k","alias":"温补系数","unit":"","default":0},{"name":"Ti","alias":"温度T,通过关联的温度测点id来获取","unit":"","default":0},{"name":"To","alias":"初始温度","unit":"","default":0}],"ioFields":{"input":null,"output":null},"type":"sequence"},"DeviceFactorProto":{"formula":303,"field_val":{"physicalvalue":"x","y":"strain"},"FieldValUnitK":null}}],"Labels":"{}","CombineInfo":""},"Data":{"DeviceCalcData":null,"ThemeData":null,"CollectTime":"0001-01-01T00:00:00Z","AlarmLevel":0},"Threshold":{"Items":[{"item":39,"field_name":"strain",
|
||
|
`
|
||
|
|
||
|
func TestCalcBystationSingle(t *testing.T) {
|
||
|
pd := &common_models.ProcessData{}
|
||
|
json.Unmarshal([]byte(processDataStrYB_Formula303), pd)
|
||
|
commDataHandler := NewCalcHandler()
|
||
|
sd := commDataHandler.calcFormula(pd)
|
||
|
bs, er := json.Marshal(sd)
|
||
|
if er != nil {
|
||
|
log.Println(string(bs))
|
||
|
}
|
||
|
println("=====")
|
||
|
}
|
||
|
|
||
|
func TestCalcBystationSingle_noFormula(t *testing.T) {
|
||
|
pd := &common_models.ProcessData{}
|
||
|
json.Unmarshal([]byte(processDataStrWSD_noFormula), pd)
|
||
|
commDataHandler := NewCalcHandler()
|
||
|
sd := commDataHandler.calcFormula(pd)
|
||
|
bs, er := json.Marshal(sd)
|
||
|
if er != nil {
|
||
|
log.Println(string(bs))
|
||
|
}
|
||
|
println("=====")
|
||
|
}
|