Пример #1
0
def arithmetic_sequence_non_adjacent(row_values, step_count_k=2):
    event_occurred = False
    step_increment = None
    step_count = None
    sample_symbols = {}
    for value_idx, value in enumerate(row_values):
        _, symbols, _, _, _ = utilities.generate_pattern_symbols_and_case(
            str(value).strip(), False)
        if value_idx not in sample_symbols.keys():
            sample_symbols[value_idx] = []
        sample_symbols[value_idx].append(symbols)

    # example
    # row_values=['1','2001','2002','2003','2004']
    # sample_symbols={0:[set(['D'])],1:[set(['D'])],2:[set(['D'])], 3:[set(['D'])]}
    step_increment, step_count = utilities.discover_incremental_values_at_least_one_nonadjacent(
        row_values, sample_symbols)
    # print('step_increment='+str(step_increment))
    # print('step_count='+str(step_count))
    # print('step_count_k threshold='+str(step_count_k))
    if step_increment != 0 and step_count > step_count_k:
        # INCREMENTAL RULE FIRES
        event_occurred = True
    # print('event_occurred='+str(event_occurred))

    return event_occurred, step_count
Пример #2
0
def integer_sequence_adjacent(row_values):
    event_occurred = False
    step_increment = None
    step_count = None
    sample_symbols = {}
    numeric_values = []
    sequential_values_list = []
    sequential_values = []
    sequence_found = False
    if len(row_values) >= 2:
        for value_idx, value in enumerate(row_values):
            # generate symbols NOT sensitive to outliers
            _, symbols, _, _, _ = utilities.generate_pattern_symbols_and_case(
                str(value).strip(), False)
            if symbols == set(['D']):
                numeric_values.append(int(value))
            else:
                numeric_values.append(None)
        # input('numeric_values='+str(numeric_values))
        for i in range(len(numeric_values) - 1):
            if (numeric_values[i] != None and numeric_values[i + 1] != None
                    and numeric_values[i] + 1 == numeric_values[i + 1]):
                sequential_values += [numeric_values[i]]
                sequence_found = True
            else:
                if sequence_found == True:
                    if i > 0 and numeric_values[i - 1] + 1 == numeric_values[
                            i] and numeric_values[i] != None:
                        sequential_values += [numeric_values[i]]
                    sequential_values_list.append(sequential_values)
                    sequence_found = False
                sequential_values = []

        if sequence_found == True:
            if numeric_values[-2] + 1 == numeric_values[
                    -1] and numeric_values[-1] != None:
                sequential_values += [numeric_values[-1]]
            sequential_values_list.append(sequential_values)

        # input('sequential_values_list='+str(sequential_values_list))
        if len(sequential_values_list) > 0:
            event_occurred = True
            max_sequence, max_sequence_length = FindMaxLength(
                sequential_values_list)
            if max_sequence_length > 1:
                event_occurred = True
                step_count = max_sequence_length - 1

    return event_occurred, step_count