<commit_before>from datetime import datetime

from calculator.operations import *
from calculator.exceptions import *


def create_new_calculator(operations={}):
    dictionary = {
            'operations': operations,
            'history': []
            }
 
    return dictionary

def perform_operation(calc, operation, params):
    """
    
    Executes given operation with given params. It returns the result of the
    operation execution.

    :param calc: A calculator.
    :param operation: String with the operation name. ie: 'add'
    :param params: Tuple containing the list of nums to operate with.
                   ie: (1, 2, 3, 4.5, -2)
                   
    def test_perform_operation(self):
        res = perform_operation(self.calc, 'add', (5, 3))
        self.assertEqual(res, 8)
    """
    def add_to_history(op_result):
        calc['history'].append((datetime.now().strftime('%Y-%m-%d %H:%M:%S'), operation, params, op_result))
    
    result = calc['operations'].get(operation)(*params)
    add_to_history(result)

    return result


def add_new_operation(calc, operation):
    """
    Adds given operation to the list of supported operations for given calculator.

    :param calc: A calculator.
    :param operation: Dict with the single operation to be added.
                      ie: {'add': add_function}
                       add_new_operation(self.calc, operation={'add': self.add})
    """
    if type(operation) == dict:
        calc['operations'].update(operation)
    else:
        raise InvalidOperation("Given operation is invalid.")


def get_operations(calc):
    return list(calc['operations'].keys())
    """
    Returns the list of operation names supported by given calculator.
    """

def get_history(calc):
    """
    Returns the history of the executed operations since the last reset or<commit_msg>add_to_history is less brittle. re-added dictionary definition to create_new_calculator that was accidentally removed<commit_after>from datetime import datetime

from calculator.operations import *
from calculator.exceptions import *


def create_new_calculator(operations={}):
    dictionary = {
            'operations': operations,
            'history': []
        }
        
    return dictionary

def perform_operation(calc, operation, params):
    """
    
    Executes given operation with given params. It returns the result of the
    operation execution.

    :param calc: A calculator.
    :param operation: String with the operation name. ie: 'add'
    :param params: Tuple containing the list of nums to operate with.
                   ie: (1, 2, 3, 4.5, -2)
                   
    def test_perform_operation(self):
        res = perform_operation(self.calc, 'add', (5, 3))
        self.assertEqual(res, 8)
    """
    def add_to_history(op_result):
        calc['history'].append((datetime.now().strftime('%Y-%m-%d %H:%M:%S'), operation, params, op_result))
    
    result = calc['operations'].get(operation)(*params)
    add_to_history(result)

    return result


def add_new_operation(calc, operation):
    """
    Adds given operation to the list of supported operations for given calculator.

    :param calc: A calculator.
    :param operation: Dict with the single operation to be added.
                      ie: {'add': add_function}
                       add_new_operation(self.calc, operation={'add': self.add})
    """
    if type(operation) == dict and callable(list(operation.values())[0]):
        calc['operations'].update(operation)
    else:
        raise InvalidOperation("Given operation is invalid.")


def get_operations(calc):
    return list(calc['operations'].keys())
    """
    Returns the list of operation names supported by given calculator.
    """

def get_history(calc):
    """
    Returns the history of the executed operations since the last reset or
{'fraction_non_alphanumeric': 0.10644910644910645, 'fraction_numerical': 0.004921004921004921, 'mean_word_length': 2.8351539225422044, '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': '187002', 'n_tokens_mistral': 1062, 'n_tokens_neox': 1011, 'n_words': 333}