Beispiel #1
0
class ReworkAnomaly(Anomaly):
    """Insert 1 sequence of n events coming from the case later in the case."""
    def __init__(self, max_sequence_size=2, max_distance=0):
        self.max_sequence_size = max_sequence_size
        self.max_distance = max_distance
        super(ReworkAnomaly, self).__init__()

    def apply_to_case(self, case):
        if len(case) <= 1:
            return NoneAnomaly().apply_to_case(case)

        size = np.random.randint(2, min(len(case), self.max_sequence_size) + 1)
        start = np.random.randint(0, len(case) - size + 1)
        distance = np.random.randint(
            0,
            min(len(case) - (start + size), self.max_distance) + 1)

        t = case.events
        dupe_sequence = [Event.clone(e) for e in t[start:start + size]]

        inserted = [e.json for e in dupe_sequence]

        anomalous_trace = t[:start + size +
                            distance] + dupe_sequence + t[start + size +
                                                          distance:]
        case.events = anomalous_trace

        case.attributes['label'] = dict(anomaly=str(self),
                                        attr=dict(size=int(size),
                                                  start=int(start + size +
                                                            distance),
                                                  inserted=inserted))

        return case
 def clone(trace):
     events = [Event.clone(event) for event in trace.events]
     return Case(id=trace.id, events=events, **dict(trace.attributes))