# MO API 格式 (2023/02/21)
[TOC]
## Object API
#### **[POST]** /v1/object
* Request
```
{
"object_type" : string,
"name" : string,
"object_id" : string,
"templates" : [
{
"template": "ac_comfort_template",
"template_name" : "name show on UI",
"feature" : {
"example_field1" : "cold",
"example_field2" : null, #使用者沒有填的空欄位填null
...
},
"goal_setting" : [{}, {}, ...],
"active" : bool,
"datasource":{
"storage_name":"db123",
"type":"influxdb",
"config":{
"database":"8adbf4ba-0468-4949-861a-ece029218761",
"username":"0d3db427-588f-4716-96e4-6d967ebdd5cb",
"password":"N2fvaFBAIbzPiC5k3pJxGN1kt",
"host":"60.250.255.134",
"port":8086
}
}
},
{
"template": "other_template",
"template_name" : "name show on UI",
"feature" : { ... },
"goal_setting" : [{}, {}, ...],
"active" : bool,
"datasource": {}
}
]
}
```
* Response
```
# 正確新增object
{
"errCode" : 200,
"data" : "success"
}
# 新增object時有錯誤
{
"errCode" : 600
"data" : string # explain why error happens
}
```
#### **[PUT]** /v1/object/{object_id}
* Request
```
{
"object_type" : string,
"name" : string,
"object_id" : string,
"templates" : [
{
"template": "ac_comfort_template",
"template_name" : "name show on UI",
"feature" : {
"example_field1" : "cold",
"example_field2" : 100,
...
},
"goal_setting" : [{}, {}, ...],
"active" : bool,
"datasource:{
"storage_name":"db123",
"type":"influxdb",
"config":{
"database":"8adbf4ba-0468-4949-861a-ece029218761",
"username":"0d3db427-588f-4716-96e4-6d967ebdd5cb",
"password":"N2fvaFBAIbzPiC5k3pJxGN1kt",
"host":"60.250.255.134",
"port":8086
}
}
},
{
"template": "other_template",
"template_name" : "name show on UI",
"feature" : { ... },
"goal_setting" : [{}, {}, ...],
"active" : bool,
"datasource": {}
}
]
}
```
* Response
```
# 正確更改object
{
"errCode" : 200,
"data" : "success"
}
# 更改object時有錯誤
{
"errCode" : int, # define yourself
"data" : string # explain why error happens
}
```
#### **[DELETE]** /v1/object
* Request
```
{
"object_ids" : [] # object_id string array
}
```
* Response
```
# 正確刪除object
{
"errCode" : 200,
"data" : "success"
}
# 刪除object時有錯誤
{
"errCode" : 600,
"data" : string # explain why error happens
}
```
#### **[GET]** /v1/object/status/{object_id}
* 等goal setting更改好以及模型管理API完成再回頭串
* Response
```
{
"errCode" : 200,
"data" : {
"templates" : [
{
"template" : string,
"template_name" : "name show on UI",
"status": string,
"model_name" : string,
"prediction_time" : string
},
{
"template" : string,
"template_name" : "name show on UI",
"status": string,
"model_name" : string,
"prediction_time" : string
},
{
"template" : string,
"template_name" : "name show on UI",
"status": string,
"model_name" : string,
"prediction_time" : string
}
]
}
}
# Get object status 有錯誤
{
"errCode" : 600
"data" : string # explain why error happens
}
```
#### **[GET]** /v1/object/info/{object_id}
* /v1/object: 建立新的object需要的欄位,(每個template傳一組goal_setting即可)
* /v1/object/info/{object_id} : 拿到已建立好的object欄位值
* Response
```
{
"errCode" : 200,
"data" : {
"object_type" : string,
"name" : string,
"object_id" : string,
"templates" : [
{
"template": "ac_comfort_template",
"template_name" : "name show on UI",
"feature" : { ... },
"goal_setting" : [{}, {}, ...],
"active" : bool
},
{
"template": "other_template",
"template_name" : "name show on UI",
"feature" : { ... },
"goal_setting" : [{}, {}, ...],
"active" : bool
}
]
}
}
# Get object 有錯誤
{
"errCode" : 600
"data" : string # explain why error happens
}
```
**Note : feature、goal_setting,欄位格式如下範例**
```
"featue" : {
"ac_switch" : {
"select_type" : "fixed" or "datasource" 固定欄位或是從datasource
"name" : "辦公區空調開關", # 欄位顯示名稱
"value" : null, # 可填預設或空值 (使用者輸入後則會取代)
"need" : true, # 是否必填
"type" : bool, # 資料型態 (bool, string, int, float, time, option、multi-option)
# time格式 : "08:00" 24H,一個小時為單位
"option" : { # 如果資料型態為option,需提供選項內容,以及存下對應的string or int
"星期一" : 1
"星期二" : Tuesday,
},
"limit" : [0, 100] # 如果資料型態為int or float,需提供上下限
"description" : "", # 欄位下面的說明文字
}
}
```
## [AI TEMPLATE]
1. AI Template分設備分AI應用,倆倆都不同
- Ex: 大型空調的能源預測 跟 冰機的能源預測 欄位就會不一樣
2. 大型空調:
+ AC Thermal Comfort Optimization
+ AC Energy Demand Prediction
3. 冰機:
+ Chiller Energy Demand Prediction
#### **1. Thermal Comfort Optimization**
```
{
"template": "air_conditioning_system-energy_consumption_prediction",
"template_name": "Energy Consumption Prediction",
"feature": {
"ac_switch": {
"name": "AC Switch",
"select_type": "datasource",
"value": null,
"need": True,
"type": "string",
"option": {},
"description": ""
},
"ac_temp": {
"name": "AC Temperature",
"select_type": "datasource",
"value": null,
"need": True,
"type": "string",
"option": {},
"description": ""
},
"ac_wind": {
"name": "AC Wind Speed",
"select_type": "datasource",
"value": null,
"need": True,
"type": "string",
"option": {},
"description": ""
},
"indoor_temp": {
"name": "Indoor Temperature",
"select_type": "datasource",
"value": null,
"need": True,
"type": "string",
"option": {},
"description": ""
},
"indoor_humid": {
"name": "Indoor Humidity",
"select_type": "datasource",
"value": null,
"need": True,
"type": "string",
"option": {},
"description": ""
},
"outdoor_temp": {
"name": "Outdoor Temperature",
"select_type": "datasource",
"value": null,
"need": False,
"type": "string",
"option": {},
"description": "Model performance may be affected if the field is blank"
},
"outdoor_humid": {
"name": "Outdoor Humidity",
"select_type": "datasource",
"value": null,
"need": False,
"type": "string",
"option": {},
"description": "Model performance may be affected if the field is blank"
},
"ac_power": {
"name": "AC Power",
"select_type": "datasource",
"value": null,
"need": False,
"type": "string",
"option": {},
"description": ""
},
"ac_mode": {
"name": "AC Mode",
"select_type": "datasource",
"value": null,
"need": False,
"type": "string",
"option": {},
"description": ""
},
"outdoor_air_quality": {
"name": "Outdoor Air Quality",
"select_type": "datasource",
"value": null,
"need": False,
"type": "string",
"option": {},
"description": ""
},
"indoor_air_quality": {
"name": "Indoor Air Quality",
"select_type": "datasource",
"value": null,
"need": False,
"type": "string",
"option": {},
"description": ""
}
},
"goal_setting": {
"thermal_comfort_zone": {
"name": "Thermal Comfort Zone",
"select_type": "fixed",
"value": null,
"need": True,
"type": "multi-option",
"option": {
"冷": 1,
"稍冷": 2,
"舒適偏冷": 3,
"適中": 4,
"舒適偏熱": 5,
"稍熱": 6,
"熱": 7
},
"description": ""
},
"week": {
"name": "Week",
"select_type": "fixed",
"value": null,
"need": True,
"type": "multi-option",
"option": {
"Monday": 1,
"Tuesday": 2,
"Wednesday": 3,
"Thursday": 4,
"Friday": 5,
"Saturday": 6,
"Sunday": 7
},
"description": ""
},
"start_time": {
"name": "Start",
"select_type": "",
"value": null,
"need": True,
"type": "time",
"option": {},
"description": ""
},
"end_time": {
"name": "End",
"select_type": "",
"value": null,
"need": True,
"type": "time",
"option": {},
"description": ""
}
}
}
```
#### **2. Air Conditioning - Energy Consumption Prediction**
```
{
"template": "air_conditioning_system-thermal_comfort_optimization",
"template_name": "Thermal Comfort Optimization"
"feature": {
"pred_freq": {
"name": "Prediction Frequency",
"select_type": "fixed",
"value": null,
"need": True,
"type": "option",
"option": {
"Daily": "day",
"Hourly": "hour"
},
"description": ""
},
"load_rate": {
"name": "Load Rate",
"select_type": "datasource",
"value": null,
"need": True,
"type": "string",
"option": {},
"description": ""
},
"indoor_temp": {
"name": "Indoor Temperature",
"select_type": "datasource",
"value": null,
"need": False,
"type": "string",
"option": {},
"description": "Model performance may be affected if the field is blank"
},
"indoor_humid": {
"name": "Indoor Humidity",
"select_type": "datasource",
"value": null,
"need": False,
"type": "string",
"option": {},
"description": "Model performance may be affected if the field is blank"
},
"outdoor_temp": {
"name": "Outdoor Temperature",
"select_type": "datasource",
"value": null,
"need": False,
"type": "string",
"option": {},
"description": "Model performance may be affected if the field is blank"
},
"outdoor_humid": {
"name": "Outdoor Humidity",
"select_type": "datasource",
"value": null,
"need": False,
"type": "string",
"option": {},
"description": "Model performance may be affected if the field is blank"
}
},
"goal_setting": {
"mild_threshold": {
"name": "Mild warning threshold",
"select_type": "",
"value": null,
"need": True,
"type": "int",
"option": {},
"limit": [
0,
1000000
],
"description": ""
},
"moderate_threshold": {
"name": "Moderate warning threshold",
"select_type": "",
"value": null,
"need": True,
"type": "int",
"option": {},
"limit": [
0,
1000000
],
"description": ""
},
"severe_threshold": {
"name": "Severe warning threshold",
"select_type": "",
"value": null,
"need": True,
"type": "int",
"option": {},
"limit": [
0,
1000000
],
"description": ""
},
"week": {
"name": "Week",
"select_type": "fixed",
"value": null,
"need": True,
"type": "multi-option",
"option": {
"Monday": 1,
"Tuesday": 2,
"Wednesday": 3,
"Thursday": 4,
"Friday": 5,
"Saturday": 6,
"Sunday": 7
},
"description": ""
},
"start_time": {
"name": "Start",
"select_type": "",
"value": null,
"need": True,
"type": "time",
"option": {},
"description": ""
},
"end_time": {
"name": "End",
"select_type": "",
"value": null,
"need": True,
"type": "time",
"option": {},
"description": ""
}
}
}
```
#### **3. Chiller - Energy Demand Prediction**
```
{
"template": "chiller_system-energy_demand_prediction",
"template_name": "Energy Consumption Prediction",
"feature": {
"pred_freq": {
"name": "Prediction Frequency",
"select_type": "fixed",
"value": null,
"need": True,
"type": "option",
"option": {
"Daily": "day",
"Hourly": "hour"
},
"description": ""
},
"load_rate": {
"name": "Load Rate",
"select_type": "datasource",
"value": null,
"need": True,
"type": "string",
"option": {},
"description": ""
},
"inlet_temp": {
"name": "Inlet Water Temperature",
"select_type": "datasource",
"value": null,
"need": True,
"type": "string",
"option": {},
"description": ""
},
"outlet_temp": {
"name": "Outlet Water Temperature",
"select_type": "datasource",
"value": null,
"need": True,
"type": "string",
"option": {},
"description": ""
},
"indoor_temp": {
"name": "Indoor Temperature",
"select_type": "datasource",
"value": null,
"need": False,
"type": "string",
"option": {},
"description": "Model performance may be affected if the field is blank"
},
"indoor_humid": {
"name": "Indoor Humidity",
"select_type": "datasource",
"value": null,
"need": False,
"type": "string",
"option": {},
"description": "Model performance may be affected if the field is blank"
},
"outdoor_temp": {
"name": "Outdoor Temperature",
"select_type": "datasource",
"value": null,
"need": False,
"type": "string",
"option": {},
"description": "Model performance may be affected if the field is blank"
},
"outdoor_humid": {
"name": "Outdoor Humidity",
"select_type": "datasource",
"value": null,
"need": False,
"type": "string",
"option": {},
"description": "Model performance may be affected if the field is blank"
}
},
"goal_setting": {
"mild_threshold": {
"name": "Mild warning threshold",
"select_type": "",
"value": null,
"need": True,
"type": "int",
"option": {},
"limit": [
0,
1000000
],
"description": ""
},
"moderate_threshold": {
"name": "Moderate warning threshold",
"select_type": "",
"value": null,
"need": True,
"type": "int",
"option": {},
"limit": [
0,
1000000
],
"description": ""
},
"severe_threshold": {
"name": "Severe warning threshold",
"select_type": "",
"value": null,
"need": True,
"type": "int",
"option": {},
"limit": [
0,
1000000
],
"description": ""
},
"week": {
"name": "Week",
"select_type": "fixed",
"value": null,
"need": True,
"type": "multi-option",
"option": {
"Monday": 1,
"Tuesday": 2,
"Wednesday": 3,
"Thursday": 4,
"Friday": 5,
"Saturday": 6,
"Sunday": 7
},
"description": ""
},
"start_time": {
"name": "Start",
"select_type": "",
"value": null,
"need": True,
"type": "time",
"option": {},
"description": ""
},
"end_time": {
"name": "End",
"select_type": "",
"value": null,
"need": True,
"type": "time",
"option": {},
"description": ""
}
}
}
```
#### **4. Object example - air_conditioning_system**
```
example = {"object_type":"air_conditioning_system",
"name": "test_object",
"object_id":"id1234",
"templates":[
{
"template": "air_conditioning_system-thermal_comfort_optimization",
"template_name": "air_conditioning_system-thermal_comfort_optimization",
"feature":{
"ac_switch": "HistRawData_a650f1b2-46e1-46a2-b4f2-5b99fb5d1ccd_辦公區空調開關數值",
"ac_temp": "HistRawData_a650f1b2-46e1-46a2-b4f2-5b99fb5d1ccd_辦公區空調溫度數值",
"ac_wind": "HistRawData_a650f1b2-46e1-46a2-b4f2-5b99fb5d1ccd_辦公區空調風速數值",
"indoor_temp": "HistRawData_a650f1b2-46e1-46a2-b4f2-5b99fb5d1ccd_室內溫度",
"indoor_humid": "HistRawData_a650f1b2-46e1-46a2-b4f2-5b99fb5d1ccd_室內溼度",
"outdoor_temp": "HistRawData_a650f1b2-46e1-46a2-b4f2-5b99fb5d1ccd_溫度",
"outdoor_humid": "HistRawData_a650f1b2-46e1-46a2-b4f2-5b99fb5d1ccd_濕度",
"ac_power": "HistRawData_a650f1b2-46e1-46a2-b4f2-5b99fb5d1ccd_辦公室空調用電",
"ac_mode": null,
"outdoor_air_quality":null,
"indoor_air_quality":null
},
"goal_setting":[
{
"thermal_comfort_zone":[3,4],
"week":[1,2,3,4,5],
"start_time":"08:00",
"end_time":"18:00"
}
],
"active": True,
"datasource":{
"storage_name":"db123",
"type":"influxdb",
"config":{
"database":"8adbf4ba-0468-4949-861a-ece029218761",
"username":"0d3db427-588f-4716-96e4-6d967ebdd5cb",
"password":"N2fvaFBAIbzPiC5k3pJxGN1kt",
"host":"60.250.255.134",
"port":8086
}
}
},
{
"template": "air_conditioning_system-energy_consumption_prediction",
"template_name": "air_conditioning_system-energy_consumption_prediction",
"feature":{
"pred_freq": "hour",
"load_rate": "HistRawData_a650f1b2-46e1-46a2-b4f2-5b99fb5d1ccd_辦公室空調用電",
"indoor_temp": "HistRawData_a650f1b2-46e1-46a2-b4f2-5b99fb5d1ccd_室內溫度",
"indoor_humid": "HistRawData_a650f1b2-46e1-46a2-b4f2-5b99fb5d1ccd_室內溼度",
"outdoor_temp": "HistRawData_a650f1b2-46e1-46a2-b4f2-5b99fb5d1ccd_溫度",
"outdoor_humid": "HistRawData_a650f1b2-46e1-46a2-b4f2-5b99fb5d1ccd_濕度"
},
"goal_setting":[
{
"mild_threshold": 70,
"moderate_threshold": 100,
"severe_threshold": 200,
"week":[1,2,3,4,5],
"start_time":"08:00",
"end_time":"18:00"
},
{
"mild_threshold": 50,
"moderate_threshold": 80,
"severe_threshold": 100,
"week":[6,7],
"start_time":"08:00",
"end_time":"18:00"
},
],
"active": True,
"datasource":{
"storage_name":"db123",
"type":"influxdb",
"config":{
"database":"8adbf4ba-0468-4949-861a-ece029218761",
"username":"0d3db427-588f-4716-96e4-6d967ebdd5cb",
"password":"N2fvaFBAIbzPiC5k3pJxGN1kt",
"host":"60.250.255.134",
"port":8086
}
}
}
]
}
```
#### **5. Object example - chiller_system**
```
example3 = {"object_type":"chiller_system",
"name": "test_object4",
"object_id":"id999",
"templates":[
{
"template": "chiller_system-energy_demand_prediction",
"template_name": "chiller_system-energy_demand_prediction",
"feature":{
"pred_freq": "hour",
"load_rate": "HistRawData_a650f1b2-46e1-46a2-b4f2-5b99fb5d1ccd_辦公室空調用電",
"inlet_temp": "HistRawData_a650f1b2-46e1-46a2-b4f2-5b99fb5d1ccd_室內溫度",
"outlet_temp": "HistRawData_a650f1b2-46e1-46a2-b4f2-5b99fb5d1ccd_室內溫度",
"indoor_temp": "HistRawData_a650f1b2-46e1-46a2-b4f2-5b99fb5d1ccd_室內溫度",
"indoor_humid": "HistRawData_a650f1b2-46e1-46a2-b4f2-5b99fb5d1ccd_室內溼度",
"outdoor_temp": null,
"outdoor_humid": null
},
"goal_setting":[
{
"mild_threshold": 70,
"moderate_threshold": 80,
"severe_threshold": 90,
"week":[1,2,3,4],
"start_time":"00:00",
"end_time":"18:00"
},
{
"mild_threshold": 100,
"moderate_threshold": 110,
"severe_threshold": 120,
"week":[4],
"start_time":"20:00",
"end_time":"23:00"
},
],
"active": True,
"datasource":{
"storage_name":"db123",
"type":"influxdb",
"config":{
"database":"8adbf4ba-0468-4949-861a-ece029218761",
"username":"0d3db427-588f-4716-96e4-6d967ebdd5cb",
"password":"N2fvaFBAIbzPiC5k3pJxGN1kt",
"host":"60.250.255.134",
"port":8086
}
}
}
]
}
```
## Model API
#### [Post] v1/model/train
* 說明 : save and train model
* Request:
```
{
"project_id" : int,
"model_id" : string, # unique
"name" : string,
"template" : string,
"dataset" : [
{
"object_id" : string
},
{
"object_id" : string
}
]
}
```
* Response:
```
# 正確 add model and train
{
"errCode" : 200,
"data" : "success"
}
# 錯誤
{
"errCode" : 600,
"data" : string # explain why error happens
}
```
#### [Put] v1/model/rename
* 說明 : rename model
* Request:
```
{
"model_id": string,
"name": string
}
```
* Response:
```
# 正確 rename model
{
"errCode" : 200,
"data" : "success"
}
# 錯誤
{
"errCode" : 600,
"data" : string # explain why error happens
}
```
#### [Put] v1/model/train
* 說明 : edit model
* Request:
```
{
"model_id" : string, # unique
"name" : string,
"template" : string,
"dataset" : [
{
"object_id" : string
},
{
"object_id" : string
}
]
}
```
* Response:
```
# 正確 update model and train
{
"errCode" : 200,
"data" : "success"
}
# 錯誤
{
"errCode" : 600,
"data" : string # explain why error happens
}
```
#### [Post] v1/model/deploy
* 說明 : deploy model
* Request:
```
{
"model_id" : string, # unique
"template" : string,
"dataset" : [
{
"object_id" : string
},
{
"object_id" : string
}
]
}
```
* Response:
```
# 正確 deploy model
{
"errCode" : 200,
"data" : "success"
}
# 錯誤
{
"errCode" : 600,
"data" : string # explain why error happens
}
```
#### [Delete] v1/model/delete
* 說明 : delete model
* Request:
```
{
"models" : [
{
"model_id" : string,
"template" : string
},
{
"model_id" : string,
"template" : string
}
]
}
```
* Response:
```
# 正確 delete model
{
"errCode" : 200,
"data" : "success"
}
# 錯誤
{
"errCode" : 600,
"data" : string # explain why error happens
}
```
#### [Post] v1/model/status
* 說明 : model的training status
* Request :
```
{
"models" : [
{
"model_id" : string,
"template" : string
},
{
"model_id" : string,
"template" : string
}
]
}
```
* Response :
```
{
"errCode" : 200,
"data" : {
"models":[
{
"model_id" : string,
"params": [
{
"index": string,
"value": float
},
{
"index": string,
"value": float,
"predict": []float, # 預測每隔一小時或一天後的資料,按照順序
"freq": string # day or hour
}
],
"train" : {
"training_status" : string, #status : Success、Running、Fail
"training_result" : string,
"last_training_start_time" : string,
"last_training_finish_time": string
}
},
{
"model_id" : string,
"params": [],
"train" : {
"training_status" : string,
"training_result" : string,
"last_training_start_time" : string,
"last_training_finish_time" : string
}
}
]
}
}
Example:
{
"errCode" : 200,
"data" : {
"models":[
{
"model_id" : 'test_thermal_comfort',
"params": [
{
"index": "r2",
"value": 0.9982897258187522,
},
{ "index": "rmse",
"value": 0.17305151433941773,
}
],
"train" : {
"training_status" : 'success',
"training_result" : '{"r2": 0.9982897258187522, "rmse": 0.17305151433941773}',
"last_training_start_time" : 'string',
"last_training_finish_time": 'string'
}
},
{
"model_id" : 'test_forecasting',
"params": [
{
"index": "rmse",
"value": 3.252483, # average of 6 value
"predict": [2.9695, 3.0125, 3.2181, 3.3828, 3.3414, 3.5906],
"freq": 'hour'
}
],
"train" : {
"training_status" : 'success',
"training_result" : '{"1hr": 2.9695, "2hr": 3.0125, "3hr": 3.2181, "4hr": 3.3828, "5hr": 3.3414, "6hr": 3.5906}',
"last_training_start_time" : 'string',
"last_training_finish_time" : 'string'
}
}
]
}
}
```
## Log API
#### [Get] v1/log/setting/project_id
* Response :
```
{
"errCode" : 200,
"data" : {
"event_type" : []string
"scenario": []string
}
}
```
#### [Post] v1/log/filter
* Resuest :
```
{
"project_id": int,
"filter": {
"event_type": []string,
"from": int, #從第幾筆開始顯示
"to": int, #到第幾筆結束
"scenario" : string, #template
"search_model": string, #search model name
"time_range": []string,
"order": {
"by": string, #time, scenario, event_type or model_name
"method": string #排序 : ASC、DSC
}
}
}
```
* Response :
```
{
"errCode" : 200,
"data" : {
"result": [
{
"time": timestamp,
"scenario": string,
"event_type": string,
"model_name": string,
"event": string
}
],
"total_count": int
}
}