import os
import sys
import matplotlib.pyplot as plt

%matplotlib inline

import cellpy.parameters.prms as prms
from cellpy import cellreader

from cellpy import log

log.setup_logging(default_level="DEBUG")

"""
Explanation: Cellpy tweaking
Notebook for testing ideas and check stuff.
Remember to run the notebook in the correct environment (for conda, issue conda install nb_conda to be able to switch environments).
End of explanation
"""


# print settings
prm_dicts = [d for d in dir(prms) if not d.startswith("_")]

for d in prm_dicts:
    if isinstance(getattr(prms, d), (dict,)) and not d.startswith("excel"):
        print(f"\n--------------------{d}----------------------")
        for variable in getattr(prms, d):
            print(f"{variable}: ", end="")
            print(eval("prms.%s['%s']" % (d, variable)))

"""
Explanation: Some digging into the cellpy structure
End of explanation
"""


current_file_path = os.getcwd()
relative_test_data_dir = "../testdata"
test_data_dir = os.path.abspath(os.path.join(current_file_path, relative_test_data_dir))
test_data_dir_raw = os.path.join(test_data_dir, "data")
test_res_file = "20160805_test001_45_cc_01.res"
test_res_file_full = os.path.join(test_data_dir_raw, test_res_file)
test_data_dir_out = os.path.join(test_data_dir, "out")
test_data_dir_cellpy = os.path.join(test_data_dir, "hdf5")
test_cellpy_file = "20160805_test001_45_cc.h5"
test_cellpy_file_tmp = "tmpfile.h5"
test_cellpy_file_full = os.path.join(test_data_dir_cellpy, test_cellpy_file)
test_cellpy_file_tmp_full = os.path.join(test_data_dir_cellpy, test_cellpy_file_tmp)
test_run_name = "20160805_test001_45_cc"

assert os.path.isfile(test_res_file_full)
assert os.path.isfile(test_cellpy_file_full)
assert os.path.isdir(test_data_dir)
# os.listdir(test_data_dir)

"""
Explanation: Defining filenames etc
End of explanation
"""


celldata = cellreader.CellpyData()
# celldata.from_raw(test_res_file_full)
# celldata.set_mass(0.34)
celldata.load(test_cellpy_file_full)

data = celldata.cell

for x in dir(data):
    if not x.startswith("__"):
        if not x in ["summary", "raw", "steps"]:
            print(f"{x}: {getattr(data,x)}")

data.summary.head()

data.raw.head()

data.steps.head()

celldata.make_summary()

print(data.summary_made)

"""
Explanation: Loading and looking at what we got
End of explanation
"""


# lets see what cycles we have
cycles = celldata.get_cycle_numbers()
print(cycles)

"""
Explanation: dfsummary_made is wrong in the cellpyfile
Task 1: capacity voltage curves
Would like to make it possible to chose how the voltage curves are presented.
End of explanation
"""


