import pandas as pd
from wildboar.datasets import load_dataset, list_datasets

# Get the list of all available datasets in the 'wildboar/ucr' repository
available_datasets = list_datasets(repository='wildboar/ucr')

available_datasets = ["FordB"]
for dataset_name in available_datasets:
    try:
        # Load the dataset
        x, y = load_dataset(dataset_name, repository='wildboar/ucr')
        
        # Convert x to a DataFrame
        x_df = pd.DataFrame(x)
        
        # Convert y to a Series with the name 'label'
        y_df = pd.Series(y, name='label')
        
        # Concatenate x and y along columns (axis=1)
        merged_df = pd.concat([x_df, y_df], axis=1)
        
        # Save the DataFrame to a CSV file
        filename = f'{dataset_name}_merged.csv'
        merged_df.to_csv(filename, index=False)
        
        print(f"File saved as '{filename}'")
    except Exception as e:
        print(f"Failed to process dataset '{dataset_name}': {e}")