gpt4 book ai didi

javascript - 将输出 JSON 发送到 MTurk 提​​交

转载 作者:行者123 更新时间:2023-11-30 21:11:17 24 4
gpt4 key购买 nike

我有一个 HTML 表格,可以由 MTurk 编辑以收集数据。我构建了一个函数来将表转换为 json,以便它在每个 HIT 中显示在一行中,除非我不确定现在如何提交它。我已成功将数据聚合到 json,然后将其记录在控制台中。我对 HTML 和 Javascript 比较陌生。理想的答案将清楚地展示我将如何在沙盒中将数据提交回亚马逊。

Javascript

  <script language='Javascript'>
function deleteRow(row)
{
var i=row.parentNode.parentNode.rowIndex;
document.getElementById('Table').deleteRow(i);
}


function addRow(row)
{
var i = row.parentNode.parentNode.rowIndex;
var tr = document.getElementById('Table').insertRow(i+1);
tr.innerHTML = row.parentNode.parentNode.innerHTML;
tr.children[0].innerHTML = tr.parentNode.querySelectorALL("tr").length-1;
}

$('#convert-table').click(function()
{
var table = $('#Table').tableToJSON(
{
onlyColumns:[0,1,2],
extractor:function(cellIndex, $cell) {
return $cell.find('input').val();
}
});
console.log(table);
alert(JSON.stringify(table));
});


</script>

HTML

<HTMLQuestion xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2011-11-11/HTMLQuestion.xsd">
<HTMLContent><![CDATA[
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/>
<script type='text/javascript' src='https://s3.amazonaws.com/mturk-public/externalHIT_v1.js'></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://storage.googleapis.com/jquerytabletohtml/jquery.tabletojson.js"></script>
</head>
<body>
<form name='mturk_form' method='post' id='mturk_form' action='https://www.mturk.com/mturk/externalSubmit'>
<input type='hidden' value='' name='assignmentId' id='assignmentId'/>

<h1 align="center">Insertion of Missing Data</h1>
<h2>Instructions:</h2>
<p>Open the document <a href="https://storage.googleapis.com/directionalsurvey/Amazon%20Turk%20Test%20files/PDFS/100122514.pdf" target='_blank'>HERE</a> and look for a missing value by scanning a column in the pdf until the data shown below does not line up. when you find one insert a row and enter the three variables Measured Depth, Inclination, and Azimuth.</p>
<p> The variables could appear as: </p>
<ul>
<li><b>Measured Depth</b></li>
<ul><li>MD, Depth, Measured Depth, M.D.</li></ul>
<li><b>Inclination</b></li>
<ul><li>Incl, IncAng, Inclination Angle, Inclination</li></ul>
<li><b>Azimuth</b></li>
<ul><li>Azi, Azimuth Angle, DirDeg, Directional Angle</li></ul>
</ul>

<p>I expect there to be <b>~ 5 </b>missing rows... when you are done hit submit.</p>

<div id="tablediv">
<table id="Table" border="1">
<tr>
<td><b>Measured Depth</b></td>
<td><b>Inclination</b></td>
<td><b>Azimuth</b></td>
<td><b>Delete?</b></td>
<td><b>Add Row?</b></td>
</tr>
<tr>
<td><input size=25 type="text" id="Measured Depth0[]" contenteditable="true" value='339'></td>
<td><input size=25 type="text" id="Inclination0[]" contenteditable='true' value='0.540000021'></td>
<td><input size=25 type="text" id="Azimuth0[]" contenteditable='true' value='310.7200012'></td>
<td><input type="button" id="delbutton0" value="Delete" onclick="deleteRow(this)"/></td>
<td><input type="button" id="addmorebutton0" value="Add Row Below" onclick="addRow(this)"/></td>
</tr>
<tr>
<td><input size=25 type="text" id="Measured Depth1[]" contenteditable="true" value='432'></td>
<td><input size=25 type="text" id="Inclination1[]" contenteditable='true' value='0.930000007'></td>
<td><input size=25 type="text" id="Azimuth1[]" contenteditable='true' value='326.3599854'></td>
<td><input type="button" id="delbutton1" value="Delete" onclick="deleteRow(this)"/></td>
<td><input type="button" id="addmorebutton1" value="Add Row Below" onclick="addRow(this)"/></td>
</tr>
</table>
</div>
<button id="convert-table">Convert!</button>
<p><input type='submit' id='submitButton' value='Submit' /></p></form>
<script language='Javascript'>turkSetAssignmentID();</script>

</body>
</html>
]]>
</HTMLContent>
<FrameHeight>900</FrameHeight>
</HTMLQuestion>

最佳答案

你真的很接近。在

正下方
<input type='hidden' value='' name='assignmentId' id='assignmentId'/>

元素,再添加一个:

<input type='hidden' value='' name='data' id='data'/>

然后,而不是做

alert(JSON.stringify(table));

这样做:

$('#data').val(JSON.stringify(table));

这将导致隐藏的 data 输入元素的值保存 table 的值。当 Worker 按下提交时,这个隐藏字段将被传输到 MTurk 并在您获得 HIT 时可用。

关于javascript - 将输出 JSON 发送到 MTurk 提​​交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46106308/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com