Spaces:
Sleeping
Sleeping
| // Format confidence as percentage | |
| export const formatConfidence = (confidence: number): string => { | |
| return `${(confidence * 100).toFixed(1)}%`; | |
| }; | |
| // Format processing time | |
| export const formatProcessingTime = (ms: number): string => { | |
| if (ms < 1000) { | |
| return `${ms}ms`; | |
| } | |
| return `${(ms / 1000).toFixed(2)}s`; | |
| }; | |
| // Format relative time (e.g., "2 mins ago") | |
| export const formatRelativeTime = (dateString: string): string => { | |
| const date = new Date(dateString); | |
| const now = new Date(); | |
| const diffInSeconds = Math.floor((now.getTime() - date.getTime()) / 1000); | |
| if (diffInSeconds < 60) { | |
| return 'just now'; | |
| } | |
| const diffInMinutes = Math.floor(diffInSeconds / 60); | |
| if (diffInMinutes < 60) { | |
| return `${diffInMinutes} min${diffInMinutes > 1 ? 's' : ''} ago`; | |
| } | |
| const diffInHours = Math.floor(diffInMinutes / 60); | |
| if (diffInHours < 24) { | |
| return `${diffInHours} hour${diffInHours > 1 ? 's' : ''} ago`; | |
| } | |
| const diffInDays = Math.floor(diffInHours / 24); | |
| if (diffInDays < 7) { | |
| return `${diffInDays} day${diffInDays > 1 ? 's' : ''} ago`; | |
| } | |
| return date.toLocaleDateString(); | |
| }; | |
| // Truncate text with ellipsis | |
| export const truncateText = (text: string, maxLength: number): string => { | |
| if (text.length <= maxLength) { | |
| return text; | |
| } | |
| return `${text.substring(0, maxLength)}...`; | |
| }; | |
| // Format memory size | |
| export const formatMemory = (mb: number): string => { | |
| if (mb < 1) { | |
| return `${(mb * 1024).toFixed(0)} KB`; | |
| } | |
| return `${mb.toFixed(2)} MB`; | |
| }; | |
| // Get confidence level label | |
| export const getConfidenceLevel = (confidence: number): string => { | |
| if (confidence >= 0.9) return 'High confidence'; | |
| if (confidence >= 0.7) return 'Medium confidence'; | |
| return 'Low confidence'; | |
| }; | |