diff --git a/detector/compute_noise.py b/detector/compute_noise.py index 21d82d6..805b3d8 100644 --- a/detector/compute_noise.py +++ b/detector/compute_noise.py @@ -37,8 +37,38 @@ def avg_diff(machine, suite, mode, first): return None return median(diffs) +def equal_sign(a, b): + if a >= 0 and b >= 0: + return True + if a <= 0 and b <= 0: + return True + return False + +def avg_consequent_diff(machine, suite, mode, first): + prev = first + current = first.next() + diffs = [] + consequent = 0 + while current: + diff = prev.get('score') - current.get('score') + if diff != 0: + if equal_sign(diff, consequent): + consequent += diff + else: + diffs.append(abs(consequent)) + consequent = diff + + prev = current + current = current.next() + if consequent != 0: + diffs.append(abs(consequent)) + if len(diffs) == 0: + return None + return median(diffs) + for machine in tables.Machine.all(): if machine.id != 28 and machine.id != 29 and machine.id != 26: + #if machine.id != 28: continue for mode in tables.Mode.allWith(machine): @@ -50,7 +80,7 @@ for machine in tables.Machine.all(): first = tables.Score.firstOfRecent(machine, suite, mode) if not first: continue - diff = avg_diff(machine, suite, mode, first) + diff = avg_consequent_diff(machine, suite, mode, first) if not diff: continue tables.RegressionScoreNoise.insertOrUpdate(machine, suite, mode, diff) @@ -64,7 +94,7 @@ for machine in tables.Machine.all(): first = tables.Breakdown.firstOfRecent(machine, suite, mode) if not first: continue - diff = avg_diff(machine, suite, mode, first) + diff = avg_consequent_diff(machine, suite, mode, first) if not diff: continue tables.RegressionBreakdownNoise.insertOrUpdate(machine, suite, mode, diff)