fm2x.com
fm2x = Form to Function


> Home > Technology > Sample scripts > Logic visualisation

fm2x clients often create forms or questionnaires of considerable logical complexity (sample logic table). It is not unusual for the logic presented to be incomplete or incorrect. Network graphs are a convenient way of presenting logic back to clients for verification and validation.

Graphviz is open source software for generating diagrams of abstract graphs and networks. Although there is a python library, using it through dot, a command line generator, is simpler and easier to test. Here is how fm2x interfaced its tabular logic generator to create a network logic diagram:

#Typical dot syntax where question numbers are preceded with Q 
#Q1->Q2 [style=bold,fontsize=10]; Q1->Q2 [label="Q6=='1'"fontsize=10];
#Q1->Q3A [label="Q6=='2'",fontsize=10]; Q1->Q4 [label="Q6=='3'",fontsize=10];
#Q2->Q4 [style=bold]; Q3A->Q4 [style=bold]; Q4->Q8 [style=bold];
t="";
for type,name,qnid,prompt,code in r:
code=code.replace('r','').replace(';','');
if type<>'page':continue;
lines=code.split("");
for line in lines:
code1=line.split("page=");
code1[0]=code1[0].replace("'","'");
if code1[0]=="" and len(lines)>1:code1[0]="Default"
try: t+='''%s->%s [label="%s",fontsize=10];'''%(name,code1[1],code1[0]);
except: pass
dot='''digraph hierarchy {bgcolor=lightgoldenrod1; %s } '''%(t);
pngfile='/imgs/medixdat/logic.png';
dotfile='/imgs/medixdat/logic.dot';
f=open(dotfile,'w'); f.write(dot);
command = '''echo '%s' |dot -Tpng -o %s '''%(dot,pngfile);
os.system(command);
Then just provide access to the png file. Apologies, full file paths have been masked.
© 2008 fm2x limited