1 Star 0 Fork 1

shanhe/Rosetta

forked from 三个小小道/Rosetta 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
loader.py 1.24 KB
一键复制 编辑 原始数据 按行查看 历史
三个小小道 提交于 2023-12-17 12:24 . fsnet
import sys
def load_flow(fname, load_time=0, load_length=1, load_direction=1, no_neg=False, offset=1460, compress=True):
'''
load_time = 0 means don't load packet timestamp (the return value will be a list of ±length)
load_length = 0 means masking the packet length to ±1
no_neg, offset: add lengths with offset to ensure that they are all non-negative numbers
'''
flow = []
try:
f = open(fname, "r")
lines = f.readlines()
f.close()
if len(lines) == 0:
print("Empty cell:", fname)
sys.exit(-1)
start_time = float(lines[0].split('\t')[0])
for li in lines:
li = li.split("\t")
p = int(li[1])
if load_direction == 0:
p = p if p >= 0 else -p
if load_direction == 1 and no_neg:
p += offset
if compress:
p = p // 10
if load_length == 0:
p = 1 if p > 0 else -1
if load_time == 0:
flow.append(p)
else:
t = float(li[0])
flow.append((t - start_time, p))
except:
print ("Could not load", fname)
sys.exit(-1)
return flow
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mountains-river/Rosetta.git
[email protected]:mountains-river/Rosetta.git
mountains-river
Rosetta
Rosetta
main

搜索帮助