报表

汇总时长

POST /v1/reports/summary

最大范围 366 天;默认按天且不分组;标签组不可直接相加。

请求体

必填

application/json

类型: object

字段类型必填说明与约束
fromDatestring否筛选开始日(含) {"format":"date"}
toDateExclusivestring否筛选结束日(不含) {"format":"date"}
fromstring是开始时间(含);与 to 同时提供 {"format":"date-time"}
tostring是结束时间(不含);与 from 同时提供 {"format":"date-time"}
statestring否记录、任务或操作状态;语义取决于接口 {"enum":["running","stopped","invalid"]}
projectIdsarray<string>否项目 ID 筛选;GET 用逗号分隔,POST 用数组 {"minItems":1,"maxItems":100}
projectIds[]string否{"minLength":1,"maxLength":512}
tagIdsarray<string>否标签 ID;GET 筛选用逗号分隔,正文用数组 {"minItems":1,"maxItems":100}
tagIds[]string否{"minLength":1,"maxLength":512}
tagMatchstring否标签匹配:any 或 all {"enum":["any","all"]}
noProjectboolean否仅匹配无项目的记录
noTagsboolean否仅匹配无标签的记录
includeDescendantsboolean否筛选时包含后代标签
archivedstring否归档筛选:active、only 或 all {"enum":["active","only","all"]}
matchstring否时间匹配:overlaps 或 startsWithin {"enum":["overlaps","startsWithin"]}
textstring否搜索文本;使用 POST 避免进入 URL {"maxLength":500}
limitinteger否每页数量,默认 100,最多 500 {"minimum":1,"maximum":500}
cursorstring否不透明游标;原样传回,不要解析 {"maxLength":8192}
timeZonestring是IANA 时区,例如 Asia/Shanghai {"maxLength":128}
periodstring否统计粒度:day、week 或 month {"enum":["day","week","month"],"default":"day"}
groupBystring否分组维度:none、project 或 tag {"enum":["none","project","tag"],"default":"none"}
includeRunningboolean否统计时是否计入运行中的计时
includeAncestorsboolean否统计时包含祖先标签
weekStartsOnstring否每周起点,默认 monday {"enum":["monday","sunday"]}
完整 JSON Schema
{
  "type": "object",
  "required": [
    "from",
    "to",
    "timeZone"
  ],
  "properties": {
    "fromDate": {
      "type": "string",
      "format": "date",
      "description": "筛选开始日(含)"
    },
    "toDateExclusive": {
      "type": "string",
      "format": "date",
      "description": "筛选结束日(不含)"
    },
    "from": {
      "type": "string",
      "format": "date-time",
      "description": "开始时间(含);与 to 同时提供"
    },
    "to": {
      "type": "string",
      "format": "date-time",
      "description": "结束时间(不含);与 from 同时提供"
    },
    "state": {
      "type": "string",
      "enum": [
        "running",
        "stopped",
        "invalid"
      ],
      "description": "记录、任务或操作状态;语义取决于接口"
    },
    "projectIds": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 512
      },
      "minItems": 1,
      "maxItems": 100,
      "description": "项目 ID 筛选;GET 用逗号分隔,POST 用数组"
    },
    "tagIds": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 512
      },
      "minItems": 1,
      "maxItems": 100,
      "description": "标签 ID;GET 筛选用逗号分隔,正文用数组"
    },
    "tagMatch": {
      "type": "string",
      "enum": [
        "any",
        "all"
      ],
      "description": "标签匹配:any 或 all"
    },
    "noProject": {
      "type": "boolean",
      "description": "仅匹配无项目的记录"
    },
    "noTags": {
      "type": "boolean",
      "description": "仅匹配无标签的记录"
    },
    "includeDescendants": {
      "type": "boolean",
      "description": "筛选时包含后代标签"
    },
    "archived": {
      "type": "string",
      "enum": [
        "active",
        "only",
        "all"
      ],
      "description": "归档筛选:active、only 或 all"
    },
    "match": {
      "type": "string",
      "enum": [
        "overlaps",
        "startsWithin"
      ],
      "description": "时间匹配:overlaps 或 startsWithin"
    },
    "text": {
      "type": "string",
      "maxLength": 500,
      "description": "搜索文本;使用 POST 避免进入 URL"
    },
    "limit": {
      "type": "integer",
      "minimum": 1,
      "maximum": 500,
      "description": "每页数量,默认 100,最多 500"
    },
    "cursor": {
      "type": "string",
      "maxLength": 8192,
      "description": "不透明游标;原样传回,不要解析"
    },
    "timeZone": {
      "type": "string",
      "maxLength": 128,
      "description": "IANA 时区,例如 Asia/Shanghai"
    },
    "period": {
      "type": "string",
      "enum": [
        "day",
        "week",
        "month"
      ],
      "default": "day",
      "description": "统计粒度:day、week 或 month"
    },
    "groupBy": {
      "type": "string",
      "enum": [
        "none",
        "project",
        "tag"
      ],
      "default": "none",
      "description": "分组维度:none、project 或 tag"
    },
    "includeRunning": {
      "type": "boolean",
      "description": "统计时是否计入运行中的计时"
    },
    "includeAncestors": {
      "type": "boolean",
      "description": "统计时包含祖先标签"
    },
    "weekStartsOn": {
      "type": "string",
      "enum": [
        "monday",
        "sunday"
      ],
      "description": "每周起点,默认 monday"
    }
  },
  "additionalProperties": false
}

调用示例

将路径参数和请求参数替换为实际值。请求体按上述结构保存到 request.json。

curl --fail-with-body --request POST 'https://api.treering.cn/v1/reports/summary' \
  --header "Authorization: Bearer $TREERING_API_TOKEN" \
  --header 'Content-Type: application/json' \
  --data-binary @request.json

响应

200

成功响应;具体状态取决于操作结果。

application/json

类型: object

字段类型必填说明与约束
totalDurationSecondsnumber是去重后的总时长,单位秒
totalEntryCountnumber是去重后的记录总数
bucketsarray<object>是按日期及分组拆分的统计
buckets[]object否
buckets[].datestring是报表时区中的日期
buckets[].groupIdstring | null是分组资源 ID;无分组为 null
buckets[].groupId (anyOf 1)string否
buckets[].groupId (anyOf 2)null否
buckets[].durationSecondsnumber是持续时间,单位秒,可有小数
buckets[].entryCountnumber是记录数量
evaluatedAtstring是服务端计算结果的时间
excludedInvalidCountnumber是排除的无效记录数量
groupingIsAdditiveboolean是各分组是否可直接相加
完整 JSON Schema
{
  "type": "object",
  "required": [
    "totalDurationSeconds",
    "totalEntryCount",
    "buckets",
    "evaluatedAt",
    "excludedInvalidCount",
    "groupingIsAdditive"
  ],
  "properties": {
    "totalDurationSeconds": {
      "type": "number",
      "description": "去重后的总时长,单位秒"
    },
    "totalEntryCount": {
      "type": "number",
      "description": "去重后的记录总数"
    },
    "buckets": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "date",
          "groupId",
          "durationSeconds",
          "entryCount"
        ],
        "properties": {
          "date": {
            "type": "string",
            "description": "报表时区中的日期"
          },
          "groupId": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "description": "分组资源 ID;无分组为 null"
          },
          "durationSeconds": {
            "type": "number",
            "description": "持续时间,单位秒,可有小数"
          },
          "entryCount": {
            "type": "number",
            "description": "记录数量"
          }
        }
      },
      "description": "按日期及分组拆分的统计"
    },
    "evaluatedAt": {
      "type": "string",
      "description": "服务端计算结果的时间"
    },
    "excludedInvalidCount": {
      "type": "number",
      "description": "排除的无效记录数量"
    },
    "groupingIsAdditive": {
      "type": "boolean",
      "description": "各分组是否可直接相加"
    }
  }
}

400, 401, 403, 404, 413, 422, 429, 500, 503

错误响应;请按 code 处理。

application/json

类型: object

字段类型必填说明与约束
codestring是机器可读错误码
messagestring否错误说明;请按 code 处理程序逻辑
requestIdstring否请求追踪标识
operationIdstring否请求回执标识,无需查询状态
完整 JSON Schema
{
  "type": "object",
  "required": [
    "code"
  ],
  "properties": {
    "code": {
      "type": "string",
      "description": "机器可读错误码"
    },
    "message": {
      "type": "string",
      "description": "错误说明;请按 code 处理程序逻辑"
    },
    "requestId": {
      "type": "string",
      "description": "请求追踪标识"
    },
    "operationId": {
      "type": "string",
      "description": "请求回执标识,无需查询状态"
    }
  },
  "additionalProperties": true
}

目录