@@ -46,6 +46,35 @@ om_find_dh_elid <- function(elid, ds) {
4646 return (model_search_elid )
4747}
4848
49+ om_model_run_monitor <- function (ds_model , minspast = 60 , elids = FALSE , limit = 100 ) {
50+ status_sql = " select a.elementid, a.elemname, b.status_mesg, b.runid, b.host, b.last_updated,
51+ CASE
52+ WHEN report is NULL THEN
53+ replace(remote_url,'runlog'||b.runid||'.'||c.elementid, 'report'||c.elementid||'-'||b.runid)
54+ ELSE report
55+ END as report
56+ from scen_model_element as a, system_status as b
57+ left outer join scen_model_run_elements as c
58+ on( b.element_key = c.elementid and c.runid = b.runid )
59+ where a.elementid = b.element_key
60+ "
61+ if (minspast > 0 ) {
62+ status_sql = fn $ paste(status_sql , " and b.last_updated >= (now() - interval '$minspast minutes')" )
63+ }
64+ if (! is.logical(elids )) {
65+ elist = paste0(" (" , paste(elids , collapse = " ," ), " )" )
66+ status_sql = fn $ paste(status_sql , " and a.elementid in $elist" )
67+ }
68+
69+ status_sql = fn $ paste(status_sql , " order by last_updated DESC LIMIT $limit" )
70+ message(status_sql )
71+ status_recs = sqldf :: sqldf(
72+ status_sql ,
73+ connection = ds_model $ connection
74+ )
75+ return (status_recs )
76+ }
77+
4978# CIA_data Function: Grabs data from vahydro and returns data frame
5079# data frame contains flow and percent change data for 2 runids of all upstream and downstream river segments
5180# ' Cumulative Impact Analysis Data Function
0 commit comments