2015-10-13 75 views

回答

0

編輯的代碼片段。看起來數據的所有差異都是900毫秒,但是這個代碼應該適用於任何其他值。

需要注意的是,它假定數據中看似存在「從高到低」排序。

var csv = [ 
 
    '1374225300,126.0,1662.0,379.0,337.0,1091.0,893.0', 
 
    '1374224400,84.0,1491.0,251.0,289.0,909.0,801.0', 
 
    '1374223500,72.0,1200.0,126.0,180.0,651.0,682.0 ', 
 
    '1374222600,84.0,1011.0,126.0,180.0,505.0,563.0 ', 
 
    '1374221700,72.0,718.0,84.0,109.0,295.0,441.0 ' 
 
    //... etcetera 
 
]; 
 

 
function getPairDifference(pair) { 
 
    //"pair" is a zero-based integer. 
 
    // "0" will return a difference between csv rows "0" & "1" 
 
    // "1" will return a difference between csv rows "1" & "2" 
 
    // etcetera... 
 

 
    var firstVal = parseInt(csv[pair].split(",")[0]); 
 
    var secondVal = parseInt(csv[pair + 1].split(",")[0]); 
 
    return firstVal - secondVal; 
 
} 
 

 
for (var i = 0; i < csv.length; i += 1) { 
 
    // Demo code to visualize numbers. 
 
    // Actual function call of interest is simply "getPairDifference(i)" 
 
    $("<div></div>").text("DIFF "+i+": " + getPairDifference(i)).appendTo("body"); 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

+0

所以我分析的UNIX時間戳爲float。我現在應該如何繼續?我不太瞭解上面的功能。這裏是我的代碼的相關部分: for(var i =(csv.length-1); i> = 0; i--)var a = csv [i] .split(「,」); var time = parseFloat(a [0]); –

+0

您可以從CSV數據中添加幾條演示線嗎?如果不知道數據結構,很難獲得完整的圖片。 – Ingmars

+0

在這裏你去:1374225300,126.0,1662.0,379.0,337.0,1091.0,893.0 1374224400,84.0,1491.0,251.0,289.0,909.0,801.0 1374223500,72.0,1200.0,126.0,180.0,651.0,682.0 1374222600,84.0 ,1011.0,126.0,180.0,505.0,563.0 1374221700,72.0,718.0,84.0,109.0,295.0,441.0 1374220800,84.0,168.0,84.0,84.0,168.0,323.0 1374219900,42.0,109.0,42.0,72.0,84.0 ,214.0 1374219000,42.0,84.0,84.0,84.0,0.0,103.0 1374218100,3.0,72.0,42.0,36.0,0.0,53.0 1374217200,0.0,39.0,0.0,0.0,0.0,0.0 –