Azure 时序见解预览版中的时序模型Time Series Model in Azure Time Series Insights Preview

本文介绍时序模型及其功能,以及如何在 Azure 时序见解预览版环境中开始生成和更新自己的模型。This article describes Time Series Model, the capabilities, and how to start building and updating your own models in the Azure Time Series Insights Preview environment.

提示

摘要Summary

一直以来,从 IoT 设备收集的数据缺少上下文信息,以致难以快速查找和分析传感器。Traditionally, the data that's collected from IoT devices lacks contextual information, which makes it difficult to find and analyze sensors quickly. 时序模型的主要动机是简化 IoT 或时序数据的查找和分析。The main motivation for Time Series Model is to simplify finding and analyzing IoT or Time Series data. 为了实现此目标,它会启用时序数据的策划、维护和扩充,以帮助准备随时可供使用的分析数据集。It achieves this objective by enabling the curation, maintenance, and enrichment of time series data to help prepare consumer-ready datasets for analytics.

方案:Contoso 的新智能烤箱Scenario: Contoso's new smart oven

下面虚构了一个 Contoso 智能烤箱的场景。Consider the fictitious scenario of a Contoso smart oven. 在此场景中,假设每部 Contoso 智能烤箱有五个温度传感器,顶部的四个电热丝各配有一个传感器,烤箱本体配有一个传感器。In this scenario, suppose that each Contoso smart oven has five temperature sensors, one for each of four top burners and one for the oven itself. 每个 Contoso 温度传感器单独发送、存储和可视化到目前为止的数据。Until recently, each Contoso temperature sensor sent, stored, and visualized its data individually. Contoso 依赖使用基本图表来监视其厨房电器,每个图表对应于一个传感器。For its kitchen appliance monitoring, Contoso relied on basic charts, one for each individual sensor.

尽管 Contoso 对其最初的数据和可视化解决方案感到满意,但有几处限制也不容忽视:While Contoso was satisfied with its initial data and visualization solution, several limitations became apparent:

  • 客户想要知道,当顶部的大部分电热丝都打开时,整个烤箱的温度会有多高。Customers wanted to know how hot the overall oven would get when most of the top burners were on. 在整个烤箱的工作状况方面,Contoso 很难进行分析并提供统一的答案。Contoso had more difficulty analyzing and presenting a unified answer about the conditions of the overall oven.
  • Contoso 工程师希望验证在顶部的电热丝同时工作时,会不会导致用电效率下降。Contoso engineers wanted to verify that the top burners being run simultaneously wouldn't result in inefficient power draw. 很难通过交叉参考来确定哪些温度和电压传感器彼此关联,以及如何在存储中定位这些传感器。There was difficulty cross-referencing which temperature and voltage sensors were associated with each other and how to locate them in the store.
  • Contoso 质量保证团队希望审核并比较两个传感器版本之间的历史记录。The Contoso quality assurance team wanted to audit and compare the history between two sensor versions. 难以确定哪些数据属于哪个传感器版本。There was difficulty determining what data belonged to which sensor version.

由于不能构建、组织和定义统括式的智能烤箱时序模型,每个温度传感器都会保留失位、隔离且参考价值不大的数据点。Without the ability to structure, organize, and define the overarching smart oven time series model, each temperature sensor maintained dislocated, isolated, and less informative data points. 由于每个数据集相互独立,更难以将这些数据点转化为可行的见解。Turning these data points into actionable insights was more difficult since each dataset lived independently of the others.

这些限制揭示了随 Contoso 的新烤箱附送智能数据聚合与可视化工具的重要性:These limitations revealed the importance of smart data aggregation and visualization tools to accompany Contoso's new oven:

  • 如果能够将数据关联且合并一个可方便查看的视图,则可以证明数据可视化的作用。Data visualization proves useful when you're able to associate and combine data into a convenient view. 例如,将电压传感器与温度传感器一起显示。An example is showing voltage sensors along with temperature sensors.
  • 既要管理多个实体的多维数据,同时又要提供比较、缩放和时间范围功能,可能很难实现。Managing multidimensional data for several entities along with comparison, zooming, and time range functionalities can be difficult to accomplish.

时序模型为此虚构示例中出现的许多场景提供一个便利的解决方案Time Series Model provides a convenient solution for many of the scenarios encountered in this fictitious example:

时序模型智能烤箱图表示例Time Series Model smart oven charting example

  • 时序模型在查询和导航中起着至关重要的作用,因为它允许跨时间范围以及在传感器与设备类型之间绘制比较比较,因此可将数据上下文化。Time Series Model plays a vital role in queries and navigation because it contextualizes data by allowing comparisons to be drawn across time ranges and between sensor and device kinds. (A)(A)
  • 数据之所以能够进一步上下文化,是因为时序模型中保存的数据将时序查询计算结果作为变量保留,并在查询时重新使用这些结果。Data is further contextualized because data persisted in Time Series Model preserves time series query computations as variables and reuses them at query time.
  • 时序模型对数据进行组织与聚合,以改进可视化和管理功能。Time Series Model organizes and aggregates data for improved visualization and management capabilities. (B)(B)

关键功能Key capabilities

时序模型的目标是让用户毫不费力地管理时序上下文化,它在时序见解预览版中可以实现以下功能。With the goal to make it simple and effortless to manage time series contextualization, Time Series Model enables the following capabilities in Time Series Insights Preview. 它可以帮助你:It helps you:

  • 利用标量函数、聚合操作等创作和管理计算或公式。Author and manage computations or formulas leveraging scalar functions, aggregate operations, and so on.
  • 定义父子关系以实现导航、搜索和引用。Define parent-child relationships to enable navigation, search, and reference.
  • 定义与实例(定义为实例字段)关联的属性,并使用这些属性来创建层次结构。 Define properties that are associated with the instances, defined as instance fields, and use them to create hierarchies.

组件Components

时序模型包括三个核心组件:Time Series Model has three core components:

组合这些组件可以指定时序模型以及组织 Azure 时序见解数据。These components are combined to specify a time series model and to organize your Azure Time Series Insights data.

时序模型概述图表Time Series Model overview chart

可以通过时序见解预览版界面来创建和管理时序模型。A time series model can be created and managed through the Time Series Insights Preview interface. 可以通过模型设置 API 来管理时序模型设置。Time Series Model settings can be managed through the Model Settings API.

时序模型实例Time Series Model instances

时序模型实例是时序本身的虚拟表示形式。 Time Series Model instances are virtual representations of the time series themselves.

在大多数情况下,实例由保存为时序 ID 的 deviceIdassetId 唯一标识。In most cases, instances are uniquely identified by deviceId or assetId, which are saved as time series IDs.

实例具有与自身关联的、称作“实例属性”的描述性信息,例如时序 ID、类型、名称、说明、层次结构和实例字段。 Instances have descriptive information associated with them called instance properties, such as a time series ID, type, name, description, hierarchies, and instance fields. 实例属性最起码包括层次结构信息。At a minimum, instance properties include hierarchy information.

实例字段是描述性信息的集合,可包含层次结构级别的值,以及制造商、运营商等信息。 Instance fields are a collection of descriptive information that can include values for hierarchy levels, as well as manufacturer, operator, and so on.

为时序见解环境配置事件源后,可在时序模型中自动发现和创建实例。After an event source is configured for the Time Series Insights environment, instances are automatically discovered and created in a time series model. 可以使用时序模型查询通过时序见解资源管理器来创建或更新实例。The instances can be created or updated via the Time Series Insights explorer by using Time Series Model queries.

Contoso 风力发电厂演示提供了多个实时实例示例。The Contoso Wind Farm demo provides several live instance examples.

时序模型实例示例Time Series Model instance example

实例属性Instance properties

实例由 timeSeriesIdtypeIdnamedescriptionhierarchyIdsinstanceFields 定义。Instances are defined by timeSeriesId, typeId, name, description, hierarchyIds, and instanceFields. 每个实例只映射到一个类型以及一个或多个层次结构。 Each instance maps to only one type, and one or more hierarchies.

属性Property 说明Description
timeSeriesIdtimeSeriesId 与实例关联的时序的 UUID。The UUID of the time series the instance is associated with.
typeIdtypeId 与实例关联的时序模型类型的 UUID。The UUID of the Time Series Model type the instance is associated with. 默认情况下,所有已发现的新实例都会关联到默认类型。By default, all discovered new instances get associated to a default type.
namename name 属性可选,区分大小写。The name property is optional and case-sensitive. 如果未提供 name,则默认值为 timeSeriesIdIf name isn't available, it defaults to timeSeriesId. 如果提供了名称,仍然可以在 well 中使用 timeSeriesIdIf a name is provided, timeSeriesId is still available in the well.
descriptiondescription 实例的文本说明。A text description of the instance.
hierarchyIdshierarchyIds 定义实例所属的层次结构。Defines which hierarchies the instance belongs to.
instanceFieldsinstanceFields 实例的属性,并且是定义实例的任何静态数据。The properties of an instance and any static data that defines an instance. 它们定义层次结构或非层次结构属性的值,同时还支持索引,以便能够执行搜索操作。They define values of hierarchy or non-hierarchy properties while also supporting indexing to perform search operations.

备注

层次结构是使用实例字段生成的。Hierarchies are built by using instance fields. 可为其他实例属性定义添加更多的 instanceFieldsAdditional instanceFields can be added for further instance property definitions.

实例具有以下 JSON 表示形式:Instances have the following JSON representation:

{
  "timeSeriesId": ["PU2"],
  "typeId": "545314a5-7166-4b90-abb9-fd93966fa39b",
  "hierarchyIds": ["95f0a8d1-a3ef-4549-b4b3-f138856b3a12"],
  "description": "Pump #2",
  "instanceFields": {
    "Location": "Redmond",
    "Fleet": "Fleet 5",
    "Unit": "Pump Unit 3",
    "Manufacturer": "Contoso",
    "ScalePres": "0.54",
    "scaleTemp": "0.54"
  }
}

提示

有关时序见解实例 API 以及创建、读取、更新和删除 (CRUD) 支持,请阅读数据查询一文和实例 API REST 文档For Time Series Insights Instance API and create, read, update, and delete (CRUD) support, read the Data querying article and the Instance API REST documentation.

时序模型层次结构Time Series Model hierarchies

时序模型层次结构通过指定属性名称及其关系来组织实例。 Time Series Model hierarchies organize instances by specifying property names and their relationships.

可以在给定的时序见解环境中配置多个层次结构。You can configure multiple hierarchies in a given Time Series Insights environment. 一个时序模型实例可以映射到一个或多个层次结构(多对多的关系)。A Time Series Model instance can map to a single hierarchy or multiple hierarchies (many-to-many relationship).

Contoso 风力发电厂演示客户端界面显示了标准实例和类型层次结构。The Contoso Wind Farm demo client interface displays a standard instance and type hierarchy.

时序模型层次结构示例Time Series Model hierarchy example

层次结构定义Hierarchy definition

层次结构由层次结构的 idnamesource 定义。Hierarchies are defined by hierarchy id, name, and source.

属性Property 说明Description
idid 层次结构的唯一标识符,例如,在定义实例时使用。The unique identifier for the hierarchy, which is used, for example, when you define an instance.
namename 用于提供层次结构名称的字符串。A string used to provide a name for the hierarchy.
sourcesource 指定组织的层次结构或路径,即,用户想要创建的层次结构的自上而下的父子顺序。Specifies the organizational hierarchy or path, which is a top-down parent-child order of the hierarchy that users want to create. 父子属性映射实例字段。The parent-child properties map instance fields.

层次结构的 JSON 表示形式如下:Hierarchies are represented in JSON as:

{
  "hierarchies": [
    {
      "id": "6e292e54-9a26-4be1-9034-607d71492707",
      "name": "Location",
      "source": {
        "instanceFieldNames": [
          "state",
          "city"
        ]
      }
    },
    {
      "id": "a28fd14c-6b98-4ab5-9301-3840f142d30e",
      "name": "ManufactureDate",
      "source": {
        "instanceFieldNames": [
          "year",
          "month"
        ]
      }
    }
  ]
}

在上面的 JSON 示例中:In the previous JSON example:

  • Location 定义包含父级 states 和子级 cities 的层次结构。Location defines a hierarchy with parent states and child cities. 每个 location 可以包含多个 states,而后者又可以包含多个 citiesEach location can have multiple states, which in turn can have multiple cities.
  • ManufactureDate 定义包含父级 year 和子级 month 的层次结构。ManufactureDate defines a hierarchy with parent year and child month. 每个 ManufactureDate 可以包含多个 years,而后者又可以包含多个 monthsEach ManufactureDate can have multiple years, which in turn can have multiple months.

提示

有关时序见解实例 API 和 CRUD 支持,请阅读数据查询一文和层次结构 API REST 文档For Time Series Insights Instance API and CRUD support, read the Data querying article and the Hierarchy API REST documentation.

层次结构示例Hierarchy example

假设层次结构 H1 包含 buildingfloorroom 作为其 instanceFieldNames 定义的一部分:Consider an example where hierarchy H1 has building, floor, and room as part of its instanceFieldNames definition:

{
  "id": "aaaaaa-bbbbb-ccccc-ddddd-111111",
  "name": "H1",
  "source": {
    "instanceFieldNames": [
      "building",
      "floor",
      "room"
    ]
  }
}

根据上述定义和多个时序中使用的实例字段,层次结构属性和值将如下表中所示:Given the instance fields used in the previous definition and several time series, the hierarchy attributes and values appear as shown in the following table:

时序 IDTime Series ID 实例字段Instance fields
ID1ID1 "building" = "1000", "floor" = "10", "room" = "55""building" = "1000", "floor" = "10", "room" = "55"
ID2ID2 "building" = "1000", "room" = "55""building" = "1000", "room" = "55"
ID3ID3 "floor" = "10""floor" = "10"
ID4ID4 "building" = "1000", "floor" = "10""building" = "1000", "floor" = "10"
ID5ID5 “building”、“floor”和“room”均未设置。None of "building", "floor", or "room" is set.

时序 ID1 和 ID4 在 Azure 时序见解资源管理器中显示为层次结构 H1 的一部分,因为它们包含已完全定义且正确排序的 building 、floor 和 room 参数。Time Series ID1 and ID4 are displayed as part of hierarchy H1 in the Azure Time Series Insights explorer because they have fully defined and correctly ordered building, floor, and room parameters.

其他 ID 分类到“无父实例”下,因为它们不符合指定的数据层次结构。 The others are classified under Unparented Instances because they don't conform to the specified data hierarchy.

时序模型类型Time Series Model types

时序模型类型可帮助你定义用于执行计算的变量或公式。 Time Series Model types help you define variables or formulas for doing computations. 类型与特定的时序见解实例相关联。Types are associated with a specific Time Series Insights instance.

一个类型可以包含一个或多个变量。A type can have one or more variables. 例如,某个时序模型实例的类型为“温度传感器”,其中包括变量“平均温度”、“最小温度”和“最大温度”。 For example, a Time Series Model instance might be of type Temperature Sensor, which consists of the variables avg temperature, min temperature, and max temperature.

Contoso 风力发电厂演示可视化了与相应实例关联的多个时序模型类型。The Contoso Wind Farm demo visualizes several Time Series Model types associated with their respective instances.

时序模型类型示例Time Series Model type example

提示

有关时序见解实例 API 和 CRUD 支持,请阅读数据查询一文和类型 API REST 文档For Time Series Insights Instance API and CRUD support, read the Data querying article and the Type API REST documentation.

Type 属性Type properties

时序模型类型由 idnamedescriptionvariables 定义。Time Series Model types are defined by id, name, description, and variables.

属性Property 说明Description
idid 类型的 UUID。The UUID for the type.
namename 用于提供类型名称的字符串。A string used to provide a name for the type.
descriptiondescription 类型的字符串说明。A string description for the type.
variablesvariables 指定与类型关联的变量。Specify variables associated with the type.

类型符合以下 JSON 示例:Types conform to the following JSON example:

{
  "types": [
    {
      "id": "1be09af9-f089-4d6b-9f0b-48018b5f7393",
      "name": "DefaultType",
      "description": "Default type",
      "variables": {
        "EventCount": {
          "kind": "aggregate",
          "value": null,
          "filter": null,
          "aggregation": {
            "tsx": "count()"
          }
        },
        "Interpolated Speed": {
          "kind": "numeric",
          "value": {
              "tsx": "$event.[speed].Double"
          },
          "filter": null,
          "interpolation": {
              "kind": "step",
              "boundary": {
                  "span": "P1D"
              }
          },
          "aggregation": {
              "tsx": "left($value)"
          }
        }
      }
    }
  ]
}

变量Variables

时序见解类型可能有多个变量,这些变量指定事件的公式和计算规则。Time Series Insights types might have many variables that specify formula and computation rules on events.

每个变量可以是以下三个种类之一:数字、分类和聚合。 Each variable can be one of three kinds: numeric, categorical, and aggregate.

  • “数字”种类适用于连续值。 Numeric kinds work with continuous values.
  • “分类”种类适用于一组定义的离散值。 Categorical kinds work with a defined set of discrete values.
  • “聚合”值组合单个种类(要么全为数字,要么全为分类)的多个变量。 Aggregate values combine multiple variables of a single kind (either all numeric or all categorical).

下表显示了每个变量种类的相关属性。The following table displays which properties are relevant for each variable kind.

时序模型变量表Time Series Model variable table

数字变量Numeric variables

变量属性Variable property 说明Description
变量筛选器Variable filter 筛选器是可选的条件子句,用于限制可在计算中考虑的行数。Filters are optional conditional clauses to restrict the number of rows being considered for computation.
变量值Variable value 来自设备或传感器的,或使用时序表达式进行转换的用于计算的遥测值。Telemetry values used for computation coming from the device or sensors or transformed by using Time Series Expressions. 数字种类变量的类型必须为 DoubleNumeric kind variables must be of the type Double.
变量内插Variable interpolation 内插指定如何使用现有数据重构信号。Interpolation specifies how to reconstruct a signal by using existing data. StepLinear 内插选项适用于数字变量。Step and Linear interpolation options are available for numeric variables.
变量聚合Variable aggregation 支持通过 AvgMinMaxSumCountFirstLast 和时间加权(AvgMinMaxSumLeft)运算符进行计算。Support computation through Avg, Min, Max, Sum, Count, First, Last and time-weighted (Avg, Min, Max, Sum, Left) operators.

变量符合以下 JSON 示例:Variables conform to the following JSON example:

"Interpolated Speed": {
  "kind": "numeric",
  "value": {
    "tsx": "$event.[speed].Double"
  },
  "filter": null,
  "interpolation": {
    "kind": "step",
    "boundary": {
      "span": "P1D"
    }
  },
  "aggregation": {
    "tsx": "left($value)"
  }
}

分类变量Categorical variables

变量属性Variable property 说明Description
变量筛选器Variable filter 筛选器是可选的条件子句,用于限制可在计算中考虑的行数。Filters are optional conditional clauses to restrict the number of rows being considered for computation.
变量值Variable value 来自设备或传感器的用于计算的遥测值。Telemetry values used for computation coming from the device or sensors. 分类种类变量的类型必须是 LongStringCategorical kind variables must be either Long or String.
变量内插Variable interpolation 内插指定如何使用现有数据重构信号。Interpolation specifies how to reconstruct a signal by using existing data. Step 内插选项适用于分类变量。The Step interpolation option is available for categorical variables.
变量类别Variable categories 类别在来自设备或传感器的值与某个标签之间创建映射。Categories create a mapping between the values coming from the device or sensors to a label.
变量的默认类别Variable default category 默认类别适用于“categories”属性中未映射的所有值。The default category is for all values that aren't being mapped in the "categories" property.

变量符合以下 JSON 示例:Variables conform to the following JSON example:

"Status": {
  "kind": "categorical",
  "value": {
     "tsx": "toLong($event.[Status].Double)"
},
  "interpolation": {
    "kind": "step",
    "boundary": {
      "span" : "PT1M"
    }
  },
  "categories": [
    {
      "values": [0, 1, 2],
      "label": "Good"
    },
    {
      "values": [3],
      "label": "Bad"
    }
  ],
  "defaultCategory": {
    "label": "Not Applicable"
  }
}

聚合变量Aggregate variables

变量属性Variable property 说明Description
变量筛选器Variable filter 筛选器是可选的条件子句,用于限制可在计算中考虑的行数。Filters are optional conditional clauses to restrict the number of rows being considered for computation.
变量聚合Variable aggregation 支持通过 AvgMinMaxSumCountFirstLast 进行计算。Support computation through Avg, Min, Max, Sum, Count, First, Last.

变量符合以下 JSON 示例:Variables conform to the following JSON example:

"Aggregate Speed": {
  "kind": "aggregate",
  "filter": null,
  "aggregation": {
    "tsx": "avg($event.Speed.Double)"
  }
}

变量存储在时序模型的类型定义中,可以通过查询 API 以内联方式提供,以重写存储的定义。Variables are stored in the type definition of a time series model and can be provided inline via Query APIs to override the stored definition.

后续步骤Next steps