Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
86 lines
1.8 KiB
Python
86 lines
1.8 KiB
Python
"""
|
|
Utility functions for RAG Evaluation Framework
|
|
"""
|
|
|
|
import hashlib
|
|
import uuid
|
|
from datetime import datetime
|
|
from typing import Optional
|
|
|
|
|
|
def generate_id(prefix: str = "") -> str:
|
|
"""
|
|
Generate unique ID (32 characters)
|
|
|
|
Args:
|
|
prefix: Optional prefix for the ID
|
|
|
|
Returns:
|
|
32-character unique ID
|
|
"""
|
|
unique_str = f"{prefix}{uuid.uuid4().hex}{datetime.now().isoformat()}"
|
|
return hashlib.md5(unique_str.encode()).hexdigest()
|
|
|
|
|
|
def generate_biz_seq(prefix: str = "BIZ") -> str:
|
|
"""
|
|
Generate business sequence number
|
|
|
|
Args:
|
|
prefix: Prefix for business sequence
|
|
|
|
Returns:
|
|
Business sequence number
|
|
"""
|
|
timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
|
|
random_suffix = uuid.uuid4().hex[:8].upper()
|
|
return f"{prefix}{timestamp}{random_suffix}"
|
|
|
|
|
|
def generate_sys_seq(prefix: str = "SYS") -> str:
|
|
"""
|
|
Generate system sequence number
|
|
|
|
Args:
|
|
prefix: Prefix for system sequence
|
|
|
|
Returns:
|
|
System sequence number
|
|
"""
|
|
timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
|
|
random_suffix = uuid.uuid4().hex[:8].upper()
|
|
return f"{prefix}{timestamp}{random_suffix}"
|
|
|
|
|
|
def get_current_time() -> datetime:
|
|
"""Get current datetime"""
|
|
return datetime.now()
|
|
|
|
|
|
def format_datetime(dt: Optional[datetime] = None) -> str:
|
|
"""
|
|
Format datetime to string
|
|
|
|
Args:
|
|
dt: Datetime object, defaults to current time
|
|
|
|
Returns:
|
|
Formatted datetime string (YYYY-MM-DD HH:MM:SS)
|
|
"""
|
|
if dt is None:
|
|
dt = datetime.now()
|
|
return dt.strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
|
|
def calculate_file_size_mb(size_bytes: int) -> float:
|
|
"""
|
|
Convert file size from bytes to MB
|
|
|
|
Args:
|
|
size_bytes: File size in bytes
|
|
|
|
Returns:
|
|
File size in MB
|
|
"""
|
|
return size_bytes / (1024 * 1024)
|