addRouteNode function
Record a visit to screen: increment its visitCount or add it.
Implementation
RouteGraphFile addRouteNode(RouteGraphFile g, String screen, String ts) {
final s = screen.trim();
if (s.isEmpty) return g;
final nodes = List<RouteGraphNode>.of(g.nodes);
final i = nodes.indexWhere((n) => n.screen == s);
if (i >= 0) {
nodes[i] = nodes[i].copyWith(
lastSeen: ts,
visitCount: nodes[i].visitCount + 1,
);
} else {
nodes.add(RouteGraphNode(
screen: s,
firstSeen: ts,
lastSeen: ts,
visitCount: 1,
));
}
return RouteGraphFile(
schemaVersion: g.schemaVersion,
type: g.type,
nodes: nodes,
edges: g.edges,
sync: g.sync.markDirty(ts),
);
}