為型別新增轉換

本指南說明如何在 Manufacturing Data Engine (MDE) 中,為特定型別新增轉換。

選擇轉換

MDE 提供多種轉換方式。預設設定套件提供兩種轉換,可與該預設設定套件中的任何類型建立關聯:

  • 群組事件變更轉換:這項轉換會監控代碼或代碼群組中的任何欄位,並在任何代碼中的受監控值變更時產生事件。這項轉換可以與任何原型的類型建立關聯。
  • 時間區間設定轉換:這項轉換會將時間區間設定函式套用至某類型的所有標記。視窗化是指在單一記錄中,彙整一段時間內的多筆記錄。視窗轉換可以與任何原型類型建立關聯。這項功能可摘要 1 分鐘到 60 分鐘的標籤記錄。轉換的結果是原始訊息,其中包含所選時間範圍內價值運算式的摘要值。

預設設定套件提供處理這兩項轉換所發出原始訊息所需的訊息類別、剖析器和型別。以下是處理各項「轉換」產生的原始訊息時,可用的兩種「類型」:

  • group-event-change-records:群組事件變更轉換的輸出訊息目的地類型。
  • window-transformation-records:Windowing Transformation 輸出訊息的目的地類型。

如要啟用「轉換」,請在「類型」網頁介面中選取指定的「轉換」,或使用 Configuration API 端點將其與「類型」建立關聯。

列出可用的轉換

如要在任何 MDE 系統中查看可用轉換的清單,請按照下列步驟操作:

REST

您可以使用專屬的 Configuration Manager API 端點,列出可用的轉換:

GET /configuration/v1/transformations

系統會傳回下列 JSON,其中包含可用的轉換及其功能:

{
  "transformations": [
    {
      "name": "eventChange",
      "displayName": "MDE Event Change",
      "description": "Monitors the value of one or more tag that has a common group key. Fires an event whenever any of the contributing tags changes its value",
      "disabled": false,
      "sample": {
        "keyExpression": {
          "displayName": "Key Expression",
          "description": "A SpEL expression that extracts the group key from the MDE message.proto which groups one or more tags as one unit whose values will be monitored for a change. The key must evaluate to a string",
          "value": "#message['tagName']"
        },
        "valueExpression": {
          "displayName": "Value Expression",
          "description": "A SpEL expression that extracts the value from the MDE message.proto to be monitored for a change. The value must evaluate to a string",
          "value": "#message['data']['numeric'].toString()"
        }
      }
    },
    {
      "name": "window",
      "displayName": "MDE Numeric Value Windowing",
      "description": "Create a periodic stats event that provides values such as average, min, and max for an expression that extracts a numeric value from the tag messages",
      "disabled": false,
      "sample": {
        "durationMinutes": {
          "displayName": "Window Duration in Minutes",
          "description": "A positive integer that represents how long the window will summarize events before producing the summary tag, this is in the granularity of minutes and it cannot be higher than 2 hours",
          "value": "1"
        },
        "valueExpression": {
          "displayName": "Value Expression",
          "description": "A SpEL expression that extracts the value from the MDE message.proto to be used as the numeric value of the tags that will be summarized. The value must evaluate to a number, and it's internally out",
          "value": "#message['data']['numeric']"
        },
        "id": {
          "displayName": "Window Unique ID",
          "description": "A unique ID that represents this instance of the window transformation, this should be unique if you are adding multiple instances of the window transformation to the same type",
          "value": "1-min-window"
        }
      }
    }
  ]
}

控制台

使用網頁介面,在「類型」部分下方,開啟特定類型的「編輯類型版本」選單,然後展開面板的「轉換及連結」部分。

轉換清單

將轉換與型別建立關聯

將任何現有類型與可用的轉換建立關聯後,系統會轉換該類型的所有代碼。轉換結果會以新標記的形式,併入「轉換類型」的 MDE。轉換後的標記名稱會採用新名稱,新名稱衍生自原始標記名稱和轉換名稱。

如要將「類型」與「轉換」建立關聯,請按照下列步驟操作:

REST

如要將轉換與指定型別建立關聯,請在這個 Configuration Manager API 端點中呼叫 PATCH 方法:

PATCH /configuration/v1/types/TYPE_NAME/versions/VERSION_NUMBER

要求的「主體」應包含要附加至類型的「轉換」清單,以及「設定參數」的值:

{
    "transformations": [
        {
            "window": {
                "id": "WINDOW_TRANSFORMATION_IDE",
                "durationMinutes": WINDOW_TRANSFORMATION_MINUTES,
                "valueExpression": "VALUE_EXPRESSION_VALUE"
            }
        },
        {
            "eventChange": {
                "keyExpression": "KEY_EXPRESSION_VALUE",
                "valueExpression": "VALUE_EXPRESSION_VALUE"
            }
        }
    ]
}

在先前的範例呼叫中,替換下列項目:

  • TYPE_NAME:要修改的型別名稱。
  • VERSION_NUMBER:要修改的 Type 版本。

在「Body」(主體) 中,將下列項目替換為設定視窗轉換的項目:

  • WINDOW_TRANSFORMATION_ID:轉換的專屬 ID,經過轉換處理後,也會附加至原始代碼名稱。
  • WINDOW_TRANSFORMATION_MINUTES:要套用時間範圍的長度 (以分鐘為單位)
  • VALUE_EXPRESSION_VALUE:標記原型中的元素,將做為值欄位監控。數字預設標記為 #message['data']['numeric']

在「Body」中,取代下列項目來設定事件變更轉換:

  • KEY_EXPRESSION_VALUE:代碼原型中的元素,用於將應一併監控的代碼分組。如要監控單一代碼,請使用 #message['tagName']
  • VALUE_EXPRESSION_VALUE:標記 proto 中的元素,用於監控值變更。必須解析為 String。在數值預設代碼中,#message['data']['numeric'].toString()

控制台

  1. 如要將「轉換」與類型建立關聯,請在「類型」分頁中開啟「編輯類型版本」網頁介面部分。

  2. 展開「轉換及連結」部分:

    轉換清單

  3. 如要新增「轉換」,請從清單中選取所需轉換,然後按一下「新增」

    轉換 ADD

  4. 接著提供必要參數,然後按一下「儲存」

    轉換參數

「視窗轉換」的參數如下:

  • WINDOW_TRANSFORMATION_ID:轉換的專屬 ID,經過轉換處理後,也會附加至原始代碼名稱。
  • WINDOW_TRANSFORMATION_MINUTES:要套用時間範圍的長度 (以分鐘為單位)
  • VALUE_EXPRESSION_VALUE:標記原型中的元素,將做為值欄位監控。數字預設標記為 #message['data']['numeric']

「事件變更轉換」的參數如下:

  • KEY_EXPRESSION_VALUE:代碼原型中的元素,用於將應一併監控的代碼分組。如要監控單一代碼,請使用 #message['tagName']
  • VALUE_EXPRESSION_VALUE:標記 proto 中的元素,用於監控值變更。必須解析為 String。在數值預設代碼中,#message['data']['numeric'].toString()