-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from roundtableAI/link-updates
- Loading branch information
Showing
9 changed files
with
431 additions
and
263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,44 @@ | ||
import Survey from '../../library/core/survey.js'; | ||
import SingleSelect from '../../library/elements/singleSelect.js'; | ||
import BoundingBox from '../../library/elements/boundingBox.js'; | ||
import ProgressBar from '../../library/plugins/progressBar.js'; | ||
|
||
// Add images and questions for each page | ||
const imageUrls = ['https://i.redd.it/three-cats-v0-xraium6wenpb1.jpg?width=720&format=pjpg&auto=webp&s=78e59ff2a4c87196176b11a4eaf83aafe5f1e917', | ||
'https://s3.amazonaws.com/cdn-origin-etr.akc.org/wp-content/uploads/2017/11/12153852/American-Eskimo-Dog-standing-in-the-grass-in-bright-sunlight-400x267.jpg']; | ||
|
||
async function addLabelingPage(survey, imageUrl, index) { | ||
const imageContainsCat = new SingleSelect({ | ||
id: `labeling-q${index}`, | ||
text: `Does this contain a cat?<br/><img src="${imageUrl}" style="width:100%;">`, | ||
subText: 'Please select the correct answer', | ||
options: ['Yes', 'No'], | ||
}); | ||
const id = `q${index}`; | ||
await survey.showPage({ id, elements: [ imageContainsCat ] }); | ||
} | ||
const imageUrls = ['https://www.usnews.com/object/image/00000168-b98c-d246-a9f9-fddd8bb50000/190204-seattletunnel-editorial.jpg?update-time=1549301335348&size=responsive640', | ||
'https://www.giviexplorer.com/imagesC/11886/576x576xGIVI-Explorer_friends4adventure_Ecuador-cover.jpg']; | ||
|
||
async function addBoundingBoxPage(survey, imageUrl, index) { | ||
const catBoundingBox = new BoundingBox({ | ||
const boundingBoxQ = new BoundingBox({ | ||
id: `bb-q${index}`, | ||
text: `Draw a bounding box around the cat in the image below`, | ||
text: `Draw a bounding box around the vehicles in the image below`, | ||
subText: `If there are no vehicles, skip to the next page`, | ||
imageUrl: imageUrl, | ||
}); | ||
const id = `q${index}-bb`; | ||
await survey.showPage({ id, elements: [ catBoundingBox ] }); | ||
await survey.showPage({ id, elements: [ boundingBoxQ ] }); | ||
} | ||
|
||
async function runSurvey() { | ||
const survey = new Survey({ | ||
participantId: 'participant_123', | ||
condition: 'test', | ||
participantId: 'test-participant', | ||
condition: 'car-labeling', | ||
}); | ||
// Initial labeling pages | ||
|
||
const progressBar = new ProgressBar({ | ||
maxPages: imageUrls.length, | ||
styles: { | ||
bar: { | ||
backgroundColor: 'black' | ||
} | ||
} | ||
}); | ||
survey.addPlugin(progressBar); | ||
|
||
// Bounding box pages | ||
for (let i = 0; i < imageUrls.length; i++) { | ||
await addLabelingPage(survey, imageUrls[i], i); | ||
await addBoundingBoxPage(survey, imageUrls[i], i); | ||
} | ||
|
||
const catImages = imageUrls.filter((url, index) => survey.getResponse(`labeling-q${index}`) === 'Yes'); | ||
|
||
if (catImages.length > 0) { | ||
// Add the progress bar plugin with custom styles and total pages | ||
const progressBar = new ProgressBar({ maxPages: catImages.length, progressAsPercentage: true }); | ||
survey.addPlugin(progressBar); | ||
|
||
// Bounding box pages | ||
for (let i = 0; i < catImages.length; i++) { | ||
await addBoundingBoxPage(survey, imageUrls[i], i); | ||
} | ||
|
||
survey.finishSurvey('Thank you for completing the task!'); | ||
}; | ||
survey.finishSurvey('Thank you for completing the task!'); | ||
} | ||
|
||
runSurvey(); |
Oops, something went wrong.