Stale Data Monitor For KX Dashboard (non-kdb solution)

We are looking to implement a KX Dashboard Solution to the UI that shows if data in a table is stale (or how long was the last update). Ideally, we would like a warning that is not dependent on kdb; maybe a JavaScript or alternative client side warning.

With a little help from ChatGPT, this Virtual Query solution compares the Data Source time, “OpenDate” (datetime) to the browser time. “Source” is a real-time data stream (or polled data set). Can show comparison in a data grid table, and use a Highlight Rule to differentiate between true and false state.

function (source, callback) {
  var now = new Date();
    // Adds a 5 second buffer to current browser time
    var nowWithBuffer = new Date(now.getTime() - 5000); // 5 second buffer

    var result = {
        "columns": [
            "Data Source",
            "Is Stale",
            "Current Time"
        ],
        "meta": {
            "Data Source": 15,
            "Is Stale": 11,
            "Current Time": 12
        },
        "rows": []
    };

    result.rows = (source.rows || []).map(function(row) {
        // Convert kdb+ DateTime string to JS Date object
        var openDate = new Date(row.OpenDate);

        // Compare OpenDate to now
        var isStale = openDate < nowWithBuffer;

        // Format OpenDate for display
        var openDateStr = openDate.toISOString().replace('T', ' ').substring(0, 19);

        return {
            "Data Source": openDateStr,
            "Is Stale": isStale,
            "Current Time": now.toISOString().replace('T', ' ').substring(0, 19)
        };
    });

    callback(result);
}