POST
/api/analytics/arithmetic
分析模組
基本運算
示範用的最基本運算,驗證資料從前端送入、由分析引擎計算、再回傳的完整流程。
權限:目前免驗證(正式版需 Token)
輸入參數
| 欄位 | 型別 | 必填 | 說明 |
|---|---|---|---|
a |
number | 是 | 數字 A |
op |
string | 是 | 運算:add / subtract / multiply / divide |
b |
number | 是 | 數字 B(op=divide 時不可為 0) |
請求範例
curl -X POST https://api.boshanweb.com/api/analytics/arithmetic \
-H 'Content-Type: application/json' \
-d '{"a":12.5,"op":"divide","b":4}'成功回傳
{
"ok": true,
"id": "...",
"type": "arithmetic",
"result": {
"operation": "divide",
"a": 12.5,
"b": 4,
"result": 3.125
},
"duration_ms": 92
}
POST
/api/analytics/statistics
分析模組
敘述統計
輸入一組數字,回傳平均數、變異數、標準差、最大最小值、偏態與峰態。
權限:目前免驗證(正式版需 Token)
輸入參數
| 欄位 | 型別 | 必填 | 說明 |
|---|---|---|---|
data |
number[] | 是 | 數值陣列,長度 3 至 100000 |
請求範例
curl -X POST https://api.boshanweb.com/api/analytics/statistics \
-H 'Content-Type: application/json' \
-d '{"data":[4,8,15,16,23,42]}'成功回傳
{
"ok": true,
"id": "...",
"type": "statistics",
"result": {
"mean": 18,
"variance": 182,
"stddev": 13.49074,
"min": 4,
"max": 42,
"skewness": 1.24261,
"kurtosis": 1.79975,
"nobs": 6
},
"duration_ms": 88
}
POST
/api/analytics/correlation
分析模組
相關分析
輸入兩組等長數列,回傳相關係數 r(−1 ~ 1)與判定係數 R²。
權限:目前免驗證(正式版需 Token)
輸入參數
| 欄位 | 型別 | 必填 | 說明 |
|---|---|---|---|
x |
number[] | 是 | 自變數數列 |
y |
number[] | 是 | 依變數數列(長度需與 x 相同) |
請求範例
curl -X POST https://api.boshanweb.com/api/analytics/correlation \
-H 'Content-Type: application/json' \
-d '{"x":[1,2,3,4,5],"y":[2,4.1,5.9,8.2,9.8]}'成功回傳
{
"ok": true,
"id": "...",
"type": "correlation",
"result": {
"correlation": 0.99883,
"rsquared": 0.99766,
"nobs": 5
},
"duration_ms": 101
}
POST
/api/analytics/regression
分析模組
線性迴歸(同步)
以最小平方法配適簡單線性迴歸,即時回傳截距、斜率與 R²。適合小量資料。
權限:目前免驗證(正式版需 Token)
輸入參數
| 欄位 | 型別 | 必填 | 說明 |
|---|---|---|---|
x |
number[] | 是 | 自變數數列 |
y |
number[] | 是 | 依變數數列(長度需與 x 相同) |
請求範例
curl -X POST https://api.boshanweb.com/api/analytics/regression \
-H 'Content-Type: application/json' \
-d '{"x":[1,2,3,4,5],"y":[3,5,7,9,11]}'成功回傳
{
"ok": true,
"id": "...",
"type": "regression",
"result": {
"intercept": 1,
"slope": 2,
"rsquared": 1,
"nobs": 5
},
"duration_ms": 83
}
POST
/api/analytics/regression/async
背景任務
線性迴歸(背景)
把迴歸任務送入佇列,立即回傳查詢識別碼。適合大量資料或長時間運算,避免前端久等。
權限:目前免驗證(正式版需 Token)
輸入參數
| 欄位 | 型別 | 必填 | 說明 |
|---|---|---|---|
x |
number[] | 是 | 自變數數列 |
y |
number[] | 是 | 依變數數列 |
請求範例
curl -X POST https://api.boshanweb.com/api/analytics/regression/async \
-H 'Content-Type: application/json' \
-d '{"x":[1,2,3,4,5],"y":[3,5,7,9,11]}'成功回傳
{
"ok": true,
"id": "uuid",
"status": "queued",
"status_url": "/api/analytics/runs/{uuid}"
}
GET
/api/analytics/runs/{uuid}
背景任務
查詢任務結果
輪詢任務狀態。status 為 queued / running / success / failed,完成後 result 即為分析結果。
權限:目前免驗證(正式版需 Token)
輸入參數
| 欄位 | 型別 | 必填 | 說明 |
|---|---|---|---|
uuid |
string | 是 | 建立任務時回傳的識別碼(路徑參數) |
請求範例
curl https://api.boshanweb.com/api/analytics/runs/{uuid} \
-H 'Accept: application/json'成功回傳
{
"ok": true,
"id": "uuid",
"type": "regression",
"status": "success",
"result": {
"intercept": 1,
"slope": 2,
"rsquared": 1,
"nobs": 5
},
"duration_ms": 95
}錯誤回傳格式
當輸入未通過驗證或運算發生錯誤時,API 會回傳對應的錯誤訊息。
驗證失敗(HTTP 422)
{
"message": "The x.2 field must be a number.",
"errors": {
"x.2": [
"The x.2 field must be a number."
]
}
}運算錯誤(HTTP 422)
{
"ok": false,
"id": "...",
"error": "除數不可為 0"
}