feat(platform): add online statistics summary
This commit is contained in:
@@ -871,6 +871,44 @@ func (s *Service) DailyMileage(ctx context.Context, query url.Values) (Page[Dail
|
||||
return s.store.DailyMileage(ctx, resolvedQuery)
|
||||
}
|
||||
|
||||
func (s *Service) OnlineStatisticsSummary(ctx context.Context, query url.Values) (OnlineStatisticsSummary, error) {
|
||||
resolvedQuery, err := s.resolveVehicleQuery(ctx, query)
|
||||
if err != nil {
|
||||
return OnlineStatisticsSummary{}, err
|
||||
}
|
||||
coverage, err := s.store.VehicleCoverageSummary(ctx, resolvedQuery)
|
||||
if err != nil {
|
||||
return OnlineStatisticsSummary{}, err
|
||||
}
|
||||
serviceSummary, err := s.store.VehicleServiceSummary(ctx)
|
||||
if err != nil {
|
||||
return OnlineStatisticsSummary{}, err
|
||||
}
|
||||
opsHealth, err := s.store.OpsHealth(ctx)
|
||||
if err != nil {
|
||||
return OnlineStatisticsSummary{}, err
|
||||
}
|
||||
total := coverage.TotalVehicles
|
||||
online := coverage.OnlineVehicles
|
||||
offline := total - online
|
||||
if offline < 0 {
|
||||
offline = 0
|
||||
}
|
||||
rate := 0.0
|
||||
if total > 0 {
|
||||
rate = float64(online) / float64(total) * 100
|
||||
}
|
||||
return OnlineStatisticsSummary{
|
||||
VehicleCount: total,
|
||||
OnlineVehicleCount: online,
|
||||
OfflineVehicleCount: offline,
|
||||
OnlineRatePercent: rate,
|
||||
RedisOnlineKeys: opsHealth.RedisOnlineKeys,
|
||||
ProtocolStats: serviceSummary.Protocols,
|
||||
Evidence: "由车辆服务覆盖汇总、实时来源状态和 Redis 在线 key 计算",
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Service) QualitySummary(ctx context.Context, query url.Values) (QualitySummary, error) {
|
||||
return s.store.QualitySummary(ctx, query)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user