2013-10-24 21 views
1

我是新來Xively。現在我試圖從我得到的提要中訪問數據點歷史記錄。 從這個文檔:http://xively.github.io/xively-js/docs/看來,我可以使用的方法xively.datapoint.history(feedID,datastreamID,選擇{},回調(數據)),但我不知道如何使用它。如何訪問Xively數據點的歷史與JavaScript?

我知道參數feedID,datastreamID,但我不確定選項... 來自Xively網站https://xively.com/dev/docs/api/quick_reference/historical_data/,我想我應該把開始和結束參數。我使用飼料ID:40053和數據流ID:airpressure。你可以在這裏嘗試輸入飼料ID,以獲得更多的信息:http://xively.github.io/xively-js/demo/

我嘗試下面的代碼,但它不工作。我是不是做錯了什麼,或者數據點歷史本身受到限制,不能被訪問?

// Make sure the document is ready to be handled 
$(document).ready(function($) { 

    // Set the Xively API key (https://xively.com/users/YOUR_USERNAME/keys) 
    xively.setKey("yWYxyi3HpdqFCBtKHueTvOGoGROSAKxGRFAyQWk5d3JNdz0g" ); 

    // Replace with your own values 
    var feedID  = 40053;   
    var datastreamID = "airpressure";  // Datastream ID 

    // Get datastream data from Xively 
    xively.datapoint.history(feedID, datastreamID, 
    { 
    start:"2013-09-10T00:00:00.703576Z", 
    end:"2013-10-10T00:00:00.703576Z" 
    }, 
    function(data){ 
    //data.forEach(function(datapoints){document.write(JSON.stringify(datapoints["value"], null, 4));}); 
document.write(JSON.stringify(data, null, 4)); 
    }); 
}); 

回答

1

我沒看過的文檔的權利... 每個查詢的最大持續時間爲6個小時,因此更改結束時間爲「2013-09-10T06:00:00.703576 Z解決了我的問題

0

Alvinadi 這是正確的另一件你可以做的是設置間隔參數大於0的東西。這將減少數據點的密度,並且只返回一個數據點指定的每秒數在間隔中,但是,當試圖檢索th時,這可能很有用平均大量的數據。

這裏的API文檔說明可用間隔:https://xively.com/dev/docs/api/quick_reference/historical_data/

臨提示:設置參數limit=1000返回結果的最大數量,而不必通過數據進行分頁。

1

您可以使用參數:durationinterval

xively.datapoint.history (feedID, datastreamID1, **{ duration: "14days", interval: "1000"}**, 
    function(data){ 
     document.write(JSON.stringify(data, null, 4)); 
    } 
);