// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // ! This script is provided "as is" by Applied Maths. ! // ! You are free to use and modify this script for your own needs. ! // ! Redistribution or reproduction of the script is prohibited. ! // ! DISCLAIMER: ! // ! Improper use of scripts may corrupt your database. ! // ! Running this script is entirely at your own responsibility. ! // ! Applied Maths accepts no lialibility for any consequences ! // ! resulting from its use. ! // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! DIALOG dlg; string fieldlist,field,st; integer i,ii,j,nr,vl,selonly,sortbyfreq,ok,rs,totocc; TABLE fields; INDEX idx; float centx,centy,rad,ang,totang,curang,pi,cr,cg,cb; float pieang[]; float px,py,lastpy; integer quartcount[],quartidx[][]; for i=1 to DbGetFieldCount do fieldlist=fieldlist+DbGetFieldName(i)+" "; DlgAddText(dlg,"Select the field you want to calculate statistics for",15,15,150,30); DlgAddList(dlg,fieldlist,field,15,55,150,150,"LIST"); DlgAddCheck(dlg,"From selection only",selonly,200,20,120,15); DlgAddCheck(dlg,"Sort by frequency",sortbyfreq,200,50,120,15); DlgAddButton(dlg,"TAB-delimited file",11,200,80,120,27); DlgAddButton(dlg,"Pie chart",12,200,120,120,27); DlgAddButton(dlg,"Cancel",999,200,160,120,27); while field="" do { rs=DlgShow(dlg,"Field statistics",350,240); if (rs=0) or (rs=999) then stop; if field="" then message("You must select a field!"); } TableCreate(fields,DbGetPath+"\result.txt","Fieldname Occurrence"); for i=1 to DbGetEntryCount do { if i/200=floor(i/200) then setbusy("Scanning database - "+str(i,0,0)); ok=0; if DbGetSel(DbGetEntryKey(i)) then ok=1; if not(selonly) then ok=1; if ok then { st=DbGetField(DbGetEntryKey(i),field); nr=IdxGet(idx,st); if nr=0 then { nr=TableAddRow(fields);IdxSet(idx,st,nr); TableSetField(fields,nr,1,st); TableSetField(fields,nr,2,"0"); } vl=val(TableGetField(fields,nr,2)); TableSetField(fields,nr,2,str(vl+1,0,0)); totocc=totocc+1; } } setbusy(""); if not(sortbyfreq) then TableSort(fields,1); if sortbyfreq then { for i=1 to TableGetRowCount(fields) do TableSetField(fields,i,2,str(100000-val(TableGetField(fields,i,2)),7,0)); TableSort(fields,2); for i=1 to TableGetRowCount(fields) do TableSetField(fields,i,2,str(100000-val(TableGetField(fields,i,2)),0,0)); } if rs=11 then { TableSave(fields); execute("notepad.exe "+DbGetPath+"\result.txt"); } if rs=12 then { if totocc=0 then { message("No fields found!"); stop; } centx=9;centy=6.5;rad=4; pi=3.1415927; totang=0; PrnStartScreen(18,13); ii=TableGetRowCount(fields); if ii>20 then { message("Truncated to first 20 fields!"); ii=20; } for i=1 to ii do { ang=val(TableGetField(fields,i,2))/totocc*2*pi; PrnPolygonPoint(centx,centy); PrnPolygonPoint(centx+cos(totang)*rad,centy-sin(totang)*rad); curang=totang; pieang[i]=totang+ang/2; totang=totang+ang; while curangtotang then curang=totang; PrnPolygonPoint(centx+cos(curang)*rad,centy-sin(curang)*rad); } cr=70; cg=70; cb=70; if i= 1 then { cr=100; cg= 30; cb= 30; } if i= 2 then { cr= 30; cg=100; cb= 30; } if i= 3 then { cr= 30; cg= 30; cb=100; } if i= 4 then { cr=100; cg=100; cb= 30; } if i= 5 then { cr=100; cg= 30; cb=100; } if i= 6 then { cr= 30; cg=100; cb=100; } if i= 7 then { cr= 50; cg= 20; cb= 20; } if i= 8 then { cr= 20; cg= 50; cb= 20; } if i= 9 then { cr= 20; cg= 20; cb= 50; } if i=10 then { cr= 50; cg= 50; cb= 10; } if i=11 then { cr= 50; cg= 10; cb= 50; } if i=12 then { cr= 10; cg= 50; cb= 50; } PrnLinestyle(0.02,0,0,0); PrnPolygonDraw(cr,cg,cb); ang=pieang[i]/(pi/2);nr=floor(ang); if nr>3 then nr=3; quartcount[nr]=quartcount[nr]+1;j=quartcount[nr]; quartidx[nr][j]=i; } PrnLinestyle(0.01,0,0,0); PrnTextstyle("arial",0.4,0,0,0,0); for nr=0 to 3 do { if (nr=0) or (nr=1) then lastpy=centy+0.3; else lastpy=centy-0.3; for ii=1 to quartcount[nr] do { if (nr=0) or (nr=2) then i=ii; else i=quartcount[nr]+1-ii; i=quartidx[nr][i]; ang=pieang[i]; PrnMoveto(centx+cos(ang)*(rad+0.1),centy-sin(ang)*(rad+0.1)); px=centx+cos(ang)*(rad+0.7);py=centy-sin(ang)*(rad+0.7); if (nr=0) or (nr=1) then { if py>lastpy-0.4 then py=lastpy-0.4; } else { if py