1234567891011121314151617181920212223242526272829303132333435363738 |
- """
- @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
|