"""Synthetic wall-power sampling; original trapezoidal integration unchanged. The saved 40 W, 600 s log supplies the fixed 1 s time grid. A hypothetical triangle centered at 305 s exposes sampling error. No real server is measured. """ import csv import math import time from pathlib import Path from power_kernel import integrate DEFAULT=dict(base_power_w=40,burst_power_w=0,burst_half_width_s=30,sampling='every_1s') PERIODS={f'every_{n}s':n for n in (1,2,5,10,30,60)} BOUNDS=dict(base_power_w=(0,200),burst_power_w=(0,400),burst_half_width_s=(1,120)) CENTER=305 DURATION=600 def validate(p): if not isinstance(p,dict) or set(p)!=set(DEFAULT) or not isinstance(p['sampling'],str) or p['sampling'] not in PERIODS: raise ValueError('Unknown or missing parameters') for k,(lo,hi) in BOUNDS.items(): v=p[k] if type(v) not in (int,float) or not math.isfinite(v) or not lo<=v<=hi or v!=round(v): raise ValueError('Parameter out of range/off integer step: '+k) def triangle_integral(t,half_width): """Exact integral in seconds of a unit-height triangle, from zero to t.""" left,right=CENTER-half_width,CENTER+half_width if t<=left:return 0. if t<=CENTER:return (t-left)**2/(2*half_width) if t