rtc_backend/apps/devices/services.py
repair-agent 7a6a519fbe
All checks were successful
Build and Deploy Backend / build-and-deploy (push) Successful in 3m13s
fix: auto repair bugs #26, #25, #24
2026-02-24 16:19:40 +08:00

27 lines
697 B
Python

"""
设备模块服务层
"""
from .models import Device, UserDevice
class DeviceStatsService:
"""设备统计服务"""
@staticmethod
def get_bindrate(user):
"""获取用户设备绑定率"""
total_count = Device.objects.count()
if total_count == 0:
return {
'total_count': 0,
'bound_count': 0,
'bind_rate': 0,
}
bound_count = Device.objects.filter(status='bound').count()
bind_rate = bound_count / total_count * 100
return {
'total_count': total_count,
'bound_count': bound_count,
'bind_rate': round(bind_rate, 2),
}