-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest_staging.py
More file actions
46 lines (37 loc) · 1.75 KB
/
Copy pathtest_staging.py
File metadata and controls
46 lines (37 loc) · 1.75 KB
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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# unit test for input_power_staging.py — uses FakeDriver with the .stages list interface
import input_power_staging as staging
class FakeDriver:
def __init__(self, did, stages, count, minp, maxp):
self.id=did; self.stages=stages; self.count=count
self.min_power=minp; self.max_power=maxp
def group_capacity(self): return self.count*self.max_power
# 1 soyo base [1,2], 2 soyo group [2], 1 MP2 [2]
drivers = [
FakeDriver('base', [1,2], 1, 10, 900),
FakeDriver('soyo_grp', [2], 2, 10, 900),
FakeDriver('mp2', [2], 1, 200, 2400),
]
ok, cap = staging.check_stage1_capacity(drivers, 666)
print('stage1 capacity %i W, covers threshold 666: %s\n' % (cap, ok))
def show(demand, stage):
alloc = staging.distribute(demand, drivers, stage, 666)
gt = {d.id: alloc[d.id]*d.count for d in drivers}
served = sum(gt.values())
print('demand %5i stage %i -> base %4i soyo/ea %4i(x2=%4i) mp2 %4i | served %5i miss %4i'
% (demand, stage, alloc['base'], alloc['soyo_grp'], gt['soyo_grp'],
alloc['mp2'], served, demand-served))
print('--- stage 1 (only base) ---')
for d in [200, 600, 900, 1500]: show(d, 1)
print('\n--- stage 2 (equal share, saturation overflow) ---')
for d in [400, 800, 1200, 2400, 3600, 3700, 4000, 4500, 5100, 5700]: show(d, 2)
print('\n--- tiny demand (mp below min_power sleeps) ---')
for d in [50, 150, 300, 600]: show(d, 2)
print('\n--- handover: soyo [1], mp2 [2] ---')
drivers2 = [FakeDriver('soyo',[1],1,10,900), FakeDriver('mp2',[2],1,200,3000)]
def show2(demand, stage):
a = staging.distribute(demand, drivers2, stage, 666)
print('demand %5i stage %i -> soyo %4i mp2 %4i' % (demand, stage, a['soyo'], a['mp2']))
for d in [200,600,900]: show2(d,1)
for d in [700,1500,3000,3500]: show2(d,2)