Skip to content

Commit ed2721c

Browse files
committed
Created a next-model pager"
1 parent df7e910 commit ed2721c

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

cli/macrostrat/cli/subsystems/xdd/fixtures/kg-views.sql

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,3 +286,22 @@ WITH stats AS (
286286
SELECT st.*, n_runs, n_entities, n_matches, n_strat_names, created, last_update
287287
FROM macrostrat_xdd.source_text st
288288
JOIN stats s ON s.source_text_id = st.id;
289+
290+
291+
/** Function that returns an ID of the "next" model run to be targeted for annotation */
292+
CREATE OR REPLACE FUNCTION macrostrat_xdd.next_model_run_id()
293+
RETURNS integer AS $$
294+
WITH next_run AS (
295+
SELECT mr.id, mr.timestamp, coalesce(sum((mr1.supersedes = mr.id)::integer), 0) n_superseding
296+
FROM macrostrat_xdd.model_run mr
297+
LEFT JOIN macrostrat_xdd.model_run mr1
298+
ON mr1.supersedes = mr.id
299+
JOIN macrostrat_xdd.source_text st
300+
ON st.id = mr.source_text_id
301+
WHERE st.xdd_tags ILIKE '%geo_entities%'
302+
GROUP BY mr.id, mr.timestamp
303+
ORDER BY n_superseding, timestamp
304+
LIMIT 1
305+
)
306+
SELECT id FROM next_run;
307+
$$ LANGUAGE SQL;

0 commit comments

Comments
 (0)