BehaviorAnalyzer.py 958 B

123456789101112131415161718192021222324252627282930313233343536
  1. # -*- coding: utf-8 -*-
  2. """
  3. @author: zsc
  4. @time: 2024/11/18
  5. @desc: 行为分析
  6. """
  7. import time
  8. import random
  9. from collections import defaultdict
  10. import matplotlib.pyplot as plt
  11. # 行为分析模块
  12. class BehaviorAnalyzer:
  13. def __init__(self, data):
  14. self.data = data
  15. def analyze(self):
  16. # 根据新的数据结构调整分析逻辑
  17. behavior_count = defaultdict(lambda: defaultdict(int))
  18. action_stats = defaultdict(int)
  19. product_stats = defaultdict(int)
  20. channel_stats = defaultdict(int)
  21. for item in self.data:
  22. user = item['user']
  23. action = item['action']
  24. product = item['product']
  25. channel = item['channel']
  26. behavior_count[user][action] += 1
  27. action_stats[action] += 1
  28. product_stats[product] += 1
  29. channel_stats[channel] += 1
  30. return behavior_count, action_stats, product_stats, channel_stats