0
嗨我想使用robfilter
使用。作爲默認robfilter反應不是JSON序列化因此我創建了自己的包使用此功能:opencpu不一致的json序列化
detectOutliers <- function(json, windowWidth) {
x <- json
robfil <- robust.filter(x[[2]], width=windowWidth, outlier="T", online=FALSE)
outlierDf <- data.frame(period=x[[1]], totalAmount=x[[2]], isOutlier=robfil$ol)
return(outlierDf)
}
當一個像
args <- fromJSON('{"json":[{"Period":1393632000,"x":453.2003},{"Period":1396310400,"x":742.9013},{"Period":1398902400,"x":52366.3592},{"Period":1401580800,"x":7660.234},{"Period":1404172800,"x":3967.7503},{"Period":1406851200,"x":2620.771},{"Period":1409529600,"x":1927.5348},{"Period":1412121600,"x":2094.795},{"Period":1414800000,"x":1830.223},{"Period":1417392000,"x":2286.1982},{"Period":1420070400,"x":3047.4511},{"Period":1422748800,"x":2001.4622},{"Period":1425168000,"x":1763.6833},{"Period":1427846400,"x":2033.9456},{"Period":1430438400,"x":4568.8964},{"Period":1433116800,"x":2104.0584},{"Period":1435708800,"x":1522.6288},{"Period":1438387200,"x":533.8585},{"Period":1441065600,"x":667.3039}], "windowWidth":11}')
outliers <- do.call(detectOutliers, args)
outliers
本地測試它正確地顯示了以下數據幀,其中每行填充
period totalAmount isOutlier
1 1393632000 453.2003 0
2 1396310400 742.9013 0
3 1398902400 52366.3592 1
4 1401580800 7660.2340 0
5 1404172800 3967.7503 0
.....
toJson(outliers)
反過來正確串行化該數據幀。
但在opencpu稱爲像
curl http://opencpuURL/ocpu/library/possibly/R/detectOutliers/json -d \
'{"json":[{"Period":1393632000,"x":453.2003},{"Period":1396310400,"x":742.9013},{"Period ":1398902400,"x":52366.3592},{"Period":1401580800,"x":7660.234},{"Period":1404172800,"x":3967.7503},{"Period":1406851200,"x":2620.771},{"Period ":1409529600,"x":1927.5348},{"Period":1412121600,"x":2094.795},{"Period":1414800000,"x":1830.223},{"Period":1417392000,"x":2286.1982},{"Period ":1420070400,"x":3047.4511},{"Period":1422748800,"x":2001.4622},{"Period":1425168000,"x":1763.6833},{"Period":1427846400,"x":2033.9456},{"Period ":1430438400,"x":4568.8964},{"Period":1433116800,"x":2104.0584},{"Period":1435708800,"x":1522.6288},{"Period":1438387200,"x":533.8585},{"Period ":1441065600,"x":667.3039}],"windowWidth":11}' \
-H "Content-Type: application/json"
後的結果很奇怪。正如你所看到只包含2場
[
{
"period": 1393632000,
"totalAmount": 453.2003,
"isOutlier": 0
},
{
"period": 1396310400,
"totalAmount": 742.9013,
"isOutlier": 0
},
{
"totalAmount": 52366.3592,
"isOutlier": 1
},
....
這裏有什麼問題一定行?