Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions docs/device/4-device-collector.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,94 @@ topics:
- error_code
```

---
### 模板语法使用

## 概述

模板语法是一种动态生成字符串的强大工具,特别适用于根据时间范围动态生成文件路径和文件名。基于 [Handlebars](https://handlebarsjs.com/) 模板引擎,集成了 [Day.js](https://day.js.org/) 时间处理库。

通过掌握这些模板语法,您可以轻松创建动态的文件路径和文件名,大大提高数据管理的灵活性和自动化程度。

## 基本语法

### 支持的变量

目前支持以下两个时间变量:

- `start_time` - 当前采集任务的开始时间
- `end_time` - 当前采集任务的结束时间

### 基本模板格式

```
{{变量名.format('格式字符串')}}
```

### 示例

```javascript
// 基本用法
'{{start_time.format("YYYY-MM-DD")}}'
// 输出: "2021-01-01"

// 组合使用
'data/{{start_time.format("YYYY")}}/{{start_time.format("MM")}}/file.log'
// 输出: "data/2021/01/file.log"
```

## 时间格式化

### 常用格式化选项

基于 [Day.js 格式化文档](https://day.js.org/docs/en/display/format),支持以下格式:

| 格式 | 输出 | 描述 |
|------|------|------|
| `YYYY` | 2021 | 四位年份 |
| `YY` | 21 | 两位年份 |
| `MM` | 01-12 | 月份(补零) |
| `M` | 1-12 | 月份 |
| `DD` | 01-31 | 日期(补零) |
| `D` | 1-31 | 日期 |
| `HH` | 00-23 | 小时(补零) |
| `H` | 0-23 | 小时 |
| `mm` | 00-59 | 分钟(补零) |
| `m` | 0-59 | 分钟 |
| `ss` | 00-59 | 秒(补零) |
| `s` | 0-59 | 秒 |

### 格式化示例

```javascript
// 日期格式
'{{start_time.format("YYYY-MM-DD")}}' // 2021-01-01
'{{start_time.format("YYYY/MM/DD")}}' // 2021/01/01
'{{start_time.format("MM-DD-YYYY")}}' // 01-01-2021

// 时间格式
'{{start_time.format("HH:mm:ss")}}' // 10:30:00
'{{start_time.format("HH-mm")}}' // 10-30

// 组合格式
'{{start_time.format("YYYY-MM-DD HH:mm:ss")}}' // 2021-01-01 10:30:00
'{{start_time.format("YYYYMMDD_HHmmss")}}' // 20210101_103000

// 按年月日组织的文件夹结构
'logs/{{start_time.format("YYYY")}}/{{start_time.format("MM")}}/{{start_time.format("DD")}}'
// 输出: logs/2021/01/01

// 时间范围文件夹
'data/{{start_time.format("YYYY-MM-DD")}}_to_{{end_time.format("YYYY-MM-DD")}}'
// 输出: data/2021-01-01_to_2021-01-02
```

## 参考文档

- [Handlebars 官方文档](https://handlebarsjs.com/guide/)
- [Day.js 官方文档](https://day.js.org/docs/en/display/format)
- [Day.js 格式化选项](https://day.js.org/docs/en/display/format#list-of-all-available-formats)

---

通过以上详细步骤和说明,管理员可全面、准确地对设备数采客户端进行配置,确保设备数据采集工作的高效运行。
Expand Down
6 changes: 3 additions & 3 deletions docs/use-case/4-online-simulation-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ tar -czvf install.tar.gz ./install

- 源码构建与编译后的可执行程序

可参考平台文档 👉 https://docs.coscene.cn/docs/sim-and-tests/regression/test-bundle-management
可参考 [Test Bundle 管理文档](../sim-and-tests/regression/4-test-bundle-management.md) 获取更多信息

**_对于企业用户,还支持 GitHub / GitLab 持续集成上传构建产物,跳过手动上传过程。_**

Expand Down Expand Up @@ -127,7 +127,7 @@ test_case/

### 文件结构规范

请严格遵循[平台规定的路径结构](https://docs.coscene.cn/docs/sim-and-tests/regression/intro):
请严格遵循[平台规定的路径结构](../sim-and-tests/regression/1-intro.md):

![文件结构示意图](./img/4-online-simulation-test-13.png)

Expand All @@ -152,7 +152,7 @@ test_case/
- 手动选择记录执行
- 按标签或版本筛选测试集

详细配置参考 👉 https://docs.coscene.cn/docs/sim-and-tests/regression/config-management
详细配置请参考[测试配置管理文档](../sim-and-tests/regression/3-config-management.md)
![4-online-simulation-test-18](./img/4-online-simulation-test-18.png)
![4-online-simulation-test-19](./img/4-online-simulation-test-19.png)
![4-online-simulation-test-20](./img/4-online-simulation-test-20.png)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,96 @@ topics:

---

### Template Syntax Usage

## Overview

Template syntax is a powerful tool for dynamically generating strings, particularly suitable for dynamically generating file paths and filenames based on time ranges. Based on the [Handlebars](https://handlebarsjs.com/) template engine, integrated with the [Day.js](https://day.js.org/) time processing library.

By mastering these template syntaxes, you can easily create dynamic file paths and filenames, greatly improving the flexibility and automation of data management.

## Basic Syntax

### Supported Variables

Currently supports the following two time variables:

- `start_time` - The start time of the current collection task
- `end_time` - The end time of the current collection task

### Basic Template Format

```
{{variable_name.format('format_string')}}
```

### Examples

```javascript
// Basic usage
'{{start_time.format("YYYY-MM-DD")}}'
// Output: "2021-01-01"

// Combined usage
'data/{{start_time.format("YYYY")}}/{{start_time.format("MM")}}/file.log'
// Output: "data/2021/01/file.log"
```

## Time Formatting

### Common Formatting Options

Based on [Day.js formatting documentation](https://day.js.org/docs/en/display/format), supports the following formats:

| Format | Output | Description |
|--------|--------|-------------|
| `YYYY` | 2021 | 4-digit year |
| `YY` | 21 | 2-digit year |
| `MM` | 01-12 | Month (zero-padded) |
| `M` | 1-12 | Month |
| `DD` | 01-31 | Date (zero-padded) |
| `D` | 1-31 | Date |
| `HH` | 00-23 | Hour (zero-padded) |
| `H` | 0-23 | Hour |
| `mm` | 00-59 | Minute (zero-padded) |
| `m` | 0-59 | Minute |
| `ss` | 00-59 | Second (zero-padded) |
| `s` | 0-59 | Second |

### Formatting Examples

```javascript
// Date formats
'{{start_time.format("YYYY-MM-DD")}}' // 2021-01-01
'{{start_time.format("YYYY/MM/DD")}}' // 2021/01/01
'{{start_time.format("MM-DD-YYYY")}}' // 01-01-2021

// Time formats
'{{start_time.format("HH:mm:ss")}}' // 10:30:00
'{{start_time.format("HH-mm")}}' // 10-30

// Combined formats
'{{start_time.format("YYYY-MM-DD HH:mm:ss")}}' // 2021-01-01 10:30:00
'{{start_time.format("YYYYMMDD_HHmmss")}}' // 20210101_103000

// Folder structure organized by year/month/day
'logs/{{start_time.format("YYYY")}}/{{start_time.format("MM")}}/{{start_time.format("DD")}}'
// Output: logs/2021/01/01

// Time range folders
'data/{{start_time.format("YYYY-MM-DD")}}_to_{{end_time.format("YYYY-MM-DD")}}'
// Output: data/2021-01-01_to_2021-01-02
```

## Reference Documentation

- [Handlebars Official Documentation](https://handlebarsjs.com/guide/)
- [Day.js Official Documentation](https://day.js.org/docs/en/display/format)
- [Day.js Formatting Options](https://day.js.org/docs/en/display/format#list-of-all-available-formats)

---

Through these detailed steps and instructions, administrators can comprehensively and accurately configure the device data collection client, ensuring efficient operation of device data collection.

If you have any questions, please feel free to contact us for support.

Loading