新增消息趋势分析
This commit is contained in:
@@ -92,3 +92,39 @@ def get_groups():
|
||||
except Exception as e:
|
||||
logger.error(f"获取群组列表失败: {e}")
|
||||
return jsonify({'error': str(e)}), 500
|
||||
|
||||
|
||||
@messages_bp.route('/api/hourly_message_trend', methods=['GET'])
|
||||
@login_required
|
||||
def get_hourly_message_trend():
|
||||
"""获取按小时聊天趋势数据API"""
|
||||
try:
|
||||
server = current_app.dashboard_server
|
||||
# 获取查询参数
|
||||
group_id = request.args.get('group_id')
|
||||
days = int(request.args.get('days', 1))
|
||||
|
||||
# 调用数据库方法获取按小时消息趋势数据
|
||||
trend_data = server.message_storage.get_hourly_message_trend(group_id=group_id, days=days)
|
||||
|
||||
# 格式化数据为前端需要的格式
|
||||
hours = []
|
||||
counts = []
|
||||
for item in trend_data:
|
||||
hours.append(item['hour_slot'])
|
||||
counts.append(item['message_count'])
|
||||
|
||||
# 获取群组名称
|
||||
group_name = server.contact_manager.get_nickname(group_id) if group_id else "所有群组"
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'data': {
|
||||
'hours': hours,
|
||||
'counts': counts,
|
||||
'group_name': group_name
|
||||
}
|
||||
})
|
||||
except Exception as e:
|
||||
logger.error(f"获取按小时聊天趋势数据失败: {e}")
|
||||
return jsonify({'success': False, 'error': str(e)}), 500
|
||||
Reference in New Issue
Block a user