X-Git-Url: http://iramuteq.org/git?p=iramuteq;a=blobdiff_plain;f=tableau.py;h=514c8cf71c0c0a3438469bd7f3e35322c206506c;hp=a8f74284891432d15059fafeb0440e76c0ee72ba;hb=ab4c9b7b0ac41c8a5e910caff895a5486f80188b;hpb=22cd27b2bbe9ab1ffa7ef06fa764b5147ae17dad diff --git a/tableau.py b/tableau.py index a8f7428..514c8cf 100644 --- a/tableau.py +++ b/tableau.py @@ -7,12 +7,15 @@ import codecs import sys import xlrd import ooolib +import os import tempfile import re import htmlentitydefs -from numpy import * import shelve +from uuid import uuid4 +import logging +log = logging.getLogger('iramuteq.tableau') ## # Removes HTML or XML character references and entities from a text string. @@ -55,8 +58,11 @@ class Tableau() : self.parametre = {'filename' : filename} self.parametre['filetype'] = filetype self.parametre['encodage'] = encodage + self.parametre['pathout'] = os.path.dirname(os.path.abspath(filename)) self.parametre['mineff'] = 3 self.parametre['syscoding'] = sys.getdefaultencoding() + self.parametre['type'] = 'matrix' + self.parametre['name'] = 'unNOm' self.sups = {} self.actives = {} self.listactives = None @@ -71,6 +77,7 @@ class Tableau() : self.colnb = 0 self.rownb = 0 self.classes = [] + self.parametres = self.parametre def read_tableau(self, fileout) : d=shelve.open(fileout) @@ -130,7 +137,6 @@ class Tableau() : doc = ooolib.Calc(opendoc=self.parametre['filename']) doc.set_sheet_index(0) (cols, rows) = doc.get_sheet_dimensions() - print cols, rows for row in range(1, rows + 1): ligne = [] for col in range(1, cols + 1): @@ -200,13 +206,21 @@ class Tableau() : return dico def select_col(self, listcol) : - ArTable = array(self.linecontent) - selcol = ArTable[:, listcol] - selcol = selcol.tolist() + dc = dict(zip(listcol, listcol)) + selcol = [[val for i, val in enumerate(row) if i in dc] for row in self.linecontent] return selcol + + def getactlistfromselection(self, listact) : + selcol = self.select_col(listact) + self.actives = self.make_dico(selcol) + return [[val, self.actives[val][0]] for val in self.actives] + + def make_listactives(self) : + self.listactives = [val for val in self.actives if val != 'NA' and self.actives[val] >= self.parametre['mineff']] def write01(self, fileout, dico, linecontent) : - self.listactives = [val for val in dico if val != 'NA' and dico[val] >= self.parametre['mineff']] + if self.listactives is None : + self.listactives = [val for val in dico if val != 'NA' and dico[val] >= self.parametre['mineff']] out = [['0' for forme in self.listactives] for line in linecontent] for i, forme in enumerate(self.listactives) : for line in dico[forme][1] : @@ -220,10 +234,7 @@ class Tableau() : def make_01_from_selection(self, listact, listsup = None, dowrite = True) : selcol = self.select_col(listact) self.actives = self.make_dico(selcol) - if 'Act01' in self.dictpathout and dowrite: - self.write01(self.dictpathout['Act01'], self.actives, selcol) - elif 'mat01' in self.dictpathout and dowrite: - self.write01(self.dictpathout['mat01'], self.actives, selcol) + self.write01(self.dictpathout['mat01'], self.actives, selcol) if listsup is not None : selcol = self.select_col(listsup) self.sups = self.make_dico(selcol) @@ -304,7 +315,6 @@ class Tableau() : def make_table_from_classe(self, cl, la) : ln = [line[0] for line in self.classes if line[1] == cl] out = [['0' for col in la] for line in ln] - print self.actives for i, act in enumerate(la) : for j, line in enumerate(ln) : if line in self.actives[act][1] :