0
我做了一個小提琴來測試我的JavaScript。我原本無法獲取CSV數據,因爲我的谷歌雲存儲桶未設置跨源請求標頭。在修改json頭文件並將數據提取到我的小提琴中時,我得到了一些工作。在MTurk Worker沙箱中執行以測試我的數據後,不再拉到我的手錶中,而且控制檯中也沒有錯誤。我真的不確定會發生什麼問題,所以我在這裏發帖,因爲我沒有任何可以解決的問題。任何建議,以搜索將非常感激。d3.csv工作在jsfiddle不工作MTurk工作者沙盒
附加信息:鉻停止我的這個頁面鏈接工作不工作
workersandbox.mturk.com重定向你太多次。 嘗試清除您的Cookie。 ERR_TOO_MANY_REDIRECTS
但是,在Firefox中HIT顯示效果很好。
的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))
}
});