<commit_before>from collections import deque
from cubes.model import Attribute

def _wma(values):
    n = len(values)
    denom = n * (n + 1) / 2
    total = 0.0
    idx = 1
    for val in values:
        total += float(idx) * float(val)
        idx += 1
    return round(total / denom, 4)

def _sma(values):
    # use all the values
    return round(reduce(lambda i, c: c + i, values, 0.0) / len(values), 2)

def weighted_moving_average_factory(measure, drilldown_paths, source_aggregations):
    return _moving_average_factory(measure, drilldown_paths, source_aggregations, _wma, 'wma')

def simple_moving_average_factory(measure, drilldown_paths, source_aggregations):
    return _moving_average_factory(measure, drilldown_paths, source_aggregations, _sma, 'sma')

def _moving_average_factory(measure, drilldown_paths, source_aggregations, avg_func, aggregation_name):
    if not drilldown_paths or not source_aggregations:<commit_msg>allow for Decimal and other types not inherently addable to float in SMA calculator.<commit_after>from collections import deque
from cubes.model import Attribute

def _wma(values):
    n = len(values)
    denom = n * (n + 1) / 2
    total = 0.0
    idx = 1
    for val in values:
        total += float(idx) * float(val)
        idx += 1
    return round(total / denom, 4)

def _sma(values):
    # use all the values
    return round(reduce(lambda i, c: float(c) + i, values, 0.0) / len(values), 2)

def weighted_moving_average_factory(measure, drilldown_paths, source_aggregations):
    return _moving_average_factory(measure, drilldown_paths, source_aggregations, _wma, 'wma')

def simple_moving_average_factory(measure, drilldown_paths, source_aggregations):
    return _moving_average_factory(measure, drilldown_paths, source_aggregations, _sma, 'sma')

def _moving_average_factory(measure, drilldown_paths, source_aggregations, avg_func, aggregation_name):
    if not drilldown_paths or not source_aggregations:
{'fraction_non_alphanumeric': 0.08853633572159672, 'fraction_numerical': 0.01023541453428864, 'mean_word_length': 4.63400576368876, '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': '2835870', 'n_tokens_mistral': 690, 'n_tokens_neox': 637, 'n_words': 176}