2 # -*- coding: utf-8 -*-
3 #Author: Pierre Ratinaud
4 #Copyright (c) 2008-2009 Pierre Ratinaud
9 #import wx.lib.agw.aui as aui
11 from chemins import ConstructPathOut, ChdTxtPathOut, FFF, ffr, PathOut, StatTxtPathOut
12 from ConfigParser import ConfigParser
13 from functions import ReadProfileAsDico, GetTxtProfile, read_list_file, ReadList, exec_rcode, print_liste, BugReport, DoConf
14 from ProfList import *
15 from guiparam3d import param3d, simi3d
16 from PrintRScript import write_afc_graph, print_simi3d
17 from profile_segment import *
18 from functions import ReadList
21 from search_tools import SearchFrame
22 from dialog import PrefGraph, PrefExport, PrefSimpleFile, PrefDendro
23 from corpusNG import Corpus
31 class GraphPanelAfc(wx.Panel):
32 def __init__(self, parent, dico, list_graph, clnb, itempath = 'liste_graph_afc', coding = sys.getdefaultencoding()):
33 wx.Panel.__init__(self,parent)
38 self.itempath = itempath
39 self.parent = self.GetParent()#parent
40 self.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "courier"))
43 self.TabCHD = self.parent.GetParent()
44 self.nb = self.TabCHD.GetParent()
45 self.ira = self.nb.GetParent()
46 self.panel_1 = wx.ScrolledWindow(self, -1, style=wx.TAB_TRAVERSAL)
47 afc_img = wx.Image(os.path.join(self.ira.images_path,'button_afc.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
48 self.butafc = wx.BitmapButton(self, -1, afc_img)
49 self.Bind(wx.EVT_BUTTON, self.afc_graph, self.butafc)
50 self.dirout = os.path.dirname(self.Dict['ira'])
51 for i in range(0,len(list_graph)):
52 if os.path.exists(os.path.join(self.dirout,list_graph[i][0])) :
53 self.listimg.append(wx.StaticBitmap(self.panel_1, -1, wx.Bitmap(os.path.join(self.dirout,list_graph[i][0]), wx.BITMAP_TYPE_ANY)))
54 self.labels.append(wx.StaticText(self.panel_1, -1, list_graph[i][1]))
56 self.param = { 'typegraph' : 0,
78 self.__set_properties()
81 def __set_properties(self):
82 self.panel_1.EnableScrolling(True,True)
83 #self.panel_1.SetSize((1000,1000))
84 self.panel_1.SetScrollRate(20, 20)
86 def __do_layout(self):
87 self.sizer_1 = wx.BoxSizer(wx.VERTICAL)
88 self.sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
89 self.sizer_3 = wx.BoxSizer(wx.VERTICAL)
90 self.sizer_2.Add(self.butafc, 0, 0, 0)
91 for i in range(0, len(self.listimg)):
92 self.sizer_3.Add(self.listimg[i], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
93 self.sizer_3.Add(self.labels[i], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
94 self.panel_1.SetSizer(self.sizer_3)
95 self.sizer_2.Add(self.panel_1, 1, wx.EXPAND, 0)
96 self.SetSizer(self.sizer_2)
98 def afc_graph(self,event):
99 #dirout = os.path.dirname(self.Dict['ira'])
100 while os.path.exists(os.path.join(self.dirout,'graph_afc_'+str(self.afcnb)+'.png')):
102 self.fileout = ffr(os.path.join(self.dirout,'graph_afc_'+str(self.afcnb)+'.png'))
103 dial = PrefGraph(self.parent,-1,self.param,'')
104 dial.CenterOnParent()
105 val = dial.ShowModal()
107 self.param = {'typegraph' : dial.choicetype.GetSelection(),
108 'width' : dial.spin1.GetValue(),
109 'height' : dial.spin2.GetValue(),
110 'what' : dial.choice1.GetSelection(),
111 'qui' : dial.choice2.GetSelection(),
112 'do_select_nb' : dial.check1.GetValue(),
113 'do_select_chi' : dial.check2.GetValue(),
114 'select_nb' : dial.spin_nb.GetValue(),
115 'select_chi' : dial.spin_chi.GetValue(),
116 'over' : dial.check3.GetValue(),
117 'cex_txt' : dial.check4.GetValue(),
118 'txt_min' : dial.spin_min.GetValue(),
119 'txt_max' : dial.spin_max.GetValue(),
120 'tchi' : dial.check_tchi.GetValue(),
121 'tchi_min' : dial.spin_min_tchi.GetValue(),
122 'tchi_max' : dial.spin_max_tchi.GetValue(),
123 'taillecar' : dial.spin3.GetValue(),
124 'facteur' : [dial.spin_f1.GetValue(),dial.spin_f2.GetValue(), dial.spin_f3.GetValue()],
126 'film' : str(dial.film.GetValue()).upper(),
127 'alpha' : dial.slider_sphere.GetValue()
129 self.nb.parent = self.ira
130 self.DictPathOut = self.Dict
131 self.RscriptsPath = self.ira.RscriptsPath
134 """ % self.DictPathOut['RData']
135 if self.itempath == 'liste_graph_afcf' :
138 afc_table <- afcf_table
139 chistabletot <- specfp
141 elif self.itempath == 'liste_graph_afct' :
144 afc_table <- afct_table
145 chistabletot <- spectp
147 txt += write_afc_graph(self)
148 filetmp = tempfile.mktemp()
149 file = open(filetmp,'w')
152 pid = exec_rcode(self.ira.RPath, filetmp)
153 check_Rresult(self.ira, pid)
154 if self.param['typegraph'] == 0 :
156 if self.param['qui'] == 0 : value = u'actives'
157 if self.param['qui'] == 1 : value = u'supplémentaires'
158 if self.param['qui'] == 2 : value = u'étoilées'
159 if self.param['qui'] == 3 : value = u'classes'
161 if self.param['what'] == 0 : value = u'Coordonnées'
162 if self.param['what'] == 1 : value = u'Corrélations'
163 txt += value + u' - facteur %i / %i' % (self.param['facteur'][0], self.param['facteur'][1])
164 if self.param['do_select_nb'] : txt += u' - sélection de %i variables' % self.param['select_nb']
165 if self.param['do_select_chi'] : txt += u' - sélection des variables avec chi2 > %i ' % self.param['select_chi']
166 if self.param['over'] : txt += u' - Eviter les recouvrements'
167 if self.param['cex_txt'] : txt += u' - taille du texte proportionnel à la masse'
168 if self.param['tchi'] : txt += u' - taille du texte proportionnel au chi2 d\'association'
169 list_graph = read_list_file(self.DictPathOut[self.itempath], self.coding)
170 list_graph.append([self.fileout, txt])
171 print_liste(self.DictPathOut[self.itempath], list_graph)
172 self.sizer_3.Add(wx.StaticBitmap(self.panel_1, -1, wx.Bitmap(self.fileout, wx.BITMAP_TYPE_ANY)), 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
173 self.sizer_3.Add(wx.StaticText(self.panel_1,-1, txt), 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
174 self.sizer_3.Fit(self.panel_1)
177 self.panel_1.Scroll(0,self.panel_1.GetScrollRange(wx.VERTICAL))
180 class GraphPanel(wx.ScrolledWindow):
181 def __init__(self, parent, dico, list_graph, txt = '', style = wx.TAB_TRAVERSAL):
182 wx.ScrolledWindow.__init__(self, parent, style = style)
186 self.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "courier"))
189 self.dirout = os.path.dirname(self.Dict['ira'])
190 self.deb = wx.StaticText(self, -1, txt)
191 for i in range(0,len(list_graph)):
192 if os.path.exists(os.path.join(self.dirout,list_graph[i][0])) :
193 self.listimg.append(wx.StaticBitmap(self, -1, wx.Bitmap(os.path.join(self.dirout,list_graph[i][0]), wx.BITMAP_TYPE_ANY)))
194 self.labels.append(wx.StaticText(self, -1, list_graph[i][1]))
196 self.__set_properties()
199 def __set_properties(self):
200 self.SetScrollRate(20, 20)
202 def __do_layout(self):
203 self.sizer_1 = wx.BoxSizer(wx.VERTICAL)
204 self.sizer_2 = wx.BoxSizer(wx.VERTICAL)
205 self.sizer_3 = wx.BoxSizer(wx.HORIZONTAL)
206 self.sizer_1.Add(self.deb)
207 for i in range(0, len(self.listimg)):
208 self.sizer_1.Add(self.listimg[i], 1, wx.ALIGN_CENTER_HORIZONTAL, 0)
209 self.sizer_1.Add(self.labels[i], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
210 self.sizer_2.Add(self.sizer_1, 1, wx.EXPAND, 0)
211 self.SetSizer(self.sizer_1)
212 self.sizer_1.Fit(self)
215 def __init__(self, parent, corpus, parametres, Alceste=False):
220 self.parametres = parametres
221 self.pathout = PathOut(parametres['ira'])
222 self.pathout.basefiles(ChdTxtPathOut)
223 DictPathOut = self.pathout
224 self.DictPathOut = DictPathOut
227 Profile = DictPathOut['PROFILE_OUT']
228 AntiProfile = DictPathOut['ANTIPRO_OUT']
229 if isinstance(self.corpus, Corpus) :
230 self.encoding = self.corpus.parametres['syscoding']
231 self.corpus.make_ucecl_from_R(self.pathout['uce'])
232 elif 'tableau' in dir(gparent) :
233 self.encoding = gparent.tableau.parametres['syscoding']
235 #AnalyseConf = ConfigParser()
236 #AnalyseConf.readfp(codecs.open(filename,'r', self.encoding))
237 #AnalyseConf.read(filename)
238 #if 'analyse' in AnalyseConf.sections() :
239 # section = 'analyse'
240 #elif 'questionnaire' in AnalyseConf.sections() :
241 # section = 'questionnaire'
242 #elif 'chd_dist_quest' in AnalyseConf.sections() :
243 # section = 'chd_dist_quest'
244 #self.section = section
245 #clnb = AnalyseConf.get(section, 'clusternb')
247 clnb = parametres['clnb']
248 dlg = progressbar(self, maxi = 4 + clnb)
250 corpname = self.corpus.parametres['corpus_name']
251 print 'lecture des profils'
252 dlg.Update(2, u'lecture des profils')
254 DictProfile = ReadProfileAsDico(self, Profile, Alceste, self.encoding)
255 self.DictProfile = DictProfile
256 print 'lecture des antiprofils'
257 DictAnti = ReadProfileAsDico(self, AntiProfile, Alceste, self.encoding)
259 panel = wx.Panel(parent, -1)
260 sizer1 = wx.BoxSizer(wx.VERTICAL)
262 panel.chd_toolbar = wx.ToolBar(panel, -1, wx.DefaultPosition, wx.DefaultSize, wx.TB_FLAT | wx.TB_NODIVIDER)
263 panel.chd_toolbar.SetToolBitmapSize(wx.Size(16, 16))
265 if isinstance(self.corpus, Corpus) :
266 panel.corpus = self.corpus
267 self.ID_sg = wx.NewId()
268 butsg = wx.Button(panel.chd_toolbar, self.ID_sg, u"Profils des segments répétés ")
269 panel.chd_toolbar.AddControl(butsg)
270 panel.chd_toolbar.AddSeparator()
271 self.ID_export = wx.NewId()
272 butexp = wx.Button(panel.chd_toolbar, self.ID_export, u"Exporter le corpus ")
273 panel.chd_toolbar.AddControl(butexp)
274 panel.chd_toolbar.AddSeparator()
275 self.ID_colored = wx.NewId()
276 butcol = wx.Button(panel.chd_toolbar, self.ID_colored, u"Corpus en couleur ")
277 panel.chd_toolbar.AddControl(butcol)
278 panel.chd_toolbar.AddSeparator()
279 self.ID_searchf = wx.NewId()
280 butsearchf = wx.Button(panel.chd_toolbar, self.ID_searchf, u"Outil de navigation ")
281 panel.chd_toolbar.AddControl(butsearchf)
282 panel.chd_toolbar.AddSeparator()
284 self.ID_proftype =wx.NewId()
285 butpt = wx.Button(panel.chd_toolbar, self.ID_proftype, u"Profils des types ")
286 panel.chd_toolbar.AddControl(butpt)
287 panel.chd_toolbar.AddSeparator()
289 self.ID_clusterstat =wx.NewId()
290 butclusterstat = wx.Button(panel.chd_toolbar, self.ID_clusterstat, u"Stat par classe ")
291 panel.chd_toolbar.AddControl(butclusterstat)
292 panel.chd_toolbar.AddSeparator()
295 self.ID_rapport = wx.NewId()
296 #rap_img = wx.Image(os.path.join(self.parent.images_path,'icone_rap_16.png'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
297 #panel.chd_toolbar.AddLabelTool(self.ID_rapport, "rapport", rap_img, shortHelp=u"Produire le rapport", longHelp=u"Exporter un rapport en texte simple")
298 butrap = wx.Button(panel.chd_toolbar, self.ID_rapport, u"Rapport ")
299 panel.chd_toolbar.AddControl(butrap)
301 panel.chd_toolbar.Realize()
302 sizer1.Add(panel.chd_toolbar,0, wx.EXPAND, 5)
304 #self.TabChdSim = wx.aui.AuiNotebook(self.parent.nb, -1, wx.DefaultPosition)
305 notebook_flags = aui.AUI_NB_DEFAULT_STYLE | aui.AUI_NB_TAB_EXTERNAL_MOVE | aui.AUI_NB_TAB_MOVE | aui.AUI_NB_TAB_FLOAT| wx.NO_BORDER
306 panel.TabChdSim = aui.AuiNotebook(panel, -1, wx.DefaultPosition)
307 panel.TabChdSim.SetAGWWindowStyleFlag(notebook_flags)
308 panel.TabChdSim.SetArtProvider(aui.ChromeTabArt())
309 sizer1.Add(panel.TabChdSim,10, wx.EXPAND, 5)
310 panel.SetSizer(sizer1)
314 if isinstance(self.corpus, Corpus) :
315 panel.TabChdSim.corpus = corpus
316 panel.TabChdSim.corpus.dictpathout = self.DictPathOut
317 panel.parametres = self.parametres
319 self.notenb = self.parent.nb.GetPageCount()
320 if os.path.exists(DictPathOut['pre_rapport']):
321 #self.tabRap = wx.TextCtrl(self.TabChdSim, -1, "", style=wx.TE_MULTILINE | wx.TE_RICH2)
322 #self.tabRap.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "courier"))
323 with codecs.open(DictPathOut['pre_rapport'], 'r', self.encoding) as f :
325 #self.tabRap.write(txt)
326 #self.tabRap.ShowPosition(0)
331 if os.path.exists(self.DictPathOut['liste_graph_chd']) :
332 list_graph = read_list_file(self.DictPathOut['liste_graph_chd'], self.encoding)
333 CHD = GraphPanelDendro(panel.TabChdSim, DictPathOut, list_graph, txt = self.debtext)
334 panel.TabChdSim.AddPage(CHD,'CHD')
336 panel.ProfNB = aui.AuiNotebook(panel, -1, wx.DefaultPosition)
337 panel.ProfNB.SetArtProvider(aui.ChromeTabArt())
338 #self.ProfNB.SetTabCtrlHeight(100)
339 panel.AntiProfNB = aui.AuiNotebook(panel, -1, wx.DefaultPosition)
340 if os.path.exists(DictPathOut['prof_seg']) :
341 prof_seg = ReadProfileAsDico(self, DictPathOut['prof_seg'], False, self.encoding)
342 self.prof_seg_nb = aui.AuiNotebook(panel, -1, wx.DefaultPosition)
343 for i in range(0, clnb):
344 dlg.Update(3+i, 'Classe %i' %(i+1))
345 ind = '/'.join(DictProfile[str(i + 1)][0][0:2])
346 indpour = ' - '.join([ind, DictProfile[str(i + 1)][0][2]])
347 print 'construction liste classe %i' % i
348 self.tabprofile = ProfListctrlPanel(self.parent, self, DictProfile[str(i + 1)], Alceste, i + 1)
349 self.tabantiprofile = ProfListctrlPanel(self.parent, self, DictAnti[str(i + 1)], Alceste, i + 1)
350 panel.ProfNB.AddPage(self.tabprofile, 'classe %s %s(%s%%)' % (str(i + 1), sep, indpour))
351 panel.AntiProfNB.AddPage(self.tabantiprofile, 'classe %s' % str(i + 1))
352 if os.path.exists(DictPathOut['prof_seg']) :
353 self.tab_prof_seg = ProfListctrlPanel(self.parent, self, prof_seg[str(i + 1)], False, i + 1)
354 self.prof_seg_nb.AddPage(self.tab_prof_seg, 'classe %i' % (i + 1))
357 self.TabAFC = aui.AuiNotebook(panel.TabChdSim, -1, wx.DefaultPosition)
359 list_graph=read_list_file(DictPathOut['liste_graph_afc'], self.encoding)
360 self.tabAFCGraph = GraphPanelAfc(self.TabAFC, DictPathOut, list_graph, self.clnb, coding=self.encoding)
361 self.TabAFC.AddPage(self.tabAFCGraph, 'AFC')
363 if os.path.exists(self.DictPathOut['afc_facteur']) :
364 dictrow, first = ReadList(self.DictPathOut['afc_facteur'], self.encoding)
365 self.TabAFC_facteur = ListForSpec(self.parent, parametres, dictrow, first)
366 dictrow, first = ReadList(self.DictPathOut['afc_row'], self.encoding)
367 self.TabAFC_ligne = ListForSpec(self.parent, self.parametres, dictrow, first)
368 dictrow, first = ReadList(self.DictPathOut['afc_col'], self.encoding)
369 self.TabAFC_colonne = ListForSpec(parent, self.parametres, dictrow, first)
370 self.TabAFC.AddPage(self.TabAFC_facteur, 'Facteurs')
371 self.TabAFC.AddPage(self.TabAFC_colonne, u'Colonnes')
372 self.TabAFC.AddPage(self.TabAFC_ligne, u'Lignes')
374 sizer_3 = wx.BoxSizer(wx.VERTICAL)
375 self.parent.nb_panel_2 = wx.Panel(panel.TabChdSim, -1)
376 self.parent.button_simi = wx.Button(self.parent.nb_panel_2, -1, "Voyager")
377 self.parent.simi3dpanel = simi3d(self.parent.nb_panel_2, -1)
378 sizer_3.Add(self.parent.simi3dpanel, 1, wx.EXPAND, 0)
379 sizer_3.Add(self.parent.button_simi, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
380 self.parent.nb_panel_2.SetSizer(sizer_3)
381 self.TabAFC.AddPage(self.parent.nb_panel_2, "graph 3D")
382 self.parent.Bind(wx.EVT_BUTTON, self.onsimi, self.parent.button_simi)
384 panel.TabChdSim.AddPage(panel.ProfNB, 'Profils')
385 panel.TabChdSim.AddPage(panel.AntiProfNB, 'Antiprofils')
386 dlg.Update(4 + self.clnb, 'Affichage...')
388 panel.TabChdSim.AddPage(self.TabAFC, 'AFC')
389 if os.path.exists(DictPathOut['prof_seg']) :
390 panel.TabChdSim.AddPage(self.prof_seg_nb, u'Profils des segments répétés')
392 if isinstance(self.corpus, Corpus) :
393 panel.Bind(wx.EVT_BUTTON, self.on_export_classes, id = self.ID_export)
394 panel.Bind(wx.EVT_BUTTON, self.onprofseg, id = self.ID_sg)
395 panel.Bind(wx.EVT_BUTTON, self.oncolored, id = self.ID_colored)
396 panel.Bind(wx.EVT_BUTTON, self.onsearchf, id = self.ID_searchf)
397 panel.Bind(wx.EVT_BUTTON, self.onproftype, id = self.ID_proftype)
398 panel.Bind(wx.EVT_BUTTON, self.onclusterstat, id = self.ID_clusterstat)
400 panel.Bind(wx.EVT_BUTTON, self.ongetrapport, id = self.ID_rapport)
401 self.parent.nb.AddPage(panel, 'Classification - %s' % corpname)
402 self.parent.ShowTab(True)
403 self.parent.nb.SetSelection(self.parent.nb.GetPageCount() - 1)
404 #for pane in self.parent._mgr.GetAllPanes() :
405 # if isinstance(pane.window, aui.AuiNotebook):
407 # nb.SetAGWWindowStyleFlag(notebook_flags)
408 # nb.SetArtProvider(aui.ChromeTabArt())
410 self.parent._mgr.Update()
412 def onsimi(self,event):
413 outfile = print_simi3d(self)
414 error = exec_rcode(self.parent.RPath, outfile, wait = True)
416 def ongetrapport(self, event) :
417 dial = PrefSimpleFile(self, self.parent, **{'mask' : '*.txt', 'title': 'Rapport'})
418 dial.fbb.SetValue(self.DictPathOut['rapport'])
419 dial.CenterOnParent()
420 res = dial.ShowModal()
422 fileout = dial.fbb.GetValue()
424 with open(fileout, 'w') as f :
425 f.write(self.debtext + '\n' + GetTxtProfile(self.DictProfile))
427 dlg = wx.MessageDialog(self.parent, msg, u"Rapport", wx.OK | wx.NO_DEFAULT | wx.ICON_INFORMATION)
434 def on_export_classes(self, event) :
435 corpus = self.parent.nb.GetPage(self.parent.nb.GetSelection()).corpus
436 dial = PrefExport(self, self.parent)
437 dial.fbb.SetValue(os.path.join(os.path.dirname(corpus.dictpathout['ira']), 'export_corpus.txt'))
438 dial.CenterOnParent()
439 res = dial.ShowModal()
441 if dial.radio_type.GetSelection() == 0 : alc = True
443 if dial.radio_lem.GetSelection() == 0 : lem = True
445 self.corpus.export_corpus_classes(dial.fbb.GetValue(), alc = alc, lem = lem)
448 dlg = wx.MessageDialog(self.parent, msg, u"Export", wx.OK | wx.NO_DEFAULT | wx.ICON_INFORMATION)
453 def onprofseg(self, event):
455 corpus = self.parent.nb.GetPage(self.parent.nb.GetSelection()).corpus
456 ProfileSegment(self.parent,corpus)
458 BugReport(self.parent)
460 def onproftype(self, event):
462 corpus = self.parent.nb.GetPage(self.parent.nb.GetSelection()).corpus
463 ProfilType(self.parent, corpus)
465 BugReport(self.parent)
467 def oncolored(self,evt) :
468 dial = PrefSimpleFile(self, self.parent, **{'mask' : '*.html', 'title': 'Corpus en couleur'})
469 dial.fbb.SetValue(os.path.join(os.path.dirname(self.corpus.dictpathout['ira']), 'corpus_couleur.html'))
470 dial.CenterOnParent()
471 res = dial.ShowModal()
473 fileout = dial.fbb.GetValue()
475 txt = self.corpus.make_colored_corpus()
476 with open(fileout, 'w') as f :
478 msg = u"Fini !\nVoulez-vous ouvrir le corpus dans votre navigateur ?"
479 dlg = wx.MessageDialog(self.parent, msg, u"Corpus en couleur", wx.NO | wx.YES | wx.NO_DEFAULT | wx.ICON_QUESTION)
481 if dlg.ShowModal() == wx.ID_YES :
482 webbrowser.open(fileout)
485 def onclusterstat(self, evt) :
486 dial = PrefSimpleFile(self, self.parent, **{'mask' : '*.csv', 'title': 'Stat par classe'})
487 dial.fbb.SetValue( os.path.join(os.path.dirname(self.corpus.dictpathout['ira']), 'stat_par_classe.csv'))
488 dial.CenterOnParent()
489 res = dial.ShowModal()
491 fileout = dial.fbb.GetValue()
494 self.corpus.get_stat_by_cluster(fileout)
496 dlg = wx.MessageDialog(self.parent, msg, u"Stat par classe", wx.OK | wx.NO_DEFAULT | wx.ICON_INFORMATION)
498 if dlg.ShowModal() == wx.ID_OK :
501 def onsearchf(self, evt) :
502 if 'FrameSearch' not in dir(self.parent) :
503 self.parent.FrameSearch = SearchFrame(self.parent, -1, u"Rechercher...", self.corpus)
504 self.parent.FrameSearch.Show()
508 def PrintRapport(self, corpus, parametres, txt = True):
509 #if sys.platform == 'win32':
515 |i|R|a|M|u|T|e|Q| - %s
519 """ % datetime.datetime.now().ctime()
520 totocc = corpus.gettotocc()
522 txt += u'nombre d\'uci: %i%s' % (corpus.getucinb(), sep)
523 txt += u'nombre d\'uce: %i%s' % (corpus.getucenb(), sep)
524 txt += u'nombre de formes: %i%s' % (len(corpus.formes), sep)
525 txt += u'nombre d\'occurrences: %i%s' % (totocc, sep)
526 txt += u'moyenne d\'occurrences par forme: %f%s' % (float(totocc) / float(len(self.corpus.formes)), sep)
527 txt += u'nombre de lemmes: %i%s' % (len(corpus.lems), sep)
528 txt += u'nombre de formes actives: %i%s' % (corpus.getactivesnb(1), sep)
529 txt += u'nombre de formes supplémentaires: %i%s' % (corpus.getactivesnb(2), sep)
530 txt += u'nombre de formes actives de fréquence >= %i: %i%s' % (parametres['eff_min_forme'], parametres['nbactives'], sep)
531 txt += u'moyenne d\'occurrences par uce :%f%s' % (float(totocc) / float(corpus.getucenb()), sep)
532 if 'tailleuc1' in parametres :
533 if parametres['classif_mode'] != 0 :
534 txt += u'taille uc1 : %i\n' % parametres['tailleuc1']
536 txt += u'taille uc1 / uc2: %i / %i - %i / %i%s' % (parametres['tailleuc1'], parametres['tailleuc2'], parametres['lenuc1'], parametres['lenuc2'], sep)
538 self.Ucenb = self.nbind
539 txt += u'nombre d\'individus : %i%s' % (self.nbind, sep)
540 txt += u'nombre de classes : %i%s' % (self.clnb, sep)
542 txt += u'nombre de classes : %i%s' % (parametres['clnb'], sep)
543 if parametres['classif_mode'] == 0 or parametres['classif_mode'] == 1 :
544 txt += u'%i uce classées sur %i (%.2f%%)%s' % (sum([len(cl) for cl in corpus.lc]), corpus.getucenb(), (float(sum([len(cl) for cl in corpus.lc])) / float(corpus.getucenb())) * 100, sep)
545 elif self.parametres['classif_mode'] == 2 :
546 txt += u'%i uci classées sur %i (%.2f%%)%s' % (sum([len(cl) for cl in corpus.lc]), corpus.getucinb(), (float(sum([len(cl) for cl in corpus.lc]))) / float(corpus.getucinb()) * 100, sep)
547 elif analyse == 'quest' :
548 txt += u'%i uce classées sur %i (%.2f%%)%s' % (self.ucecla, self.Ucenb, (float(self.ucecla) / float(self.Ucenb)) * 100, sep)
551 ###########################
553 ###########################
554 """ % parametres['time']
555 file = open(self.pathout['pre_rapport'], 'w')
560 def __init__(self, ira, corpus, parametres):
561 self.pathout = PathOut(dirout = parametres['pathout'])
563 self.dictpathout = StatTxtPathOut(parametres['pathout'])
564 #self.corpus.read_corpus_from_shelves(self.corpus.dictpathout['db'])
566 self.encoding = self.corpus.parametres['syscoding']
567 self.parametres = parametres
569 self.DictSpec, first = ReadList(self.dictpathout['tablespecf'], self.corpus.parametres['syscoding'])
570 self.DictType, firstt = ReadList(self.dictpathout['tablespect'], self.corpus.parametres['syscoding'])
571 self.DictEff, firsteff = ReadList(self.dictpathout['tableafcm'], self.corpus.parametres['syscoding'])
572 self.DictEffType, firstefft = ReadList(self.dictpathout['tabletypem'], self.corpus.parametres['syscoding'])
573 self.DictEffRelForme, firsteffrelf = ReadList(self.dictpathout['eff_relatif_forme'], self.corpus.parametres['syscoding'])
574 self.DictEffRelType, firsteffrelt = ReadList(self.dictpathout['eff_relatif_type'], self.corpus.parametres['syscoding'])
576 self.TabStat = aui.AuiNotebook(ira.nb, -1, wx.DefaultPosition)
577 self.TabStat.parametres = parametres
578 self.ListPan = ListForSpec(ira, self.parent, self.DictSpec, first)
579 self.ListPant = ListForSpec(ira, self.parent, self.DictType, firstt)
580 self.ListPanEff = ListForSpec(ira, self.parent, self.DictEff, firsteff)
581 self.ListPanEffType = ListForSpec(ira, self.parent, self.DictEffType, firstefft)
582 self.ListPanEffRelForme = ListForSpec(ira, self.parent, self.DictEffRelForme, firsteffrelf)
583 self.ListPanEffRelType = ListForSpec(ira, self.parent, self.DictEffRelType, firsteffrelt)
585 self.TabStat.AddPage(self.ListPan, u'formes')
586 self.TabStat.AddPage(self.ListPant, u'Types')
587 self.TabStat.AddPage(self.ListPanEff, u'Effectifs formes')
588 self.TabStat.AddPage(self.ListPanEffType, u'Effectifs Type')
589 self.TabStat.AddPage(self.ListPanEffRelForme, u'Effectifs relatifs formes')
590 self.TabStat.AddPage(self.ListPanEffRelType, u'Effectifs relatifs Type')
591 if self.parametres['clnb'] > 2 :
592 self.TabAFC = aui.AuiNotebook(self.TabStat, -1, wx.DefaultPosition)
593 list_graph=read_list_file(self.dictpathout['liste_graph_afcf'], encoding = self.encoding)
594 self.tabAFCGraph = GraphPanelAfc(self.TabAFC, self.dictpathout, list_graph, self.parametres['clnb'], itempath ='liste_graph_afcf', coding = self.encoding)
595 self.TabAFC.AddPage(self.tabAFCGraph, 'AFC formes')
596 list_graph=read_list_file(self.dictpathout['liste_graph_afct'], encoding = self.encoding)
597 self.tabAFCTGraph = GraphPanelAfc(self.TabAFC, self.dictpathout, list_graph, self.parametres['clnb'], itempath ='liste_graph_afct', coding=self.encoding)
598 self.TabAFC.AddPage(self.tabAFCTGraph, 'AFC type')
599 self.TabStat.AddPage(self.TabAFC, 'AFC')
602 ira.nb.AddPage(self.TabStat, u'Spécificités')
604 self.TabStat.corpus = self.corpus
605 ira.nb.SetSelection(self.parent.nb.GetPageCount() - 1)
606 ira.ShowAPane("Tab_content")
609 def __init__(self, ira, corpus, parametres):
610 self.pathout = PathOut(dirout = os.path.dirname(parametres['pathout']))
614 self.TabStat = aui.AuiNotebook(ira.nb, -1, wx.DefaultPosition)
615 self.TabStat.parametres = parametres
616 # CHD = GraphPanel(panel.TabChdSim, DictPathOut, list_graph, txt = self.debtext)
617 # panel.TabChdSim.AddPage(CHD,'CHD')
619 #self.TabStatTot = wx.TextCtrl(self.TabStat, -1, style=wx.NO_BORDER | wx.TE_MULTILINE | wx.TE_RICH2)
620 list_graph = [['zipf.png', 'zipf']]
621 self.TabStatTot = GraphPanel(ira.nb, self.pathout, list_graph, self.result['glob'])
622 #self.TabStatTot.write(self.result['glob'])
623 self.TabStat.AddPage(self.TabStatTot, 'global')
624 for item in self.result:
626 datam = [['forme', 'nb']]
627 self.ListPan = ListPanel(ira, self, self.result[item])
628 self.TabStat.AddPage(self.ListPan, item)
629 ira.nb.AddPage(self.TabStat, 'Stat')
630 ira.nb.SetSelection(ira.nb.GetPageCount() - 1)
631 ira.ShowAPane("Tab_content")
633 def read_result(self) :
634 lcle = {'total' :u'total.csv', u'formes_actives':u'formes_actives.csv', u'formes_supplémentaires':u'formes_supplémentaires.csv', u'hapax': u'hapax.csv'}
637 with open(self.pathout[lcle[key]], 'r') as f :
638 self.result[key] = [line.split(';') for line in f.read().splitlines()]
639 self.result[key] = dict([[i,[line[0],int(line[1]), line[2]]] for i, line in enumerate(self.result[key])])
640 with open(self.pathout['glob.txt'], 'r') as f :
641 self.result['glob'] = f.read()
643 class GraphPanelDendro(wx.Panel):
644 def __init__(self,parent, dico, list_graph, txt=False):
645 wx.Panel.__init__(self,parent)
647 self.dictpathout = dico
648 self.dirout = os.path.dirname(self.dictpathout['ira'])
649 self.list_graph = list_graph
650 self.parent = self.GetParent()#parent
651 self.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "courier"))
654 self.tabchd = self.parent.GetParent()
655 self.ira = self.tabchd.GetParent()
656 self.panel_1 = wx.ScrolledWindow(self, -1, style=wx.TAB_TRAVERSAL)
657 self.deb = wx.StaticText(self.panel_1, -1, txt)
658 dendro_img = wx.Image(os.path.join(self.ira.images_path,'but_dendro.png'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
659 self.butdendro = wx.BitmapButton(self, -1, dendro_img)
661 for i in range(0,len(list_graph)):
662 if os.path.exists(os.path.join(self.dirout,list_graph[i][0])) :
663 self.listimg.append(wx.StaticBitmap(self.panel_1, -1, wx.Bitmap(os.path.join(self.dirout,list_graph[i][0]), wx.BITMAP_TYPE_ANY)))
664 self.labels.append(wx.StaticText(self.panel_1, -1, list_graph[i][1]))
666 self.__set_properties()
669 def __set_properties(self):
670 self.panel_1.EnableScrolling(True,True)
671 #self.panel_1.SetSize((1000,1000))
672 self.panel_1.SetScrollRate(20, 20)
673 self.Bind(wx.EVT_BUTTON, self.ondendro, self.butdendro)
674 self.param = {'width' : 700,
678 'taille_classe' : True,
681 self.type_dendro = [ u"phylogram", u"cladogram", u"fan", u"unrooted", u"radial" ]
683 def __do_layout(self):
684 self.sizer_1 = wx.BoxSizer(wx.VERTICAL)
685 self.sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
686 self.sizer_3 = wx.BoxSizer(wx.VERTICAL)
687 self.sizer_3.Add(self.deb)
688 self.sizer_2.Add(self.butdendro, 0, 0, 0)
689 for i in range(0, len(self.listimg)):
690 self.sizer_3.Add(self.listimg[i], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
691 self.sizer_3.Add(self.labels[i], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
692 self.panel_1.SetSizer(self.sizer_3)
693 self.sizer_2.Add(self.panel_1, 1, wx.EXPAND, 0)
694 self.SetSizer(self.sizer_2)
696 def make_param(self, dial):
697 self.param['width'] = dial.m_spinCtrl2.GetValue()
698 self.param['height'] = dial.m_spinCtrl1.GetValue()
699 self.param['type_dendro'] = dial.m_choice1.GetSelection()
700 self.param['color_nb'] = dial.m_radioBox1.GetSelection()
701 self.param['taille_classe'] = dial.m_checkBox1.GetValue()
702 self.param['type_tclasse'] = dial.m_radioBox2.GetSelection()
704 def make_dendro(self) :
705 while os.path.exists(os.path.join(self.dirout, 'dendrogamme_' + str(self.graphnb)+'.png')) :
707 fileout = ffr(os.path.join(self.dirout,'dendrogamme_' + str(self.graphnb)+'.png'))
708 width = self.param['width']
709 height = self.param['height']
710 type_dendro = self.type_dendro[self.param['type_dendro']]
711 if self.param['taille_classe'] :
715 if self.param['color_nb'] == 0 :
719 if self.param['type_tclasse'] == 0 :
723 dendro_path = self.dictpathout['Rdendro']
724 classe_path = self.dictpathout['uce']
729 classes <- read.csv2("%s", row.names=1)
730 classes <- classes[,1]
731 open_file_graph("%s", width=%i, height=%i)
732 plot.dendropr(tree.cut1$tree.cl, classes, type.dendro="%s", histo=%s, bw=%s, lab=NULL, tclasse=%s)
733 """ % (ffr(dendro_path), ffr(self.ira.RscriptsPath['Rgraph']), ffr(classe_path), ffr(fileout), width, height, type_dendro, histo, bw, tclasse)
735 tmpfile = tempfile.mktemp()
736 with open(tmpfile, 'w') as f :
738 error = exec_rcode(self.ira.RPath, tmpfile, wait=True)
739 check_Rresult(self.ira, error)
740 self.list_graph.append([fileout, 'Dendrogramme CHD1 - %s' % type_dendro])
741 print_liste(self.dictpathout['liste_graph_chd'], self.list_graph)
742 self.sizer_3.Add(wx.StaticBitmap(self.panel_1, -1, wx.Bitmap(fileout, wx.BITMAP_TYPE_ANY)), 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
743 self.sizer_3.Add(wx.StaticText(self.panel_1,-1, 'Dendrogramme CHD1 - %s' % type_dendro), 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
744 self.sizer_3.Fit(self.panel_1)
746 self.panel_1.Scroll(0,self.panel_1.GetScrollRange(wx.VERTICAL))
749 def ondendro(self, evt):
750 dial = PrefDendro(self.ira, self.param)
751 val = dial.ShowModal()
753 self.make_param(dial)
756 class WordCloudLayout:
757 def __init__(self, ira, parent, filename):
758 self.dictpathout = parent.corpus.dictpathout
759 self.pathout = os.path.dirname(filename)
760 self.corpus = parent.corpus
762 self.Tab = aui.AuiNotebook(ira.nb, -1, wx.DefaultPosition)
763 list_graph = [['nuage_1.png', 'Nuage']]
764 self.TabStatTot = GraphPanel(ira.nb, self.dictpathout, list_graph)
765 #self.TabStatTot.write(self.result['glob'])
766 self.Tab.AddPage(self.TabStatTot, 'Nuage')
767 self.Tab.corpus = parent.corpus
768 ira.nb.AddPage(self.Tab, 'WordCloud %s' % parent.conf.get('wordcloud','corpus_name'))
769 ira.nb.SetSelection(ira.nb.GetPageCount() - 1)
770 ira.ShowAPane("Tab_content")
773 def __init__(self, ira, parametres) :
774 #self.text = wx.TextCtrl(ira, -1, "", wx.Point(0, 0), wx.Size(200, 200), wx.NO_BORDER | wx.TE_MULTILINE | wx.TE_RICH2 | wx.TE_READONLY)
775 self.panel = CopusPanel(ira, parametres)
776 ira.nb.AddPage(self.panel, 'Description %s' % parametres['corpus_name'])
777 #self.text.write(DoConf().totext(parametres))
778 ira.nb.SetSelection(ira.nb.GetPageCount() - 1)
779 ira.ShowAPane("Tab_content")
781 class CopusPanel(wx.Panel) :
782 def __init__(self, parent, parametres) :
783 wx.Panel.__init__ ( self, parent, id = wx.ID_ANY, pos = wx.DefaultPosition, size = wx.Size( 500,300 ), style = wx.TAB_TRAVERSAL )
784 self.parametres = parametres
785 fgSizer5 = wx.FlexGridSizer( 0, 2, 0, 0 )
786 fgSizer5.SetFlexibleDirection( wx.BOTH )
787 fgSizer5.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )
788 self.fgSizer5 = fgSizer5
790 self.m_staticText18 = wx.StaticText( self, wx.ID_ANY, u"Description du corpus", wx.DefaultPosition, wx.DefaultSize, 0 )
792 self.m_staticText18.Wrap( -1 )
793 fgSizer5.Add( self.m_staticText18, 0, wx.ALL, 5 )
795 self.m_staticText19 = wx.StaticText( self, wx.ID_ANY, u"", wx.DefaultPosition, wx.DefaultSize, 0 )
796 self.m_staticText19.Wrap( -1 )
797 fgSizer5.Add( self.m_staticText19, 0, wx.ALL, 5 )
799 self.m_staticText20 = wx.StaticText( self, wx.ID_ANY, u"Nom", wx.DefaultPosition, wx.DefaultSize, 0 )
800 self.m_staticText20.Wrap( -1 )
801 fgSizer5.Add( self.m_staticText20, 0, wx.ALL, 5 )
803 self.m_staticText21 = wx.StaticText( self, wx.ID_ANY, parametres['corpus_name'], wx.DefaultPosition, wx.DefaultSize, 0 )
804 self.m_staticText21.Wrap( -1 )
805 fgSizer5.Add( self.m_staticText21, 0, wx.ALL, 5 )
807 description = {'lang' : u'langue',
808 'encoding' : u'encodage'}
810 keys = ['lang', 'encoding', 'originalpath', 'pathout', 'date', 'time']
812 self.addkeys(keys, description)
814 self.m_staticText18 = wx.StaticText( self, wx.ID_ANY, u"Paramètres", wx.DefaultPosition, wx.DefaultSize, 0 )
815 self.m_staticText18.Wrap( -1 )
816 fgSizer5.Add( self.m_staticText18, 0, wx.ALL, 5 )
818 self.m_staticText19 = wx.StaticText( self, wx.ID_ANY, u"", wx.DefaultPosition, wx.DefaultSize, 0 )
819 self.m_staticText19.Wrap( -1 )
820 fgSizer5.Add( self.m_staticText19, 0, wx.ALL, 5 )
822 keys = ['ucemethod', 'ucesize', 'keep_caract', 'expressions']
823 self.addkeys(keys, description)
825 self.m_staticText18 = wx.StaticText( self, wx.ID_ANY, u"Statistiques", wx.DefaultPosition, wx.DefaultSize, 0 )
826 self.m_staticText18.Wrap( -1 )
827 fgSizer5.Add( self.m_staticText18, 0, wx.ALL, 5 )
829 self.m_staticText19 = wx.StaticText( self, wx.ID_ANY, u"", wx.DefaultPosition, wx.DefaultSize, 0 )
830 self.m_staticText19.Wrap( -1 )
831 fgSizer5.Add( self.m_staticText19, 0, wx.ALL, 5 )
833 keys = ['ucinb', 'ucenb', 'occurrences', 'formesnb', 'hapax']
834 self.addkeys(keys, description)
836 self.SetSizer( fgSizer5 )
839 def addkeys(self, keys, description) :
841 option = self.parametres.get(key,u'non défnini')
842 if isinstance(option, int) :
844 text = wx.StaticText( self, wx.ID_ANY, description.get(key, key), wx.DefaultPosition, wx.DefaultSize, 0 )
846 self.fgSizer5.Add( text, 0, wx.ALL, 5 )
848 text = wx.StaticText( self, wx.ID_ANY, option, wx.DefaultPosition, wx.DefaultSize, 0 )
850 self.fgSizer5.Add( text, 0, wx.ALL, 5 )
852 # def read_result(self) :
853 # #self.corpus.read_corpus_from_shelves(self.corpus.dictpathout['db'])
854 # #self.corpus.make_et_table()
856 # with open(os.path.join(self.pathout,'glob.txt'), 'r') as f :
857 # self.result['glob'] = f.read()