From 78bad4dc02aacd56ea7f579c67ce62815ac37025 Mon Sep 17 00:00:00 2001
From: Daniel Friesel <daniel.friesel@uos.de>
Date: Mon, 18 Nov 2019 13:39:13 +0100
Subject: dfatool: save preprocessing stats in cache

---
 bin/analyze-archive.py |  5 +++++
 lib/dfatool.py         | 10 ++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/bin/analyze-archive.py b/bin/analyze-archive.py
index ee6b1d8..787510d 100755
--- a/bin/analyze-archive.py
+++ b/bin/analyze-archive.py
@@ -272,6 +272,11 @@ if __name__ == '__main__':
     raw_data = RawData(args)
 
     preprocessed_data = raw_data.get_preprocessed_data()
+
+    if raw_data.preprocessing_stats['num_valid'] == 0:
+        print('No valid data available. Abort.')
+        sys.exit(2)
+
     by_name, parameters, arg_count = pta_trace_to_aggregate(preprocessed_data, ignored_trace_indexes)
 
     filter_aggregate_by_param(by_name, parameters, opts['filter-param'])
diff --git a/lib/dfatool.py b/lib/dfatool.py
index bd210be..d2837ef 100644
--- a/lib/dfatool.py
+++ b/lib/dfatool.py
@@ -577,7 +577,9 @@ class RawData:
     def load_cache(self):
         if os.path.exists(self.cache_file):
             with open(self.cache_file, 'r') as f:
-                self.traces = json.load(f)
+                cache_data = json.load(f)
+                self.traces = cache_data['traces']
+                self.preprocessing_stats = cache_data['preprocessing_stats']
                 self.preprocessed = True
 
     def save_cache(self):
@@ -586,7 +588,11 @@ class RawData:
         except FileExistsError:
             pass
         with open(self.cache_file, 'w') as f:
-            json.dump(self.traces, f)
+            cache_data = {
+                'traces' : self.traces,
+                'preprocessing_stats' : self.preprocessing_stats
+            }
+            json.dump(cache_data, f)
 
     def _state_is_too_short(self, online, offline, state_duration, next_transition):
         # We cannot control when an interrupt causes a state to be left
-- 
cgit v1.2.3