X-Git-Url: http://iramuteq.org/git?p=iramuteq;a=blobdiff_plain;f=tabfrequence.py;h=376c8bf557946b59534f6aaa1be59f3d50333765;hp=563e5b418405bbbd2e91ef8aaa57c3769e6d3b24;hb=287f9e72c3e3d666b016dff0fa3dc39419adfcc2;hpb=6919f2ef8d85c176c7be824b606c4b71142e10fd;ds=sidebyside diff --git a/tabfrequence.py b/tabfrequence.py index 563e5b4..376c8bf 100644 --- a/tabfrequence.py +++ b/tabfrequence.py @@ -13,19 +13,21 @@ from time import sleep from analysematrix import AnalyseMatrix from functions import exec_rcode, check_Rresult from dialog import FreqDialog -from PrintRScript import PrintRScript +from PrintRScript import PrintRScript, FreqMultiScript +from operator import itemgetter class Frequences(AnalyseMatrix) : def doparametres(self, dlg=None) : if dlg is None : return else : - dial = FreqDialog(self.parent, -1, self.tableau.get_colnames(), u"Fréquences", size=(350, 200)) + dial = FreqDialog(self.parent, self.tableau.get_colnames(), u"Fréquences") dial.CenterOnParent() val = dial.ShowModal() if val == wx.ID_OK : - self.parametres['colsel'] = dial.list_box_1.GetSelections() + self.parametres['colsel'] = dial.m_listBox1.GetSelections() self.parametres['header'] = dial.header + self.parametres['NA'] = dial.includeNA.GetValue() else : self.parametres = None dial.Destroy() @@ -55,12 +57,26 @@ class Frequences(AnalyseMatrix) : compteur <- 1 """ % (sel, listfiles, titles) + if self.parametres['NA'] : + txt += """ + countNA <- TRUE + """ + else : + txt += """ + countNA <- FALSE + """ + txt += """ for (i in select) { - freq <- table(dm[,i]) + if (countNA) { + freq <- table(dm[,i], useNA = 'ifany') + } else { + freq <- table(dm[,i]) + } sumfreq <- sum(freq) pour <- prop.table(as.matrix(freq), 2) * 100 sumpour <- sum(pour) + pour <- round(pour, 2) ntable <- cbind(as.matrix(freq), pour) graphout <- listfiles[compteur] if (Sys.info()["sysname"]=='Darwin') { @@ -102,16 +118,21 @@ class Frequences(AnalyseMatrix) : content = f.read().splitlines() content.pop(0) content.pop(0) + content = ['\t'.join(line.split('\t')[1:]).replace('"','') for line in content] + content = '\n'.join(content) + content = content.split(u'***\t****\t****') + content = [[line.split('\t') for line in tab.splitlines() if line.split('\t') != ['']] for tab in content] + listtab = [tab for tab in content if tab != []] texte = '' - for ligne in content: - ligne = ligne.replace('"', '') - ligne = ligne.split('\t') - if ligne[1] == u'***' : - if tab != []: - listtab.append(tab) - tab = [] - else : - tab.append(ligne) + #for ligne in content: + # ligne = ligne.replace('"', '') + # ligne = ligne.split('\t') + # if ligne[1] == u'***' : + # if tab != []: + # listtab.append(tab) + # tab = [] + # else : + # tab.append(ligne) pretexte = u''' \n

Fréquences

@@ -128,7 +149,7 @@ class Frequences(AnalyseMatrix) : texte += '' texte += """ %s%s%s %% - """ % (line[3], line[1], line[2]) + """ % (line[2], line[0], line[1]) texte += '' texte += '' texte += """ @@ -139,4 +160,44 @@ class Frequences(AnalyseMatrix) : with open(fileout, 'w') as f : f.write(pretexte + texte) #return fileout + +class FreqMultiple(Frequences): + def doanalyse(self): + select = self.parametres['colsel'] + freq = self.tableau.countmultiple(select) + tot = sum([freq[forme][0] for forme in freq]) + freq = [[forme, freq[forme][0], `round((float(freq[forme][0])/tot)*100, 2)`,`len(list(set(freq[forme][1])))`, `round((float(len(list(set(freq[forme][1]))))/self.tableau.rownb)*100,2)`] for forme in freq] + freq = sorted(freq, key=itemgetter(1), reverse=True) + freq = [[line[0], `line[1]`, line[2], line[3], line[4]] for line in freq] + freq.insert(0, [u'mod', 'freq', 'percent of total', 'row number', 'percent of rows']) + self.freq = freq + with open(self.pathout['frequences.csv'], 'w') as f : + f.write('\n'.join(['\t'.join(line) for line in freq])) + self.rscript = FreqMultiScript(self) + self.rscript.make_script() + self.doR(self.rscript.scriptout) + self.dolayout() + + def dolayout(self): + pretexte = u''' + + \n

Fréquences

+
+ ''' % self.parent.SysEncoding + txt = """ + \n' + txt += '
\n +
+ """ + txt += '
'.join([''.join(line) for line in self.freq]) + '
graphgraph
' % (os.path.basename(self.pathout['barplotfreq.png']), os.path.basename(self.pathout['barplotrow.png'])) + txt += "\n" + with open(self.pathout['resultats.html'], 'w') as f : + f.write(pretexte + txt) + + + + + + + \ No newline at end of file