# PHM API Phase2
## anomaly detection/diagnostics
* Server Url: http://localhost:8001/api/Diagnostics
### 異常偵測建模(Internal use)
* /Anomaly/Detector/BuildModel
:::spoiler [POST]
#Request body
[Example Value]
{
"sensorId": "3fa85f64-5717-4562-b3fc-2c963f66afa"
}
[Example Schema]
{
sensorId: UUID, NOT NULL
}
#Responses
[201]
[Example Value]
{
"message": "Start building the anomaly detection model."
}
[Example Schema]
{
message: string
}
[400]
[Example Value]
{
"message": "Bad request."
}
[Example Schema]
{
message: string
}
[404]
[Example Value]
{
"message": "The sensor is not exist."
}
[Example Schema]
{
message: string
}
:::
### 異常偵測並診斷 (Internal use)
* /Anomaly/Detector/Detection
:::spoiler [POST]
#Request body
[Example Value]
{
"sensorId": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
}
[Example Schema]
{
sensorId: UUID, NOT NULL
}
#Responses
[200]
[Example Value]
{
"message": "The detection is normal and the event is created."
}
[201]
[Example Value]
{
"message": "The detection is anomaly and the event is created."
}
:::
### 資料蒐集與資料管理
* /Command/
:::spoiler [POST]
#Request body
[Example Value]
{
"physicalSensorId": "3fa85f64-5717-4562-b3fc-2c963f66afa",
"function": "build"
}
[Example Schema]
{
sensorId: UUID
function: string
}
#Responses
[201]
[Example Value]
{
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa"
}
[Example Schema]
{
message: string
}
[400]
[Example Value]
{
"message": "Bad request."
}
[Example Schema]
{
message: string
}
[500]
[Example Value]
{
"message": "Server can not connect the sensor $sensorId."
}
[Example Schema]
{
message: string
}
:::
:::spoiler [GET]
[Example Value]
[
{
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa",
"startTime": "2022-09-14T01:50:08.732687Z",
"endTime": "2022-09-14T01:50:08.732687Z",
"nextTime: "2022-09-14T01:50:08.732687Z",
"realEndTime: "2022-09-14T01:50:08.732687Z",
"status": started,
"receivedData": 20,
"totalData": 72,
"function": "monitor",
"physicalSensorId": "3fa85f64-5717-4562-b3fc-2c963f66afa",
"groupId": "3fa85f64-5717-4562-b3fc-2c963f66afa"
}
]
[Example Schema]
[
{
id: UUID
startTime: Time
endTime: Time
nextTime: Time
realEndTime
status: string
function: string
status: string //["started","pending","finished","unhealthy"]
sensorId: UUID
groupId: UUID
}
]
:::
* /Command/{id}/
:::spoiler [PATCH]
#Request body
[Example Value]
{
"receivedData": 21,
"nextTime": "2022-09-14T01:50:08.732687Z",
"realEndTime": "2022-09-14T01:50:08.732687Z",
"status": "started"
}
[Example Schema]
{
receivedData: string,
nextTime: Time,
realEndTime: Time,
status: string
}
#Responses
[201]
[Example Value]
{
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
}
[Example Schema]
{
id: UUID
}
[400]
[Example Value]
{
"message": "Bad request."
}
[Example Schema]
{
message: string
}
[404]
[Example Value]
{
"message": "The rule not found."
}
[Example Schema]
{
message: string
}
:::
* /SensorData/
:::spoiler [POST]
#Request body
[Example Value]
{
"sensorId": "3fa85f64-5717-4562-b3fc-2c963f66afa",
"commandId": "3fa85f64-5717-4562-b3fc-2c963f66afa",
"dataLength": "2s"
}
[Example Schema]
{
sensorId: UUID
dataLength: string //一筆資料的長度(ex: 2s)
}
#Responses
[201]
[Example Value]
{
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa"
"dataLength": "2s",
"rawData": "/root/",
"fftData": "/root/",
"oaData": int,
"healthType": "A",
"createdTime": "2022-09-14T01:50:08.732687Z",
"sensorId": "3fa85f64-5717-4562-b3fc-2c963f66afa",
"groupId": "3fa85f64-5717-4562-b3fc-2c963f66afa"
}
[Example Schema]
{
id: UUID
dataLength: string //一筆資料的長度(ex: 2s)
rawData: string //資料存放路徑
fftData: string //資料存放路徑
oaData: int
healthType: string
createdTime: Time
sensorId: UUID
groupId: UUID
}
[400]
[Example Value]
{
"message": "Bad request."
}
[Example Schema]
{
message: string
}
[500]
[Example Value]
{
"message": "Server can not connect the sensor $sensorId."
}
[Example Schema]
{
message: string
}
:::
:::spoiler [GET]
[Parameters]
{
groupId
}
[Example Value]
[
{
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa",
"dataLength": "2s",
"rawData": "/root/",
"fftData": "/root/",
"oaData": int,
"healthType": "A",
"createdTime": "2022-09-14T01:50:08.732687Z",
"sensorId": "3fa85f64-5717-4562-b3fc-2c963f66afa",
"groupId": "3fa85f64-5717-4562-b3fc-2c963f66afa"
}
]
[Example Schema]
[
{
id: UUID
sensorId: UUID
groupId: UUID
dataLength: string //一筆資料的長度(ex: 2s)
rawData: string //資料存放路徑,
fftData: string //資料存放路徑,
oaData: int
healthType: string
createdTime: Time
}
]
#Responses
[400]
[Example Value]
{
"message": "Bad request."
}
[Example Schema]
{
message: string
}
[404]
[Example Value]
{
"message": "Not found."
}
[Example Schema]
{
message: string
}
:::
* /SensorData/{id}/
:::spoiler [DELETE]
#Responses
[204]
[Example Value]
{
"message": "The sensor data has been delete."
}
[Example Schema]
{
message: string
}
:::
### 異常事件管理
* /Event/
:::spoiler [GET]
[Parameters]
{
floor,
anomalyType,
createdTime,
groupId
}
[Example Value]
[
{
"eventId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"serialNumber": "AAABBBCCC",
"buildingName": "立德大樓",
"floor": "9",
"anomalyType": "不平衡",
"faith": 56,
"alert": "true", //未解除
"alertLevel" 2,
"detectResult": "anomaly",
"trained": "false", //未訓練
"createdTime": "2022-09-14T01:50:08.732687Z",
"sensorId":3fa85f64-5717-4562-b3fc-2c963f66afa6",
"dataId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"groupId": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
}
]
[Example Schema]
[
{
eventId: UUID, NOT NULL,
serialNumber: string,
buildingName: string,
floor: string,
anomalyType: string,
faith: int,
alert: bool,
trained: bool, default:false
alertLevel: int,
OA: text,
FFT: text,
RAW: text,
detect: string,
createdTime: date time,
groupId: UUID
}
]
#Responses
[400]
[Example Value]
{
"message": "Bad request."
}
[Example Schema]
{
message: string
}
[404]
[Example Value]
{
"message": "Not found."
}
[Example Schema]
{
message: string
}
:::
:::spoiler [POST]
#Request body
[Example Value]
{
"anomalyType": "不平衡",
"alertLevel": 2, //If detect is normal, and then the alertLevel value will be a zero.
"detectResult": "anomaly",
"createdTime": "2022-09-14T01:50:08.732687Z",
"sensorId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"dataId": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
}
[Example Schema]
{
anomalyType: string
alertLevel: int
detectResult: string
createdTime: Time
sensorId: UUID, NOT NULL
dataId: UUID, NOT NULL
}
#Responses
[201]
[Example Value]
{
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
}
[Example Schema]
{
id: UUID
}
[400]
[Example Value]
{
"message": "Bad request."
}
[Example Schema]
{
message: string
}
:::
* /Event/{id}/
:::spoiler [PATCH]
#Request body
[Example Value]
{
"anomalyType": "不平衡",
"alert": "True" //未解除,
"trained": "False" //未訓練
}
[Example Schema]
{
anomalyType: string
alert: bool
trained: bool
}
#Responses
[201]
[Example Value]
{
"message": "The event is updated."
}
[Example Schema]
{
message: string
}
[404]
[Example Value]
{
"message": "The event not found."
}
[Example Schema]
{
message: string
}
:::
:::spoiler [DELETE]
#Responses
[204]
[Example Value]
{
"message": "The event has been deleted."
}
[Example Schema]
{
message: string
}
[404]
[Example Value]
{
"message": "The event not found."
}
[Example Schema]
{
message: string
}
:::
### 異常類別規則管理
* /Anomaly/Rule/Manage/
:::spoiler [GET]
[Parameters]
{
name,
anomalyType,
material,
lessThan15kWAlarm,
greaterThan15kWAlarm,
amplitude,
groupId
}
[Example Value]
[
{
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"name": "軸承變形-剛性",
"anomalyType": "不平衡",
"material": "剛性",
"logic": "and",
"lessThan15kWAlarm": 1.8,
"greaterThan15kWAlarm": 4.5,
"amplitude": [1,2],
"groupId": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
}
]
[Example Schema]
[
{
id: UUID,
name: string,
anomalyType: string,
material: string,
logic: string,
lessThan15kWAlarm: float,
greaterThan15kWAlarm: float,
amplitude: array,
groupId: UUID
}
]
#Responses
[400]
[Example Value]
{
"message": "Bad request."
}
[Example Schema]
{
message: string
}
[404]
[Example Value]
{
"message": "Not found."
}
[Example Schema]
{
message: string
}
:::
:::spoiler [POST]
#Request body
[Example Value]
[
{
"name": "軸承變形-剛性",
"anomalyType": "不平衡",
"material": "剛性",
"logic": "and",
"lessThan15kWAlarm": 1.8,
"greaterThan15kWAlarm": 4.5,
"amplitude": [1,2],
"groupId": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
}
]
[Example Schema]
[
{
name: string,
anomalyType: string,
material: string,
logic: string,
lessThan15kWAlarm: float,
greaterThan15kWAlarm: float,
amplitude: array,
groupId: UUID
}
]
#Responses
[201]
[Example Value]
{
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
}
[Example Schema]
{
id: UUID
}
[400]
[Example Value]
{
"message": "Bad request."
}
[Example Schema]
{
message: string
}
:::
* /Anomaly/Rule/Manage/{id}/
:::spoiler [PATCH]
#Request body
[Example Value]
{
"name": "軸承變形-剛性",
"anomalyType": "不平衡",
"material": "剛性",
"logic": "and",
"lessThan15kWAlarm": 1.8,
"greaterThan15kWAlarm": 4.5,
"amplitude": [1,2],
"groupId": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
}
[Example Schema]
{
name: string,
anomalyType: string,
material: string,
logic: string,
lessThan15kWAlarm: float,
greaterThan15kWAlarm: float,
amplitude: array,
groupId: UUID
}
#Responses
[201]
[Example Value]
{
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
}
[Example Schema]
{
id: UUID
}
[400]
[Example Value]
{
"message": "Bad request."
}
[Example Schema]
{
message: string
}
[404]
[Example Value]
{
"message": "The rule not found."
}
[Example Schema]
{
message: string
}
:::
:::spoiler [DELETE]
#Responses
[204]
[Example Value]
{
"message": "The rule has been deleted."
}
[Example Schema]
{
message: string
}
[404]
[Example Value]
{
"message": "The rule not found."
}
[Example Schema]
{
message: string
}
:::
### 異常類別診斷
* /Anomaly/Rule/
:::spoiler [POST]
#Request body
[Example Value]
[
{
"sensorDataId": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
}
]
[Example Schema]
[
{
sensorDataId: UUID
ruleId: UUID
}
]
#Responses
[201]
[Example Value]
{
"anomalyType": "不平衡"
}
[Example Schema]
{
anomalyType: string
}
[400]
[Example Value]
{
"message": "Bad request."
}
[Example Schema]
{
message: string
}
:::
---
* PHM 與EdgeX 溝通的API
* PHM 添加 Sensor 的API
* 下command要資料
* 偵測建模需要的天數,是否會更動?
* 異常偵測建模是否針對單一sensor相同group,或是相同group可以使用不同sensor?
* create a table for building the model
* machine and equipment 是否該擁有type欄位來區別 ex:冰水機 or 熱水機
* rule table and rule api
* 計算下次查看command table 的時間
* 開關機維持command的運作(目前設計為每1分鐘檢查command table是否有到期但尚未執行的command)
* 關機時間過長是否會影響建模的資料數
* rule 類別如何建立 流程?
## issue
* Q1. 依據PES的文件在異常偵測模型建模時就會需要sensor所屬設備中的轉速、馬達功率、基底材質,但在UX的文件中,sensor在進行建模時尚未被設備添加進入設備中故拿不到這些數值。
###### tags: `PHM` `anomaly` `detection` `diagnostics`