对ericsson t68 手机 calendar 记录文件的报表制作

CPUG联盟::

CPUG::门户plone

BPUG

SPUG

ZPUG

SpreadPython Python宣传

{{{richter <[email protected]>

}}}

1. 对ericsson t68 手机 calendar 记录文件的报表制作

功能介绍

报表的主要功能是汲取原始数据中的时间、事件内容,完成排序和格式化。这样可以以月为单位,将每个月通过手机纪录的calendar事件做成报表,察看作了哪些事,还有哪些事没完成。也许一些有同样需求的朋友可以用到:)

ericsson的各种纪录的格式为.vcs,样例如下

BEGIN:VCALENDAR
VERSION:1.0
BEGIN:VEVENT
DTSTART:20071101T010000Z
DTEND:20071101T013000Z
SUMMARY;CHARSET=UTF-7:+abc-
LOCATION;CHARSET=UTF-7:+UWxT+A-
AALARM:20071101T005500Z
CATEGORIES:VACATION
END:VEVENT
BEGIN:VEVENT
DTSTART:20071101T015000Z
DTEND:20071101T025000Z
SUMMARY;CHARSET=UTF-7:+database
LOCATION;CHARSET=UTF-7:+UWxT+A-
AALARM:20071101T014500Z
CATEGORIES:VACATION
END:VEVENT
BEGIN:VEVENT
DTSTART:20071101T060000Z
DTEND:20071101T063000Z
SUMMARY;CHARSET=UTF-7:+test-
AALARM:20071101T055500Z
CATEGORIES:VACATION
END:VEVENT
BEGIN:VEVENT
DTSTART:20071129T020000Z
DTEND:20071230T023000Z
SUMMARY;CHARSET=UTF-7:+12211212-
CATEGORIES:MISCELLANEOUS
END:VEVENT
END:VCALENDAR

程序如下

   1 def calccolumnsize(l): 
   2     """wheather the cal columns size is equals"""
   3     columns=range(len(l))
   4     j=0
   5     for i in l:
   6         print len(i)
   7         columns[j]=len(i)
   8         j+=1
   9     index=0
  10     # when column's length not equal,the writetable can't continue
  11     for iq in columns:
  12         print 'iq is ',iq
  13         if index+1<len(columns):
  14             if columns[index]!=columns[index+1]:
  15                 raise Exception('a fatal error,column size not equal!!')
  16             index+=1
  17 
  18 def calclongestrow(l):
  19     blocklongest=[]
  20     temp=range(len(l[0]))
  21     """calc the longest content in per row of column. \n
  22     in vcs, it's column SUMMARY"""
  23     lineid=0
  24     
  25     oneblockhighest=[]
  26     for j in temp:
  27 #        for i in l: 
  28 # ignore first column,which is starttime
  29         oneblockhighest.append(len(l[1][lineid]))
  30         list.sort(oneblockhighest)
  31         blocklongest.append(oneblockhighest[-1])
  32         lineid+=1
  33         oneblockhighest=[]
  34                               
  35     return blocklongest
  36 
  37 def decodeUTF7(s):
  38     """wrap a fandation method"""
  39     return s.decode('utf7')   
  40 
  41 def parserVcsbyline(f):
  42     """parser t68 calendar vcs file """
  43     bigli=[]
  44     headli=[]
  45     tailli=[]
  46     sourceli=[]
  47     bodytempli1=[]
  48     bodytempli2=[]
  49     bodytempli3=[]
  50     bodytempli4=[]
  51     sourcevcs=open(f)
  52     i=sourcevcs.readline()
  53     sourceli.append(i)
  54     while len(i)>0:
  55         i=sourcevcs.readline()
  56         sourceli.append(i)
  57         
  58     pa_h1='BEGIN:VCALENDAR'
  59     pa_h2='VERSION:1.0'
  60     pa_t1='END:VCALENDAR'
  61     pa_b1='BEGIN:'
  62     pa_b2='DTSTART:'
  63     pa_b3='DTEND:'
  64     pa_b4='SUMMARY;CHARSET=UTF-7:'
  65     pa_b5='AALARM:'
  66     pa_b6='CATEGORIES:'
  67     pa_b7='END:'
  68     
  69     for j in sourceli:
  70         js=str(j)
  71         r=re.search(pa_h1, js)
  72         if r:
  73             headli.append(js)
  74 #            print js
  75         r=re.search(pa_h2, js)
  76         if r:
  77             headli.append(js)
  78 #            print js
  79         r=re.search(pa_t1, js)
  80         if r:
  81             tailli.append(js)
  82 #            print js
  83 #search body1
  84         r=re.search(pa_b1, js)
  85         if r:
  86             bodytempli1.append(js[len(pa_b1):])
  87 
  88 #            bigli.append(js)
  89 #search body2,start time
  90         r=re.search(pa_b2, js)
  91         if r:
  92             bodytempli2.append(js[len(pa_b2):-1])
  93 #search body3,end time
  94         r=re.search(pa_b3, js)
  95         if r:
  96             bodytempli3.append(js[len(pa_b3):-1])            
  97 #search body4,summary
  98         r=re.search(pa_b4, js)
  99         if r:
 100 #            bodytempli4.append(js)
 101             bodytempli4.append(decodeUTF7(js[len(pa_b4):-1]))
 102 
 103     bigli.append(bodytempli2)
 104 #    bigli.append(bodytempli3)
 105     bigli.append(bodytempli4)
 106             
 107         
 108 #   for debug
 109 
 110     print 'headli is ',headli
 111     print 'tailli is ', tailli
 112 # print bigli's element    
 113     for i in bigli:
 114         print 'bigli ',i
 115         print len(i)
 116     return bigli
 117 
 118 def sortblock(l):
 119     """sort by starttime of per block,
 120     \the result of sorted object is list has a set of list which include
 121     \time and event summary"""
 122     sortedblock={}
 123     temp=range(len(l[0]))
 124     for i in temp:
 125         blockcontent=[]
 126         for il in l:
 127             k=il[i]
 128 #            print k
 129             blockcontent.append(k)
 130         
 131         sortedblock[l[0][i]]=blockcontent
 132     for i in sortedblock:    
 133         print sortedblock.get(i)
 134     s=sortedblock.keys()
 135     s.sort()
 136 #    print s
 137     temp=[]
 138     for i in s:
 139         temp.append(sortedblock.get(i))
 140 #    for i in temp:
 141 #        print i
 142     return temp
 143 
 144 def writetable(width1,width,gap,l):
 145     """get list,then print to table"""
 146 
 147 # check the column's size
 148     try:
 149         calccolumnsize(l)
 150     except (Exception),why:
 151         print str(why)
 152         raise why
 153 # sort the source column
 154     nl=sortblock(l)
 155 #    l=sortblock(l)
 156 # calc high of per printblock
 157 # 1)mod operation for one cloumn's content
 158 # 2)to decide one cloumn's high from mod number
 159     longlist=calclongestrow(l)
 160     # blockhigh is list which has contained each block high
 161     blockhigh=[]
 162     for i in longlist:
 163         blockhigh.append(i/width+1)
 164     print 'blockhigh is ',blockhigh
 165     
 166     #fill the blackspace for summary grp
 167     line=0
 168     for i in nl:
 169         i[0]=i[0][0:8]
 170         i[0]+='*'*(blockhigh[line]*width1-len(i[0]))
 171         i[1]+='.'*(blockhigh[line]*width-len(i[1]))
 172         line+=1
 173         print i[0].encode('cp936')
 174         print i[1].encode('cp936')
 175     table=[]
 176     nm_block=0
 177     
 178     for i in nl:
 179         for j in range(blockhigh[nm_block]):
 180             table.append(i[0][j*width1:(j+1)*width1]+ ' '*gap+'|'+' ' +i[1][j*width:(j+1)*width])
 181         nm_block+=1
 182         table.append('-'*width1+'-'*gap+'--'+'-'*width+'-'*width)
 183         
 184     print '********* final test!! *********'
 185     for i in table:
 186         print i.encode('cp936')
 187     print '********* final test end *********'

报表样张

0071101**  | 安装kal平台(所有软件)..
--------------------------------------------
20071101**  | 和肖张讲scada,含调整记d
**********  | atabase........
--------------------------------------------
20071101**  | 整理两次备标我写的文章....
--------------------------------------------
20071129**  | 豆腐鸡血鸭血鸭肝虾皮,海带。去
--------------------------------------------
20071201**  | 安装kal平台(所有软件)..
**********  | ...............
--------------------------------------------

1.1. 反馈


社区项目分类

MicroProj/2007-11-15 (last edited 2009-12-25 07:12:43 by localhost)