Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2137000
  • 博文数量: 103
  • 博客积分: 206
  • 博客等级: 入伍新兵
  • 技术积分: 1819
  • 用 户 组: 普通用户
  • 注册时间: 2012-09-12 10:24
个人简介

效字当先,以质为本。

文章分类
文章存档

2019年(2)

2018年(4)

2017年(7)

2016年(3)

2015年(14)

2014年(33)

2013年(31)

2012年(9)

分类: Python/Ruby

2014-03-16 20:03:44

先发个日志的格式参考:

点击(此处)折叠或打开

  1. #! -*- coding: utf-8 -*-
  2. import time
  3. import re
  4. import xlrd
  5. from xlwt import *
  6. def get_fluxandtime(filename):    
  7.     with open(filename,"r") as f:
  8.         reg = r"\[(\d+?)\]"
  9.         flux_reg = re.compile(reg)
  10.         list1 = {}
  11.         for line in f:
  12.             _time = line.split(",")[0]
  13.             _time2 = time.strptime(_time,'%Y-%m-%d %H:%M:%S')
  14.             _date_shijianchuo = int(time.mktime(_time2))
  15.             flux1 = re.findall(flux_reg,line)
  16.             _flux1 = ''.join(flux1)
  17.             _5mintues = (_date_shijianchuo / 300)*300
  18.             timeArray = time.localtime(_5mintues)
  19.             otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
  20.             list1[otherStyleTime] = list1.get(otherStyleTime,0) + int(_flux1)
  21.         return list1

  22. def input_excel():
  23.     details = get_fluxandtime("ASDL_log_20140310")
  24.     a_date = details.keys()
  25.     row =1
  26.     w = Workbook()
  27.     sheet = w.add_sheet('pv_flux_sum',cell_overwrite_ok=True)
  28.     for b_date in a_date:
  29.         _flux = details[b_date]                
  30.         flux_in = _flux/1024/1024
  31.         Titles = ("time,pv_flux_sum(MB)").split(",")
  32.         ceii = 0
  33.         for title in Titles:
  34.             sheet.write(0,ceii,title)
  35.             ceii +=1
  36.         sheet.write(row,0,b_date)
  37.         sheet.write(row,1,flux_in)
  38.         row += 1
  39.     time_sjc = time.time()
  40.     w.save("pv-objct_sum_%s.xls"%time_sjc)


  41. if __name__ == '__main__':
  42.     # print get_fluxandtime("ASDL_log_20140310")
  43.     input_excel()

阅读(1747) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

dsy8510092014-03-17 22:32:25

其实我这里有个小bug可以优化的,就是入excel时候,标题重复执行了N遍,应该把for循环放外面去;