getRouteStatistics method
Gets route statistics for monitoring and analysis
routingTable - Routing table to analyze
Returns map with various statistics
Implementation
Map<String, dynamic> getRouteStatistics(RoutingTable<T> routingTable) {
final routes = routingTable.routes.values;
final costs = routes.map((r) => r.cost).toList();
final updateTimes = routes.map((r) => r.lastUpdate).toList();
return {
'totalRoutes': routes.length,
'directlyConnected': routes.where((r) => r.isDirectlyConnected).length,
'indirectRoutes': routes.where((r) => !r.isDirectlyConnected).length,
'averageCost':
costs.isEmpty ? 0.0 : costs.reduce((a, b) => a + b) / costs.length,
'maxCost': costs.isEmpty ? 0 : costs.reduce((a, b) => a > b ? a : b),
'minCost': costs.isEmpty ? 0 : costs.reduce((a, b) => a < b ? a : b),
'oldestUpdate':
updateTimes.isEmpty
? null
: updateTimes.reduce((a, b) => a.isBefore(b) ? a : b),
'newestUpdate':
updateTimes.isEmpty
? null
: updateTimes.reduce((a, b) => a.isAfter(b) ? a : b),
'staleRoutes':
routes
.where(
(r) => DateTime.now().difference(r.lastUpdate) > routeTimeout,
)
.length,
};
}