<commit_before>import sqlite3

from util.constants import QUERIES


def export_results(data, database_path):
    connection = sqlite3.connect(database_path)
    cursor = connection.cursor()

    creation_datetime = sqlite3.datetime.datetime.now()
    table_name = ('_'.join(['euler', 'linear', creation_datetime.strftime('%Y_%m_%d_%H_%M_%S')]))

    cursor.execute(QUERIES['create_sims'])
    cursor.execute(QUERIES['insert_sim'], (table_name, creation_datetime))
    connection.commit()

    cursor.execute(QUERIES['create_sim'].format(table_name))

    for i in range(len(data['t'])):
        cursor.execute(
            QUERIES['insert_data'].format(table_name),
            (data['t'][i], data['x'][i], data['x_ref'][i],
             data['y'][i], data['y_ref'][i], data['theta'][i],
             data['theta_ref'][i], data['v_c'][i], data['w_c'][i])
        )
        connection.commit()

    cursor.close()
    connection.close()<commit_msg>refactor: Use database context manager<commit_after>import datetime

from db_context_manager import DBContextManager
from util.constants import QUERIES


def export_results(data, database_path):
    creation_datetime = datetime.datetime.now()

    with DBContextManager(database_path) as cursor:
        table_name = ('_'.join(['euler', 'linear', creation_datetime.strftime('%Y_%m_%d_%H_%M_%S')]))
        cursor.execute(QUERIES['create_sims'])

        cursor.execute(QUERIES['insert_sim'], (table_name, creation_datetime))

        cursor.execute(QUERIES['create_sim'].format(table_name))

        for i in range(len(data['t'])):
            cursor.execute(
                QUERIES['insert_data'].format(table_name),
                (data['t'][i], data['x'][i], data['x_ref'][i],
                 data['y'][i], data['y_ref'][i], data['theta'][i],
                 data['theta_ref'][i], data['v_c'][i], data['w_c'][i])
            )
{'fraction_non_alphanumeric': 0.175, 'fraction_numerical': 0.0015957446808510637, 'mean_word_length': 3.738035264483627, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7178883', 'n_tokens_mistral': 615, 'n_tokens_neox': 612, 'n_words': 89}