File size: 911 Bytes
097cfcc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""Helper functions for data cleaning and validation."""
import re
from typing import Optional


def clean_text(text: Optional[str]) -> str:
    """Clean text by removing extra whitespace."""
    if not text:
        return ""
    return " ".join(text.split())


def parse_rating(rating: Optional[str]) -> Optional[float]:
    """Parse rating string to float."""
    if not rating:
        return None
    match = re.search(r'[0-9.]+', str(rating))
    return float(match.group()) if match else None


def parse_installs(installs: Optional[str]) -> Optional[int]:
    """Parse installs string to integer."""
    if not installs:
        return None
    match = re.search(r'[0-9,]+', str(installs))
    if match:
        return int(match.group().replace(',', ''))
    return None


def validate_app_id(app_id: str) -> bool:
    """Validate app ID format."""
    return bool(re.match(r'^[a-zA-Z0-9._]+$', app_id))