X-Git-Url: http://iramuteq.org/git?p=iramuteq;a=blobdiff_plain;f=tabchdalc.py;h=ce058335fa78ffc2d5aa54cf4c87af7ab6f1ede5;hp=4f79e4b89cf373442d4d1e5c9310c46d682258e1;hb=434a6105156cca276a69c294c8b99369cf41c66f;hpb=12b4b71c8c8feb6154abc04dfa9bb93a521ef789 diff --git a/tabchdalc.py b/tabchdalc.py index 4f79e4b..ce05833 100644 --- a/tabchdalc.py +++ b/tabchdalc.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- #Author: Pierre Ratinaud #Copyright (c) 2008-2009 Pierre Ratinaud -#Lisense: GNU/GPL +#License: GNU/GPL from chemins import ConstructPathOut, ChdTxtPathOut, ConstructAfcUciPath, ffr, PathOut from functions import sortedby, CreateIraFile, print_liste, exec_rcode, check_Rresult @@ -17,57 +17,62 @@ import tempfile import time -class AnalyseQuest(): - def __init__(self, parent): - dlg = PrefQuestAlc(parent) - dlg.CenterOnParent() - self.val = dlg.ShowModal() - parametres = parent.tableau.parametre - if self.val == wx.ID_OK : - parametres['nbcl_p1'] = dlg.spin_nbcl.GetValue() - parametres['mincl'] = dlg.spin_mincl.GetValue() - if dlg.m_radioBox1.GetSelection() == 1 : - parametres['listact'] = dlg.nactives - parametres['listsup'] = dlg.varsup +class AnalyseQuest(AnalyseMatrix): + def doparametres(self, dlg = None): + if dlg is not None : + dial = PrefQuestAlc(self.parent, self.tableau) + dial.CenterOnParent() + self.val = dial.ShowModal() + #parametres = self.tableau.parametre + if self.val == wx.ID_OK : + self.parametres['nbcl_p1'] = dial.spin_nbcl.GetValue() + self.parametres['mincl'] = dial.spin_mincl.GetValue() + if dial.m_radioBox1.GetSelection() == 1 : + self.parametres['listact'] = dial.nactives + self.parametres['listsup'] = dial.varsup + else : + self.parametres['formatted'] = 1 else : - parametres['formatted'] = 1 - DoQuestAlceste(parent, parametres) + self.parametres = None + dial.Destroy() + # DoQuestAlceste(parent, parametres) -class DoQuestAlceste(AnalyseMatrix): - def __init__(self, parent, parametres): - parametres['pathout'] = ConstructPathOut(parent.tableau.parametre['filename'], 'gnepaMatrix') - self.parametres = parametres - self.parametres['type'] = 'gnepamatrix' +#class DoQuestAlceste(AnalyseMatrix): + def doanalyse(self): + #parametres['pathout'] = ConstructPathOut(parent.tableau.parametre['filename'], 'ReinertMatrix') + #self.parametres = parametres + #self.parametres['type'] = 'reinertmatrix' self.DictForme = {} self.DictFormeSup = {} self.Min = 10 self.Linecontent = [] - self.parent = parent - self.RPath = self.parent.PathPath.get('PATHS', 'rpath') + #self.parent = parent + #self.RPath = self.parent.PathPath.get('PATHS', 'rpath') #self.dictpathout = PathOut(dirout = self.pathout) #self.dictpathout = self.pathout #self.dictpathout.basefiles(ChdTxtPathOut) #self.pathout = self.dictpathout self.clnb = '' - self.ListAct = parametres.get('listact', False) + self.ListAct = self.parametres.get('listact', False) self.ucecla = '' - dlg = wx.ProgressDialog("Traitements", - "Veuillez patienter...", - maximum=5, - parent=self.parent, - style=wx.PD_APP_MODAL | wx.PD_AUTO_HIDE | wx.PD_ELAPSED_TIME - ) + #dlg = wx.ProgressDialog("Traitements", + # "Veuillez patienter...", + # maximum=5, + # parent=self.parent, + # style=wx.PD_APP_MODAL | wx.PD_AUTO_HIDE | wx.PD_ELAPSED_TIME + # ) - AnalyseMatrix.__init__(self, parent, parent.tableau, self.parametres, dlg = dlg) + #AnalyseMatrix.__init__(self, parent, parent.tableau, self.parametres, dlg = dlg) #----------------------------------------------------------- - def doanalyse(self) : +# def doanalyse(self) : #------------------------------------------------------------------- - self.dictpathout = self.pathout - self.dictpathout.basefiles(ChdTxtPathOut) - self.parent.tableau.dictpathout = self.dictpathout + #self.dictpathout = self.pathout + self.pathout.basefiles(ChdTxtPathOut) + self.tableau.pathout.basefiles(ChdTxtPathOut) +# self.parent.tableau.dictpathout = self.dictpathout self.dlg.Center() count = 1 @@ -76,22 +81,23 @@ class DoQuestAlceste(AnalyseMatrix): count += 1 self.dlg.Update(count, u"passage en O/1") if 'formatted' in self.parametres: - self.parent.tableau.make_01_alc_format(self.dictpathout['mat01']) + self.tableau.make_01_alc_format(self.pathout['mat01.csv']) else: - self.parent.tableau.make_01_from_selection(self.parametres['listact'], self.parametres['listsup']) - file = open(self.dictpathout['listeuce1'], 'w') + print self.parametres['listsup'] + self.tableau.make_01_from_selection(self.parametres['listact'], self.parametres['listsup']) + file = open(self.pathout['listeuce1'], 'w') file.write('num uce;num uc\n') - for i in range(0, len(self.parent.tableau.linecontent)): + for i in range(0, len(self.tableau.linecontent)): file.write('%i;%i\n' % (i, i)) file.close() - self.nbind = len(self.parent.tableau.linecontent) + self.nbind = len(self.tableau.linecontent) #------------------------------------------------------------ - RchdQuest(self.dictpathout, self.parent.RscriptsPath, self.parametres['nbcl_p1'], self.parametres['mincl']) + RchdQuest(self.pathout, self.parent.RscriptsPath, self.parametres['nbcl_p1'], self.parametres['mincl']) #------------------------------------------------------------ count += 1 self.dlg.Update(count, u"Analyse (patientez...)") - pid = exec_rcode(self.RPath, self.dictpathout['Rchdquest'], wait = False) + pid = exec_rcode(self.parent.RPath, self.pathout['Rchdquest'], wait = False) while pid.poll() == None : self.dlg.Pulse(u"Analyse (patientez...)") time.sleep(0.2) @@ -99,24 +105,24 @@ class DoQuestAlceste(AnalyseMatrix): #------------------------------------------------------------ count += 1 self.dlg.Update(count, u"Ecriture des résultats") - self.parent.tableau.buildprofil() - self.clnb = self.parent.tableau.clnb + self.tableau.buildprofil() + self.clnb = self.tableau.clnb self.parametres['clnb'] = self.clnb - self.ucecla = self.parent.tableau.ucecla + self.ucecla = self.tableau.ucecla self.BuildProfile() temps = time.time() - self.t1 PrintRapport(self, self, {}, istxt = False) - self.parent.tableau.save_tableau(self.dictpathout['db']) + self.tableau.save_tableau(self.pathout['db']) #CreateIraFile(self.dictpathout, self.clnb, corpname = os.path.basename(self.parent.filename), section = 'questionnaire') - 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'],] - chd_graph_list = [[os.path.basename(self.dictpathout['dendro1']), u'dendrogramme à partir de chd1']] - chd_graph_list.append([os.path.basename(self.dictpathout['arbre1']), u'chd1']) - print_liste(self.dictpathout['liste_graph_afc'], afc_graph_list) - print_liste(self.dictpathout['liste_graph_chd'], chd_graph_list) + afc_graph_list = [[os.path.basename(self.pathout['AFC2DL_OUT']), u'Variables actives - coordonnées - facteurs 1 / 2'], + [os.path.basename(self.pathout['AFC2DSL_OUT']), u'variables illustratives - coordonnées - facteurs 1 / 2'], + [os.path.basename(self.pathout['AFC2DCL_OUT']), u'Classes - Coordonnées - facteur 1 / 2'],] + chd_graph_list = [[os.path.basename(self.pathout['dendro1']), u'dendrogramme à partir de chd1']] + chd_graph_list.append([os.path.basename(self.pathout['arbre1']), u'chd1']) + print_liste(self.pathout['liste_graph_afc'], afc_graph_list) + print_liste(self.pathout['liste_graph_chd'], chd_graph_list) - self.tableau = self.parent.tableau + #self.tableau = self.parent.tableau #OpenCHDS(self.parent, self, self.dictpathout['ira'], False) #------------------------------------------------------------ print 'fini', time.time() - self.t1 @@ -128,16 +134,16 @@ class DoQuestAlceste(AnalyseMatrix): txt = '' txt += """ source("%s") - """ % self.parent.RscriptsPath['chdfunct'] + """ % ffr(self.parent.RscriptsPath['chdfunct']) txt += """ load("%s") - """ % self.dictpathout['RData'] + """ % ffr(self.pathout['RData']) txt += """ dataact<-read.csv2("%s", header = FALSE, sep = ';',quote = '\"', row.names = 1, na.strings = 'NA') - """ % self.dictpathout['Contout'] + """ % ffr(self.pathout['Contout']) txt += """ dataet<-read.csv2("%s", header = FALSE, sep = ';',quote = '\"', row.names = 1, na.strings = 'NA') - """ % self.dictpathout['ContEtOut'] + """ % ffr(self.pathout['ContEtOut']) txt += """ clnb<-%i """ % self.clnb @@ -145,7 +151,7 @@ class DoQuestAlceste(AnalyseMatrix): tablesqrpact<-BuildProf(as.matrix(dataact),n1,clnb) tablesqrpet<-BuildProf(as.matrix(dataet),n1,clnb) PrintProfile(n1,tablesqrpact[4],tablesqrpet[4],tablesqrpact[5],tablesqrpet[5],%i,"%s","%s") - """ % (self.clnb, self.dictpathout['PROFILE_OUT'], self.dictpathout['ANTIPRO_OUT']) + """ % (self.clnb, ffr(self.pathout['PROFILE_OUT']), ffr(self.pathout['ANTIPRO_OUT'])) txt += """ colnames(tablesqrpact[[2]])<-paste('classe',1:clnb,sep=' ') colnames(tablesqrpact[[1]])<-paste('classe',1:clnb,sep=' ') @@ -155,13 +161,13 @@ class DoQuestAlceste(AnalyseMatrix): ptabletot<-rbind(as.data.frame(tablesqrpact[1]),as.data.frame(tablesqrpet[1])) gbcluster<-n1 write.csv2(chistabletot,file="%s") - """ % self.dictpathout['chisqtable'] + """ % ffr(self.pathout['chisqtable']) txt += """ write.csv2(ptabletot,file="%s") - """ % self.dictpathout['ptable'] + """ % ffr(self.pathout['ptable']) txt += """ write.csv2(gbcluster,file="%s") - """ % self.dictpathout['SbyClasseOut'] + """ % ffr(self.pathout['SbyClasseOut']) if self.clnb > 2 : txt += """ library(ca) @@ -174,7 +180,7 @@ class DoQuestAlceste(AnalyseMatrix): fin<-rowtot afc<-AddCorrelationOk(afc) source("%s") - """ % self.parent.RscriptsPath['Rgraph'] + """ % ffr(self.parent.RscriptsPath['Rgraph']) txt += """ afc <- summary.ca.dm(afc) @@ -182,7 +188,7 @@ class DoQuestAlceste(AnalyseMatrix): write.csv2(afc_table$facteur, file = "%s") write.csv2(afc_table$colonne, file = "%s") write.csv2(afc_table$ligne, file = "%s") - """ % (self.dictpathout['afc_facteur'], self.dictpathout['afc_col'], self.dictpathout['afc_row']) + """ % (ffr(self.pathout['afc_facteur']), ffr(self.pathout['afc_col']), ffr(self.pathout['afc_row'])) txt += """ xlab <- paste('facteur 1 - ', round(afc$facteur[1,2],2), sep = '') @@ -196,16 +202,16 @@ class DoQuestAlceste(AnalyseMatrix): """ % "0.9" txt += """ xyminmax <- PlotAfc2dCoul(afc, as.data.frame(chistabletot), "%s", what='coord', deb=1, fin=(debet-1), xlab = xlab, ylab = ylab) - """ % (self.dictpathout['AFC2DL_OUT']) + """ % (ffr(self.pathout['AFC2DL_OUT'])) txt += """ PlotAfc2dCoul(afc, as.data.frame(chistabletot), "%s", what='coord', deb=debet, fin=fin, xlab = xlab, ylab = ylab, xmin = xyminmax$xminmax[1], xmax = xyminmax$xminmax[2], ymin = xyminmax$yminmax[1], ymax = xyminmax$yminmax[2]) - """ % (self.dictpathout['AFC2DSL_OUT']) + """ % (ffr(self.pathout['AFC2DSL_OUT'])) txt += """ PlotAfc2dCoul(afc, as.data.frame(chistabletot), "%s", col = TRUE, what='coord', xlab = xlab, ylab = ylab, xmin = xyminmax$xminmax[1], xmax = xyminmax$xminmax[2], ymin = xyminmax$yminmax[1], ymax = xyminmax$yminmax[2]) - """ % (self.dictpathout['AFC2DCL_OUT']) + """ % (ffr(self.pathout['AFC2DCL_OUT'])) txt += """ save.image(file="%s") - """ % self.dictpathout['RData'] + """ % ffr(self.pathout['RData']) tmpfile = tempfile.mktemp(dir=self.parent.TEMPDIR) tmpscript = open(tmpfile, 'w') tmpscript.write(txt)