Skip to content
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

kobotoolbox: add job examples #633

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Conversation

hunterachieng
Copy link
Contributor

@hunterachieng hunterachieng commented Feb 6, 2025

DO NOT MERGE UNTIL kobo 3.0 is released

Short Description

Implement job examples for kobotoolbox adaptor

Closes #970

AI Usage

Please disclose how you've used AI in this work (it's cool, we just want to
know!):

  • Code generation (copilot but not intellisense)
  • Learning or fact checking
  • Strategy / design
  • Optimisation / refactoring
  • Translation / spellchecking / doc gen
  • Other
  • I have not used AI

You can read more details in our
Responsible AI Policy

adaptors/library/jobs/kobotoolbox-create-asset.js Outdated Show resolved Hide resolved
@@ -0,0 +1,6 @@
fn(state => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the value of the fn() block in this example?

Signed-off-by: Hunter Achieng <[email protected]>
Signed-off-by: Hunter Achieng <[email protected]>
Signed-off-by: Hunter Achieng <[email protected]>
@josephjclark
Copy link
Contributor

Ok that new example is great!

I think it would be nice to have another example which uses http helpers to do something a bit more weird. Something we can't do with the other APIs.

I don't know what that is. Maybe you can ask around the team for ideas? Or look at the APIs and see if you can invent something?

I wouldn't spend ages on this. I agree with @aleksa-krolls that 2 or 3 examples is ideal. But as this is a small API and for our users the use-case is surely just "I want to download some/all form submissions", there might not be much value in that.

I suppose the other thing I can think of (in the same example or a different one) is to download submissions after a certain date. You'd need to use the query strings for that which aren't well documented but I could probably help

@hunterachieng
Copy link
Contributor Author

Ok that new example is great!

I think it would be nice to have another example which uses http helpers to do something a bit more weird. Something we can't do with the other APIs.

I don't know what that is. Maybe you can ask around the team for ideas? Or look at the APIs and see if you can invent something?

I wouldn't spend ages on this. I agree with @aleksa-krolls that 2 or 3 examples is ideal. But as this is a small API and for our users the use-case is surely just "I want to download some/all form submissions", there might not be much value in that.

I suppose the other thing I can think of (in the same example or a different one) is to download submissions after a certain date. You'd need to use the query strings for that which aren't well documented but I could probably help

I can add the example with the date filters. Let me read the docs again and will ping you if I am stuck

@aleksa-krolls
Copy link
Member

@hunterachieng maybe an example that uses cursor? Something like the below which gets all submissions greater or equal to the cursor date.

https://kf.kobotoolbox.org/api/v2/assets/${survey.uid}/data/?format=json&query={"_submission_time":{"$gte":"${cursorDate}"}

@hunterachieng
Copy link
Contributor Author

@josephjclark I have re-read the docs and the only other thing we can do is ordering the items such as ?ordering=date_modified

@josephjclark
Copy link
Contributor

@hunterachieng what about Aleksa's suggestion? You can pass a query on get submissions

You could also use http to fetch a form I'd (maybe via another query)

Signed-off-by: Hunter Achieng <[email protected]>
@hunterachieng
Copy link
Contributor Author

@josephjclark I have implemented the example but I used http.get since getSubmissions does not take in any options object

@josephjclark
Copy link
Contributor

@hunterachieng why do we not have options in getSubmissions? The issue asks for this:

getSubmissions(formId, options) // options is { query, limit, start }

@hunterachieng
Copy link
Contributor Author

@hunterachieng why do we not have options in getSubmissions? The issue asks for this:

getSubmissions(formId, options) // options is { query, limit, start }

I have added it back

Signed-off-by: Hunter Achieng <[email protected]>
return state;
});

getSubmissions($.formId, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cool, but

  1. we ought to use cursor() to set up the cursor. This should simulate a whole job step
  2. the fn block doesn't do anything

Maybe we can make this more interesting by doing:

  1. getForms() to pull down all forms
  2. each($.data, getSubmissions($.data.id, { query })

That then is a job that gets all submissions for all forms, using a cursor. Cool!

Also, please double check that kobo (and the template) exports cursor from common!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes cursor is exported in both

Signed-off-by: Hunter Achieng <[email protected]>
Copy link
Contributor

@josephjclark josephjclark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me! Thanks @hunterachieng

@aleksa-krolls as you're a bit savvier with Kobo any comments?

I don't want to merge this until the update is out, so let's keep this open but approved for now.

@aleksa-krolls
Copy link
Member

@josephjclark made a small change to one of the comments, but otherwise looks good to merge whenever ready

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants