Use a custom Data Analytics API in IoT Studio

Updated at:
Copy as MD

This topic describes how to create a custom data metric using Data Analytics and display it in an IoT Studio report component.

Prerequisites

Step 1: Create a project

  1. On the Project Management page, click Create Project.

  2. On the New Project page, move the pointer to the Create Blank Project area, and click Create Blank Project.

  3. In the New Blank Project dialog box, enter a project name (for example, studio_link_la_test) and a description.

  4. Click Confirm.

Step 2: Associate the product and its devices

  1. On the project homepage, click Product in the left navigation bar.

  2. On the Products page, click Associate with IoT Platform Product in the upper-left corner of the product list.

  3. In the Associate IoT Product panel, select the product that you created (for example, Temperature and Humidity Sensor), and select the Associate the product and all its devices checkbox.

    关联产品和设备

  4. Click OK.

    You can view the associated products in the product list on the Products page of the project.

Step 3: Back up product data

  1. Log in to the IoT Platform console. On the Instance Overview page, find and go to your purchased data-lake-based instance.

  2. In the left navigation bar, select Data Analysis > Data Management.

  3. In the Product List, find the product that you created (for example, a Temperature and Humidity Sensor) and back it up.

    • Back up a single product

    Click Backup in the Actions column of the product.

    • Back up multiple products

      Select the checkbox before the product name, and click Backup below the list.

  4. In the Backup dialog box, set Backup Type and Backup Cycle, and click OK.

    Parameter

    Description

    Backup Type

    Backups are stored in the same region by default. You cannot change this setting.

    Backup Period

    You can select 1 month, 2 months, 3 months, 4 months, 5 months, 6 months, 7 months, 8 months, 9 months, 1 year, 2 years, 3 years, 5 years, 10 years, or Permanent (102 years).

  5. (Optional) In the product list, find the target product and click Edit, Stop, or Start to modify the backup settings.

Step 4: Create custom metrics by group

  1. Import raw metrics for the product. For more information, see Import raw metrics.

  2. Create three atomic metrics, for example, Maximum Temperature, Minimum Temperature, and Average Temperature. For more information, see Create an atomic metric.

    The identifiers for the three atomic metrics are avg_temperature, min_temperature, and max_temperature. Set the metric type to Count and the unit to Celsius for all three metrics.

  3. Configure and publish the corresponding derived metrics for the new atomic metrics.

    1. In the left navigation bar, select Data Analytics > Data Assets.

    2. On the Metrics Management tab, click Group View.

    3. Click the name of the created IoT Studio group (for example, studio_link_la_test) to go to the Group Details page.

      Note

      After you complete Step 1: Create a project, an IoT Studio group is also created in the Group View. The name of the group is the same as the name of the project.

    4. On the Group Details page, click Metric List, and then click Create Metric.

    5. On the Create Metric page, configure the metric definition parameters as shown in the following table.

      Parameter

      Description

      Metric Domain

      Select Group.

      Group

      Select the IoT Studio group that you created, such as studio_link_la_test.

      Derivative Scope

      Select This entity.

      参数

    6. After you complete the configuration, click Finish and Go Live.

    7. You can view the new metrics in the Metric List on the Group Details page.

      指标

  4. Backfill the metrics. For more information, see Metric backfill.

    Data Analytics calculates derived metrics on a T+1 basis. You can use the metric backfill feature to backfill historical data and quickly obtain derived metric data.

Step 5: Create a custom service API

  1. In the left navigation bar, select Data Analytics > Data Service.

  2. In the API List, click Custom Service API, and then click Create API.

  3. On the Create API page, configure the basic information for the API, and then click Next.

    API

  4. On the Configure Parameters and Test page, complete the parameter configuration.

    In the Data Source area, set the data source type to Metric, Metric Domain to Group, and Data Scope to Derived Metric. In the Request Parameters section, bind the field to Business Time, set the parameter name to date_time, the parameter type to VARCHAR, the operator to BETWEEN, and the sample value to 20210201 ~ 20210228. The Response Parameters section must include the DOUBLE-type derived metric fields and the VARCHAR-type Business Time field.

  5. After you complete the configuration, in the Test API Area, enter test values for the request parameters and click Start Test.

    测试

  6. Click Publish.

Step 6: Use the custom API in IoT Studio

  1. Go back to the IoT Studio project homepage. On the Data Service tab, you can view the published custom service APIs.

    自定义API

  2. On the Project Home page, under Project Development, select Web Application.

  3. Click New above the application list.

  4. In the Create Web Application dialog box, enter the application name and description, and click OK.

    After the application is created, the web application editor automatically opens.

  5. Add a table component.

    1. In the web application editor, click the component icon 组件 on the far left.

    2. In the component list on the left, search for Table and drag the component onto the canvas.

    3. Select the component, and in the Style settings on the right, click Configure Data Source next to Display Data.

    4. In the Data Source Configuration panel, select an existing custom API and complete the configuration.

      配置数据源

    5. Configure the data display. For more information, see Table.

    6. After you finish the configuration, the table component displays data from the custom API.

      表格