{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import glob\n",
    "\n",
    "base_dirs = [\"genius_hq\", \"imslp\", \"podcasts\", \"tency\", \"youtube_music\"]\n",
    "manifest_out_dir = \"/app/suno/data/audio_2ch_48khz_lg/\"\n",
    "\n",
    "for subset in [\"train\", \"val\"]:\n",
    "    subset_filepaths = []\n",
    "    for base_dir in base_dirs:\n",
    "        root_dir = f\"/app/suno/data/audio_2ch_48khz_lg/{subset}/{base_dir}\"\n",
    "        filepaths = glob.glob(root_dir + \"/*.wav\")\n",
    "        subset_filepaths.extend(filepaths)\n",
    "        print(f\"Found {len(filepaths)} files in {root_dir}. Total: {len(subset_filepaths)}\")\n",
    "\n",
    "    # write to csv file\n",
    "    with open(f\"{manifest_out_dir}/ear_{subset}.csv\", \"w\") as f:\n",
    "        for filepath in subset_filepaths:\n",
    "            f.write(f\"{filepath}\\n\")\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "\n",
    "# load train scores \n",
    "train_scores = pd.read_csv(\"/home/christian/code/christian/metadata/ear_train_corruptions.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "\n",
    "print(train_scores.columns)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = train_scores\n",
    "\n",
    "threshold = 0.9\n",
    "# Create mask for high logit values, excluding filepath and total_score\n",
    "columns_to_check = [col for col in df.columns if col not in ['filepath', 'total_score']]\n",
    "high_logit_mask = (df[columns_to_check] > threshold).any(axis=1)\n",
    "\n",
    "# Filter the dataframe using the mask\n",
    "high_logit_rows = df[high_logit_mask]\n",
    "\n",
    "# Print how many rows were found\n",
    "print(f\"Found {len(high_logit_rows)} rows with high logit values\")\n",
    "\n",
    "# For each row, print filepath, score, and which columns had high values\n",
    "for idx, row in high_logit_rows.iterrows():\n",
    "    high_cols = [col for col in columns_to_check if row[col] > threshold]\n",
    "    print(f\"\\nFile: {row['filepath']}\")\n",
    "    print(f\"Total Score: {row['total_score']}\")\n",
    "    print(\"High logit features:\", high_cols)\n",
    "    print(\"Values:\", {col: row[col] for col in high_cols})  # This will show the actual values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Create masks for both conditions\n",
    "columns_to_check = [col for col in df.columns if col not in ['filepath', 'total_score']]\n",
    "high_logit_mask = (df[columns_to_check] > 0.5).any(axis=1)\n",
    "high_score_mask = df['total_score'] > 2\n",
    "\n",
    "# Combine masks with OR condition\n",
    "combined_mask = high_logit_mask | high_score_mask\n",
    "\n",
    "# Get the filepaths for rows that DON'T meet either condition (using ~)\n",
    "filepath_list = df[~combined_mask]['filepath'].tolist()\n",
    "\n",
    "# Print the length and first few entries\n",
    "print(f\"Total filepaths found: {len(filepath_list)}\")\n",
    "print(\"\\nFirst few filepaths:\")\n",
    "for path in filepath_list[:5]:\n",
    "    print(path)\n",
    "\n",
    "# If you need to save the list to a file:\n",
    "with open('/app/suno/data/audio_2ch_48khz_lg/ear_train_filtered_v1.csv', 'w') as f:\n",
    "     for path in filepath_list:\n",
    "         f.write(f\"{path}\\n\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# hisotgram "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "suno_env",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
