跳转至

指标树归因

1. 功能概述

指标树归因适用于对 复杂指标(由多个子指标组成)进行拆解分析,通过指标树结构自动识别“增长来自哪一部分”。

指标树归因支持:

  • 时间对比归因(tree_time_compare)

  • 同类对比归因(tree_peer_compare)

两者的输入结构相同,只是对比方式不同。

2. 接口 URL

时间对比归因

POST /anymetrics/api/v1/attribution/tree_time_compare

同类对比归因

POST /anymetrics/api/v1/attribution/tree_peer_compare

3. 公共请求参数(HEADERS)

参数名 类型 必选 描述
tenant-id String 租户 ID,用于指定业务空间
auth-type String 认证方式:UID / TOKEN
auth-value String 认证凭证值

说明:
公共参数可在 Aloudata CAN → API 集成 页面获取。

image.png


4. 请求参数(Request Body)

字段名 类型 是否必选 描述
metricTreeDef Object 指标树定义(来自 breakdown 接口)
attribution Object 归因计算配置(对比方式、过滤条件等)

4.1 metricTreeDef 结构说明

由 指标拆解接口(breakdown) 返回:

  • metricTreeNodes:每个节点的指标名称

  • metricTree:每个节点的表达式(引用子节点)

  • metricDefinitions:临时指标定义

  • rootNode:根节点 ID

示例(来自 breakdown):

{
  "rootNode": "node_001",
  "metricTree": {
    "node_001": "[node_002] - [node_003]",
    "node_002": "[node_004] * [node_005]"
  },
  "metricTreeNodes": {
    "node_001": "profit",
    "node_002": "revenue",
    "node_003": "cost",
    "node_004": "order_count",
    "node_005": "price"
  }
}

4.2 attribution 结构

时间对比:

字段名 类型 描述
attributionCalculateType String AVG(均值归因)
filters Array 全局过滤条件
currentTimeConstraint String 当前时间范围表达式
compareTimeConstraint String 对比时间范围表达式

同类对比:

字段名 类型 描述
attributionCalculateType String AVG(均值归因)
filters Array 全局过滤条件
currentObject Object 当前对象(filters + timeConstraint)
compareObject Object 对比对象(filters + timeConstraint)

5. 请求示例

5.1 时间对比示例(tree_time_compare)

{
  "metricTreeDef": {
    "rootNode": "node_001",
    "metricTree": {
      "node_001": "[node_002] - [node_003]",
      "node_002": "[node_004] * [node_005]"
    },
    "metricTreeNodes": {
      "node_001":"profit",
      "node_002":"revenue",
      "node_003":"cost",
      "node_004":"order_count",
      "node_005":"price"
    }
  },
  "attribution": {
    "filters": [],
    "attributionCalculateType": "AVG",
    "currentTimeConstraint": "[metric_time__month]>=\"2025-01\" AND [metric_time__month]<=\"2025-03\"",
    "compareTimeConstraint": "[metric_time__month]>=\"2024-11\" AND [metric_time__month]<=\"2025-01\""
  }
}

5.2 同类对比示例(tree_peer_compare)

{
  "metricTreeDef": { ... },
  "attribution": {
    "filters": [],
    "attributionCalculateType": "AVG",
    "currentObject": {
      "filters": ["[store]=\"杭州店\""],
      "timeConstraint": "[metric_time__day]=\"2025-07-07\""
    },
    "compareObject": {
      "filters": ["[store]=\"南京店\""],
      "timeConstraint": "[metric_time__day]=\"2025-07-06\""
    }
  }
}

6. 响应结构说明

响应为一个 Map,key 为节点 ID,每个节点的 value 是该指标的归因结果。

示例结构:

{
  "node_001": {
    "@currentValue": 10.0,
    "@compareValue": 12.0,
    "@growth": -2.0,
    "@growthRate": -0.166,
    "@overallContributionRate": -0.5,
    "@relativeContributionRate": -0.3
  },
  "node_002": { ... }
}

7. 字段含义解释

字段名 含义
@currentValue 当前对象(或当前时间)的计算值
@compareValue 对比对象(或对比时间)的计算值
@growth 增长值,= current - compare
@growthRate 增长率,= (current - compare) / compare
@overallContributionRate 在整棵指标树中的贡献占比
@relativeContributionRate 相对贡献值,一般用于排序