def test_regression_output(self): """ @return: @rtype: """ self.addTypeEqualityFunc(D, self.assertRoundDecimalEqual) assertTupleEqual = self.assertTupleEqual # results = [] for args, expected in self.exp: args.delay = 0 init_args = args.get_args() nsteps, step_size = args.get_step() sim = TempSim(*init_args) if step_size: result = sim.iterate(nsteps, step_size) else: result = sim.iterate(nsteps) # assertEqual(expected, result) for exp_step, r_step in zip(expected, result): assertTupleEqual(exp_step, r_step, init_args) # results.append((args, result)) # use SimArgs as a dummy TempSim to compare. # Fill in missing attrs using result data args.seconds, args.current_temp = result[-1] # noinspection PyTypeChecker self.assertTempSimEqual(args, sim)
def test_iterate(self): """ @return: None @rtype: None """ assertEqual = self.assertEqual for args in self.init_args: exp_sim = TempSim(*args, leak_const=0) test_sim = TempSim(*args, leak_const=0) step = exp_sim.step n = 10000 exp_steps = [step() for _ in range(n)] res_steps = test_sim.iterate(n) # unloop assert otherwise hangup caused # by trying to process too long of a diff in # repr string for step_no, (exp_step, res_step) in enumerate(zip(exp_steps, res_steps)): assertEqual(exp_step, res_step, step_no) assertEqual(exp_sim, test_sim) # repeat the same thing to ensure iterate works # on subsequent calls. exp_steps = [step() for _ in range(n)] res_steps = test_sim.iterate(n) for step_no, (exp_step, res_step) in enumerate(zip(exp_steps, res_steps)): assertEqual(exp_step, res_step, step_no) assertEqual(exp_sim, test_sim)
def run_decay_test(n=5400, start_temp=D('37.04'), c=TempSim.DEFAULT_COOL_CONSTANT): """ @return: @rtype: """ sim = TempSim(start_temp, 19, 0, D(c)) steps = sim.iterate(n) return steps
def test_cooling(c=D('-0.000039')): delsim() from scripts.run.temp_sim import TempSim sim = TempSim(42, 15, 0, c) steps = sim.iterate(40000) # _str = str # steps = [(_str(x), _str(y)) for x, y in steps] return steps
def manyboth(): import sys try: del sys.modules['scripts.run.temp_sim'] except KeyError: pass from scripts.run.temp_sim import TempSim from random import uniform Decimal = D rnd_2_const = Decimal('-1e-5') repr_quant = Decimal("1.00000000000") tcs = [] kps = [] cs = [] hd1 = Decimal(6.8) hd2 = Decimal(0) try: while True: rnd = uniform(4, 7.5) cconst = Decimal(rnd) * rnd_2_const sim = TempSim(D('37.114'), 19, hd1, cconst) sim.quietiter(250000) temp1 = sim.current_temp tstart = sim.seconds sim.heat_duty = hd2 bump_steps = sim.iterate(250000) temp2 = sim.current_temp dt = temp2 - temp1 t63 = temp1 + dt * Decimal('0.63') if dt > 0: cmp = t63.__lt__ else: cmp = t63.__gt__ tend = next(i for i, t in bump_steps if cmp(t)) dPV = temp2 - temp1 dCO = hd2 - hd1 tc = tend - tstart kp = dPV / dCO tcs.append(tc) kps.append(kp) cs.append(sim.cool_rate) print("Const:", sim.cool_rate.quantize(repr_quant), "Ti:", int(tc), "Kp:", kp.quantize(repr_quant)) except KeyboardInterrupt: return list(zip(cs, tcs, kps))
def plotsim(n=7200, c=D('-0.00004679011328')): try: import sys del sys.modules['scripts.run.temp_sim'] except KeyError: pass from scripts.run.temp_sim import TempSim sim = TempSim(D('37.115'), 19, 0, c) steps = sim.iterate(n) from officelib.xllib.xlcom import xlBook2 xl, wb = xlBook2('PID.xlsx') ws = wb.Worksheets(2) cells = ws.Cells firstcol = 19 cells.Range(cells(2, firstcol), cells(len(steps) + 1, firstcol + 1)).Value = [(str(t), str(v)) for t, v in steps]
def plot_m(h, linest_formula, linest_range, plotcell, xcol, ycol): from scripts.run.temp_sim import TempSim from officelib.xllib.xladdress import cellRangeStr sim = TempSim(28, 19, 50, heat_constant=h) data = sim.iterate(30000) xs, ys = zip(*data) start = next(i for i, pv in enumerate(ys) if pv > 30) end = next((i for i, pv in enumerate(ys, start) if pv > 36), len(ys) - 1) assert ys[start] > 30 assert ys[end] > 36 xldata = [(str(x), str(y)) for x, y in zip(xs[start:end], ys[start:end])] plotxl_by_cell(xldata, plotcell) linest_args = linest_formula % ( cellRangeStr( (2, ycol), (end - start, ycol) ), cellRangeStr( (2, xcol), (end - start, xcol) ) ) # print(linest_args) linest_range.FormulaArray = linest_args