import type { SpeakerRow } from '@/types/api' import type { DeploymentProgress } from './types' export function deploymentProgress(speakers: SpeakerRow[]): DeploymentProgress { if (speakers.length === 0) { return { percent: 0, synced: 0, total: 0, mode: 'online' } } const withRevision = speakers.filter( (s) => s.published_revision_id && s.last_applied_revision_id, ) if (withRevision.length > 0) { const synced = withRevision.filter( (s) => s.published_revision_id === s.last_applied_revision_id, ).length return { percent: Math.round((synced / withRevision.length) * 100), synced, total: withRevision.length, mode: 'revision', } } const online = speakers.filter((s) => s.live?.agent_ok).length return { percent: Math.round((online / speakers.length) * 100), synced: online, total: speakers.length, mode: 'online', } }