2017-09-05 3 views
0

このCSVをJavaScriptで解析するにはどうすればよいですか?私のCSVが2次元であると仮定してJavaScriptを作成すると、代わりに1次元CSVで動作する

1363085391,42.890000000000,5.432200000000 
1363088879,47.570000000000,4.981800000000 
1363120475,56.560000000000,1.768000000000 
1363132522,53.000000000000,1.000000000000 
1363214378,48.630000000000,4.000000000000 
[...] 

カナダドルの場合はbitcoin price and trade volume historyです。しかし、このリストは大変です。これまでに行われたすべての取引が表示されます。だから私はそれを1日に数百のデータポイントから週に1つに減らそうとしている。ボリュームを合計して価格を平均化することによって、データポイントを時間間隔の間隔に基本的に「単調化」します。このようにして、より単純なデータでは、my line chartの行はずっとよく見えるはずです。

残念ながらスクリプトは機能しません。 CSVは2次元配列であると仮定していますが、現実には1次元だけだと思いますか? CSVを適切に解析するように変更するにはどうすればよいですか?

function simplifyData(data_set) { 
 
    interval_length = 3600; // hourly intervals 
 

 
    last_price = 0; 
 
    idx = 0; 
 
    while (idx < data_set.length) { 
 

 
    // reset value for this interval 
 
    volume = 0; 
 
    price_sum = 0; 
 
    count = 0; 
 
    timestamp = data_set[idx]['timestamp'] + interval_length; 
 

 
    // get sums for this interval 
 
    while (data_set[idx]['timetamp'] < timestamp) { 
 
     volume += data_set[idx]['volume']; 
 
     price_sum += data_set[idx]['price']; 
 
     count++; 
 
     idx++; 
 
     if (idx >= data_set.length) 
 
     break; 
 
    } 
 

 
    // get average price 
 
    price = count > 0 ? price_sum/count : last_price; 
 
    last_price = price; 
 

 
    // add new row to monotized data array 
 
    monotized_data.append([ 
 
     timestamp: timestamp, 
 
     volume: volume, 
 
     price: price 
 
    ]); 
 
    } 
 
} 
 

 
// Format: time (UNIX timestamp), price, amount traded 
 
// http://api.bitcoincharts.com/v1/csv/localbtcCAD.csv.gz 
 
var complexCadCsv = "1363085391,42.890000000000,5.432200000000 
 
1363088879,47.570000000000,4.981800000000 
 
1363120475,56.560000000000,1.768000000000 
 
1363132522,53.000000000000,1.000000000000 
 
1363214378,48.630000000000,4.000000000000 
 
1363217281,48.770000000000,2.000200000000 
 
1363223157,48.860000000000,2.046500000000 
 
1363232051,49.110000000000,4.235500000000 
 
1363272551,54.250000000000,1.000000000000 
 
1363283662,49.780000000000,5.925600000000 
 
1363293072,55.500000000000,1.027000000000 
 
1363321440,56.000000000000,5.357100000000 
 
1363346950,55.220000000000,7.016900000000 
 
1363379555,55.600000000000,4.945900000000 
 
1363379607,55.740000000000,1.000000000000 
 
1363381362,49.220000000000,0.101600000000 
 
1363382662,49.220000000000,4.896100000000 
 
1363391161,55.380000000000,2.000000000000 
 
1363401704,56.060000000000,1.000000000000 
 
1363467393,56.000000000000,0.892900000000 
 
1363496639,56.700000000000,1.500100000000 
 
1363524530,56.930000000000,6.000100000000 
 
1363527377,56.900000000000,6.497900000000 
 
1363542700,56.000000000000,2.142900000000 
 
1363547113,55.000000000000,3.000000000000 
 
1363564084,57.040000000000,2.156400000000 
 
1363638453,57.880000000000,0.331700000000 
 
1363729323,70.000000000000,0.857100000000 
 
1363740718,73.070000000000,0.136800000000 
 
1363795449,63.450000000000,1.000000000000 
 
1363795494,63.860000000000,1.000100000000 
 
1363795603,63.430000000000,0.157700000000 
 
1363798700,68.390000000000,1.462200000000 
 
1363800835,68.180000000000,1.991300000000 
 
1363803497,67.940000000000,1.014600000000 
 
1363803790,68.160000000000,1.027100000000 
 
1363814790,69.580000000000,1.050000000000 
 
1363814810,68.270000000000,0.929400000000 
 
1363825583,68.250000000000,5.230600000000 
 
1363829358,78.000000000000,1.050000000000 
 
1363836583,83.300000000000,2.999800000000 
 
1363837642,84.000000000000,2.000000000000 
 
1363895966,75.410000000000,0.663000000000 
 
1363944788,75.000000000000,4.000000000000 
 
1363984884,90.000000000000,1.111100000000 
 
1363987472,90.000000000000,1.111100000000 
 
1363988438,89.350000000000,0.074000000000 
 
1363989586,85.090000000000,1.999900000000 
 
1364000191,88.000000000000,1.000000000000 
 
1364002717,85.230000000000,1.490100000000 
 
1364010104,70.730000000000,1.000000000000 
 
1364013267,86.000000000000,1.162800000000 
 
1364073182,78.000000000000,3.900000000000 
 
1364089933,80.000000000000,3.025000000000 
 
1364249509,74.360000000000,1.485600000000 
 
1364262262,89.550000000000,1.116700000000 
 
1364265293,90.040000000000,1.055000000000 
 
1364310351,92.450000000000,1.081700000000 
 
1364334487,81.210000000000,1.994800000000 
 
1364355951,94.630000000000,1.420000000000 
 
1364357864,95.380000000000,1.048400000000 
 
1364358542,94.800000000000,1.054900000000 
 
1364364067,82.820000000000,13.219800000000 
 
1364395451,99.100000000000,0.100900000000 
 
1364400184,102.700000000000,1.000000000000 
 
1364401183,100.570000000000,1.093800000000 
 
1364403945,101.420000000000,1.000000000000 
 
1364411110,101.720000000000,0.498800000000 
 
1364436263,106.740000000000,1.799900000000 
 
1364436873,94.960000000000,1.000000000000 
 
1364437451,94.520000000000,0.999900000000 
 
1364440483,104.190000000000,0.499900000000 
 
1364489123,109.760000000000,1.047800000000 
 
1364490688,109.730000000000,1.000000000000 
 
1364494732,100.230000000000,1.000000000000 
 
1364498537,95.620000000000,1.950000000000 
 
1364502332,95.780000000000,1.200700000000 
 
1364505883,99.490000000000,0.251300000000 
 
1364513250,103.900000000000,0.517100000000 
 
1364516343,83.470000000000,1.018300000000 
 
1364573738,97.140000000000,0.257400000000 
 
1364580938,95.700000000000,1.000000000000 
 
1364598407,102.000000000000,1.000000000000 
 
1364600233,102.000000000000,1.000000000000 
 
1364601641,102.000000000000,1.010000000000 
 
1364605133,105.000000000000,1.000000000000 
 
1364709921,99.880000000000,1.000000000000 
 
1364712798,99.990000000000,1.000100000000 
 
1364748894,101.470000000000,1.000000000000 
 
1364755340,100.590000000000,3.000000000000 
 
1364792969,106.000000000000,1.000000000000 
 
1364799933,102.400000000000,1.000000000000 
 
1364800923,101.560000000000,1.000000000000 
 
1364828813,112.000000000000,2.000000000000 
 
1364832014,115.000000000000,5.000000000000 
 
1364832308,115.000000000000,3.000000000000 
 
1364834249,112.720000000000,5.855000000000 
 
1364838578,115.240000000000,5.727400000000 
 
1364841672,104.360000000000,12.457200000000 
 
1364923361,120.900000000000,2.999900000000 
 
1364936087,120.710000000000,4.970600000000 
 
1364948998,124.810000000000,4.999800000000 
 
1364959661,127.170000000000,0.995000000000 
 
1364965648,121.770000000000,1.000000000000 
 
1364973827,136.060000000000,1.000000000000 
 
1364974001,147.890000000000,4.000100000000 
 
1364998794,140.320000000000,3.563200000000 
 
1365026364,123.790000000000,1.015400000000 
 
1365027711,127.780000000000,6.260900000000 
 
1365046987,138.360000000000,4.000000000000 
 
1365057275,138.500000000000,5.499900000000 
 
1365065898,157.040000000000,1.999400000000 
 
1365090058,145.220000000000,5.509000000000 
 
1365104881,164.890000000000,5.458200000000 
 
1365105565,139.710000000000,1.250000000000 
 
1365138055,145.850000000000,1.849900000000 
 
1365167322,166.250000000000,0.601500000000 
 
1365173858,146.080000000000,1.999900000000 
 
1365174283,148.260000000000,0.134900000000 
 
1365183486,149.890000000000,3.000100000000 
 
1365184905,161.740000000000,2.000100000000 
 
1365205476,152.790000000000,1.000000000000 
 
1365210365,175.000000000000,1.000000000000 
 
1365219395,150.960000000000,0.999700000000 
 
1365220927,150.910000000000,1.000000000000 
 
1365268452,153.390000000000,0.652000000000 
 
1365272285,170.000000000000,1.000000000000 
 
1365274795,170.000000000000,1.000000000000 
 
1365278764,170.000000000000,1.000000000000 
 
1365278930,154.030000000000,0.519400000000 
 
1365280374,170.000000000000,1.000000000000 
 
1365281909,154.560000000000,0.650000000000 
 
1365283450,170.000000000000,1.000000000000 
 
1365287835,170.000000000000,1.541200000000 
 
1365303267,153.940000000000,3.500100000000 
 
1365312742,155.620000000000,0.128500000000 
 
1365325139,161.570000000000,3.000000000000 
 
1365349680,169.230000000000,2.000000000000 
 
1365354798,138.110000000000,1.010000000000 
 
1365356226,180.190000000000,1.664900000000 
 
1365362290,174.010000000000,0.287300000000 
 
1365377549,173.640000000000,2.000000000000 
 
1365379774,175.010000000000,1.000000000000 
 
1365384562,179.980000000000,2.222500000000 
 
1365396478,183.290000000000,2.000000000000 
 
1365434139,203.850000000000,0.098100000000 
 
1365434614,208.360000000000,1.000000000000 
 
1365437520,197.620000000000,2.000000000000 
 
1365440837,195.520000000000,4.000000000000 
 
1365449254,197.610000000000,4.000000000000 
 
1365467994,202.160000000000,2.990500000000 
 
1365469985,202.160000000000,1.500200000000 
 
1365478982,206.360000000000,0.997700000000 
 
1365479416,206.220000000000,1.000000000000 
 
1365479554,203.290000000000,1.000000000000 
 
1365486039,207.860000000000,0.465300000000 
 
1365500973,219.210000000000,2.280900000000 
 
1365518766,228.930000000000,1.970100000000 
 
1365518846,225.910000000000,0.996000000000 
 
1365520063,229.770000000000,0.747300000000 
 
1365521859,235.270000000000,3.000000000000 
 
1365521926,235.270000000000,0.850100000000 
 
1365524515,240.510000000000,3.326200000000 
 
1365524659,235.400000000000,0.999100000000 
 
1365526701,238.440000000000,1.000000000000 
 
1365527072,242.330000000000,2.000000000000 
 
1365527199,240.510000000000,1.309700000000 
 
1365529148,251.570000000000,1.000000000000 
 
1365537800,265.560000000000,1.000000000000 
 
1365542522,305.000000000000,1.508200000000 
 
1365542586,305.000000000000,1.893400000000 
 
1365551390,335.650000000000,0.715000000000 
 
1365554253,265.540000000000,1.000000000000 
 
1365558982,284.240000000000,1.000000000000 
 
1365563330,306.440000000000,0.326300000000 
 
1365566909,310.950000000000,0.064300000000 
 
1365578721,338.530000000000,1.181600000000 
 
1365606252,273.660000000000,1.000000000000 
 
1365610294,281.800000000000,2.129200000000 
 
1365612809,265.810000000000,2.000000000000 
 
1365618499,262.140000000000,1.000000000000 
 
1365628947,250.000000000000,1.944000000000 
 
1365629291,253.640000000000,1.182800000000 
 
1365642148,151.740000000000,2.000000000000 
 
1365642413,141.270000000000,2.000000000000 
 
1365678778,188.540000000000,3.993100000000 
 
1365703940,148.580000000000,4.455400000000 
 
1365716351,151.650000000000,0.680000000000 
 
1365717197,136.400000000000,1.000000000000 
 
1365717771,122.450000000000,1.951800000000 
 
1365724442,124.000000000000,2.000000000000 
 
1365773281,117.460000000000,1.251500000000 
 
1365773887,121.000000000000,1.991800000000 
 
1365776714,122.360000000000,2.231100000000 
 
1365795875,114.590000000000,1.000000000000 
 
1365796323,115.000000000000,2.000000000000 
 
1365798963,106.190000000000,2.000000000000 
 
1365802678,106.180000000000,1.000000000000 
 
1365804038,111.410000000000,1.790000000000 
 
1365810280,109.980000000000,1.500000000000 
 
1365811712,115.000000000000,2.000000000000 
 
1365813104,109.970000000000,1.000000000000 
 
1365816966,165.200000000000,3.026600000000 
 
1365819572,150.000000000000,1.066700000000 
 
1365820699,128.730000000000,1.649900000000 
 
1365823425,124.060000000000,3.224400000000 
 
1365826775,150.000000000000,1.066700000000 
 
1365877655,150.000000000000,2.000000000000 
 
1365878739,159.330000000000,2.008500000000 
 
1365884739,150.000000000000,4.000000000000 
 
1365888397,150.000000000000,3.000000000000 
 
1365956959,150.000000000000,5.330000000000 
 
1365961896,140.000000000000,0.535700000000 
 
1365979939,142.140000000000,1.000000000000 
 
1365991144,128.990000000000,2.000000000000 
 
1365993080,150.000000000000,1.333300000000 
 
1366014910,135.000000000000,4.444400000000 
 
1366022593,149.640000000000,0.467800000000 
 
1366044482,123.500000000000,3.029100000000 
 
1366045307,119.750000000000,1.002100000000 
 
1366048928,119.750000000000,0.668100000000 
 
1366055142,109.990000000000,0.181800000000 
 
1366062216,109.480000000000,1.080000000000 
 
1366065512,100.000000000000,0.181000000000 
 
1366085870,88.150000000000,1.000000000000 
 
1366085948,91.540000000000,0.436900000000 
 
1366097421,74.700000000000,10.495300000000 
 
1366129928,96.000000000000,2.083300000000 
 
1366130124,99.720000000000,4.000000000000 
 
1366133447,99.890000000000,1.000000000000 
 
1366135520,103.730000000000,1.100000000000 
 
1366138028,95.390000000000,1.100000000000 
 
1366144237,69.480000000000,1.511300000000 
 
1366145377,75.000000000000,2.586700000000 
 
1366155682,89.800000000000,2.000000000000 
 
1366158005,88.800000000000,1.000000000000 
 
1366158456,89.800000000000,1.993300000000 
 
1366164776,94.000000000000,2.000000000000 
 
1366173698,102.640000000000,1.997400000000 
 
1366198863,103.450000000000,1.991400000000 
 
1366211035,102.450000000000,2.196200000000 
 
1366218782,94.000000000000,3.000000000000 
 
1366225431,94.000000000000,2.042600000000 
 
1366233216,214.470000000000,1.000000000000 
 
1366318951,108.730000000000,0.919700000000 
 
1366387777,129.690000000000,1.982200000000 
 
1366394307,135.420000000000,0.184600000000 
 
1366413885,134.140000000000,0.298200000000 
 
1366551162,136.710000000000,0.129600000000 
 
1366553999,140.700000000000,2.487500000000 
 
1366620334,137.830000000000,0.420800000000 
 
1366671189,107.380000000000,1.500000000000 
 
1366684569,141.740000000000,1.000000000000 
 
1366686872,142.090000000000,1.055600000000 
 
1366687106,142.130000000000,1.759000000000 
 
1366746322,148.230000000000,3.373100000000 
 
1366825778,159.250000000000,0.125600000000 
 
1366903154,166.040000000000,1.540000000000 
 
1366903247,168.230000000000,0.118900000000 
 
1366906417,165.440000000000,1.588300000000 
 
1366906495,166.300000000000,1.000000000000 
 
1366912064,164.670000000000,2.130000000000 
 
1366914573,164.820000000000,0.182000000000 
 
1366978559,143.290000000000,1.395800000000 
 
1367001597,144.390000000000,1.038900000000 
 
1367002599,165.650000000000,1.000000000000 
 
1367024672,142.890000000000,0.810000000000 
 
1367027540,144.780000000000,1.450500000000 
 
1367027692,146.310000000000,2.000000000000 
 
1367029695,143.800000000000,0.750000000000 
 
1367034952,143.800000000000,3.129500000000 
 
1367043181,143.710000000000,2.261500000000 
 
1367085501,141.190000000000,1.416600000000 
 
1367100612,155.680000000000,1.281900000000 
 
1367182014,170.140000000000,1.000000000000 
 
1367182173,169.720000000000,1.119500000000 
 
1367186205,170.710000000000,1.000000000000 
 
1367275779,153.550000000000,1.465300000000 
 
1367289143,198.350000000000,6.049900000000 
 
1367323428,197.180000000000,7.000000000000 
 
1367331486,155.660000000000,1.606000000000 
 
1367348392,189.950000000000,5.264600000000 
 
1367351603,146.060000000000,2.998800000000 
 
1367356384,188.010000000000,7.138000000000 
 
1367364586,167.170000000000,0.179500000000 
 
1367364740,191.010000000000,7.853000000000 
 
1367378952,165.000000000000,1.818200000000 
 
1367423338,142.430000000000,3.931900000000 
 
1367446179,133.240000000000,2.251600000000 
 
1367457397,131.820000000000,1.273400000000 
 
1367474137,129.410000000000,0.390000000000 
 
1367506472,125.970000000000,0.079400000000 
 
1367517588,112.580000000000,4.441400000000 
 
1367534445,116.880000000000,0.171100000000 
 
1367562381,108.910000000000,0.550900000000 
 
1367591999,106.120000000000,0.471200000000 
 
1367595257,104.460000000000,0.478600000000 
 
1367599098,144.030000000000,1.041500000000 
 
1367604271,99.230000000000,2.962700000000 
 
1367625410,103.810000000000,2.022900000000" 
 

 
var finalOutput = simplifyData(complexCadCsv); 
 

 
$(".new_csv").append(finalOutput);
<!--<script src="https://rawgit.com/evanplaice/jquery-csv/master/src/jquery.csv.min.js"></script>--> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<h1>New simplified CSV</h1> 
 
<div class="new_csv"></div>

+0

を呼び出すべきであるあなたが行を持っており、列は2次元ではありませんか? –

+0

私は分かりません。コードをくれた人が言ったことだ。 https://www.reddit.com/r/Bitcoin/comments/6ul8y3/where_do_i_download_bitcoins_price_history_as_xls/dmi3kmg/ –

+0

「monotized_data」とは何ですか?コメントは配列だと言っていますが、配列には 'append'メソッドはありません。 Javascriptで「プッシュ」と呼ばれています。 – Barmar

答えて

2

data_set文字列ですが、simplifyData()は、それがオブジェクトの配列だかのようにアクセスされます。まずそれを変換する必要があります。

data_set = data_set.split('\n').map(line => { 
    var linearray = line.split(','); 
    return { 
     timestamp: parseInt(linearray[0], 10), 
     price: parseFloat(linearray[1]), 
     volume: parseFloat(linearray[2]) 
    }; 
}); 

そしてmonotized_data.appendへのお電話で、あなたは中括弧を持っている必要があるとき、あなたは角括弧を持っている、とあなたはpush()

monotized_data.push({ 
     timestamp: timestamp, 
     volume: volume, 
     price: price 
    }); 

function simplifyData(data_set) { 
 
    interval_length = 3600; // hourly intervals 
 

 
    last_price = 0; 
 
    idx = 0; 
 
    
 
    monotized_data = [] 
 
    
 
    while (idx < data_set.length) { 
 

 
    // reset value for this interval 
 
    volume = 0; 
 
    price_sum = 0; 
 
    count = 0; 
 
    
 
    // Format: time (UNIX timestamp), price, amount traded 
 
    // timestamp: data_set[idx][0] 
 
    // price:  data_set[idx][1] 
 
    // volume: data_set[idx][2] 
 
    
 
    timestamp = data_set[idx][0] + interval_length; 
 

 
    // get sums for this interval 
 
    while (data_set[idx][0] < timestamp) { 
 
     volume += data_set[idx][2]; 
 
     price_sum += data_set[idx][1]; 
 
     count++; 
 
     idx++; 
 
     if (idx >= data_set.length) 
 
     break; 
 
    } 
 

 
    // get average price 
 
    price = count > 0 ? price_sum/count : last_price; 
 
    last_price = price; 
 

 
    // add new row to monotized data array 
 
    monotized_data.push({ 
 
     timestamp: timestamp, 
 
     volume: volume, 
 
     price: price 
 
    }); 
 
    } 
 
} 
 

 
// Format: time (UNIX timestamp), price, amount traded 
 
// http://api.bitcoincharts.com/v1/csv/localbtcCAD.csv.gz 
 
var complexCadCsv = `1363085391,42.890000000000,5.432200000000 
 
1363088879, 47.570000000000, 4.981800000000 
 
1363120475, 56.560000000000, 1.768000000000 
 
1363132522, 53.000000000000, 1.000000000000 
 
1363214378, 48.630000000000, 4.000000000000 
 
1363217281, 48.770000000000, 2.000200000000 
 
1363223157, 48.860000000000, 2.046500000000 
 
1363232051, 49.110000000000, 4.235500000000 
 
1363272551, 54.250000000000, 1.000000000000 
 
1363283662, 49.780000000000, 5.925600000000 
 
1363293072, 55.500000000000, 1.027000000000 
 
1363321440, 56.000000000000, 5.357100000000 
 
1363346950, 55.220000000000, 7.016900000000 
 
1363379555, 55.600000000000, 4.945900000000 
 
1363379607, 55.740000000000, 1.000000000000 
 
1363381362, 49.220000000000, 0.101600000000 
 
1363382662, 49.220000000000, 4.896100000000 
 
1363391161, 55.380000000000, 2.000000000000 
 
1363401704, 56.060000000000, 1.000000000000 
 
1363467393, 56.000000000000, 0.892900000000 
 
1363496639, 56.700000000000, 1.500100000000 
 
1363524530, 56.930000000000, 6.000100000000 
 
1363527377, 56.900000000000, 6.497900000000 
 
1363542700, 56.000000000000, 2.142900000000 
 
1363547113, 55.000000000000, 3.000000000000 
 
1363564084, 57.040000000000, 2.156400000000 
 
1363638453, 57.880000000000, 0.331700000000 
 
1363729323, 70.000000000000, 0.857100000000 
 
1363740718, 73.070000000000, 0.136800000000 
 
1363795449, 63.450000000000, 1.000000000000 
 
1363795494, 63.860000000000, 1.000100000000 
 
1363795603, 63.430000000000, 0.157700000000 
 
1363798700, 68.390000000000, 1.462200000000 
 
1363800835, 68.180000000000, 1.991300000000 
 
1363803497, 67.940000000000, 1.014600000000 
 
1363803790, 68.160000000000, 1.027100000000 
 
1363814790, 69.580000000000, 1.050000000000 
 
1363814810, 68.270000000000, 0.929400000000 
 
1363825583, 68.250000000000, 5.230600000000 
 
1363829358, 78.000000000000, 1.050000000000 
 
1363836583, 83.300000000000, 2.999800000000 
 
1363837642, 84.000000000000, 2.000000000000 
 
1363895966, 75.410000000000, 0.663000000000 
 
1363944788, 75.000000000000, 4.000000000000 
 
1363984884, 90.000000000000, 1.111100000000 
 
1363987472, 90.000000000000, 1.111100000000 
 
1363988438, 89.350000000000, 0.074000000000 
 
1363989586, 85.090000000000, 1.999900000000 
 
1364000191, 88.000000000000, 1.000000000000 
 
1364002717, 85.230000000000, 1.490100000000 
 
1364010104, 70.730000000000, 1.000000000000 
 
1364013267, 86.000000000000, 1.162800000000 
 
1364073182, 78.000000000000, 3.900000000000 
 
1364089933, 80.000000000000, 3.025000000000 
 
1364249509, 74.360000000000, 1.485600000000 
 
1364262262, 89.550000000000, 1.116700000000 
 
1364265293, 90.040000000000, 1.055000000000 
 
1364310351, 92.450000000000, 1.081700000000 
 
1364334487, 81.210000000000, 1.994800000000 
 
1364355951, 94.630000000000, 1.420000000000 
 
1364357864, 95.380000000000, 1.048400000000 
 
1364358542, 94.800000000000, 1.054900000000 
 
1364364067, 82.820000000000, 13.219800000000 
 
1364395451, 99.100000000000, 0.100900000000 
 
1364400184, 102.700000000000, 1.000000000000 
 
1364401183, 100.570000000000, 1.093800000000 
 
1364403945, 101.420000000000, 1.000000000000 
 
1364411110, 101.720000000000, 0.498800000000 
 
1364436263, 106.740000000000, 1.799900000000 
 
1364436873, 94.960000000000, 1.000000000000 
 
1364437451, 94.520000000000, 0.999900000000 
 
1364440483, 104.190000000000, 0.499900000000 
 
1364489123, 109.760000000000, 1.047800000000 
 
1364490688, 109.730000000000, 1.000000000000 
 
1364494732, 100.230000000000, 1.000000000000 
 
1364498537, 95.620000000000, 1.950000000000 
 
1364502332, 95.780000000000, 1.200700000000 
 
1364505883, 99.490000000000, 0.251300000000 
 
1364513250, 103.900000000000, 0.517100000000 
 
1364516343, 83.470000000000, 1.018300000000 
 
1364573738, 97.140000000000, 0.257400000000 
 
1364580938, 95.700000000000, 1.000000000000 
 
1364598407, 102.000000000000, 1.000000000000 
 
1364600233, 102.000000000000, 1.000000000000 
 
1364601641, 102.000000000000, 1.010000000000 
 
1364605133, 105.000000000000, 1.000000000000 
 
1364709921, 99.880000000000, 1.000000000000 
 
1364712798, 99.990000000000, 1.000100000000 
 
1364748894, 101.470000000000, 1.000000000000 
 
1364755340, 100.590000000000, 3.000000000000 
 
1364792969, 106.000000000000, 1.000000000000 
 
1364799933, 102.400000000000, 1.000000000000 
 
1364800923, 101.560000000000, 1.000000000000 
 
1364828813, 112.000000000000, 2.000000000000 
 
1364832014, 115.000000000000, 5.000000000000 
 
1364832308, 115.000000000000, 3.000000000000 
 
1364834249, 112.720000000000, 5.855000000000 
 
1364838578, 115.240000000000, 5.727400000000 
 
1364841672, 104.360000000000, 12.457200000000 
 
1364923361, 120.900000000000, 2.999900000000 
 
1364936087, 120.710000000000, 4.970600000000 
 
1364948998, 124.810000000000, 4.999800000000 
 
1364959661, 127.170000000000, 0.995000000000 
 
1364965648, 121.770000000000, 1.000000000000 
 
1364973827, 136.060000000000, 1.000000000000 
 
1364974001, 147.890000000000, 4.000100000000 
 
1364998794, 140.320000000000, 3.563200000000 
 
1365026364, 123.790000000000, 1.015400000000 
 
1365027711, 127.780000000000, 6.260900000000 
 
1365046987, 138.360000000000, 4.000000000000 
 
1365057275, 138.500000000000, 5.499900000000 
 
1365065898, 157.040000000000, 1.999400000000 
 
1365090058, 145.220000000000, 5.509000000000 
 
1365104881, 164.890000000000, 5.458200000000 
 
1365105565, 139.710000000000, 1.250000000000 
 
1365138055, 145.850000000000, 1.849900000000 
 
1365167322, 166.250000000000, 0.601500000000 
 
1365173858, 146.080000000000, 1.999900000000 
 
1365174283, 148.260000000000, 0.134900000000 
 
1365183486, 149.890000000000, 3.000100000000 
 
1365184905, 161.740000000000, 2.000100000000 
 
1365205476, 152.790000000000, 1.000000000000 
 
1365210365, 175.000000000000, 1.000000000000 
 
1365219395, 150.960000000000, 0.999700000000 
 
1365220927, 150.910000000000, 1.000000000000 
 
1365268452, 153.390000000000, 0.652000000000 
 
1365272285, 170.000000000000, 1.000000000000 
 
1365274795, 170.000000000000, 1.000000000000 
 
1365278764, 170.000000000000, 1.000000000000 
 
1365278930, 154.030000000000, 0.519400000000 
 
1365280374, 170.000000000000, 1.000000000000 
 
1365281909, 154.560000000000, 0.650000000000 
 
1365283450, 170.000000000000, 1.000000000000 
 
1365287835, 170.000000000000, 1.541200000000 
 
1365303267, 153.940000000000, 3.500100000000 
 
1365312742, 155.620000000000, 0.128500000000 
 
1365325139, 161.570000000000, 3.000000000000 
 
1365349680, 169.230000000000, 2.000000000000 
 
1365354798, 138.110000000000, 1.010000000000 
 
1365356226, 180.190000000000, 1.664900000000 
 
1365362290, 174.010000000000, 0.287300000000 
 
1365377549, 173.640000000000, 2.000000000000 
 
1365379774, 175.010000000000, 1.000000000000 
 
1365384562, 179.980000000000, 2.222500000000 
 
1365396478, 183.290000000000, 2.000000000000 
 
1365434139, 203.850000000000, 0.098100000000 
 
1365434614, 208.360000000000, 1.000000000000 
 
1365437520, 197.620000000000, 2.000000000000 
 
1365440837, 195.520000000000, 4.000000000000 
 
1365449254, 197.610000000000, 4.000000000000 
 
1365467994, 202.160000000000, 2.990500000000 
 
1365469985, 202.160000000000, 1.500200000000 
 
1365478982, 206.360000000000, 0.997700000000 
 
1365479416, 206.220000000000, 1.000000000000 
 
1365479554, 203.290000000000, 1.000000000000 
 
1365486039, 207.860000000000, 0.465300000000 
 
1365500973, 219.210000000000, 2.280900000000 
 
1365518766, 228.930000000000, 1.970100000000 
 
1365518846, 225.910000000000, 0.996000000000 
 
1365520063, 229.770000000000, 0.747300000000 
 
1365521859, 235.270000000000, 3.000000000000 
 
1365521926, 235.270000000000, 0.850100000000 
 
1365524515, 240.510000000000, 3.326200000000 
 
1365524659, 235.400000000000, 0.999100000000 
 
1365526701, 238.440000000000, 1.000000000000 
 
1365527072, 242.330000000000, 2.000000000000 
 
1365527199, 240.510000000000, 1.309700000000 
 
1365529148, 251.570000000000, 1.000000000000 
 
1365537800, 265.560000000000, 1.000000000000 
 
1365542522, 305.000000000000, 1.508200000000 
 
1365542586, 305.000000000000, 1.893400000000 
 
1365551390, 335.650000000000, 0.715000000000 
 
1365554253, 265.540000000000, 1.000000000000 
 
1365558982, 284.240000000000, 1.000000000000 
 
1365563330, 306.440000000000, 0.326300000000 
 
1365566909, 310.950000000000, 0.064300000000 
 
1365578721, 338.530000000000, 1.181600000000 
 
1365606252, 273.660000000000, 1.000000000000 
 
1365610294, 281.800000000000, 2.129200000000 
 
1365612809, 265.810000000000, 2.000000000000 
 
1365618499, 262.140000000000, 1.000000000000 
 
1365628947, 250.000000000000, 1.944000000000 
 
1365629291, 253.640000000000, 1.182800000000 
 
1365642148, 151.740000000000, 2.000000000000 
 
1365642413, 141.270000000000, 2.000000000000 
 
1365678778, 188.540000000000, 3.993100000000 
 
1365703940, 148.580000000000, 4.455400000000 
 
1365716351, 151.650000000000, 0.680000000000 
 
1365717197, 136.400000000000, 1.000000000000 
 
1365717771, 122.450000000000, 1.951800000000 
 
1365724442, 124.000000000000, 2.000000000000 
 
1365773281, 117.460000000000, 1.251500000000 
 
1365773887, 121.000000000000, 1.991800000000 
 
1365776714, 122.360000000000, 2.231100000000 
 
1365795875, 114.590000000000, 1.000000000000 
 
1365796323, 115.000000000000, 2.000000000000 
 
1365798963, 106.190000000000, 2.000000000000 
 
1365802678, 106.180000000000, 1.000000000000 
 
1365804038, 111.410000000000, 1.790000000000 
 
1365810280, 109.980000000000, 1.500000000000 
 
1365811712, 115.000000000000, 2.000000000000 
 
1365813104, 109.970000000000, 1.000000000000 
 
1365816966, 165.200000000000, 3.026600000000 
 
1365819572, 150.000000000000, 1.066700000000 
 
1365820699, 128.730000000000, 1.649900000000 
 
1365823425, 124.060000000000, 3.224400000000 
 
1365826775, 150.000000000000, 1.066700000000 
 
1365877655, 150.000000000000, 2.000000000000 
 
1365878739, 159.330000000000, 2.008500000000 
 
1365884739, 150.000000000000, 4.000000000000 
 
1365888397, 150.000000000000, 3.000000000000 
 
1365956959, 150.000000000000, 5.330000000000 
 
1365961896, 140.000000000000, 0.535700000000 
 
1365979939, 142.140000000000, 1.000000000000 
 
1365991144, 128.990000000000, 2.000000000000 
 
1365993080, 150.000000000000, 1.333300000000 
 
1366014910, 135.000000000000, 4.444400000000 
 
1366022593, 149.640000000000, 0.467800000000 
 
1366044482, 123.500000000000, 3.029100000000 
 
1366045307, 119.750000000000, 1.002100000000 
 
1366048928, 119.750000000000, 0.668100000000 
 
1366055142, 109.990000000000, 0.181800000000 
 
1366062216, 109.480000000000, 1.080000000000 
 
1366065512, 100.000000000000, 0.181000000000 
 
1366085870, 88.150000000000, 1.000000000000 
 
1366085948, 91.540000000000, 0.436900000000 
 
1366097421, 74.700000000000, 10.495300000000 
 
1366129928, 96.000000000000, 2.083300000000 
 
1366130124, 99.720000000000, 4.000000000000 
 
1366133447, 99.890000000000, 1.000000000000 
 
1366135520, 103.730000000000, 1.100000000000 
 
1366138028, 95.390000000000, 1.100000000000 
 
1366144237, 69.480000000000, 1.511300000000 
 
1366145377, 75.000000000000, 2.586700000000 
 
1366155682, 89.800000000000, 2.000000000000 
 
1366158005, 88.800000000000, 1.000000000000 
 
1366158456, 89.800000000000, 1.993300000000 
 
1366164776, 94.000000000000, 2.000000000000 
 
1366173698, 102.640000000000, 1.997400000000 
 
1366198863, 103.450000000000, 1.991400000000 
 
1366211035, 102.450000000000, 2.196200000000 
 
1366218782, 94.000000000000, 3.000000000000 
 
1366225431, 94.000000000000, 2.042600000000 
 
1366233216, 214.470000000000, 1.000000000000 
 
1366318951, 108.730000000000, 0.919700000000 
 
1366387777, 129.690000000000, 1.982200000000 
 
1366394307, 135.420000000000, 0.184600000000 
 
1366413885, 134.140000000000, 0.298200000000 
 
1366551162, 136.710000000000, 0.129600000000 
 
1366553999, 140.700000000000, 2.487500000000 
 
1366620334, 137.830000000000, 0.420800000000 
 
1366671189, 107.380000000000, 1.500000000000 
 
1366684569, 141.740000000000, 1.000000000000 
 
1366686872, 142.090000000000, 1.055600000000 
 
1366687106, 142.130000000000, 1.759000000000 
 
1366746322, 148.230000000000, 3.373100000000 
 
1366825778, 159.250000000000, 0.125600000000 
 
1366903154, 166.040000000000, 1.540000000000 
 
1366903247, 168.230000000000, 0.118900000000 
 
1366906417, 165.440000000000, 1.588300000000 
 
1366906495, 166.300000000000, 1.000000000000 
 
1366912064, 164.670000000000, 2.130000000000 
 
1366914573, 164.820000000000, 0.182000000000 
 
1366978559, 143.290000000000, 1.395800000000 
 
1367001597, 144.390000000000, 1.038900000000 
 
1367002599, 165.650000000000, 1.000000000000 
 
1367024672, 142.890000000000, 0.810000000000 
 
1367027540, 144.780000000000, 1.450500000000 
 
1367027692, 146.310000000000, 2.000000000000 
 
1367029695, 143.800000000000, 0.750000000000 
 
1367034952, 143.800000000000, 3.129500000000 
 
1367043181, 143.710000000000, 2.261500000000 
 
1367085501, 141.190000000000, 1.416600000000 
 
1367100612, 155.680000000000, 1.281900000000 
 
1367182014, 170.140000000000, 1.000000000000 
 
1367182173, 169.720000000000, 1.119500000000 
 
1367186205, 170.710000000000, 1.000000000000 
 
1367275779, 153.550000000000, 1.465300000000 
 
1367289143, 198.350000000000, 6.049900000000 
 
1367323428, 197.180000000000, 7.000000000000 
 
1367331486, 155.660000000000, 1.606000000000 
 
1367348392, 189.950000000000, 5.264600000000 
 
1367351603, 146.060000000000, 2.998800000000 
 
1367356384, 188.010000000000, 7.138000000000 
 
1367364586, 167.170000000000, 0.179500000000 
 
1367364740, 191.010000000000, 7.853000000000 
 
1367378952, 165.000000000000, 1.818200000000 
 
1367423338, 142.430000000000, 3.931900000000 
 
1367446179, 133.240000000000, 2.251600000000 
 
1367457397, 131.820000000000, 1.273400000000 
 
1367474137, 129.410000000000, 0.390000000000 
 
1367506472, 125.970000000000, 0.079400000000 
 
1367517588, 112.580000000000, 4.441400000000 
 
1367534445, 116.880000000000, 0.171100000000 
 
1367562381, 108.910000000000, 0.550900000000 
 
1367591999, 106.120000000000, 0.471200000000 
 
1367595257, 104.460000000000, 0.478600000000 
 
1367599098, 144.030000000000, 1.041500000000 
 
1367604271, 99.230000000000, 2.962700000000 
 
1367625410, 103.810000000000, 2.022900000000` 
 

 
// Parse the multi-line CSV string above into a 2D array 
 
var complexCadCsvArray = $.csv.toArrays(complexCadCsv); 
 

 
// jquery-csv `toArrays` are strings, needs to be number 
 

 
// Trim whitespace and then convert to Number 
 
var complexCadCsvJsArrayNumbers = complexCadCsvArray.map(row => row.map(el => Number(el.trim()))); 
 

 
// Reduce trade times to same-sized intervals 
 
simplifyData(complexCadCsvJsArrayNumbers); 
 

 
$(".new_csv").text($.csv.fromObjects(monotized_data)); 
 

 
// ---------- 
 
$(".existing_csv").append(complexCadCsvArray);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://rawgit.com/evanplaice/jquery-csv/master/src/jquery.csv.min.js"></script> 
 
<h1>New simplified CSV</h1> 
 
<pre class="new_csv"></pre> 
 
<h1>Existing CSV run through <a href="https://github.com/evanplaice/jquery-csv">jquery-csv</a></h1> 
 
<pre class="existing_csv"></pre>

+0

こんにちは!これらの線に沿った何か? https://jsfiddle.net/c5c130fw/2/ –

+0

私は '}'がありませんでした。 – Barmar

+0

ダイスがまだありません:https://jsfiddle.net/c5c130fw/6/ –

関連する問題