-
Notifications
You must be signed in to change notification settings - Fork 1
/
workload.py
69 lines (64 loc) · 1.76 KB
/
workload.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
67
68
69
#!/usr/bin/env python2.7
from commons import *
from timelist import TimeList
class Workload:
def __init__(self, filename=None):
self.minimum = 0.0
self.scale = 1.0
self.repeat = False
self.deferrable = False
self.compression = 1.0
self.filename = filename
self.load = self.readValues(filename)
def readValues(self, filename=None):
#ret = []
ret = TimeList()
if filename == '':
# Default value
#ret = (0, 0.0)
ret[0] = 0.0
elif filename != None:
with open(filename, 'r') as f:
for line in f.readlines():
# Clean line
line = cleanLine(line)
if line.find('=') > 0:
key, value = line.split('=')
key = key.strip()
value = value.strip()
if key.startswith('workload.deferrable'):
if value.lower() == 'false':
self.deferrable = False
else:
self.deferrable = True
elif key.startswith('workload.repeat'):
if value.lower() == 'false':
self.repeat = False
else:
self.repeat = True
elif key.startswith('workload.minimum'):
self.minimum = float(value)
elif key.startswith('workload.scale'):
self.scale = float(value)
elif key.startswith('workload.compression'):
self.compression = float(value)
elif line != '':
t, v = line.split(' ')
t = parseTime(t)
v = float(v)
#ret.append((t, v))
ret[t] = v
if self.repeat:
# Repeat to make it 2 years
torepeat = list(ret.list)
last = ret.list[-1][0]
while last < 2*365*24*60*60:
for t, load in torepeat:
#ret.append((last+t, load))
ret[last+t] = load
last = ret.list[-1][0]
return ret
def getLoad(self, time):
return self.load[time]/self.scale
if __name__ == "__main__":
load = Workload('fixed.workload')