-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Engaging Crowds: Subject set completeness #2016
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4f0f54b
Install node-fetch
eatyourgreens 37604f6
Fetch subject set status from cellect
eatyourgreens 510d85e
Add completeness counts to subject set cards
eatyourgreens e0ba688
Restore workflow.default
eatyourgreens 65f5d1c
Add cellect API to tests
eatyourgreens 0d9e870
Tidy up workflow display names
eatyourgreens e072223
Split code path for grouped workflows
eatyourgreens 915d5d5
log page props errors to Sentry
eatyourgreens ff47add
Split up helper files
eatyourgreens 93e579d
Fix typo
eatyourgreens File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
65 changes: 65 additions & 0 deletions
65
packages/app-project/src/helpers/fetchSubjectSets/fetchSubjectSets.js
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { panoptes } from '@zooniverse/panoptes-js' | ||
import fetch from 'node-fetch' | ||
|
||
import { logToSentry } from '@helpers/logger' | ||
|
||
async function fetchSubjectSetData(subjectSetIDs, env) { | ||
let subject_sets = [] | ||
try { | ||
const query = { | ||
env, | ||
id: subjectSetIDs.join(',') | ||
} | ||
const response = await panoptes.get('/subject_sets', query) | ||
subject_sets = response.body.subject_sets | ||
await Promise.allSettled(subject_sets.map(subjectSet => fetchPreviewImage(subjectSet, env))) | ||
} catch (error) { | ||
console.error(error) | ||
logToSentry(error) | ||
} | ||
return subject_sets | ||
} | ||
|
||
async function fetchWorkflowCellectStatus(workflow) { | ||
let groups = {} | ||
if (workflow.grouped) { | ||
try { | ||
const workflowURL = `https://cellect.zooniverse.org/workflows/${workflow.id}/status` | ||
const response = await fetch(workflowURL) | ||
const body = await response.json() | ||
groups = body.groups ?? {} | ||
} catch (error) { | ||
console.error(error) | ||
logToSentry(error) | ||
} | ||
} | ||
return groups | ||
} | ||
|
||
async function fetchPreviewImage (subjectSet, env) { | ||
try { | ||
const response = await panoptes | ||
.get('/set_member_subjects', { | ||
env, | ||
subject_set_id: subjectSet.id, | ||
include: 'subject', | ||
page_size: 1 | ||
}) | ||
const { linked } = response.body | ||
subjectSet.subjects = linked.subjects | ||
} catch (error) { | ||
console.error(error) | ||
logToSentry(error) | ||
} | ||
} | ||
|
||
export default async function workflowSubjectSets(workflow, env) { | ||
eatyourgreens marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const subjectSetCounts = await fetchWorkflowCellectStatus(workflow) | ||
const subjectSetIDs = Object.keys(subjectSetCounts) | ||
const subjectSets = await fetchSubjectSetData(subjectSetIDs, env) | ||
subjectSets.forEach(subjectSet => { | ||
subjectSet.availableSubjects = subjectSetCounts[subjectSet.id] | ||
}) | ||
return subjectSets | ||
} | ||
|
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './fetchSubjectSets' |
89 changes: 47 additions & 42 deletions
89
packages/app-project/src/helpers/fetchWorkflowsHelper/fetchWorkflowsHelper.js
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self: this dependency adds the equivalent of "window.fetch" to Node, which doesn't have fetch functionality by default (methinks).