-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathprofilegentools.py
executable file
·84 lines (68 loc) · 2.22 KB
/
profilegentools.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#Copyright (C) 2023 University of Twente
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program. If not, see <http://www.gnu.org/licenses/>.
import random
def gaussMinMax(mu, deviation):
assert(deviation > 0)
n = random.gauss(mu, round(deviation/3))
return round(max(min((mu+deviation), n), mu-deviation))
def roundToTimeBase(time, timeBase=60):
return round(time/timeBase) * timeBase
def roundList(listIn, rate):
result = []
for i in range(0, len(listIn)):
if(listIn[i]%rate == 0):
result.append(listIn[i])
else:
result.append(listIn[i]+(rate-(listIn[i]%rate)))
return result
def createStringList(listIn, compare=None, multiplier=1, rescale=True):
if compare == None:
out = str(listIn[0]*multiplier)
for i in range(1, len(listIn)):
out = out + ',' + str(listIn[i]*multiplier)
return out
#Check if the deadline is before the next time
else:
first = True
out = ''
assert(len(listIn) == len(compare))
for i in range(0, len(listIn)-1):
if(listIn[i] < (compare[i+1]*multiplier-60)):
if first:
out = str(listIn[i]*multiplier)
first = False
else:
out = out + ',' + str(listIn[i]*multiplier)
else:
if first:
out = str(compare[i+1]*multiplier-60)
first = False
else:
out = out + ',' + str(compare[i+1]*multiplier-60)
if first:
out = str(listIn[len(listIn)-1]*multiplier)
else:
out = out + ',' + str(listIn[len(listIn)-1]*multiplier)
return out
def resample(listIn, rate):
sample = 0
idx = 0
result = []
total = 0
while(idx < len(listIn)):
if(idx % rate == (rate - 1)):
#reset
result.append(round(total/rate))
total = 0
total = total + listIn[idx]
idx += 1
return result