MCPcopy Create free account
hub / github.com/astercloud/aster / GetStats

Method GetStats

pkg/memory/preference.go:365–400  ·  view source on GitHub ↗

GetStats 获取统计信息

(userID string)

Source from the content-addressed store, hash-verified

363
364// GetStats 获取统计信息
365func (pm *PreferenceManager) GetStats(userID string) PreferenceStats {
366 pm.mu.RLock()
367 defer pm.mu.RUnlock()
368
369 stats := PreferenceStats{
370 TotalPreferences: len(pm.preferences[userID]),
371 CategoryDistribution: make(map[PreferenceCategory]int),
372 AverageStrength: 0,
373 HighStrengthCount: 0,
374 MediumStrengthCount: 0,
375 LowStrengthCount: 0,
376 }
377
378 if stats.TotalPreferences == 0 {
379 return stats
380 }
381
382 totalStrength := 0.0
383
384 for _, pref := range pm.preferences[userID] {
385 stats.CategoryDistribution[pref.Category]++
386 totalStrength += pref.Strength
387
388 if pref.Strength >= 0.7 {
389 stats.HighStrengthCount++
390 } else if pref.Strength >= 0.4 {
391 stats.MediumStrengthCount++
392 } else {
393 stats.LowStrengthCount++
394 }
395 }
396
397 stats.AverageStrength = totalStrength / float64(stats.TotalPreferences)
398
399 return stats
400}
401
402// PreferenceStats 偏好统计信息
403type PreferenceStats struct {

Callers 1

Calls

no outgoing calls

Tested by 1