[jboss-svn-commits] JBL Code SVN: r15319 - labs/jbossrules/trunk/drools-decisiontables/src/main/resources/python-dt.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Sep 24 01:57:43 EDT 2007
Author: michael.neale at jboss.com
Date: 2007-09-24 01:57:43 -0400 (Mon, 24 Sep 2007)
New Revision: 15319
Modified:
labs/jbossrules/trunk/drools-decisiontables/src/main/resources/python-dt/Example.xls
labs/jbossrules/trunk/drools-decisiontables/src/main/resources/python-dt/PyDT.py
Log:
yay, its kind of working
Modified: labs/jbossrules/trunk/drools-decisiontables/src/main/resources/python-dt/Example.xls
===================================================================
(Binary files differ)
Modified: labs/jbossrules/trunk/drools-decisiontables/src/main/resources/python-dt/PyDT.py
===================================================================
--- labs/jbossrules/trunk/drools-decisiontables/src/main/resources/python-dt/PyDT.py 2007-09-24 05:14:56 UTC (rev 15318)
+++ labs/jbossrules/trunk/drools-decisiontables/src/main/resources/python-dt/PyDT.py 2007-09-24 05:57:43 UTC (rev 15319)
@@ -58,9 +58,9 @@
print("ERROR: no premium was calculated")
premium = test_fact["Premium"]
if premium == '245' :
- print("PASSED")
+ print("PASSED STEP 1")
else :
- print("FAILED: Premium was " + test_fact["Premium"])
+ print("FAILED STEP 1: Premium was " + test_fact["Premium"])
# Load a XLS into a decision table structure for processing
@@ -69,9 +69,51 @@
book = xlrd.open_workbook(file_name)
sh = book.sheet_by_index(0)
print sh.name, sh.nrows, sh.ncols
-# print "Cell D30 is", sh.cell_value(rowx=29, colx=3)
+ condition_headers, action_headers, data = [],[],[]
for rx in range(sh.nrows):
- print sh.row(rx)
+ if rx == 0 :
+ divider = 0
+ for cx in range(sh.ncols):
+ cv = sh.cell_value(rowx=rx, colx=cx)
+ if cv == "" :
+ continue
+ if cv == "*" or cv == 'actions:' :
+ divider = cx
+ else:
+ if divider == 0 : #we are in conditions
+ condition_headers.append([cx, cv])
+ else: #we are in actions
+ action_headers.append([cx, cv])
+ else:
+ data_row = {}
+ #print condition_headers
+ for cx in range(sh.ncols):
+ cv = sh.cell_value(rowx=rx, colx=cx)
+ if cv != "":
+ data_row[cx] = cv
+ if len(data_row) > 0 :
+ data.append(data_row)
+ return {
+ "condition_headers" : condition_headers,
+ "action_headers" : action_headers,
+ "data" : data
+ }
+#some simple test
+tbl = load_xls("Example.xls")
+if tbl['condition_headers'][0][1] == "Age" :
+ print "PASSED STEP 2"
+else:
+ print "FAILED STEP 2"
-load_xls("Example.xls")
+
+test_fact = { "Age" : 42, "Risk" : "'HIGH'", "PolicyType" : "'COMPREHENSIVE'" }
+
+process_dt(test_fact, tbl)
+if not test_fact.has_key("Premium") :
+ print("ERROR: no premium was calculated")
+premium = test_fact["Premium"]
+if premium == 245 :
+ print("PASSED STEP 3")
+else :
+ print("FAILED STEP 3: Premium was " + test_fact["Premium"])
More information about the jboss-svn-commits
mailing list