Name change tracker over time

I couldn’t figure out exactly where to put this expression setup (or maybe I didn’t have the toolkit configured correctly), but I followed the same logic with some custom scripted properties and was able to achieve this!

image

I do have some bugs/questions if you guys don’t mind helping again. Right now I am using a dynamically updated dataset that, using a script transform, turns itself into the following format to fit into the XYChart dataSources property.


The path to the program name tag is also dynamic, I have multiple robots and am switching between them via a dropdown menu, so the program name I am currently tracking’s path can change.
However when I switch between robots, the chart gets wiped and no longer shows the historical name changes from the past 5 minutes. It is probably an issue with my scripting one either datasources or one of my properties, but I can’t identify it.
Additionally, if the same task has been running for 5min, as soon as it crosses the 5min mark, it gets wiped and the chart is empty. This happens because the start time goes out of scope, so I assume I need some custom logic to fix it to the start and end time of the 5min window until a new task starts?

def transform(self, value, quality, timestamp):


    import system
    if value is None or value.getRowCount() == 0:
        return []  # no history yet

    # Color mapping for known tasks
    colorMap = {
        "INT_ANS": "#00FF30",
        "PRG0601": "#FF0030",
        "WUC1_030": "#30A0FF",
        "WUC2_030": "#FFD030",
        "PNS0061": "#A030FF",
        "WCL1_030": "#FF8030",
        "WCL2_030": "#00C0C0"
    }

    rows = value.getRowCount()
    data = []
    now = system.date.now()

    for i in range(rows):
        tagValue = value.getValueAt(i, "value")
        startTs = value.getValueAt(i, "timestamp")

        # End time = next row's timestamp, or 'now' if last row
        if i < rows - 1:
            endTs = value.getValueAt(i + 1, "timestamp")
        else:
            endTs = now

        segment = {
            "color": colorMap.get(tagValue, "#888888"),  # default gray if missing
            "fromDate": system.date.format(startTs, "yyyy-MM-dd HH:mm:ss"),
            "toDate": system.date.format(endTs, "yyyy-MM-dd HH:mm:ss"),
            "name": "Program",
            "tagValue": tagValue,
            # Tooltip shows task name + time span
            "tooltip": "{}\n{} → {}".format(
                tagValue,
                system.date.format(startTs, "HH:mm:ss"),
                system.date.format(endTs, "HH:mm:ss")
            )
        }
        data.append(segment)

    return {"key": data}