import pandas as pd
import os

RAW_DATA_PATH = '/opt/airflow/data/raw/movies.csv'
PROCESSED_PATH = '/opt/airflow/data/processed/movies_clean.csv'
os.makedirs(os.path.dirname(PROCESSED_PATH), exist_ok=True)

def clean_and_normalize():
    df = pd.read_csv(RAW_DATA_PATH)
    # Sayısal değerlere çevirme
    df['IMDB'] = pd.to_numeric(df['IMDB'], errors='coerce')
    df['RottenTomatoes'] = df['RottenTomatoes'].str.replace('%','').astype(float)
    df['Metacritic'] = pd.to_numeric(df['Metacritic'], errors='coerce')
    
    # Normalize 0-100 arası
    df['IMDB_norm'] = df['IMDB'] * 10
    df['RottenTomatoes_norm'] = df['RottenTomatoes']
    df['Metacritic_norm'] = df['Metacritic']
    
    df.to_csv(PROCESSED_PATH, index=False)
    print("Data transformed successfully!")