Beispiel #1
0
def unique_pattern_counter(reading):
    """Returns an IndexedOrderedDict of unique sub-patterns in a reading"""
    counter = IndexedOrderedDict()
    idx = 0
    for row in reading:
        if counter.get(str(idx) + '_' + convert_row_to_key(row)):
            counter[str(idx) + '_' + convert_row_to_key(row)] += 1
        else:
            idx += 1
            counter[str(idx) + '_' + convert_row_to_key(row)] = 1
    return counter
Beispiel #2
0
class TaburuState(State):
    def __init__(self):
        self.parameters = IndexedOrderedDict()
        self.methods = IndexedOrderedDict()

    def apply(self, event):
        if isinstance(event, ParametersAdded):
            if event.table_name in self.parameters:
                self.parameters[event.table_name].append(event.parameters)
            else:
                self.parameters[event.table_name] = ParameterTable(
                    event.parameters)
        elif isinstance(event, MethodAdded):
            if self.methods.get(event.name) is None:
                self.methods[event.name] = event.parameter_indices
            else:
                print("Method name already exists")
                return False
        return True

    def __str__(self):
        return self.__repr__()

    def __repr__(self):
        parameters = [
            '{} {}: {}'.format(n, parameter_name, len(table))
            for n, (parameter_name,
                    table) in enumerate(self.parameters.items())
        ]
        methods = [
            "{}: {}".format(method_name, parameters)
            for method_name, parameters in self.methods.items()
        ]
        output = "Parameters:\n   "
        output += "\n   ".join(parameters)
        output += "\nMethods:\n   "
        output += "\n   ".join(methods)
        return output