addRouteEdge function
Record a transition.
Implementation
RouteGraphFile addRouteEdge(
RouteGraphFile g,
String from,
String to,
String ts,
) {
final f = from.trim();
final t = to.trim();
if (f.isEmpty || t.isEmpty || f == t) return g;
final edges = List<RouteGraphEdge>.of(g.edges);
final i = edges.indexWhere((e) => e.from == f && e.to == t);
if (i >= 0) {
edges[i] = edges[i].copyWith(count: edges[i].count + 1, lastSeen: ts);
} else {
edges.add(RouteGraphEdge(
from: f,
to: t,
count: 1,
firstSeen: ts,
lastSeen: ts,
));
}
return RouteGraphFile(
schemaVersion: g.schemaVersion,
type: g.type,
nodes: g.nodes,
edges: edges,
sync: g.sync.markDirty(ts),
);
}