| 304 | } |
| 305 | |
| 306 | func (lm *LineageManager) GetLineageStats() LineageStats { |
| 307 | lm.graph.mu.RLock() |
| 308 | defer lm.graph.mu.RUnlock() |
| 309 | |
| 310 | stats := LineageStats{ |
| 311 | TotalMemories: len(lm.graph.memoryMetadata), |
| 312 | MemoriesBySource: make(map[string]int), |
| 313 | } |
| 314 | |
| 315 | for memID, metadata := range lm.graph.memoryMetadata { |
| 316 | // 统计根记忆 |
| 317 | if len(metadata.DerivedFromIDs) == 0 { |
| 318 | stats.RootMemories++ |
| 319 | } else { |
| 320 | stats.DerivedMemories++ |
| 321 | } |
| 322 | |
| 323 | // 统计谱系深度 |
| 324 | depth := lm.GetLineageDepth(memID) |
| 325 | if depth > stats.MaxDepth { |
| 326 | stats.MaxDepth = depth |
| 327 | } |
| 328 | |
| 329 | // 统计每个数据源 |
| 330 | for _, sourceID := range metadata.SourceIDs { |
| 331 | stats.MemoriesBySource[sourceID]++ |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | return stats |
| 336 | } |