123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- package envitem
- import (
- "encoding/json"
- "fmt"
- "github.com/go-redis/redis/v8"
- "testing"
- "time"
- )
- func TestEnvItem_GetCurrentData(t *testing.T) {
- SetOptions(Options{GtServerIp: "120.55.44.4:8900"})
- e := EnvItem{
- ProjectId: 92,
- Item: "C.M.UF1_DB@press_PV",
- }
- v, ht, err := e.getCurrentValue()
- t.Log(v, ht, err)
- }
- func TestGetVirtualPlcItems(t *testing.T) {
- SetOptions(Options{GtServerIp: "47.96.12.136:8788/"})
- e := VirtualPlcItem{
- ProjectId: 92,
- PageSize: 999,
- }
- v, err := e.GetVirtualPlcItems()
- if v.Code == 200 {
- for _, line := range v.Data.List {
- fmt.Println(line.ItemName, line.Expression, line.IsVirtual, line.Frequency)
- }
- }
- t.Log(v, err)
- }
- func TestMultiEnvItem_FillCurrentValue(t *testing.T) {
- cache := redis.NewClient(&redis.Options{Addr: "47.96.12.136:6379", Password: "", MaxRetries: 5})
- SetOptions(Options{GtServerIp: "47.96.12.136:8788", FetchMultiItem: false, Cache: cache, AdjustValue: true})
- m := make(MultiEnvItem, 2)
- m["C.M.LT_CIP@out"] = &EnvItem{
- ProjectId: 92,
- Item: "C.M.LT_CIP@out",
- }
- m["C.M.RO1_DB@time_CS_display"] = &EnvItem{
- ProjectId: 92,
- Item: "C.M.RO1_DB@time_CS_display",
- }
- m["C.M.LT_QSC@out"] = &EnvItem{
- ProjectId: 92,
- Item: "C.M.LT_QSC@out",
- }
- err := m.FillCurrentValue()
- t.Log(err)
- for s, item := range m {
- t.Logf("item: %s value: %s htime: %s", s, item.Value, item.Htime)
- }
- m["C.M.LT_QSC@out"].ClearAdjust()
- }
- func TestMultiEnvItem_FillCurrentValue2(t *testing.T) {
- cache := redis.NewClient(&redis.Options{Addr: "47.96.12.136:6379", Password: "", MaxRetries: 5})
- SetOptions(Options{GtServerIp: "47.96.12.136:8788", FetchMultiItem: false, Cache: cache})
- js := `{"tmp":{"project_id":92,"device_code":"UF-4001A","plc_device_id":"0","item":"C.M.UF1_DB@press_PV","default_val":0},"feed_flow":{"project_id":92,"device_code":"UF-4001A","plc_device_id":"0","item":"C.M.UF1_FT_JS@out","default_val":0},"feed_pressure":{"project_id":92,"device_code":"UF-4001A","plc_device_id":"0","item":"C.M.UF1_PT_JS@out","default_val":0},"product_pressure":{"project_id":92,"device_code":"UF-4001A","plc_device_id":"0","item":"C.M.UF1_PT_CS@out","default_val":0},"feed_wq_turbidity":{"project_id":92,"device_code":"AIT-94061","plc_device_id":"0","item":"C.M.UF_Tur_ZJS@out","default_val":0},"water_temperature":{"project_id":92,"device_code":"TIT-34061","plc_device_id":"0","item":"C.M.RO_TT_ZJS@out","default_val":0},"product_wq_ph":{"project_id":92,"device_code":"AIT-95065b","plc_device_id":"0","item":"C.M.UF_PH_ZCS@out","default_val":0},"step":{"project_id":92,"device_code":"HB","plc_device_id":"0","item":"C.M.UF1_DB@word_control","default_val":0}}`
- var multiEnvItems MultiEnvItem
- _ = json.Unmarshal([]byte(js), &multiEnvItems)
- t.Log(multiEnvItems)
- _ = multiEnvItems.FillCurrentValue()
- for {
- //_ = multiEnvItems.FillCurrentValue()
- multiEnvItems.ClearValues()
- v := multiEnvItems.GetItemFloat64Value("feed_flow")
- t.Logf("item: %s, %f", "feed_flow", v)
- //for s, item := range multiEnvItems {
- // if item != nil {
- // t.Logf("item: %s value: %f htime: %v", s, item.GetItemFloat64Val(), item.GetItemHtime())
- // } else {
- // t.Logf("item: %s fetch failure", s)
- // }
- //
- //}
- time.Sleep(2 * time.Second)
- //ms := multiEnvItems.FindString()
- //t.Logf("%+v", multiEnvItems)
- //t.Logf("step: %d", multiEnvItems.GetItemInt64Value("step"))
- //early := checkEarly(multiEnvItems.GetItemFloat64Value("Display_Time"), multiEnvItems.GetItemFloat64Value("Filter_Time_Set"), multiEnvItems.GetItemStringValue("Step"))
- //advanced := checkAdvanced(multiEnvItems.GetItemFloat64Value("Display_Time"), multiEnvItems.GetItemFloat64Value("Filter_Time_Set"), multiEnvItems.GetItemStringValue("Step"))
- //
- //t.Logf("early: %v, advanced: %v, step: %s filterNumber: %s Display_Time: %s Filter_Time_Set: %s", early, advanced, multiEnvItems.GetItemStringValue("Step"), multiEnvItems.GetItemStringValue("Filter_Number"), multiEnvItems.GetItemStringValue("Display_Time"), multiEnvItems.GetItemStringValue("Filter_Time_Set"))
- //t.Log(err)
- //for s, item := range multiEnvItems {
- // t.Logf("item: %s value: %s htime: %s", s, item.Value, item.Htime)
- //}
- }
- }
- func TestEnvItem_Adjust(t *testing.T) {
- cache := redis.NewClient(&redis.Options{Addr: "47.96.12.136:6379", Password: "", MaxRetries: 5})
- SetOptions(Options{GtServerIp: "47.96.12.136:8788", Cache: cache, AdjustValue: true})
- e := EnvItem{
- ProjectId: 92,
- Item: "C.M.LT_QSC@out",
- }
- //v, ht, err := e.getCurrentValue()
- //e.IncreAdjust(3600 * time.Second)
- //e.IncreAdjust(3600 * time.Second)
- e.IncreAdjust(3600 * time.Second)
- //
- //e.SetAdjust("65325", 3*time.Second)
- adjust, err := e.GetAdjustInt64Val()
- //t.Log(v, ht, err)
- t.Log(adjust, err)
- }
- func TestEnvItem_GetValueForAdjust(t *testing.T) {
- cache := redis.NewClient(&redis.Options{Addr: "47.96.12.136:6379", Password: "", MaxRetries: 5})
- SetOptions(Options{GtServerIp: "47.96.12.136:8788", Cache: cache, AdjustValue: false})
- e := EnvItem{
- ProjectId: 92,
- Item: "C.M.UF1_DB@word_control",
- }
- v := e.GetItemInt64Val()
- t.Log(v)
- }
|