1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| from operator import concat
from itertools import ifilter
from time import clock
class Data_Pdf(object):
"""classe representant les elements data d'un objet table de reportlab """
def __init__(self,data_lst):
self._data_lst = data_lst
self._ncol = len (data_lst[0])
self._nligne = len (data_lst)
self._defraglist = reduce(concat,data_lst)
self._derpos = len(self._defraglist) - 1
def coord2(self,i):
u,v = divmod(self._derpos - i, self._ncol)
return (-u-1,-v-1)
def coord_elm(self,elmt):
return [ divmod(i,self._ncol) for i,u in enumerate(self._defraglist) if u==elmt ]
def coord_elm_pdf_0(self,elmt) :
return [ (i//self._ncol - self._nligne, i%self._ncol - self._ncol) for i,u in enumerate(self._defraglist) if u==elmt ]
def coord_elm_pdf(self,elmt) :
return [ self.coord2(i) for i,u in enumerate(self._defraglist) if u==elmt ]
def coord_elm_DEUX(self,elmt):
return [ divmod(i,self._ncol) for i,u in ifilter(lambda x: x[1]==elmt,enumerate(self._defraglist)) ]
def coord_elm_pdf_0_DEUX(self,elmt):
return [ (i//self._ncol - self._nligne, i%self._ncol - self._ncol) for i,u in ifilter(lambda x: x[1]==elmt,enumerate(self._defraglist)) ]
def coord_elm_pdf_DEUX(self,elmt) :
return [ self.coord2(i) for i,u in ifilter(lambda x: x[1]==elmt,enumerate(self._defraglist)) ]
data = [ [50,25,50],[100,25,25],[80,20,20],[150,10,2] ]
mes_data = Data_Pdf (data)
print '_data_list :',mes_data._data_lst
print '_nligne :',mes_data._nligne,'(nombre de sous-listes)'
print '_ncol :',mes_data._ncol,"(nombre d'elements dans les sous-listes)"
print '_defraglist :',mes_data._defraglist
print '\ncoord_elm de 25'
te = clock()
print mes_data.coord_elm(25)
tf = clock()
print tf-te
print 'coord_elm_DEUX de 25'
te = clock()
print mes_data.coord_elm_DEUX(25)
tf = clock()
print tf-te
print '\ncoord_elm_pdf_0 de 25'
te = clock()
print mes_data.coord_elm_pdf_0(25)
tf = clock()
print tf-te
print 'coord_elm_pdf_0_DEUX de 25'
te = clock()
print mes_data.coord_elm_pdf_0_DEUX(25)
tf = clock()
print tf-te
print '\ncoord_elm_pdf de 25'
te = clock()
print mes_data.coord_elm_pdf(25)
tf = clock()
print tf-te
print 'coord_elm_pdf_DEUX de 25'
te = clock()
print mes_data.coord_elm_pdf_DEUX(25)
tf = clock()
print tf-te |
Partager