summaryrefslogtreecommitdiff
path: root/lib/drift.py
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2021-03-23 15:31:15 +0100
committerDaniel Friesel <daniel.friesel@uos.de>2021-03-23 15:31:15 +0100
commit63a8b93b0fedac53b5ed4acf07aa77d7e07bd7e5 (patch)
tree3b3009c565776b4405817f9ce9d9a6ef8a5231a4 /lib/drift.py
parent038958df19613ab2750d394be04220c6f4576369 (diff)
port ET++ drift compensation to drift.py
Diffstat (limited to 'lib/drift.py')
-rw-r--r--lib/drift.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/drift.py b/lib/drift.py
index cb769f4..f2dd889 100644
--- a/lib/drift.py
+++ b/lib/drift.py
@@ -337,3 +337,29 @@ def compensate_drift_greedy(event_timestamps, transition_start_candidate_weights
)
return compensated_timestamps
+
+
+def compensate_etplusplus(
+ data, timestamps, event_timestamps, statechange_indexes, offline_index=None
+):
+ """Use hardware state changes reported by EnergyTrace++ to determine transition timestamps."""
+ expected_transition_start_timestamps = event_timestamps[::2]
+ compensated_timestamps = list()
+ drift = 0
+ for i, expected_start_ts in enumerate(expected_transition_start_timestamps):
+ expected_end_ts = event_timestamps[i * 2 + 1]
+ et_timestamps_start = bisect_left(timestamps, expected_start_ts - 10e-3)
+ et_timestamps_end = bisect_right(timestamps, expected_start_ts + 10e-3)
+
+ candidate_indexes = list()
+ for index in statechange_indexes:
+ if et_timestamps_start <= index <= et_timestamps_end:
+ candidate_indexes.append(index)
+
+ if len(candidate_indexes) == 2:
+ drift = timestamps[candidate_indexes[0]] - expected_start_ts
+
+ compensated_timestamps.append(expected_start_ts + drift)
+ compensated_timestamps.append(expected_end_ts + drift)
+
+ return compensated_timestamps