1 # -*- coding: utf-8 -*-
2 #Author: Pierre Ratinaud
3 #Copyright (c) 2008-2020 Pierre Ratinaud
6 #------------------------------------
7 # import des modules python
8 #------------------------------------
13 from time import sleep
15 #------------------------------------
16 # import des modules wx
17 #------------------------------------
20 #------------------------------------
21 # import des fichiers du projet
22 #------------------------------------
23 from chemins import ffr
24 from layout import MakeHeader,MakeStudentTable
25 from functions import exec_rcode, check_Rresult
28 class StudentDialog(wx.Dialog):
31 self, parent, ID, title, size=wx.DefaultSize, pos=wx.DefaultPosition,
32 style=wx.DEFAULT_DIALOG_STYLE
34 wx.Dialog.__init__(self) # 1
35 self.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP) # 2
36 self.Create(parent, ID, title) # 3
37 Filename=parent.PATH[0]
38 self.content=parent.table[:]
39 self.HEADER=parent.header[:]
44 #FIXME : assume une premiere ligne contenant les noms de colonnes
45 for line in self.content:
74 for key,nb in vide.items():
75 dicttot[key]=['vide',nb]
77 for key,nb in inb.items() :
79 dicttot[key]=['int',dicttot[key][1]+nb]
81 dicttot[key]=['int',nb]
82 for key,nb in fnb.items():
84 dicttot[key]=['float',dicttot[key][1]+nb]
86 dicttot[key]=['float',nb]
87 for key,nb in cnb.items():
89 dicttot[key]=['char',dicttot[key][1]+nb]
91 dicttot[key]=['char',nb]
92 acontent=array(self.content)
94 lg=[i for i,descr in dicttot.items() if descr[0]=='char']
96 if len(unique(acontent[:,i]))==2:
97 self.ListGrp.append(i)
98 elif ('' in unique(acontent[:,i]).tolist()) and len(unique(acontent[:,i]))==3:
99 self.ListGrp.append(i)
100 li=[i for i,descr in dicttot.items() if descr[0]=='int']
101 lf=[i for i,descr in dicttot.items() if descr[0]=='float']
103 print(self.ListGrp, self.ListNum)
105 for i in self.HEADER:
107 LABELLIST.append(i[0:60])
112 for i in self.ListGrp :
113 self.LabelListGrp.append(LABELLIST[i])
114 for i in self.ListNum :
115 self.LabelListNum.append(LABELLIST[i])
116 self.list_box_1 = wx.ListBox(self, -1, choices=self.LabelListGrp, style=wx.LB_MULTIPLE|wx.LB_HSCROLL)
117 self.list_box_2 = wx.ListBox(self, -1, choices=self.LabelListNum, style=wx.LB_MULTIPLE|wx.LB_HSCROLL)
118 self.button_1 = wx.Button(self, wx.ID_OK)
119 self.button_cancel = wx.Button(self, wx.ID_CANCEL)
120 self.__set_properties()
122 self.Bind(wx.EVT_LISTBOX, self.Select1, self.list_box_1)
124 self.TEMPDIR=parent.TEMPDIR
126 self.Filename=parent.fileforR
128 self.num=parent.FreqNum
129 #-------------------------------
131 def __set_properties(self):
132 # begin wxGlade: ConfChi2.__set_properties
133 self.SetTitle("Sélection des variables")
134 self.list_box_1.SetSelection(0)
135 self.list_box_2.SetSelection(0)
138 def __do_layout(self):
139 # begin wxGlade: ConfChi2.__do_layout
140 sizer_1 = wx.BoxSizer(wx.VERTICAL)
141 sizer_2 = wx.BoxSizer(wx.VERTICAL)
142 sizer_3 = wx.BoxSizer(wx.HORIZONTAL)
143 sizer_4 = wx.BoxSizer(wx.HORIZONTAL)
144 sizer_3.Add(self.list_box_1, 0, wx.EXPAND, 0)
145 sizer_3.Add(self.list_box_2, 0, wx.EXPAND|wx.ALIGN_CENTER_HORIZONTAL, 0)
146 sizer_2.Add(sizer_3, 1, wx.EXPAND, 0)
147 sizer_4.Add(self.button_cancel, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 0)
148 sizer_4.Add(self.button_1, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 0)
149 sizer_2.Add(sizer_4, 0, wx.ALIGN_CENTRE_HORIZONTAL, 0)
150 sizer_1.Add(sizer_2, 1, wx.EXPAND, 0)
151 self.SetSizer(sizer_1)
156 def Select1(self, event): # wxGlade: ConfChi2.<event_handler>
159 def ShowStudent(self,select1,select2):
161 self.encode=self.parent.SysEncoding
162 #################################################
163 #max = len(select1)*len(select2)
164 #dlg = wx.ProgressDialog("Traitements",
165 # "Veuillez patienter...",
168 # style = wx.PD_APP_MODAL
172 ###############################################
174 colgrp=[self.ListGrp[i] for i in select1]
175 colnum=[self.ListNum[i] for i in select2]
177 strcolgrp=str(tuple(colgrp)).replace(',','')
179 strcolgrp=str(tuple(colgrp))
181 strcolnum=str(tuple(colnum)).replace(',','')
183 strcolnum=str(tuple(colnum))
187 """%self.parent.RscriptsPath['Rfunct']
188 if parent.g_id: rownames='1'
189 else : rownames='NULL'
190 if parent.g_header : header = 'TRUE'
191 else : header = 'FALSE'
193 #datadm <- ReadData('%s', encoding='%s',header = %s, sep = '%s',quote = '%s', na.strings = '%s',rownames=%s)
195 datadm <- read.csv2('%s', encoding='%s',header = %s, sep = '%s',quote = '%s', na.strings = '%s',row.names=%s, dec='.')
196 """%(ffr(self.Filename),parent.encode,header, parent.colsep,parent.txtsep,parent.nastrings,rownames)
202 """%ffr(self.TEMPDIR)
212 datadm[,(j+1)]<-as.numeric(datadm[,(j+1)])
214 fileout<-paste('student',num,sep='')
215 fileout<-paste(fileout,'_',sep='')
216 fileout<-paste(fileout,count,sep='')
217 fileout<-paste(fileout,'.jpeg',sep='')
218 fileout<-file.path(tmpdir,fileout)
219 if (Sys.info()["sysname"]=='Darwin') {
220 quartz(file=fileout,type='jpeg')
223 jpeg(fileout,res=200)
226 plot(datadm[,(j+1)] ~ datadm[,(i+1)],data=datadm)
228 student<-t.test(datadm[,(j+1)] ~ datadm[,(i+1)],data=datadm)
229 pvalue<-student$p.value
230 method<-student$method
231 tvalue<-student$statistic
232 df<-student$parameter
233 grmean<-as.matrix(student$estimate)
234 out<-rbind(out,round(grmean,digits=2))
235 out<-rbind(out,pvalue)
236 out<-rbind(out,method)
237 out<-rbind(out,tvalue)
238 out<-rbind(out,round(df,digits=2))
239 out<-rbind(out,fileout)
244 restmp=tempfile.mktemp(dir=self.TEMPDIR)
246 write.csv2(out,file='%s')
248 tmpfile=tempfile.mktemp(dir=self.TEMPDIR)
249 tmpscript=open(tmpfile,'w')
250 tmpscript.write(txtR)
252 pid = exec_rcode(self.parent.RPath, tmpfile, wait = False)
253 while pid.poll() == None :
255 check_Rresult(self.parent, pid)
256 file=open(restmp,'r')
259 resl=[line.replace('\n','').replace('"','').split(';') for line in res]
268 student['grp1']=line[0].replace('mean in group ','')
269 student['mean1']=float(line[1])
271 student['grp2']=line[0].replace('mean in group ','')
272 student['mean2']=float(line[1])
274 student['p.value']=float(line[1])
276 student['method']=line[1]
278 student['t']=float(line[1])
280 student['df']=float(line[1])
282 student['graph']=line[1]
284 listr.append(student)
290 LISTFILE.append(False)
291 txt=MakeHeader('T de Student', self.encode)
296 Student=listr[ancre-1]
297 pvalue=Student['p.value']
298 Colname=self.LabelListNum[j]
299 Colgrp=self.LabelListGrp[i]
300 LISTFILE.append(Student['graph'])
305 txt+="<a href=#%s><font color=%s>%s</font></a><br />"%(ancre,color,Colname+' / '+Colgrp)
306 txt2+=MakeStudentTable(Student,self.num,ancre,Graph,os.path.basename(Student['graph']),Colname,self.encode)
308 fileout=os.path.join(self.TEMPDIR,'resultats-student_%s.html'%str(self.num))
309 File=open(fileout,'w')
312 LISTFILE.append(fileout)
319 def __init__(self,parent):
320 dlg = StudentDialog(parent, -1, "Student", size=(350, 400),
321 style = wx.DEFAULT_DIALOG_STYLE
324 val = dlg.ShowModal()
326 ColSel1=dlg.list_box_1.GetSelections()
327 ColSel2=dlg.list_box_2.GetSelections()
328 listfileout=dlg.ShowStudent(ColSel1,ColSel2)
330 parent.DictTab["t de student_%s*"%parent.FreqNum]=listfileout
331 parent.FileTabList.append(listfileout)
332 parent.newtab=wx.html.HtmlWindow(parent.nb, -1)
333 if "gtk2" in wx.PlatformInfo:
334 parent.newtab.SetStandardFonts()
335 parent.newtab.LoadPage(listfileout[len(listfileout)-1])
336 parent.nb.AddPage(parent.newtab,"t de student_%s*"%parent.FreqNum)
337 parent.nb.SetSelection(parent.nb.GetPageCount()-1)
338 parent.ShowTab(wx.EVT_BUTTON)
339 parent.DisEnSaveTabAs(True)