def main(config_file):
    with open(config_file) as f:
        config = json.load(f)
    datetime_format = config['DatetimeFormat']
    work_directory = config['WorkDirectory']
    cv_setting_file = os.path.join(work_directory, 'cv_settings.json')
    cv = TSCVSplitter(config)
    for (k, v) in cv.train_validation_split.items():
        round_dict = {}
        train_end = datetime.strptime(v['train_range'][1], datetime_format)
        validation_start_1 = datetime.strptime(v['validation_range'][0], datetime_format)
        validation_end_1 = (validation_start_1 + relativedelta(months=1, hours=(- 1)))
        train_end_prev = datetime.strftime((train_end + relativedelta(months=(- 1))), datetime_format)
        train_end_next = datetime.strftime((train_end + relativedelta(months=1)), datetime_format)
        validation_start_2 = (validation_start_1 + relativedelta(months=1))
        validation_end_2 = (validation_start_2 + relativedelta(months=1, hours=(- 1)))
        validation_start_3 = (validation_start_1 + relativedelta(months=2))
        validation_end_3 = (validation_start_3 + relativedelta(months=1, hours=(- 1)))
        validation_start_4 = (validation_start_1 + relativedelta(months=3))
        validation_end_4 = (validation_start_4 + relativedelta(months=1, hours=(- 1)))
        validation_start_1 = datetime.strftime(validation_start_1, datetime_format)
        validation_end_1 = datetime.strftime(validation_end_1, datetime_format)
        validation_start_2 = datetime.strftime(validation_start_2, datetime_format)
        validation_end_2 = datetime.strftime(validation_end_2, datetime_format)
        validation_start_3 = datetime.strftime(validation_start_3, datetime_format)
        validation_end_3 = datetime.strftime(validation_end_3, datetime_format)
        validation_start_4 = datetime.strftime(validation_start_4, datetime_format)
        validation_end_4 = datetime.strftime(validation_end_4, datetime_format)
        round_dict[1] = {'train_range': [v['train_range'][0], train_end_prev], 'validation_range': [validation_start_1, validation_end_1]}
        round_dict[2] = {'train_range': [v['train_range'][0], train_end_prev], 'validation_range': [validation_start_2, validation_end_2]}
        round_dict[3] = {'train_range': [v['train_range'][0], v['train_range'][1]], 'validation_range': [validation_start_2, validation_end_2]}
        round_dict[4] = {'train_range': [v['train_range'][0], v['train_range'][1]], 'validation_range': [validation_start_3, validation_end_3]}
        round_dict[5] = {'train_range': [v['train_range'][0], train_end_next], 'validation_range': [validation_start_3, validation_end_3]}
        round_dict[6] = {'train_range': [v['train_range'][0], train_end_next], 'validation_range': [validation_start_4, validation_end_4]}
        cv.train_validation_split[k] = round_dict
    with open(cv_setting_file, 'w') as fp:
        json.dump(cv.train_validation_split, fp, indent=True)
def main(config_file):
    with open(config_file) as f:
        config = json.load(f)
    datetime_format = config['DatetimeFormat']
    work_directory = config['WorkDirectory']
    cv_setting_file = os.path.join(work_directory, 'cv_settings.json')
    cv = TSCVSplitter(config)
    for (k, v) in cv.train_validation_split.items():
        round_dict = {}
        train_end = datetime.strptime(v['train_range'][1], datetime_format)
        validation_start_1 = datetime.strptime(v['validation_range'][0], datetime_format)
        validation_end_1 = (validation_start_1 + relativedelta(months=1, hours=(- 1)))
        train_end_prev = datetime.strftime((train_end + relativedelta(months=(- 1))), datetime_format)
        train_end_next = datetime.strftime((train_end + relativedelta(months=1)), datetime_format)
        validation_start_2 = (validation_start_1 + relativedelta(months=1))
        validation_end_2 = (validation_start_2 + relativedelta(months=1, hours=(- 1)))
        validation_start_3 = (validation_start_1 + relativedelta(months=2))
        validation_end_3 = (validation_start_3 + relativedelta(months=1, hours=(- 1)))
        validation_start_4 = (validation_start_1 + relativedelta(months=3))
        validation_end_4 = (validation_start_4 + relativedelta(months=1, hours=(- 1)))
        validation_start_1 = datetime.strftime(validation_start_1, datetime_format)
        validation_end_1 = datetime.strftime(validation_end_1, datetime_format)
        validation_start_2 = datetime.strftime(validation_start_2, datetime_format)
        validation_end_2 = datetime.strftime(validation_end_2, datetime_format)
        validation_start_3 = datetime.strftime(validation_start_3, datetime_format)
        validation_end_3 = datetime.strftime(validation_end_3, datetime_format)
        validation_start_4 = datetime.strftime(validation_start_4, datetime_format)
        validation_end_4 = datetime.strftime(validation_end_4, datetime_format)
        round_dict[1] = {'train_range': [v['train_range'][0], train_end_prev], 'validation_range': [validation_start_1, validation_end_1]}
        round_dict[2] = {'train_range': [v['train_range'][0], train_end_prev], 'validation_range': [validation_start_2, validation_end_2]}
        round_dict[3] = {'train_range': [v['train_range'][0], v['train_range'][1]], 'validation_range': [validation_start_2, validation_end_2]}
        round_dict[4] = {'train_range': [v['train_range'][0], v['train_range'][1]], 'validation_range': [validation_start_3, validation_end_3]}
        round_dict[5] = {'train_range': [v['train_range'][0], train_end_next], 'validation_range': [validation_start_3, validation_end_3]}
        round_dict[6] = {'train_range': [v['train_range'][0], train_end_next], 'validation_range': [validation_start_4, validation_end_4]}
        cv.train_validation_split[k] = round_dict
    with open(cv_setting_file, 'w') as fp:
        json.dump(cv.train_validation_split, fp, indent=True)