|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +import xlrd |
| 3 | +import datetime |
| 4 | + |
| 5 | +infos = [] |
| 6 | +info_file = xlrd.open_workbook('examples.xls') |
| 7 | +info_table = info_file.sheets()[0] |
| 8 | +row_count = info_table.nrows |
| 9 | +for row in range(7, row_count): |
| 10 | + time_string = info_table.cell(row, 4).value |
| 11 | + time_s_sp = time_string.split(':') |
| 12 | + infos.append( |
| 13 | + { |
| 14 | + 'type': info_table.cell(row, 2).value, |
| 15 | + 'number': info_table.cell(row, 3).value, |
| 16 | + 'timespan': datetime.timedelta( |
| 17 | + seconds=int(time_s_sp[2]), |
| 18 | + minutes=int(time_s_sp[1]), |
| 19 | + hours=int(time_s_sp[0])), |
| 20 | + 'class': info_table.cell(row, 5).value |
| 21 | + } |
| 22 | + ) |
| 23 | + |
| 24 | +time_all = datetime.timedelta(seconds=0) |
| 25 | +time_types = {} |
| 26 | +time_classes = {} |
| 27 | +time_numbers = {} |
| 28 | +for infor in infos: |
| 29 | + time_all += infor['timespan'] |
| 30 | + |
| 31 | + infor_type = infor['type'] |
| 32 | + if infor_type in time_types: |
| 33 | + time_types[infor_type] += infor['timespan'] |
| 34 | + else: |
| 35 | + time_types[infor_type] = infor['timespan'] |
| 36 | + |
| 37 | + infor_class = infor['class'] |
| 38 | + if infor_class in time_classes: |
| 39 | + time_classes[infor_class] += infor['timespan'] |
| 40 | + else: |
| 41 | + time_classes[infor_class] = infor['timespan'] |
| 42 | + |
| 43 | + infor_number = infor['number'] |
| 44 | + if infor_number in time_numbers: |
| 45 | + time_numbers[infor_number] += infor['timespan'] |
| 46 | + else: |
| 47 | + time_numbers[infor_number] = infor['timespan'] |
| 48 | + |
| 49 | +print '总通话时间:%s' % time_all |
| 50 | +print |
| 51 | +print '通信方式分类:' |
| 52 | +for (k, v) in time_types.items(): |
| 53 | + print k.encode('utf-8'), v |
| 54 | +print |
| 55 | +print '通信类型分类:' |
| 56 | +for (k, v) in time_classes.items(): |
| 57 | + print k.encode('utf-8'), v |
| 58 | +print |
| 59 | +print '对方号码分类:' |
| 60 | +for (k, v) in time_numbers.items(): |
| 61 | + print k.ljust(20), v |
0 commit comments