Differences between revisions 1 and 10 (spanning 9 versions)
Revision 1 as of 2007-11-15 02:10:23
Size: 1129
Editor: richter
Comment:
Revision 10 as of 2007-11-15 06:43:30
Size: 7218
Editor: richter
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
'''对ericsson t68 calendar 记录.vcs文件的报表制作''' ##language:zh
#pragma section-numbers on
'''
对ericsson t68 手机 calendar 记录文件的报表制作
'''

[[TableOfContents]]
## 默许导航,请保留
[[Include(CPUGnav)]]
{{{richter <[email protected]>
 reply-to [email protected]
 to "Python.cn@google" <[email protected]>
 date nov 15, 2007

}}}

= 对ericsson t68 手机 calendar 记录文件的报表制作 =
'''功能介绍'''
Line 5: Line 22:
ericsson的各种纪录的格式为.vcs,如下 ericsson的各种纪录的格式为.vcs,样例如下
Line 41: Line 58:

''' 程序如下 '''

{{{#!python
def calccolumnsize(l):
    """wheather the cal columns size is equals"""
    columns=range(len(l))
    j=0
    for i in l:
        print len(i)
        columns[j]=len(i)
        j+=1
    index=0
    # when column's length not equal,the writetable can't continue
    for iq in columns:
        print 'iq is ',iq
        if index+1<len(columns):
            if columns[index]!=columns[index+1]:
                raise Exception('a fatal error,column size not equal!!')
            index+=1

def calclongestrow(l):
    blocklongest=[]
    temp=range(len(l[0]))
    """calc the longest content in per row of column. \n
    in vcs, it's column SUMMARY"""
    lineid=0
    
    oneblockhighest=[]
    for j in temp:
# for i in l:
# ignore first column,which is starttime
        oneblockhighest.append(len(l[1][lineid]))
        list.sort(oneblockhighest)
        blocklongest.append(oneblockhighest[-1])
        lineid+=1
        oneblockhighest=[]
                              
    return blocklongest

def decodeUTF7(s):
    """wrap a fandation method"""
    return s.decode('utf7')

def parserVcsbyline(f):
    """parser t68 calendar vcs file """
    bigli=[]
    headli=[]
    tailli=[]
    sourceli=[]
    bodytempli1=[]
    bodytempli2=[]
    bodytempli3=[]
    bodytempli4=[]
    sourcevcs=open(f)
    i=sourcevcs.readline()
    sourceli.append(i)
    while len(i)>0:
        i=sourcevcs.readline()
        sourceli.append(i)
        
    pa_h1='BEGIN:VCALENDAR'
    pa_h2='VERSION:1.0'
    pa_t1='END:VCALENDAR'
    pa_b1='BEGIN:'
    pa_b2='DTSTART:'
    pa_b3='DTEND:'
    pa_b4='SUMMARY;CHARSET=UTF-7:'
    pa_b5='AALARM:'
    pa_b6='CATEGORIES:'
    pa_b7='END:'
    
    for j in sourceli:
        js=str(j)
        r=re.search(pa_h1, js)
        if r:
            headli.append(js)
# print js
        r=re.search(pa_h2, js)
        if r:
            headli.append(js)
# print js
        r=re.search(pa_t1, js)
        if r:
            tailli.append(js)
# print js
#search body1
        r=re.search(pa_b1, js)
        if r:
            bodytempli1.append(js[len(pa_b1):])

# bigli.append(js)
#search body2,start time
        r=re.search(pa_b2, js)
        if r:
            bodytempli2.append(js[len(pa_b2):-1])
#search body3,end time
        r=re.search(pa_b3, js)
        if r:
            bodytempli3.append(js[len(pa_b3):-1])
#search body4,summary
        r=re.search(pa_b4, js)
        if r:
# bodytempli4.append(js)
            bodytempli4.append(decodeUTF7(js[len(pa_b4):-1]))

    bigli.append(bodytempli2)
# bigli.append(bodytempli3)
    bigli.append(bodytempli4)
            
        
# for debug

    print 'headli is ',headli
    print 'tailli is ', tailli
# print bigli's element
    for i in bigli:
        print 'bigli ',i
        print len(i)
    return bigli

def sortblock(l):
    """sort by starttime of per block,
    \the result of sorted object is list has a set of list which include
    \time and event summary"""
    sortedblock={}
    temp=range(len(l[0]))
    for i in temp:
        blockcontent=[]
        for il in l:
            k=il[i]
# print k
            blockcontent.append(k)
        
        sortedblock[l[0][i]]=blockcontent
    for i in sortedblock:
        print sortedblock.get(i)
    s=sortedblock.keys()
    s.sort()
# print s
    temp=[]
    for i in s:
        temp.append(sortedblock.get(i))
# for i in temp:
# print i
    return temp

def writetable(width1,width,gap,l):
    """get list,then print to table"""

# check the column's size
    try:
        calccolumnsize(l)
    except (Exception),why:
        print str(why)
        raise why
# sort the source column
    nl=sortblock(l)
# l=sortblock(l)
# calc high of per printblock
# 1)mod operation for one cloumn's content
# 2)to decide one cloumn's high from mod number
    longlist=calclongestrow(l)
    # blockhigh is list which has contained each block high
    blockhigh=[]
    for i in longlist:
        blockhigh.append(i/width+1)
    print 'blockhigh is ',blockhigh
    
    #fill the blackspace for summary grp
    line=0
    for i in nl:
        i[0]=i[0][0:8]
        i[0]+='*'*(blockhigh[line]*width1-len(i[0]))
        i[1]+='.'*(blockhigh[line]*width-len(i[1]))
        line+=1
        print i[0].encode('cp936')
        print i[1].encode('cp936')
    table=[]
    nm_block=0
    
    for i in nl:
        for j in range(blockhigh[nm_block]):
            table.append(i[0][j*width1:(j+1)*width1]+ ' '*gap+'|'+' ' +i[1][j*width:(j+1)*width])
        nm_block+=1
        table.append('-'*width1+'-'*gap+'--'+'-'*width+'-'*width)
        
    print '********* final test!! *********'
    for i in table:
        print i.encode('cp936')
    print '********* final test end *********'
}}}

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

== 反馈 ==
[[PageComment2]]
----
["社区项目分类"]

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

TableOfContents

Include(CPUGnav) {{{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. 反馈

PageComment2


["社区项目分类"]

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