summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/analyze-archive.py21
-rw-r--r--lib/lennart/DataProcessor.py15
-rw-r--r--lib/loader.py32
-rwxr-xr-xlib/plotter.py6
4 files changed, 51 insertions, 23 deletions
diff --git a/bin/analyze-archive.py b/bin/analyze-archive.py
index bd1c824..5d4411b 100755
--- a/bin/analyze-archive.py
+++ b/bin/analyze-archive.py
@@ -226,10 +226,16 @@ def print_html_model_data(model, pm, pq, lm, lq, am, ai, aq):
def plot_traces(preprocessed_data, sot_name):
traces = list()
+ timestamps = list()
for trace in preprocessed_data:
for state_or_transition in trace["trace"]:
if state_or_transition["name"] == sot_name:
- traces.extend(map(lambda x: x["uW"], state_or_transition["offline"]))
+ timestamps.extend(
+ map(lambda x: x["plot"][0], state_or_transition["offline"])
+ )
+ traces.extend(
+ map(lambda x: x["plot"][1], state_or_transition["offline"])
+ )
if len(traces) == 0:
print(
f"""Did not find traces for state or transition {sot_name}. Abort.""",
@@ -239,12 +245,15 @@ def plot_traces(preprocessed_data, sot_name):
if len(traces) > 40:
print(f"""Truncating plot to 40 of {len(traces)} traces (random sample)""")
- traces = random.sample(traces, 40)
+ indexes = random.sample(range(len(traces)), 40)
+ timestamps = [timestamps[i] for i in indexes]
+ traces = [traces[i] for i in indexes]
- plotter.plot_y(
+ plotter.plot_xy(
+ timestamps,
traces,
- xlabel="t [1e-5 s]",
- ylabel="P [uW]",
+ xlabel="t [s]",
+ ylabel="P [W]",
title=sot_name,
family=True,
)
@@ -463,7 +472,7 @@ if __name__ == "__main__":
if name not in uw_per_sot:
uw_per_sot[name] = list()
for elem in state_or_transition["offline"]:
- elem["uW"] = list(elem["uW"])
+ elem["plot"] = list(elem["plot"])
uw_per_sot[name].append(state_or_transition)
for name, data in uw_per_sot.items():
target = f"{args.export_traces}/{name}.json"
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: