Update CoMapeo fetch script to use new endpoints, including presetRef#175
Update CoMapeo fetch script to use new endpoints, including presetRef#175rudokemper merged 11 commits intomainfrom
Conversation
| ``` | ||
|
|
||
| ### `GET /projects/abc123/observations` | ||
| ### `GET /projects/abc123/observation` |
There was a problem hiding this comment.
Here and presets, is there a reason we use singular and not plural?
The reason to (in theory) use plural is to allow a hypothetical endpoint that lists all observations (or all presets):
/projects/abc123/observations
/projects/abc123/presets
Also for consistency with "projects" in the same URL.
But I will not press this point if you prefer to leave it.
There was a problem hiding this comment.
Oh, this is not our code, this is defined upstream isnt it?
There was a problem hiding this comment.
Correct. See digidem/comapeo-cloud#61 (review)
They have changed some of the routes to singular, but not all (though it is their intention).
| url = f"{server_url}/projects/{project_id}/preset/{preset_doc_id}" | ||
| headers = { | ||
| "Authorization": f"Bearer {access_token}", | ||
| } |
There was a problem hiding this comment.
it's not a big deal yet so maybe we can sleep on this suggestion for now...
A common pattern is to not pass nitty-gritty details for the request like access_token around to different functions, but instead to instantiate a requests.Session() one time and pass that around.
So higher up in the stack (transform_comapeo_observations or even whatever calls it) would do this:
session = requests.Session()
session.headers.update({
"Authorization": f"Bearer {access_token}"
})
# ...
fetch_preset(..., session)And then here:
def fetch_preset(server_url, session, project_id, preset_doc_id):
try:
response = session.get(url)
response.raise_for_status()
# etc
except ...There was a problem hiding this comment.
Great suggestion, thank you. I implemented this.
Goal
Closes #174.
Before syncing this, we will need to do https://github.com/ConservationMetrics/gc-programs/issues/114.
What I changed and why
SAMPLE_OBSERVATIONS, and addedSAMPLE_PRESETSfor TDD; these were retrieved from a real CoMapeo cloud server running the latest version./observationroutefetch_preset. This enables us to finally add, among other things, thecategoryname, which has been requested by virtually all of our users. (Another nice one: the hash for color, so we can use the same colors e.g. in GC Explorer as what users saw on their CoMapeo map for each category)What I'm not doing here
presetRefdata for project safeguarding [comapeo] Download allpresetRefdata to have a complete record of the entire config #178max_months_lookbacktest #176/icon/:docId. Perhaps that can be part of [comapeo] Download allpresetRefdata to have a complete record of the entire config #178LLM use disclosure
Tests generated and improved by Claude Sonnet 4.5 in Cursor, with a strong amount of hand-holding.