-
Notifications
You must be signed in to change notification settings - Fork 5
/
qoe_model.py
67 lines (60 loc) · 1.9 KB
/
qoe_model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os, sys, inspect
import numpy as np
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
sys.path.insert(0, parentdir)
import json, shutil
def cal_qoe(x=0, run_dir=None):
block_data = []
qoe = .0
tmp = [3, 2, 1]
if run_dir:
if run_dir[-1] != '/':
run_dir += '/'
else:
run_dir = './'
with open(run_dir + "output/block.log", "r") as f:
for line in f.readlines():
data = json.loads(line.replace("'", '"'))
# not finished
if data["Miss_ddl"] == 0 and data["Size"] - data["Finished_bytes"] > 0.000001:
continue
block_data.append(data)
for block in block_data:
priority = float(tmp[int(block['Priority'])] / 3)
if block["Miss_ddl"] == 0:
qoe += priority
elif abs(x) > 0.00001:
qoe -= x*priority
return qoe
def aitrans_cal_qoe(x=0.9, run_dir=None):
block_data = []
urgency = []
priorities = []
qoe = 0
tmp = [3, 2, 1]
if run_dir:
if run_dir[-1] != '/':
run_dir += '/'
else:
run_dir = './'
with open(run_dir + "output/block.log", "r") as f:
for line in f.readlines():
data = json.loads(line.replace("'", '"'))
# not finished
if data["Miss_ddl"] == 0 and data["Size"] - data["Finished_bytes"] > 0.000001:
continue
block_data.append(data)
for block in block_data:
priority = float(tmp[int(block['Priority'])] / 3)
priorities.append(priority)
if block["Miss_ddl"] == 0:
urgency.append(1)
else:
urgency.append(0)
priorities[-1] *= 0
for i in range(len(urgency)):
qoe += x * priorities[i] + (1 - x) * urgency[i]
return qoe