0
現在、データセット内のevents
の数をカウントしています(読み込んでいる.csvのデータの単一の列配列)。値が0から1に変化する回数を数えます。値が0から1に変化すると、それをイベントとして分類します。 2つのイベントの間のゼロの数が60未満の場合、同じイベントでそれらを分類します。特定の長さのデータ列のイベント数をカウントする
ここでは、20行を超えるイベントをカウントするようにコードを修正しようとしています。私はif(lines[i] != 0 && i>20)
のような私の条件に入れようとしましたが、私はev
の正しい値を得ていませんでした。
processData: function(data) {
// convert our data from the file into an array
var lines = data.replace(/\n+$/, "").split("\n");
var ev = 0; // the event counter (initialized to 0)
for(var i = 0, count = 0; i < lines.length; i++) { // 'count' will be the counter of consecutive zeros
if(lines[i] != 0) { // if we encounter a non-zero line
if(count > 60) ev++; // if the count of the previous zeros is greater than 5, then increment ev (>5 mean that 5 zeros or less will be ignored)
count = 1; // reset the count to 1 instead of 0 because the next while loop will skip one zero
while(++i < lines.length && lines[i] != 0) // skip the non-zero values (unfortunetly this will skip the first (next) zero as well that's why we reset count to 1 to include this skipped 0)
;
}
else // if not (if this is a zero), then increment the count of consecutive zeros
count++;
}
this.events = ev;
あなたはそれらに少なくとも20個のエントリを持っているイベントの数を取得したいですか? –
@ibrahimmahrir正解、はい。したがって、イベントに20件未満のエントリが含まれている場合、イベントとしてカウントしたくありません。 – Gary
私はあなたに最後に尋ねなかったことの1つ:イベントは値として0を持つことができますか? 60秒未満であれば、それらの0はセパレータではなくイベントの続きであることを意味しますか? –