X-Git-Url: http://iramuteq.org/git?a=blobdiff_plain;ds=sidebyside;f=tabchi2.py;h=d82a0801c1a65fe046fa1bd65dddf87f53d7a8b7;hb=fca6f30e3159a44e2a4f053546d1d7df21ad8c6b;hp=6a8cf550460d44717147356c65b3f72c52978625;hpb=22cd27b2bbe9ab1ffa7ef06fa764b5147ae17dad;p=iramuteq
diff --git a/tabchi2.py b/tabchi2.py
index 6a8cf55..d82a080 100755
--- a/tabchi2.py
+++ b/tabchi2.py
@@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
#Author: Pierre Ratinaud
#Copyright (c) 2010 Pierre Ratinaud
-#Lisense: GNU/GPL
+#License: GNU/GPL
import HTML
import os
@@ -16,6 +16,7 @@ import wx.lib.sized_controls as sc
from time import sleep
from functions import exec_rcode, check_Rresult
from dialog import ChiDialog, PrefChi
+from analysematrix import AnalyseMatrix
def make_res(line) :
if float(line[5]) <= 0.05 and line[6] != 'warning':
@@ -45,34 +46,69 @@ def make_title(res, text) :
return ['
%s
retour
' % (i, val[-1], text[i], i) for i, val in enumerate(res)]
+chioption = { 'valobs' : True,
+ 'valtheo' : True,
+ 'resi' : False,
+ 'contrib' : True,
+ 'pourcent' : False,
+ 'pourcentl' : True,
+ 'pourcentc' : True,
+ 'graph' : True,
+ 'bw' : False,
+ }
-
-
-class MakeChi2():
- def __init__(self, parent, select1, select2, chioption):
- self.OutFrame=tempfile.mktemp(dir=parent.TEMPDIR)
- print self.OutFrame
- self.parent=parent
+class ChiSquare(AnalyseMatrix):
+ def doparametres(self, dlg = None):
+ if dlg is None :
+ return
+ dial = ChiDialog(self.parent, -1, u"Chi2", chioption, self.tableau, size=(400, 350),
+ style = wx.DEFAULT_DIALOG_STYLE
+ )
+ dial.CenterOnParent()
+ val = dial.ShowModal()
+ if val==wx.ID_OK :
+ self.colsel1 = dial.list_box_1.GetSelections()
+ self.colsel2 = dial.list_box_2.GetSelections()
+ if dial.chiopt :
+ chioption['valobs'] = dial.dial.check1.GetValue()
+ chioption['valtheo'] = dial.dial.check2.GetValue()
+ chioption['resi'] = dial.dial.check3.GetValue()
+ chioption['contrib'] = dial.dial.check4.GetValue()
+ chioption['pourcent'] = dial.dial.check5.GetValue()
+ chioption['pourcentl'] = dial.dial.check6.GetValue()
+ chioption['pourcentc'] = dial.dial.check7.GetValue()
+ chioption['graph'] = dial.dial.check8.GetValue()
+ chioption['bw'] = dial.dial.checkbw.GetValue()
+ dial.dial.Destroy()
+ dial.Destroy()
+ self.parametres.update(chioption)
+ self.chioption = chioption
+ else :
+ if dial.chiopt :
+ dial.dial.Destroy()
+ dial.Destroy()
+ self.parametres = None
+
+ def doanalyse(self):
+ self.count = 1
+ keepGoing = self.dlg.Update(self.count,u"Analyse dans R...")
+ self.OutFrame=tempfile.mktemp(dir=self.parent.TEMPDIR)
self.encode=self.parent.encode
- self.TEMPDIR=parent.TEMPDIR
- self.RPath=parent.PathPath.get('PATHS','rpath')
+ self.TEMPDIR=self.parent.TEMPDIR
+ self.RPath=self.parent.PathPath.get('PATHS','rpath')
self.TextCroise=[]
- for i in select1 :
- for j in select2 :
- self.TextCroise.append(parent.tableau.colnames[i] + ' / ' + parent.tableau.colnames[j])
+ for i in self.colsel1 :
+ for j in self.colsel2 :
+ self.TextCroise.append(self.tableau.colnames[i] + ' / ' + self.tableau.colnames[j])
rchioption = {}
- for val in chioption :
- if chioption[val]:
+ for val in self.chioption :
+ if self.chioption[val]:
rchioption[val] = 'TRUE'
else :
rchioption[val] = 'FALSE'
txt="""
source("%s")
- """%self.parent.RscriptsPath['Rfunct']
-# if parent.tableau.: rownames=1
-# else : rownames='NULL'
-# if parent.g_header : header = 'TRUE'
-# else : header = 'FALSE'
+ """%ffr(self.parent.RscriptsPath['Rfunct'])
txt += """
source("%s")
""" % ffr(self.parent.RscriptsPath['Rgraph'])
@@ -88,23 +124,23 @@ class MakeChi2():
bw <- %s
""" % (rchioption['valobs'], rchioption['valtheo'], rchioption['contrib'], rchioption['resi'], rchioption['pourcent'], rchioption['pourcentl'], rchioption['pourcentc'], rchioption['graph'], rchioption['bw'])
txt+="""
- datadm <- ReadData("%s", encoding="%s", header = TRUE, sep = "%s",quote = '%s', na.strings = "%s",rownames= 1)
+ datadm <- read.csv2("%s", encoding="%s", header = TRUE, row.names = 1, sep='\\t', quote = '"', na.string = '')
listres<-list()
listcol<-list()
cont<-1
- """%(ffr(parent.tableau.parametre['csvfile']),self.parent.encode, parent.tableau.parametre['colsep'], parent.tableau.parametre['txtsep'], self.parent.nastrings)
- if len(select1)==1:
- strsel1=str(select1).replace(',','')
+ """%(ffr(self.tableau.parametres['csvfile']), self.tableau.parametres['syscoding'])
+ if len(self.colsel1)==1:
+ strsel1=str(self.colsel1).replace(',','')
else:
- strsel1=str(select1)
- if len(select2)==1:
- strsel2=str(select2).replace(',','')
+ strsel1=str(self.colsel1)
+ if len(self.colsel2)==1:
+ strsel2=str(self.colsel2).replace(',','')
else:
- strsel2=str(select2)
+ strsel2=str(self.colsel2)
txt+="""
- for (i in c%s) {"""%strsel1
+ for (i in c%s) {""" % strsel1
txt+="""
- for (j in c%s) {"""%strsel2
+ for (j in c%s) {""" % strsel2
txt+="""
tab<-table(datadm[,i+1],datadm[,j+1])
if (min(dim(tab)) != 1) {
@@ -148,9 +184,7 @@ class MakeChi2():
chi$prl <- round((chi$observed/sr)*100,2)
chi$prc <- t(round((t(chi$observed)/sc)*100,2))
}
- fileout<-paste('histo',%i,sep='')
- fileout<-paste(fileout,'_',sep='')
- fileout<-paste(fileout,count,sep='')
+ fileout<-paste('histo_',count,sep='')
fileout<-paste(fileout,'.png',sep='')
count<-count+1
fileout<-file.path("%s",fileout)
@@ -258,7 +292,7 @@ class MakeChi2():
li<-matrix('fin_analyse',1,maxcol)
frameout<-rbind(frameout,li)
write.csv2(frameout,file="%s")
- """%(parent.FreqNum,ffr(parent.TEMPDIR),ffr(self.OutFrame))
+ """ % (ffr(self.parametres['pathout']),ffr(self.OutFrame))
tmpfile=tempfile.mktemp(dir=self.TEMPDIR)
print tmpfile
tmpscript=open(tmpfile,'w')
@@ -267,7 +301,24 @@ class MakeChi2():
pid = exec_rcode(self.RPath, tmpfile, wait = False)
while pid.poll() == None :
sleep(0.2)
- check_Rresult(self.parent, pid)
+ check_Rresult(self.parent, pid)
+ self.count += 1
+ keepGoing = self.dlg.Update(self.count,u"Ecriture des résultats")
+
+ listfileout = self.dolayout(self.chioption)
+ #listfileout=dlg.ShowChi2(ColSel1,ColSel2)
+ #parent.FreqNum += 1
+ #parent.DictTab[u"Chi2_%s*"%parent.FreqNum]=listfileout
+# parent.newtab = wx.html.HtmlWindow(parent.nb, -1)
+# if "gtk2" in wx.PlatformInfo:
+# parent.newtab.SetStandardFonts()
+# parent.newtab.LoadPage(listfileout[len(listfileout)-1])
+# parent.nb.AddPage(parent.newtab,u"Chi2_%s*"%parent.FreqNum)
+# parent.nb.SetSelection(parent.nb.GetPageCount()-1)
+# parent.ShowTab(wx.EVT_BUTTON)
+# parent.DisEnSaveTabAs(True)
+# self.count += 1
+# keepGoing = self.dlg.Update(self.count,u"Fini")
def dolayout(self, option):
ListFile=[False]
@@ -309,19 +360,10 @@ class MakeChi2():
allcoord.append(coord_res)
allhtml = [[clean_line(lcont[allcoord[i][j]+1:allcoord[i+1][j]]) for j, line in enumerate(allcoord[i])] for i, tab in enumerate(allcoord) if i!=len(allcoord)-1]
-
allhtml = [make_table(val,names[i],res) for i,val in enumerate(allhtml)]
-
links = make_link_list(res, self.TextCroise)
- #colors = [line[-1] for line in res]
-
- # good = [i for i,chi in enumerate(res) if chi[-1] == 'green' or chi[-1] == 'blue']
- #select_good = [[val[i] for i in good] for val in tout]
-
-
html_res = make_restab(res)
allhtml.insert(0,html_res)
-
titles = make_title(res, self.TextCroise)
allhtml.insert(0,titles)
@@ -345,82 +387,12 @@ class MakeChi2():
"""%self.parent.SysEncoding
-
pretxt = '
\n'.join(links)+'