# Path: cellpy/log.py
# def setup_logging(
#     default_json_path=None,
#     default_level=None,
#     env_key="LOG_CFG",
#     custom_log_dir=None,
#     reset_big_log=False,
#     max_size=5_000_000,
#     testing=False,
# ):
# 
# Path: cellpy/exceptions.py
# class NullData(Error):
#     """Raised when required data is missing (e.g. voltage = None or summary_frames are missing)"""
# 
#     pass
# 
# Path: cellpy/utils/helpers.py
# def _make_average(
#     frames, keys=None, columns=None, normalize_cycles=False, key_index_bounds=None
# ):
# def update_journal_cellpy_data_dir(
#     pages, new_path=None, from_path="PureWindowsPath", to_path="Path"
# ):
# def make_new_cell():
# def split_experiment(cell, base_cycles=None):
# def add_normalized_cycle_index(summary, nom_cap=None, column_name=None):
# def add_c_rate(cell, nom_cap=None, column_name=None):
# def add_areal_capacity(cell, cell_id, journal):
# def _remove_outliers_from_summary(s, filter_vals, freeze_indexes=None):
# def remove_outliers_from_summary_on_window(
#     s, window_size=3, cut=0.1, iterations=1, col_name=None, freeze_indexes=None
# ):
#     def fractional_std(x):
# def remove_outliers_from_summary_on_nn_distance(
#     s, distance=0.7, filter_cols=None, freeze_indexes=None
# ):
#     def neighbour_window(y):
# def remove_outliers_from_summary_on_zscore(
#     s, zscore_limit=4, filter_cols=None, freeze_indexes=None
# ):
# def remove_outliers_from_summary_on_value(
#     s, low=0.0, high=7_000, filter_cols=None, freeze_indexes=None
# ):
# def remove_outliers_from_summary_on_index(s, indexes=None, remove_last=False):
# def remove_last_cycles_from_summary(s, last=None):
# def remove_first_cycles_from_summary(s, first=None):
# def yank_after(b, last=None, keep_old=False):
# def yank_before(b, first=None, keep_old=False):
# def yank_outliers(
#     b,
#     zscore_limit=None,
#     low=0.0,
#     high=7_000.0,
#     filter_cols=None,
#     freeze_indexes=None,
#     remove_indexes=None,
#     remove_last=False,
#     iterations=1,
#     zscore_multiplyer=1.3,
#     distance=None,
#     window_size=None,
#     window_cut=0.1,
#     keep_old=False,
# ):
# def concatenate_summaries(
#     b,
#     max_cycle=None,
#     rate=None,
#     on="charge",
#     columns=None,
#     column_names=None,
#     normalize_capacity_on=None,
#     scale_by=None,
#     nom_cap=None,
#     normalize_cycles=False,
#     add_areal=False,
#     group_it=False,
#     rate_std=None,
#     rate_column=None,
#     inverse=False,
#     inverted=False,
#     key_index_bounds=[1, -2],
#     melt=False,
#     cell_type_split_position="auto",
# ):
# def create_rate_column(df, nom_cap, spec_conv_factor, column="current_avr"):
# def select_summary_based_on_rate(
#     cell,
#     rate=None,
#     on=None,
#     rate_std=None,
#     rate_column=None,
#     inverse=False,
#     inverted=False,
#     fix_index=True,
# ):
# def add_normalized_capacity(
#     cell, norm_cycles=None, individual_normalization=False, scale=1.0
# ):
# def load_and_save_resfile(filename, outfile=None, outdir=None, mass=1.00):


import logging
import pytest
from cellpy import log
from cellpy.exceptions import NullData
from cellpy.utils import helpers
def cell(dataset):
    return dataset


def test_split_experiment(cell):
    list_of_all_cycles = cell.get_cycle_numbers()
    c1, c2 = helpers.split_experiment(cell, 10)
    list_of_first_cycles = c1.get_cycle_numbers()
    list_of_last_cycles = c2.get_cycle_numbers()
    assert all(list_of_first_cycles == range(1, 10))
    assert list_of_all_cycles[-1] == list_of_last_cycles[-1]


def test_split_experiment_new(cell):
    list_of_all_cycles = cell.get_cycle_numbers()
    c1, c2 = cell.split(10)
    list_of_first_cycles = c1.get_cycle_numbers()
    list_of_last_cycles = c2.get_cycle_numbers()
    assert all(list_of_first_cycles == range(1, 10))
    assert list_of_all_cycles[-1] == list_of_last_cycles[-1]


def test_select_summary_based_on_rate(cell):
    cell.make_step_table(add_c_rate=True)
    filtered_summary = helpers.select_summary_based_on_rate(cell, 0.04)
    assert len(filtered_summary) == 3


def test_remove_outliers_on_index(cell):
    last = cell.get_cycle_numbers()[-1]

# Path: cellpy/log.py
# def setup_logging(
#     default_json_path=None,
#     default_level=None,
#     env_key="LOG_CFG",
#     custom_log_dir=None,
#     reset_big_log=False,
#     max_size=5_000_000,
#     testing=False,
# ):
# 
# Path: cellpy/exceptions.py
# class NullData(Error):
#     """Raised when required data is missing (e.g. voltage = None or summary_frames are missing)"""
# 
#     pass
# 
# Path: cellpy/utils/helpers.py
# def _make_average(
#     frames, keys=None, columns=None, normalize_cycles=False, key_index_bounds=None
# ):
# def update_journal_cellpy_data_dir(
#     pages, new_path=None, from_path="PureWindowsPath", to_path="Path"
# ):
# def make_new_cell():
# def split_experiment(cell, base_cycles=None):
# def add_normalized_cycle_index(summary, nom_cap=None, column_name=None):
# def add_c_rate(cell, nom_cap=None, column_name=None):
# def add_areal_capacity(cell, cell_id, journal):
# def _remove_outliers_from_summary(s, filter_vals, freeze_indexes=None):
# def remove_outliers_from_summary_on_window(
#     s, window_size=3, cut=0.1, iterations=1, col_name=None, freeze_indexes=None
# ):
#     def fractional_std(x):
# def remove_outliers_from_summary_on_nn_distance(
#     s, distance=0.7, filter_cols=None, freeze_indexes=None
# ):
#     def neighbour_window(y):
# def remove_outliers_from_summary_on_zscore(
#     s, zscore_limit=4, filter_cols=None, freeze_indexes=None
# ):
# def remove_outliers_from_summary_on_value(
#     s, low=0.0, high=7_000, filter_cols=None, freeze_indexes=None
# ):
# def remove_outliers_from_summary_on_index(s, indexes=None, remove_last=False):
# def remove_last_cycles_from_summary(s, last=None):
# def remove_first_cycles_from_summary(s, first=None):
# def yank_after(b, last=None, keep_old=False):
# def yank_before(b, first=None, keep_old=False):
# def yank_outliers(
#     b,
#     zscore_limit=None,
#     low=0.0,
#     high=7_000.0,
#     filter_cols=None,
#     freeze_indexes=None,
#     remove_indexes=None,
#     remove_last=False,
#     iterations=1,
#     zscore_multiplyer=1.3,
#     distance=None,
#     window_size=None,
#     window_cut=0.1,
#     keep_old=False,
# ):
# def concatenate_summaries(
#     b,
#     max_cycle=None,
#     rate=None,
#     on="charge",
#     columns=None,
#     column_names=None,
#     normalize_capacity_on=None,
#     scale_by=None,
#     nom_cap=None,
#     normalize_cycles=False,
#     add_areal=False,
#     group_it=False,
#     rate_std=None,
#     rate_column=None,
#     inverse=False,
#     inverted=False,
#     key_index_bounds=[1, -2],
#     melt=False,
#     cell_type_split_position="auto",
# ):
# def create_rate_column(df, nom_cap, spec_conv_factor, column="current_avr"):
# def select_summary_based_on_rate(
#     cell,
#     rate=None,
#     on=None,
#     rate_std=None,
#     rate_column=None,
#     inverse=False,
#     inverted=False,
#     fix_index=True,
# ):
# def add_normalized_capacity(
#     cell, norm_cycles=None, individual_normalization=False, scale=1.0
# ):
# def load_and_save_resfile(filename, outfile=None, outdir=None, mass=1.00):


# Path: tests/test_helpers.py
import logging
import pytest
from cellpy import log
from cellpy.exceptions import NullData
from cellpy.utils import helpers

def cell(dataset):
    return dataset


def test_split_experiment(cell):
    list_of_all_cycles = cell.get_cycle_numbers()
    c1, c2 = helpers.split_experiment(cell, 10)
    list_of_first_cycles = c1.get_cycle_numbers()
    list_of_last_cycles = c2.get_cycle_numbers()
    assert all(list_of_first_cycles == range(1, 10))
    assert list_of_all_cycles[-1] == list_of_last_cycles[-1]


def test_split_experiment_new(cell):
    list_of_all_cycles = cell.get_cycle_numbers()
    c1, c2 = cell.split(10)
    list_of_first_cycles = c1.get_cycle_numbers()
    list_of_last_cycles = c2.get_cycle_numbers()
    assert all(list_of_first_cycles == range(1, 10))
    assert list_of_all_cycles[-1] == list_of_last_cycles[-1]


def test_select_summary_based_on_rate(cell):
    cell.make_step_table(add_c_rate=True)
    filtered_summary = helpers.select_summary_based_on_rate(cell, 0.04)
    assert len(filtered_summary) == 3


def test_remove_outliers_on_index(cell):
    last = cell.get_cycle_numbers()[-1]

    s1 = helpers.remove_outliers_from_summary_on_index(cell.cell.summary, indexes=[15])