from config import N, REPEATS, HASH_TABLE_SIZE
from generator import generate_test_data, get_names_for_operations
from experiment import run_single_experiment
from rezults import save_to_csv, plot_results, print_analysis, save_report_md

def main():
    print(f"Количество записей: {N}")
    print(f"Количество повторов: {REPEATS}")
    print(f"Размер хеш-таблицы: {HASH_TABLE_SIZE}")
    print()

    records, records_shuffled, records_sorted = generate_test_data(N)
    names_to_find, names_to_delete = get_names_for_operations(records)
    
    experiments = [
        ('linkedlist', 'случайный', records_shuffled),
        ('linkedlist', 'отсортированный', records_sorted),
        ('hashtable', 'случайный', records_shuffled),
        ('hashtable', 'отсортированный', records_sorted),
        ('bst', 'случайный', records_shuffled),
        ('bst', 'отсортированный', records_sorted),
    ]
    
    results = []
    
    for struct_type, mode, data_records in experiments:
        print(f"Тестирование: {struct_type} - {mode}")
        
        params = {'size': HASH_TABLE_SIZE} if struct_type == 'hashtable' else None
        
        result = run_single_experiment(
            struct_type, mode, data_records,
            names_to_find, names_to_delete,
            REPEATS, params
        )
        
        results.append(result)
        
        print(f"  Insert: {result['insert_mean']:.4f} ± {result['insert_std']:.4f} sec")
        print(f"  Find:   {result['find_mean']:.4f} ± {result['find_std']:.4f} sec")
        print(f"  Delete: {result['delete_mean']:.4f} ± {result['delete_std']:.4f} sec")
        print()
    
    save_to_csv(results)                    
    plot_results(results)              
    save_report_md(results)
    print_analysis(results)
    

if __name__ == "__main__":
    main()