From: rtrimana <rtrimana@uci.edu>
Date: Mon, 20 Apr 2020 21:31:00 +0000 (-0700)
Subject: Adding a script to extract statistics of states and transitions.
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=f7373aa466f328e5c405ebc7ff208d6772aa8953;p=smartthings-infrastructure.git

Adding a script to extract statistics of states and transitions.
---

diff --git a/SummarizeLogs.py b/SummarizeLogs.py
new file mode 100644
index 0000000..e184fda
--- /dev/null
+++ b/SummarizeLogs.py
@@ -0,0 +1,51 @@
+#!/usr/bin/python
+
+import itertools
+import sys
+import os
+import glob
+
+# Input parameters:
+# - JPF directory
+# - JPF logs directory
+# - app directory
+# - list #1
+# - list #2 (if needed)
+
+# Index 0 is always for the Python script itself
+jpfLogDir = sys.argv[1]
+csvFileOutput = sys.argv[2]
+
+# Extract the status finished/unfinished
+def getStatus(text):
+	if (text.find('no errors') != -1):
+		return 'finished'
+	else:
+		return 'unfinished'
+		
+# Extract the states
+def getStates(text):
+	if not text:
+		return '0'
+	startStatesInfo = text.find('states:')
+	startIndex = text.find('=', startStatesInfo)
+	endIndex = text.find(',', startIndex)
+	return text[startIndex+1:endIndex]
+
+print("Opening log files ...\n\n")
+out = open(csvFileOutput, "w+")
+for filename in glob.glob(os.path.join(jpfLogDir, '*.log')):
+	with open(filename, 'r') as f:
+		text = f.read()
+		status = getStatus(text) # Getting status "no errors/finished" or "not finished"
+		states = getStates(text)
+		lastSlash = filename.rfind('/')
+		lastDoubleDash = filename.rfind('--')
+		fname = filename[lastSlash+1:lastDoubleDash]
+		lineReport = fname + ',' + status + ',' + states + '\n'
+		out.write(lineReport)
+		print(lineReport)
+out.close()
+		
+
+