MXL - Meddle式言語
**MXL(Meddle Expression Language)**は、Meddleコネクタで条件とロジックを定義するために使用されるシンプルな式言語です。
使用場所:
MXL式は、ペイロードデータに基づいてブール値(真/偽)に評価されます。
フィールド名 演算子 値temperature > 80pressure < 10status == "active"count != 0| 演算子 | 説明 | 例 |
|---|---|---|
> | より大きい | temperature > 80 |
< | より小さい | pressure < 10 |
>= | 以上 | humidity >= 60 |
<= | 以下 | speed <= 100 |
== | 等しい | status == "active" |
!= | 等しくない | count != 0 |
| 演算子 | 説明 | 例 |
|---|---|---|
&& | AND(両方の条件が真である必要がある) | temp > 80 && press < 10 |
| ` | ` |
数値を比較:
temperature > 25.5pressure >= 101.3count == 100speed != 0文字列値を比較(二重引用符を使用):
status == "active"mode != "manual"error_code == "E001"ブール値を比較:
enabled == truefault != falseANDを使用した複数の条件
Section titled “ANDを使用した複数の条件”すべての条件が真である必要があります:
temperature > 20 && temperature < 30pressure > 100 && humidity < 80 && status == "running"ORを使用した複数の条件
Section titled “ORを使用した複数の条件”少なくとも1つの条件が真である必要があります:
temperature > 80 || pressure > 150status == "error" || status == "fault" || status == "stopped"ANDとORの組み合わせ
Section titled “ANDとORの組み合わせ”グループ化には括弧を使用(サポートされている場合):
(temperature > 80 || pressure > 150) && status == "active"一般的なパターン
Section titled “一般的なパターン”範囲チェック
Section titled “範囲チェック”値が範囲内にあるかチェック:
temperature >= 20 && temperature <= 30しきい値アラート
Section titled “しきい値アラート”値がしきい値を超えたときにアラート:
temperature > 80pressure > 150vibration > 5.0ステータス監視
Section titled “ステータス監視”特定のステータス値をチェック:
status == "error"status != "running"mode == "manual"マルチパラメータアラート
Section titled “マルチパラメータアラート”複数の条件でアラート:
temperature > 100 || pressure > 150 || vibration > 5安全インターロック
Section titled “安全インターロック”複数の条件が満たされていることを確認:
temperature > 50 && pressure > 100 && flow > 10ユースケース別の例
Section titled “ユースケース別の例”// 高温アラートtemperature > 80
// 温度が範囲外temperature < 15 || temperature > 35
// 圧力を伴う臨界温度temperature > 100 && pressure > 150機器ステータス
Section titled “機器ステータス”// マシンが予期せず停止status == "stopped" && runtime > 0
// エラー状態status == "error" || status == "fault"
// 自動モードではないmode != "auto"// 欠陥検出defect_count > 0
// 仕様外dimension < 9.9 || dimension > 10.1
// 複数の品質パラメータhardness < 50 || surface_finish > 2.0 || weight < 100プロセス制御
Section titled “プロセス制御”// プロセスが制御不能temperature > 90 || pressure < 95 || flow < 50
// 安定した動作temperature >= 80 && temperature <= 85 && pressure > 100
// 緊急停止条件temperature > 120 || pressure > 200 || vibration > 10// 異常検出is_anomaly == true
// 高い異常スコアanomaly_score > 0.8
// 複数の指標vibration > 5 || temperature > 90 || anomaly_score > 0.7ベストプラクティス
Section titled “ベストプラクティス”1. 明確なフィールド名を使用
Section titled “1. 明確なフィールド名を使用”// 良いtemperature > 80machine_status == "running"
// 避けるt > 80s == "r"2. 適切な演算子を使用
Section titled “2. 適切な演算子を使用”// 等しいかどうかには==を使用status == "active"
// 等しくないかどうかには!=を使用count != 03. 関連する条件をグループ化
Section titled “3. 関連する条件をグループ化”// 良い - 関連する条件を一緒にtemperature > 80 && pressure > 150
// 良い - 代替条件status == "error" || status == "fault"4. 演算子の優先順位を考慮
Section titled “4. 演算子の優先順位を考慮”AND(&&)はOR(||)よりも優先順位が高い:
// これは(A && B) || Cをチェックtemperature > 80 && pressure > 150 || humidity > 90
// 明確にするために括弧を使用(temperature > 80 && pressure > 150) || humidity > 905. 式をテスト
Section titled “5. 式をテスト”さまざまな入力値で式をテストして、期待どおりに動作することを確認します。
- 算術演算なし:
temperature + 10 > 90はできません - 関数呼び出しなし:
abs(temperature) > 80はできません - ネストされたフィールドアクセスなし:
sensor.temperature > 80はできません - 文字列比較のみ: 正規表現やパターンマッチングなし
トラブルシューティング
Section titled “トラブルシューティング”式がトリガーされない
Section titled “式がトリガーされない”チェック:
- フィールド名がペイロードと正確に一致する(大文字小文字を区別)
- データ型が一致する(数値vs文字列)
- 演算子が正しい(
==であって=ではない) - 文字列値が二重引用符で囲まれている
常にトリガーされる
Section titled “常にトリガーされる”チェック:
- ロジックが正しい(ANDvsOR)
- しきい値が適切
- フィールドがペイロードに存在する
一般的なエラー:
==の代わりに=を使用- 文字列の周りの引用符が欠落
- フィールド名のタイプミス
- 演算子の優先順位が間違っている
コンテキスト内の例
Section titled “コンテキスト内の例”Triggerコネクタ
Section titled “Triggerコネクタ”{ "type": "MeddleTrigger", "config": { "mode": "DirectDispatch", "condition": "temperature > 80 && status == \"active\"", "payload": { "alert": "high_temperature" } }}Alertコネクタ
Section titled “Alertコネクタ”{ "type": "MeddleAlert", "config": { "name": "Critical Alert", "condition": "temperature > 100 || pressure > 200", "minDuration": 10, "cooldown": 300, "notification": { "type": "Email", "toEmails": ["alerts@example.com"] } }}関連ドキュメント
Section titled “関連ドキュメント”- Triggerコネクタ - 条件付きロジックにMXLを使用
- Alertコネクタ - アラート条件にMXLを使用
- 異常検知 - インテリジェントアラートのためにMXLと組み合わせる