Skip to content

Commit

Permalink
Created a next-model pager"
Browse files Browse the repository at this point in the history
  • Loading branch information
davenquinn committed Dec 16, 2024
1 parent df7e910 commit ed2721c
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions cli/macrostrat/cli/subsystems/xdd/fixtures/kg-views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,22 @@ WITH stats AS (
SELECT st.*, n_runs, n_entities, n_matches, n_strat_names, created, last_update
FROM macrostrat_xdd.source_text st
JOIN stats s ON s.source_text_id = st.id;


/** Function that returns an ID of the "next" model run to be targeted for annotation */
CREATE OR REPLACE FUNCTION macrostrat_xdd.next_model_run_id()
RETURNS integer AS $$
WITH next_run AS (
SELECT mr.id, mr.timestamp, coalesce(sum((mr1.supersedes = mr.id)::integer), 0) n_superseding
FROM macrostrat_xdd.model_run mr
LEFT JOIN macrostrat_xdd.model_run mr1
ON mr1.supersedes = mr.id
JOIN macrostrat_xdd.source_text st
ON st.id = mr.source_text_id
WHERE st.xdd_tags ILIKE '%geo_entities%'
GROUP BY mr.id, mr.timestamp
ORDER BY n_superseding, timestamp
LIMIT 1
)
SELECT id FROM next_run;
$$ LANGUAGE SQL;

0 comments on commit ed2721c

Please sign in to comment.