# -*- coding: utf-8 -*- """ @author: zsc @time: 2024/11/18 @desc: 行为分析 """ import time import random from collections import defaultdict import matplotlib.pyplot as plt # 行为分析模块 class BehaviorAnalyzer: def __init__(self, data): self.data = data def analyze(self): # 根据新的数据结构调整分析逻辑 behavior_count = defaultdict(lambda: defaultdict(int)) action_stats = defaultdict(int) product_stats = defaultdict(int) channel_stats = defaultdict(int) for item in self.data: user = item['user'] action = item['action'] product = item['product'] channel = item['channel'] behavior_count[user][action] += 1 action_stats[action] += 1 product_stats[product] += 1 channel_stats[channel] += 1 return behavior_count, action_stats, product_stats, channel_stats