X-Git-Url: http://www.iramuteq.org/git?a=blobdiff_plain;f=tabchddist.py;h=e8fc7b813dcc91ef956eec57236073b7f467bd24;hb=refs%2Fheads%2F3.0;hp=6010eaa3ff73208533861d59d1de071e65229692;hpb=7fb5b2b86f6c9a0617208ee85211177c23d12f47;p=iramuteq diff --git a/tabchddist.py b/tabchddist.py index 6010eaa..e8fc7b8 100644 --- a/tabchddist.py +++ b/tabchddist.py @@ -1,20 +1,28 @@ # -*- coding: utf-8 -*- #Author: Pierre Ratinaud -#Copyright (c) 2008 Pierre Ratinaud -#Lisense: GNU/GPL +#Copyright (c) 2008-2020 Pierre Ratinaud +#modification pour python 3 : Laurent Mérat, 6x7 - mai 2020 +#License: GNU/GPL -import wx +#------------------------------------ +# import des modules python +#------------------------------------ import os -#from rchdng import RchdFunct -from chemins import ffr, ConstructPathOut,ChdTxtPathOut -#from layout import PrintRapport -from openanalyse import OpenAnalyse -from ConfigParser import ConfigParser -from functions import CreateIraFile, print_liste, exec_rcode, check_Rresult -from dialog import CHDDialog, PrefQuestAlc, ClusterNbDialog import tempfile import time +#------------------------------------ +# import des modules wx +#------------------------------------ +import wx + +#------------------------------------ +# import des fichiers du projet +#------------------------------------ +from chemins import ffr, ConstructPathOut,ChdTxtPathOut +from functions import CreateIraFile, print_liste, exec_rcode, check_Rresult +from dialog import PrefQuestAlc, ClusterNbDialog + def RchdFunct(self,parent, rep_out, CLASSIF, encode, RscriptsPath): SEUIL_CHI2_PROF=2 @@ -50,28 +58,24 @@ def RchdFunct(self,parent, rep_out, CLASSIF, encode, RscriptsPath): while pid.poll() == None : time.sleep(0.2) check_Rresult(parent, pid) - - file=open(fileout,'rU') - lcl=file.readlines() - file.close() + f=open(fileout,'r') + lcl=f.readlines() + f.close() ListClasseOk=[line.replace('\n','').replace('"','') for line in lcl] ListClasseOk.pop(0) - clusterdlg = ClusterNbDialog(ListClasseOk, parent, -1, "Nombre de classe", size=(350, 200), style = wx.DEFAULT_DIALOG_STYLE ) clusterdlg.CenterOnParent() - # this does not return until the dialog is closed. val = clusterdlg.ShowModal() - if val == wx.ID_OK: if type(ListClasseOk)!=float : CLASSE_CH=ListClasseOk[clusterdlg.list_box_1.GetSelection()] else : CLASSE_CH=ListClasseOk else: - print "You pressed Cancel\n" + print("You pressed Cancel\n") clusterdlg.Destroy() ClusterNb=int(CLASSE_CH) txt='' @@ -130,14 +134,12 @@ def RchdFunct(self,parent, rep_out, CLASSIF, encode, RscriptsPath): afc <- summary.ca.dm(afc) afc_table <- create_afc_table(afc) """%RscriptsPath['Rgraph'] - txt+=""" dendo <- as.dendrogram(as.hclust(chd)) hthr<-sortheight[clnb] dendocut<-cut(dendo,h=hthr) save.image("%s") """%rep_out['RData'] - # txt+=""" # PARCEX<-%s # """%'0.9' @@ -171,9 +173,9 @@ def RchdFunct(self,parent, rep_out, CLASSIF, encode, RscriptsPath): txt += """ PlotAfc2dCoul(afc, as.data.frame(chistabletot), "%s", col = TRUE, what='crl') """ % (rep_out['AFC2DCoulCl']) - file=open(Rtmp,'w') - file.write(txt) - file.close() + f=open(Rtmp,'w') + f.write(txt) + f.close() pid = exec_rcode(parent.RPath, Rtmp, wait = False) while pid.poll() == None : time.sleep(0.2) @@ -182,9 +184,10 @@ def RchdFunct(self,parent, rep_out, CLASSIF, encode, RscriptsPath): class AnalyseCHDS(): + def __init__(self, parent, numactives, varsup): self.t1=time.time() -#------------------------------------------------------ + #------------------------------------------------------ self.dlg=wx.ProgressDialog("Traitements", "Veuillez patienter...", maximum = 7, @@ -194,17 +197,18 @@ class AnalyseCHDS(): self.dlg.Center() self.count = 1 keepGoing = self.dlg.Update(self.count) -#------------------------------------------------------- + #------------------------------------------------------- self.Filename=parent.filename self.parent=parent self.encode=parent.encode self.numactives=numactives self.varsup=varsup -#------------------------------------------------------- + #------------------------------------------------------- self.count += 1 keepGoing = self.dlg.Update(self.count) #self.OnAnalyse() -#------------------------------------------------------- + #------------------------------------------------------- + def OnAnalyse(self): PathOut=ConstructPathOut(self.parent.tableau.parametre['filename'],'CHDS') self.pathout = PathOut @@ -212,9 +216,9 @@ class AnalyseCHDS(): self.dictpathout=dictpathout self.parent.tableau.dictpathout = dictpathout self.RPath=self.parent.PathPath.get('PATHS','rpath') -#------------------------------------------------------- + #------------------------------------------------------- self.count += 1 - keepGoing = self.dlg.Update(self.count,u"lecture des données") + keepGoing = self.dlg.Update(self.count,"lecture des données") colact = self.parent.tableau.select_col(self.numactives) colsup = self.parent.tableau.select_col(self.varsup) self.parent.tableau.make_01_from_selection(self.numactives, self.varsup, False) @@ -222,21 +226,19 @@ class AnalyseCHDS(): savetxt(dictpathout['FILE_ACT_TEMP'],colact,fmt='%s',delimiter=';') dictpathout['FILE_ET_TEMP']=tempfile.mktemp(dir=self.parent.TEMPDIR) savetxt(dictpathout['FILE_ET_TEMP'],colsup,fmt='%s',delimiter=';') - -#------------------------------------------------------- + #------------------------------------------------------- self.count += 1 - keepGoing = self.dlg.Update(self.count,u"Analyse (patientez...)") -#------------FIXME---------- + keepGoing = self.dlg.Update(self.count,"Analyse (patientez...)") + #------------FIXME---------- clnb=RchdFunct(self,self.parent,dictpathout, 'DIANA',self.parent.SysEncoding,self.parent.RscriptsPath) self.clnb=clnb -#------------------------------------------------------- + #------------------------------------------------------- self.count += 1 - keepGoing = self.dlg.Update(self.count,u"Ecriture des résultats") + keepGoing = self.dlg.Update(self.count,"Ecriture des résultats") return dictpathout,clnb - - + def PrintResult(self,dictpathout,clnb): - with open(self.dictpathout['SbyClasseOut'], 'rU') as filein : + with open(self.dictpathout['SbyClasseOut'], 'r') as filein : content = filein.readlines() content.pop(0) for i, line in enumerate(content) : @@ -249,29 +251,29 @@ class AnalyseCHDS(): self.parent.tableau.dictpathout = self.dictpathout self.parent.tableau.save_tableau(self.dictpathout['db']) CreateIraFile(dictpathout,clnb, corpname = os.path.basename(self.Filename), section = 'chd_dist_quest') -#------------------------------------------------------- + #------------------------------------------------------- self.count += 1 - keepGoing = self.dlg.Update(self.count,u"Ouverture...") - afc_graph_list = [[os.path.basename(self.dictpathout['AFC2DL_OUT']), u'Variables actives - coordonnées - facteurs 1 / 2'], - [os.path.basename(self.dictpathout['AFC2DSL_OUT']), u'variables illustratives - coordonnées - facteurs 1 / 2'], - [os.path.basename(self.dictpathout['AFC2DCL_OUT']), u'Classes - Coordonnées - facteur 1 / 2'], - [os.path.basename(self.dictpathout['AFC2DCoul']), u'Variables actives - Corrélation - facteur 1/2'], - [os.path.basename(self.dictpathout['AFC2DCoulSup']), u'Variables illustratives - Corrélation - facteur 1 / 2'], - [os.path.basename(self.dictpathout['AFC2DCoulCl']), u'Classes - Corrélations - facteurs 1 / 2'], ] - chd_graph_list = [[os.path.basename(self.dictpathout['dendro1']), u'dendrogramme à partir de chd1']] - #chd_graph_list.append(['arbre1', u'chd1']) + keepGoing = self.dlg.Update(self.count,"Ouverture...") + afc_graph_list = [[os.path.basename(self.dictpathout['AFC2DL_OUT']), 'Variables actives - coordonnées - facteurs 1 / 2'], + [os.path.basename(self.dictpathout['AFC2DSL_OUT']), 'variables illustratives - coordonnées - facteurs 1 / 2'], + [os.path.basename(self.dictpathout['AFC2DCL_OUT']), 'Classes - Coordonnées - facteur 1 / 2'], + [os.path.basename(self.dictpathout['AFC2DCoul']), 'Variables actives - Corrélation - facteur 1/2'], + [os.path.basename(self.dictpathout['AFC2DCoulSup']), 'Variables illustratives - Corrélation - facteur 1 / 2'], + [os.path.basename(self.dictpathout['AFC2DCoulCl']), 'Classes - Corrélations - facteurs 1 / 2'], ] + chd_graph_list = [[os.path.basename(self.dictpathout['dendro1']), 'dendrogramme à partir de chd1']] + #chd_graph_list.append(['arbre1', 'chd1']) print_liste(self.dictpathout['liste_graph_afc'], afc_graph_list) print_liste(self.dictpathout['liste_graph_chd'], chd_graph_list) self.tableau = self.parent.tableau OpenAnalyse(self.parent, dictpathout['ira'], False) -#------------------------------------------------------- + #------------------------------------------------------- self.count += 1 - keepGoing = self.dlg.Update(self.count,u"Fini") + keepGoing = self.dlg.Update(self.count,"Fini") class ChdCluster(): - def __init__(self,parent): + def __init__(self,parent): dlg = PrefQuestAlc(parent, sim = True) #dlg = CHDDialog(parent,-1, u"Classification", size=(350, 400),style = wx.DEFAULT_DIALOG_STYLE) dlg.CenterOnParent() @@ -283,4 +285,3 @@ class ChdCluster(): dictpathout,clnb=chd.OnAnalyse() chd.PrintResult(dictpathout,clnb) parent.ShowTab(wx.EVT_BUTTON) -