# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# +
import sys
sys.path.append('/Users/spacecoffin/Development')

import GravelKicker as gk
import os
import pandas as pd

from datetime import datetime
from supriya.tools import nonrealtimetools
# -

this_dir = '/Users/spacecoffin/Development/GravelKicker/__gen_files'

# # Batch processing
#
# 1. Decide on a size limit for aiff files (882kb/10s file)
# 2. Generate that much files
# 3. Process those files and append results to DataFrame
# 4. Remove those files

import hurry.filesize

hurry.filesize.size(903168, system=hurry.filesize.alternative)

hurry.filesize.size(882102, system=hurry.filesize.si)

hurry.filesize.size(882000, system=hurry.filesize.si)

hurry.filesize.size(1073741824, system=hurry.filesize.alternative)

hurry.filesize.size(1073741824, system=hurry.filesize.si)

1073741824 / 882102

# # Loading

# +
dir_list = os.listdir(path=this_dir)

if "df.p" in dir_list:
    _pickle_path = os.path.join(this_dir, "df.p")
    _old_df = pd.read_pickle(_pickle_path)
    
# -

_old_df["hash"]

_old_df.dtypes

pmtx = gk.generator.gendy1.gen_params(rows=20)
df = gk.generator.gendy1.format_params(pmtx)
df.sort_values(["hash"])

for i, row in df.iterrows():
    
    session = nonrealtimetools.Session()
    
    builder = gk.generator.gendy1.make_builder(row)
    
    out = gk.generator.gendy1.build_out(builder)
    
    synthdef = builder.build()
    
    with session.at(0):
        synth_a = session.add_synth(duration=10, synthdef=synthdef)
    
    gk.util.render_session(session, this_dir, row["hash"])

dt = datetime.now().strftime("%Y_%m_%d") #_%H-%M-%S")
identifier = '{0}-len{1}'.format(dt, str(df.shape[0]))

df.to_pickle("{0}/df-{1}.p".format(this_dir, dt))

df.to_pickle("{0}/df.p".format(this_dir, dt))

# Next, we need to:
#
# 1. extract features from each file
# 2. join features with parameter df (index on hash?)
# 3. get it into a regressor



# + active=""
#
#
# def pickle_data(file_pickle, path):
#     """Saves pickle file depending on object instance"""
#
#     if isinstance(file_pickle, pd.DataFrame):
#         file_pickle.to_pickle(path)
#
#     elif isinstance(file_pickle, pyspark.RDD):
#         file_pickle.saveAsPickleFile(path)
#
#     else:
#         with open(path, 'wb') as p_file:
#             pickle.dump(file_pickle, p_file)
#
# pickle_data(data_pandas, path='{0}/pandas-df-{1}.p'.format(dat_path, identifier))

StarcoderdataJupyterScriptsDedupFiltered