浏览代码

feat: 数据中心增加三个接口

gaoyagang 1 年之前
父节点
当前提交
20ec4a1935

+ 84 - 0
datacenter_client/types.go

@@ -149,6 +149,36 @@ type (
 		FilterCycle      int64   `json:"filter_cycle"`
 		FilterCycle      int64   `json:"filter_cycle"`
 		CTime            string  `json:"c_time"`
 		CTime            string  `json:"c_time"`
 	}
 	}
+
+	DataDescribeInfo struct {
+		Count  uint32  `json:"count"`
+		Min    float64 `json:"min"`
+		Max    float64 `json:"max"`
+		Mean   float64 `json:"mean"`
+		StdDev float64 `json:"std_dev"`
+		VarDev float64 `json:"var_dev"`
+		P25    float64 `json:"p25"`
+		P50    float64 `json:"p50"`
+		P75    float64 `json:"p75"`
+		St     string  `json:"st"`
+		Et     string  `json:"et"`
+	}
+
+	RelatedItems struct {
+		Item        string  `json:"item"`
+		Coefficient float32 `json:"coefficient"`
+	}
+
+	DataCorrelationInfo struct {
+		RelatedItems map[string]*RelatedItems `json:"related_items"`
+		St           string                   `json:"st"`
+		Et           string                   `json:"et"`
+	}
+
+	DataDescribeMinAndMaxInfo struct {
+		Min float64 `json:"min"`
+		Max float64 `json:"max"`
+	}
 )
 )
 
 
 type (
 type (
@@ -271,6 +301,27 @@ type (
 		AppName    string  `json:"app_name"`
 		AppName    string  `json:"app_name"`
 		ProjectIds []int64 `json:"project_ids"`
 		ProjectIds []int64 `json:"project_ids"`
 	}
 	}
+
+	FindDataDescribeReq struct {
+		ProjectId int64
+		Items     []string
+		Stime     string
+		Etime     string
+	}
+
+	FindDataCorrelationReq struct {
+		ProjectId int64
+		Items     []string
+		Stime     string
+		Etime     string
+	}
+
+	FindDataMinAndMaxReq struct {
+		ProjectId int64
+		Items     []string
+		Stime     string
+		Etime     string
+	}
 )
 )
 
 
 type (
 type (
@@ -430,6 +481,32 @@ type (
 			RemoveProjectIds []int64 `json:"remove_project_ids"`
 			RemoveProjectIds []int64 `json:"remove_project_ids"`
 		} `json:"data"`
 		} `json:"data"`
 	}
 	}
+
+	FindDataDescribeResp struct {
+		Code int    `json:"code"`
+		Msg  string `json:"msg"`
+		Data struct {
+			List map[string]*DataDescribeInfo `json:"list"`
+		} `json:"data"`
+	}
+
+	FindDataCorrelationResp struct {
+		Code int    `json:"code"`
+		Msg  string `json:"msg"`
+		Data struct {
+			DataCorrelationInfo
+			List map[string]*DataCorrelationInfo `json:"list"`
+		} `json:"data"`
+	}
+
+	FindDataMinAndMaxResp struct {
+		Code int    `json:"code"`
+		Msg  string `json:"msg"`
+		Data struct {
+			DataCorrelationInfo
+			List map[string]*DataDescribeMinAndMaxInfo `json:"list"`
+		} `json:"data"`
+	}
 )
 )
 
 
 type (
 type (
@@ -468,5 +545,12 @@ type (
 		ResetAppSecret(ResetAppSecretReq) (*ResetAppSecretResp, error)
 		ResetAppSecret(ResetAppSecretReq) (*ResetAppSecretResp, error)
 		ExpireAppSecret(ExpireAppSecretReq) (*ExpireAppSecretResp, error)
 		ExpireAppSecret(ExpireAppSecretReq) (*ExpireAppSecretResp, error)
 		ResetAppProject(ResetAppProjectReq) (*ResetAppProjectResp, error)
 		ResetAppProject(ResetAppProjectReq) (*ResetAppProjectResp, error)
+
+		// FindDataDescribe 拉取数据分析结果, 某一个时间段内的数据, 该时间段不会跨段
+		FindDataDescribe(FindDataDescribeReq) (*FindDataDescribeResp, error)
+		// FindDataCorrelation 拉取数据相关性列表
+		FindDataCorrelation(FindDataCorrelationReq) (*FindDataCorrelationResp, error)
+		// FindDataMinAndMax 拉取数据分析结果, 时间段内的最小与最大值
+		FindDataMinAndMax(FindDataMinAndMaxReq) (*FindDataMinAndMaxResp, error)
 	}
 	}
 )
 )

+ 33 - 0
datacenter_client/v1/CreateAppInfo_test.go

@@ -99,3 +99,36 @@ func TestDcApi_RemoveAppInfo(t *testing.T) {
 
 
 	t.Log(got, err)
 	t.Log(got, err)
 }
 }
+
+func TestDcApi_FindDataDescribe(t *testing.T) {
+	got, err := d.FindDataDescribe(datacenter_client.FindDataDescribeReq{
+		ProjectId: 92,
+		Items:     []string{"x1", "x2"},
+		Stime:     "2024-03-25 05:00:00",
+		Etime:     "2024-03-25 11:00:00",
+	})
+
+	t.Log(got, err)
+}
+
+func TestDcApi_FindDataCorrelation(t *testing.T) {
+	got, err := d.FindDataCorrelation(datacenter_client.FindDataCorrelationReq{
+		ProjectId: 92,
+		Items:     []string{"x1", "x2"},
+		Stime:     "2024-03-25 05:00:00",
+		Etime:     "2024-03-25 11:00:00",
+	})
+
+	t.Log(got, err)
+}
+
+func TestDcApi_FindDataMinAndMax(t *testing.T) {
+	got, err := d.FindDataMinAndMax(datacenter_client.FindDataMinAndMaxReq{
+		ProjectId: 92,
+		Items:     []string{"x1", "x2"},
+		Stime:     "2024-03-25 05:00:00",
+		Etime:     "2024-03-25 18:00:00",
+	})
+
+	t.Log(got, err)
+}

+ 22 - 0
datacenter_client/v1/FindDataCorrelation.go

@@ -0,0 +1,22 @@
+package v1
+
+import (
+	"metawant.greentech.com.cn/gaoyagang/gt-common/datacenter_client"
+	"metawant.greentech.com.cn/gaoyagang/gt-common/httplib"
+	"strconv"
+	"strings"
+)
+
+func (d *DcApi) FindDataCorrelation(params datacenter_client.FindDataCorrelationReq) (*datacenter_client.FindDataCorrelationResp, error) {
+	serviceName := "/data/correlation"
+	h := httplib.Get(d.serviceUrl(serviceName))
+	h.Param("project_id", strconv.FormatInt(params.ProjectId, 10))
+	h.Param("items", strings.Join(params.Items, ","))
+	h.Param("stime", params.Stime)
+	h.Param("etime", params.Etime)
+
+	resp := &datacenter_client.FindDataCorrelationResp{}
+
+	err := d.call(h, resp)
+	return resp, err
+}

+ 22 - 0
datacenter_client/v1/FindDataDescribe.go

@@ -0,0 +1,22 @@
+package v1
+
+import (
+	"metawant.greentech.com.cn/gaoyagang/gt-common/datacenter_client"
+	"metawant.greentech.com.cn/gaoyagang/gt-common/httplib"
+	"strconv"
+	"strings"
+)
+
+func (d *DcApi) FindDataDescribe(params datacenter_client.FindDataDescribeReq) (*datacenter_client.FindDataDescribeResp, error) {
+	serviceName := "/data/describe"
+	h := httplib.Get(d.serviceUrl(serviceName))
+	h.Param("project_id", strconv.FormatInt(params.ProjectId, 10))
+	h.Param("items", strings.Join(params.Items, ","))
+	h.Param("stime", params.Stime)
+	h.Param("etime", params.Etime)
+
+	resp := &datacenter_client.FindDataDescribeResp{}
+
+	err := d.call(h, resp)
+	return resp, err
+}

+ 22 - 0
datacenter_client/v1/FindDataMinAndMax.go

@@ -0,0 +1,22 @@
+package v1
+
+import (
+	"metawant.greentech.com.cn/gaoyagang/gt-common/datacenter_client"
+	"metawant.greentech.com.cn/gaoyagang/gt-common/httplib"
+	"strconv"
+	"strings"
+)
+
+func (d *DcApi) FindDataMinAndMax(params datacenter_client.FindDataMinAndMaxReq) (*datacenter_client.FindDataMinAndMaxResp, error) {
+	serviceName := "/data/describe/min-max"
+	h := httplib.Get(d.serviceUrl(serviceName))
+	h.Param("project_id", strconv.FormatInt(params.ProjectId, 10))
+	h.Param("items", strings.Join(params.Items, ","))
+	h.Param("stime", params.Stime)
+	h.Param("etime", params.Etime)
+
+	resp := &datacenter_client.FindDataMinAndMaxResp{}
+
+	err := d.call(h, resp)
+	return resp, err
+}