Skip to content

Commit 318aa6d

Browse files
rdhyeeclaude
andcommitted
Add Eric's get_samples_at_geo_cord_location_via_sample_event query to parquet_cesium tutorial
Implemented Eric Kansa's combined query function that unifies Path 1 and Path 2 with richer sample metadata. This complements the existing separate path queries by providing a comprehensive view of all samples at a location. New features: - Added get_samples_at_geo_cord_location_via_sample_event() function - Combines Path 1 (direct event location) and Path 2 (via site) using UNION - Returns enriched metadata: sample_pid, sample_label, sample_description, thumbnail_url, alternate_identifiers, event_label, site_label, site_pid - Uses LEFT JOIN for sites in Path 1 (optional), INNER JOIN in Path 2 (required) - Orders results by thumbnail availability for better visual browsing - Added selectedSamplesCombined reactive cell with loading state management - Added new display section "Combined Samples at Location" with documentation - Added combinedLoading flag to track query state Architecture: - Preserves existing get_samples_1() and get_samples_2() functions unchanged - Adds parallel implementation for comparison and exploration - Maintains consistent pattern with existing loading indicators and error handling This enables users to see both simple (Path 1/Path 2 separate) and comprehensive (combined with rich metadata) views of samples at clicked locations. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent a9f4c43 commit 318aa6d

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

tutorials/parquet_cesium.qmd

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,66 @@ async function get_samples_2(pid) {
302302
return result ?? [];
303303
}
304304
305+
async function get_samples_at_geo_cord_location_via_sample_event(pid) {
306+
if (pid === null || pid ==="" || pid == "unset") {
307+
return [];
308+
}
309+
const q = `
310+
-- Path 1: Direct event location
311+
SELECT DISTINCT
312+
s.pid as sample_pid,
313+
s.label as sample_label,
314+
s.description as sample_description,
315+
s.thumbnail_url,
316+
s.alternate_identifiers,
317+
event.label as event_label,
318+
site.label as site_label,
319+
site.pid as site_pid,
320+
'direct_event_location' as location_path
321+
FROM nodes s
322+
JOIN nodes e1 ON s.row_id = e1.s AND e1.p = 'produced_by'
323+
JOIN nodes event ON e1.o[1] = event.row_id
324+
JOIN nodes e2 ON event.row_id = e2.s AND e2.p = 'sample_location'
325+
JOIN nodes g ON e2.o[1] = g.row_id
326+
LEFT JOIN nodes e3 ON event.row_id = e3.s AND e3.p = 'sampling_site'
327+
LEFT JOIN nodes site ON e3.o[1] = site.row_id
328+
WHERE s.otype = 'MaterialSampleRecord'
329+
AND event.otype = 'SamplingEvent'
330+
AND g.otype = 'GeospatialCoordLocation'
331+
AND g.pid = ?
332+
333+
UNION
334+
335+
-- Path 2: Via site location
336+
SELECT DISTINCT
337+
s.pid as sample_pid,
338+
s.label as sample_label,
339+
s.description as sample_description,
340+
s.thumbnail_url,
341+
s.alternate_identifiers,
342+
event.label as event_label,
343+
site.label as site_label,
344+
site.pid as site_pid,
345+
'via_site_location' as location_path
346+
FROM nodes s
347+
JOIN nodes e1 ON s.row_id = e1.s AND e1.p = 'produced_by'
348+
JOIN nodes event ON e1.o[1] = event.row_id
349+
JOIN nodes e2 ON event.row_id = e2.s AND e2.p = 'sampling_site'
350+
JOIN nodes site ON e2.o[1] = site.row_id
351+
JOIN nodes e3 ON site.row_id = e3.s AND e3.p = 'site_location'
352+
JOIN nodes g ON e3.o[1] = g.row_id
353+
WHERE s.otype = 'MaterialSampleRecord'
354+
AND event.otype = 'SamplingEvent'
355+
AND site.otype = 'SamplingSite'
356+
AND g.otype = 'GeospatialCoordLocation'
357+
AND g.pid = ?
358+
359+
ORDER BY thumbnail_url IS NOT NULL DESC, sample_label
360+
`;
361+
const result = await loadData(q, [pid, pid], "loading_combined", "samples_combined");
362+
return result ?? [];
363+
}
364+
305365
async function locationUsedBy(rowid){
306366
if (rowid === undefined || rowid === null) {
307367
return [];
@@ -315,6 +375,7 @@ mutable clickedPointId = "unset";
315375
mutable geoLoading = false;
316376
mutable s1Loading = false;
317377
mutable s2Loading = false;
378+
mutable combinedLoading = false;
318379
319380
// Precompute selection-driven data with loading flags
320381
selectedGeoRecord = {
@@ -344,6 +405,15 @@ selectedSamples2 = {
344405
}
345406
}
346407
408+
selectedSamplesCombined = {
409+
mutable combinedLoading = true;
410+
try {
411+
return await get_samples_at_geo_cord_location_via_sample_event(clickedPointId);
412+
} finally {
413+
mutable combinedLoading = false;
414+
}
415+
}
416+
347417
md`Retrieved ${pointdata.length} locations from ${parquet_path}.`;
348418
```
349419

@@ -553,4 +623,28 @@ s2Loading ? md`(loading…)` : md`\`\`\`
553623
${JSON.stringify(samples_2, null, 2)}
554624
\`\`\`
555625
`
626+
```
627+
628+
629+
## Combined Samples at Location (Path 1 + Path 2 with Rich Metadata)
630+
631+
<div id="loading_combined" hidden>Loading combined samples…</div>
632+
633+
This query implements Eric Kansa's `get_samples_at_geo_cord_location_via_sample_event` function, which combines both Path 1 and Path 2 using UNION and returns richer sample metadata including:
634+
635+
- Sample metadata: `sample_pid`, `sample_label`, `sample_description`
636+
- Visual assets: `thumbnail_url`, `alternate_identifiers`
637+
- Event context: `event_label`
638+
- Site information: `site_label`, `site_pid` (when available)
639+
- Path indicator: `location_path` (direct_event_location or via_site_location)
640+
641+
Results are ordered with samples that have thumbnails first, making it easier to find visually rich records.
642+
643+
```{ojs}
644+
//| echo: false
645+
samples_combined = selectedSamplesCombined
646+
combinedLoading ? md`(loading…)` : md`\`\`\`
647+
${JSON.stringify(samples_combined, null, 2)}
648+
\`\`\`
649+
`
556650
```

0 commit comments

Comments
 (0)