diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/lennart/DataProcessor.py | 15 | ||||
-rw-r--r-- | lib/loader.py | 32 | ||||
-rwxr-xr-x | lib/plotter.py | 6 |
3 files changed, 36 insertions, 17 deletions
diff --git a/lib/lennart/DataProcessor.py b/lib/lennart/DataProcessor.py index 8373e75..7546128 100644 --- a/lib/lennart/DataProcessor.py +++ b/lib/lennart/DataProcessor.py @@ -256,7 +256,8 @@ class DataProcessor: :return: power measurements in W """ first_index = 0 - all_power = [] + all_power = list() + all_ts = list() for ind in range(self.start_offset, len(self.plot_data_x)): first_index = ind if self.plot_data_x[ind] > start: @@ -272,6 +273,7 @@ class DataProcessor: self.start_offset = ind - 1 break all_power.append(self.plot_data_y[ind]) + all_ts.append(self.plot_data_x[ind]) # TODO Idea remove datapoints that are too far away def removeSD_Mean_Values(arr): @@ -293,10 +295,11 @@ class DataProcessor: if len(all_power) == 0: # print("PROBLEM") all_power.append(self.plot_data_y[nextIndAfterIndex]) + all_ts.append(0) elif len(all_power) == 1: # print("OKAY") pass - return np.array(all_power) + return np.array(all_power), np.array(all_ts) def getStatesdfatool(self, state_sleep, with_traces=False, algorithm=False): """ @@ -324,7 +327,7 @@ class DataProcessor: start_transition_ts_timing = self.reduced_timestamps[ts_index * 2] if end_transition_ts is not None: - power = self.getPowerBetween( + power, timestamps = self.getPowerBetween( end_transition_ts, start_transition_ts, state_sleep ) @@ -348,7 +351,7 @@ class DataProcessor: ), # * 10 ** 6, } if with_traces: - state["uW"] = power * 1e6 + state["plot"] = (timestamps - timestamps[0], power) energy_trace_new.append(state) energy_trace_new[-2]["W_mean_delta_next"] = ( @@ -357,7 +360,7 @@ class DataProcessor: # get energy end_transition_ts end_transition_ts = self.modified_timestamps[ts_index * 2 + 1] - power = self.getPowerBetween( + power, timestamps = self.getPowerBetween( start_transition_ts, end_transition_ts, state_sleep ) @@ -374,7 +377,7 @@ class DataProcessor: "count_dp": len(power), } if with_traces: - transition["uW"] = power * 1e6 + transition["plot"] = (timestamps - timestamps[0], power) if (end_transition_ts - start_transition_ts) * 10 ** 6 > 2_000_000: # TODO Last data set corrupted? HOT FIX!!!!!!!!!!!! REMOVE LATER diff --git a/lib/loader.py b/lib/loader.py index 94a76b3..c981ef7 100644 --- a/lib/loader.py +++ b/lib/loader.py @@ -1431,7 +1431,13 @@ class EnergyTraceWithBarcode: } if self.with_traces: - transition["uW"] = transition_power_W * 1e6 + timestamps = ( + self.interval_start_timestamp[ + transition_start_index:transition_done_index + ] + - self.interval_start_timestamp[transition_start_index] + ) + transition["plot"] = (timestamps, transition_power_W) energy_trace.append(transition) @@ -1451,7 +1457,11 @@ class EnergyTraceWithBarcode: } if self.with_traces: - state["uW"] = state_power_W * 1e6 + timestamps = ( + self.interval_start_timestamp[state_start_index:state_done_index] + - self.interval_start_timestamp[state_start_index] + ) + state["plot"] = (timestamps, state_power_W) energy_trace.append(state) @@ -1690,15 +1700,14 @@ class EnergyTraceWithLogicAnalyzer: dp = DataProcessor(sync_data=self.sync_data, energy_data=self.energy_data) dp.run() - energy_trace_new = list() - energy_trace_new.extend( - dp.getStatesdfatool( - state_sleep=self.state_duration, with_traces=self.with_traces - ) + energy_trace_new = dp.getStatesdfatool( + state_sleep=self.state_duration, with_traces=self.with_traces ) # Uncomment to plot traces - # dp.plot() # <- plot traces with sync annotatons - # dp.plot(names) # <- plot annotated traces (with state/transition names) + if offline_index == 0: + # dp.plot() # <- plot traces with sync annotatons + # dp.plot(names) # <- plot annotated traces (with state/transition names) + pass energy_trace_new = energy_trace_new[4:] energy_trace = list() @@ -2091,7 +2100,10 @@ class MIMOSA: } if self.with_traces: - data["uW"] = range_ua * self.voltage + data["plot"] = ( + np.arange(len(range_ua)) * 1e-5, + range_ua * self.voltage * 1e-6, + ) if isa == "transition": # subtract average power of previous state diff --git a/lib/plotter.py b/lib/plotter.py index 16c0145..929ceb9 100755 --- a/lib/plotter.py +++ b/lib/plotter.py @@ -136,7 +136,11 @@ def plot_xy(X, Y, xlabel=None, ylabel=None, title=None, output=None, family=Fals if family: cm = plt.get_cmap("brg", len(Y)) for i, YY in enumerate(Y): - plt.plot(np.arange(len(YY)), YY, "-", markersize=2, color=cm(i)) + if X: + XX = X[i] + else: + XX = np.arange(len(YY)) + plt.plot(XX, YY, "-", markersize=2, color=cm(i)) else: plt.plot(X, Y, "bo", markersize=2) if output: |