自定义sort排序
#!/usr/bin/python # -*- coding: utf-8 -*- import logging import sys import Queue import threading import os import time #reload(sys) #sys.setdefaultencoding('utf8') def get_key_val_line(line): info = line.split(" ") remote_addr = info[0] end_time = time.mktime(time.strptime(info[3],'[%d/%b/%Y:%H:%M:%S')) cost_time = info[5] method = info[6] request = info[7] status = info[9] body_bytes_sent = info[10] bytes_sent = info[12] ua = info[14] if status != "200" and status != "206": return #config key = ":".join([remote_addr,ua]) #key = ":".join([remote_addr,url]) #key = ":".join([remote_addr,url,ua]) #val should not change val = [end_time, float(cost_time), bytes_sent] return key, val def tsort(a, b): return int(a[0] - b[0]) def get_speed_bytes(dlinfo): dlinfo.sort(cmp = tsort) total_bytes = 0 e,t = 0.0, 0.0 for i in dlinfo: total_bytes += int(i[2]) if i[0] <= e and i[0]+i[1] > e: t += i[1] - e elif e < i[0]: t += i[1] if i[0] + i[1] > e: e = i[1] if t == 0: return t, total_bytes return total_bytes/1024/t, total_bytes if __name__ == '__main__': d_total = {} while True: line = sys.stdin.readline() if not line:break try: key, val = get_key_val_line(line.strip()) if not key: continue except: continue if d_total.has_key(key): d_total[key].append(val) else: d_total[key] = [val] sys.stdout.flush() for k, v in d_total.items(): dl_speed, total_bytes = get_speed_bytes(v) print "%.2f\t%d\t%s"%(dl_speed,total_bytes,k)
相关推荐
Python 采用自定义规则对列表进行排序 Python源码Python 采用自定义规则对列表进行排序 Python源码Python 采用自定义规则对列表进行排序 Python源码Python 采用自定义规则对列表进行排序 Python源码Python 采用...
python中自定义排序函数共3页.pdf.zip
今天小编就为大家分享一篇对python 自定义协议的方法详解,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
用python脚本过滤文本中的关键字并显示,例子
3dSlier是一款医学图像处理的软件...因为最近在学习3DSlicer 的Python脚本编程,但是却因为官网的教程太过于零散而感到苦恼,所以特意仔细的整理了3Dslicer官网上有关Python脚本编程的资料。贡献出来,供大家使用学习。
面向Arcgis的python脚本编程
本资源为一个完整工程,功能是实现使用C++在执行过程中调用Python脚本,内附VS嵌入Python环境的流程
SecureCRT运行Python脚本测试IoT-WiFi模块-基础1 讲解基础的CRT-Python
本文档主要讲述的是Python脚本使用详解;
python脚本python脚本python脚本python脚本python脚本
面向Arcgis的python脚本编程_李明巨编著
通过python脚本,使用Opencv将图像转换为视频,可以用于目标的检测。
完整的C++调用Python脚本源码,包含参数传递和函数返回值处理等,且解决传递中文参数出现乱码等问题
面向ArcGIS的Python脚本编程
统信桌面操作系统PXE部署Python脚本 统信桌面操作系统PXE部署Python脚本 统信桌面操作系统PXE部署Python脚本
python脚本
Python脚本编辑器,初学Python的朋友们可以下载来学习
根据这个排序规则,我们可以重新排列数组,将排列好的数组拼接起来输出即可’为了方便比较,并且防止数据溢出(比如C语言),采用字符串的方式拼接。我们很容易可以写出如下代码: def compare(strNum1, strNum2): ...
Python脚本,使用Selenium 模拟浏览器操作。 在使用 Chrome 浏览器,用户可以使用鼠标滑动、按键点击以及键盘输入,作为信号输入设备向浏览器传达指令,浏览器收到指令后执行渲染。 这里提到的 Selenium WebDriver ...