2017-09-22 110 views
0

我做了一个小提琴来测试我的JavaScript。我原本无法获取CSV数据,因为我的谷歌云存储桶未设置跨源请求标头。在修改json头文件并将数据提取到我的小提琴中时,我得到了一些工作。在MTurk Worker沙箱中执行以测试我的数据后,不再拉到我的手表中,而且控制台中也没有错误。我真的不确定会发生什么问题,所以我在这里发帖,因为我没有任何可以解决的问题。任何建议,以搜索将非常感激。d3.csv工作在jsfiddle不工作MTurk工作者沙盒

附加信息:铬停止我的这个页面链接工作不工作

workersandbox.mturk.com重定向你太多次。 尝试清除您的Cookie。 ERR_TOO_MANY_REDIRECTS

但是,在Firefox中HIT显示效果很好。

jsFiddle

的Javascript

var csvLink = 'https://storage.googleapis.com/directionalsurvey/testDScsv.csv'; 
var data = []; 
//var trueTVD = X6J374YZ; 
var trueTVD = 700; 
d3.csv(csvLink, function(dat) { 
    for (i = 0; i < dat.length; i++) { 
    var inner = []; 
    inner.push(dat[i]['Measured Depth']); 
    inner.push(dat[i]['Inclination']); 
    inner.push(dat[i]['Azimuth']); 
    data.push(inner); 
    } 

    var container1 = document.getElementById('Table'), 
    hot1; 

    var hot1 = new Handsontable(container1, { 
    data: data, 
    colHeaders: ['Measured Depth', "Inclination", "Azimuth"], 
    rowHeaders: true, 
    minSpareRows: 0, 
    contextMenu: ['row_above', 'row_below', 'remove_row'] 
    }); 

    function countRows() { 
    var ht = hot1 
    var rowcount = ht.countRows() - ht.countEmptyRows(); 
    return rowcount; 
    } 


    $("#get_data").click(submitForm); 

    /////////////////////////////////////////Begin Functions for Minimum Curvature Algorithm//////////////////////////// 
    function Beta(I1, I2, Az1, Az2) { 
    var dI = Deg2Rad(I2) - Deg2Rad(I1); 
    var dA = Deg2Rad(Az2) - Deg2Rad(Az1); 
    var X = math.sin(Deg2Rad(I1)) * math.sin(Deg2Rad(I2)); 
    var Y = math.cos(dI); 
    var Z = math.cos(dA); 
    var beta = math.acos(Y - (X * (1 - Z))); 
    return beta; 
    } 

    function RF(beta) { 
    var b = beta; 
    var rf = (2/b) * math.tan(b/2); 
    return rf; 
    } 

    function TVD(dmd, I1, I2, RF) { 
    var A = math.cos(Deg2Rad(I1)) + math.cos(Deg2Rad(I2)); 
    var tvd = (dmd/2) * A * RF; 
    return tvd; 
    } 

    function Deg2Rad(deg) { 
    return deg * math.pi/180; 
    } 

    function Rad2Deg(rad) { 
    return rad * 180/math.pi 
    } 

    // function to calculate the TVD 
    function TVDcalc(MD, INC, AZI, Depth) { 

    var md = MD; 
    var inc = INC; 
    var azi = AZI; 
    var i; 
    for (i = 0; i < md.length - 1; i++) { 
     var beta = Beta(inc[i], inc[i + 1], azi[i], azi[i + 1]); 
     if (inc[i] == inc[i + 1]) { 
     var rf = 1; 
     } else { 
     var rf = RF(beta); 
     } 
     var dMD = md[i + 1] - md[i]; 
     Depth.push(TVD(dMD, inc[i], inc[i + 1], rf) + Depth[i]); 
    } 
    return Depth 
    } 


    /////////////////////////////////////////End Functions for Minimum Curvature Algorithm//////////////////////////// 
    function enable(TVD) { 
    if (TVD[TVD.length - 1] >= trueTVD - 5 && TVD[TVD.length - 1] <= trueTVD + 5) { 
     //console.log(TVD[TVD.length - 1]); 
     $('#submitButton').prop("disabled", false); 
    } else { 
     $('#submitButton').prop("disabled", true); 
    } 
    } 

    function submitForm() { 
    var htContents = hot1.getSourceData() //getSourceData(1,1,countRows(),3) 
     //console.log(htContents); 
    var md = []; 
    var inc = []; 
    var azi = []; 
    var Depth = []; 
    var fd = Number($('#TVD1').val()) 
    Depth.push(fd); 
    //transform the HOT into individual arrays for ingestion in TVD calc 
    for (i = 0; i < countRows(); i++) { 
     md.push(htContents[i][0]); 
     inc.push(htContents[i][1]); 
     azi.push(htContents[i][2]); 
    } 
    var TVD = TVDcalc(md, inc, azi, Depth) 
    enable(TVD); 
    console.log("".concat("Calculated TVD: ", Math.round(Depth[Depth.length - 1]))); 
    console.log("".concat("Expected TVD: ", trueTVD)) 
    } 

}); 

回答