1234567891011121314151617181920212223242526272829303132333435363738 |
- # -*- 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):
- # 分析行为数据,例如计算每个流程的行为次数
- process_stats = defaultdict(lambda: defaultdict(int))
- action_stats = defaultdict(int)
- product_stats = defaultdict(int)
- channel_stats = defaultdict(int)
- for user_actions in self.data:
- process = user_actions['process']
- actions = user_actions['actions']
- product = user_actions['product']
- channel = user_actions['channel']
- for action in actions:
- process_stats[process][action] += 1
- action_stats[action] += 1
- product_stats[product] += 1
- channel_stats[channel] += 1
- # 将内部字典转换为普通字典
- process_stats = {process: dict(actions) for process, actions in process_stats.items()}
- return self.data, process_stats, action_stats, product_stats, channel_stats
|