class TestTankNitrox32(TestTank): def setUp(self): self.mytank = Tank(f_o2=0.32) def test_name(self): assert str(self.mytank) == "Nitrox 32" def test_mod(self): assert self.mytank.mod == 40 def test_mod_at_end(self): self.assertAlmostEqual( self.mytank.get_mod_for_given_end(30), 31.0195918624, 5, "wrong mod at end:%s" % self.mytank.get_mod_for_given_end(30), ) def test_end_at_depth(self): self.assertAlmostEqual( self.mytank.get_end_for_given_depth(40), 38.7573409377, 5, "wrong end at depth:%s" % self.mytank.get_end_for_given_depth(40), )
class TestTankisHeliox2080_2(TestTank): """Test Heliox2080 Tank 2.""" def setUp(self): """Init of the tests.""" super().setUp() self.mytank = Tank(f_o2=0.2, f_he=0.8, max_ppo2=1.4) def test_name(self): """Check Name.""" assert str(self.mytank) == 'Heliox 20/80' def test_mod(self): """Check Calculated mod.""" assert self.mytank.mod == 59 def test_mod_at_end(self): """Check Calculated mod at given end.""" self.assertAlmostEqual( self.mytank.get_mod_for_given_end(30), 96.8666243516, 5, 'wrong mod at end:%s' % self.mytank.get_mod_for_given_end(30)) def test_end_at_depth(self): """Check Calculated mod at given end.""" self.assertAlmostEqual( self.mytank.get_end_for_given_depth(40), 8.70562703148, 5, 'wrong end at depth:%s' % self.mytank.get_end_for_given_depth(40))
class TestTankisTrimix870_2(TestTank): """Test Tx8/70 Tank 2.""" def setUp(self): """Init of the tests.""" super().setUp() self.mytank = Tank(f_o2=0.08, f_he=0.7, max_ppo2=1.4) def test_name(self): """Check Name.""" assert str(self.mytank) == 'Trimix 8/70' def test_mod(self): """Check Calculated mod.""" assert self.mytank.mod == 165 def test_min_od(self): """Check Calculated minimum od.""" assert self.mytank.get_min_od() == 10 def test_mod_at_end(self): """Check Calculated mod at given end.""" self.assertAlmostEqual( self.mytank.get_mod_for_given_end(30), 79.0122229175, 5, 'wrong mod at end:%s' % self.mytank.get_mod_for_given_end(30)) def test_end_at_depth(self): """Check Calculated mod at given end.""" self.assertAlmostEqual( self.mytank.get_end_for_given_depth(40), 12.4620912698, 5, 'wrong end at depth:%s' % self.mytank.get_end_for_given_depth(40))
class TestTankisTrimix2030_2(TestTank): """Test Tx2030 Tank 2.""" def setUp(self): """Init of the tests.""" super().setUp() self.mytank = Tank(f_o2=0.2, f_he=0.3, max_ppo2=1.4) def test_name(self): """Check Name.""" assert str(self.mytank) == 'Trimix 20/30' def test_mod(self): """Check Calculated mod.""" assert self.mytank.mod == 59 def test_mod_at_end(self): """Check Calculated mod at given end.""" self.assertAlmostEqual( self.mytank.get_mod_for_given_end(30), 43.3498554235, 5, 'wrong mod at end:%s' % self.mytank.get_mod_for_given_end(30)) def test_end_at_depth(self): """Check Calculated mod at given end.""" self.assertAlmostEqual( self.mytank.get_end_for_given_depth(40), 27.4879482229, 5, 'wrong end at depth:%s' % self.mytank.get_end_for_given_depth(40))
class TestTankisAir(TestTank): """Test Air Tank.""" def setUp(self): """Init of the tests.""" super().setUp() self.mytank = Tank() def test_name(self): """Check Name.""" assert str(self.mytank) == 'Air' def test_mod(self): """Check Calculated mod.""" assert self.mytank.mod == 66 def test_mod_at_end(self): """Check Calculated mod at given end.""" self.assertAlmostEqual( self.mytank.get_mod_for_given_end(30), 31.0195918624, 5, 'wrong mod at end:%s' % self.mytank.get_mod_for_given_end(30)) def test_end_at_depth(self): """Check Calculated mod at given end.""" self.assertAlmostEqual( self.mytank.get_end_for_given_depth(40), 38.7573409377, 5, 'wrong end at depth:%s' % self.mytank.get_end_for_given_depth(40)) def test_tank_info(self): """Check str output.""" self.assertEqual(self.mytank.tank_info, '12.0l-100.0% (2423.10/2423.10l)', "Wrong Tank infos: %s" % self.mytank.tank_info)
def setUp(self): """Init of the tests.""" super().setUp() self.mytank = Tank(tank_vol=15, tank_pressure=207) self.mytank.consume_gas(405) self.mytank.consume_gas(2800)
class TestTankisTrimix870_2(TestTank): def setUp(self): self.mytank = Tank(f_o2=0.08, f_he=0.7, max_ppo2=1.4) def test_name(self): assert str(self.mytank) == "Trimix 8/70" def test_mod(self): assert self.mytank.mod == 165 def test_min_od(self): assert self.mytank.get_min_od() == 10 def test_mod_at_end(self): self.assertAlmostEqual( self.mytank.get_mod_for_given_end(30), 79.0122229175, 5, "wrong mod at end:%s" % self.mytank.get_mod_for_given_end(30), ) def test_end_at_depth(self): self.assertAlmostEqual( self.mytank.get_end_for_given_depth(40), 12.4620912698, 5, "wrong end at depth:%s" % self.mytank.get_end_for_given_depth(40), )
class TestTankNitrox32(TestTank): """Test Nitrox32 Tank.""" def setUp(self): """Init of the tests.""" super().setUp() self.mytank = Tank(f_o2=0.32) def test_name(self): """Check Name.""" assert str(self.mytank) == 'Nitrox 32' def test_mod(self): """Check Calculated mod.""" assert self.mytank.mod == 40 def test_mod_at_end(self): """Check Calculated mod at given end.""" self.assertAlmostEqual( self.mytank.get_mod_for_given_end(30), 31.0195918624, 5, 'wrong mod at end:%s' % self.mytank.get_mod_for_given_end(30)) def test_end_at_depth(self): """Check Calculated mod at given end.""" self.assertAlmostEqual( self.mytank.get_end_for_given_depth(40), 38.7573409377, 5, 'wrong end at depth:%s' % self.mytank.get_end_for_given_depth(40))
class TestTankisAir2(TestTank): """Test Air Tank 2.""" def setUp(self): """Init of the tests.""" super().setUp() self.mytank = Tank(max_ppo2=1.4) def test_name(self): """Check Name.""" assert str(self.mytank) == 'Air' def test_mod(self): """Check Calculated mod.""" assert self.mytank.mod == 56 def test_mod_at_end(self): """Check Calculated mod at given end.""" self.assertAlmostEqual( self.mytank.get_mod_for_given_end(30), 31.0195918624, 5, 'wrong mod at end:%s' % self.mytank.get_mod_for_given_end(30)) def test_end_at_depth(self): """Check Calculated mod at given end.""" self.assertAlmostEqual( self.mytank.get_end_for_given_depth(40), 38.7573409377, 5, 'wrong end at depth:%s' % self.mytank.get_end_for_given_depth(40))
class TestTankVolume3(TestTank): def setUp(self): self.mytank = Tank(tank_vol=15, tank_pressure=207) def test_vol(self): self.mytank.consume_gas(405) self.assertAlmostEqual(self.mytank.remaining_gas, 2711, 0, "Wrong Tank Volume : %s" % self.mytank.remaining_gas)
class TestTankisHeliox2080_2(TestTank): def setUp(self): self.mytank = Tank(f_o2=0.2, f_he=0.8, max_ppo2=1.4) def test_name(self): assert str(self.mytank) == "Heliox 20/80" def test_mod(self): assert self.mytank.mod == 59 def test_mod_at_end(self): self.assertAlmostEqual( self.mytank.get_mod_for_given_end(30), 96.8666243516, 5, "wrong mod at end:%s" % self.mytank.get_mod_for_given_end(30), ) def test_end_at_depth(self): self.assertAlmostEqual( self.mytank.get_end_for_given_depth(40), 8.70562703148, 5, "wrong end at depth:%s" % self.mytank.get_end_for_given_depth(40), )
class TestTankNitrox32(TestTank): """Test Nitrox32 Tank.""" def setUp(self): """Init of the tests.""" super().setUp() self.mytank = Tank(f_o2=0.32) def test_name(self): """Check Name.""" assert str(self.mytank) == 'Nitrox 32' def test_mod(self): """Check Calculated mod.""" assert self.mytank.mod == 40 def test_mod_at_end(self): """Check Calculated mod at given end.""" self.assertAlmostEqual(self.mytank.get_mod_for_given_end(30), 31.0195918624, 5, 'wrong mod at end:%s' % self.mytank.get_mod_for_given_end(30)) def test_end_at_depth(self): """Check Calculated mod at given end.""" self.assertAlmostEqual(self.mytank.get_end_for_given_depth(40), 38.7573409377, 5, 'wrong end at depth:%s' % self.mytank.get_end_for_given_depth(40))
class TestTankisTrimix870_2(TestTank): """Test Tx8/70 Tank 2.""" def setUp(self): """Init of the tests.""" super().setUp() self.mytank = Tank(f_o2=0.08, f_he=0.7, max_ppo2=1.4) def test_name(self): """Check Name.""" assert str(self.mytank) == 'Trimix 8/70' def test_mod(self): """Check Calculated mod.""" assert self.mytank.mod == 165 def test_min_od(self): """Check Calculated minimum od.""" assert self.mytank.get_min_od() == 10 def test_mod_at_end(self): """Check Calculated mod at given end.""" self.assertAlmostEqual(self.mytank.get_mod_for_given_end(30), 79.0122229175, 5, 'wrong mod at end:%s' % self.mytank.get_mod_for_given_end(30)) def test_end_at_depth(self): """Check Calculated mod at given end.""" self.assertAlmostEqual(self.mytank.get_end_for_given_depth(40), 12.4620912698, 5, 'wrong end at depth:%s' % self.mytank.get_end_for_given_depth(40))
class TestTankisTrimix2030_2(TestTank): """Test Tx2030 Tank 2.""" def setUp(self): """Init of the tests.""" super().setUp() self.mytank = Tank(f_o2=0.2, f_he=0.3, max_ppo2=1.4) def test_name(self): """Check Name.""" assert str(self.mytank) == 'Trimix 20/30' def test_mod(self): """Check Calculated mod.""" assert self.mytank.mod == 59 def test_mod_at_end(self): """Check Calculated mod at given end.""" self.assertAlmostEqual(self.mytank.get_mod_for_given_end(30), 43.3498554235, 5, 'wrong mod at end:%s' % self.mytank.get_mod_for_given_end(30)) def test_end_at_depth(self): """Check Calculated mod at given end.""" self.assertAlmostEqual(self.mytank.get_end_for_given_depth(40), 27.4879482229, 5, 'wrong end at depth:%s' % self.mytank.get_end_for_given_depth(40))
class TestTankisAir(TestTank): """Test Air Tank.""" def setUp(self): """Init of the tests.""" super().setUp() self.mytank = Tank() def test_name(self): """Check Name.""" assert str(self.mytank) == 'Air' def test_mod(self): """Check Calculated mod.""" assert self.mytank.mod == 66 def test_mod_at_end(self): """Check Calculated mod at given end.""" self.assertAlmostEqual(self.mytank.get_mod_for_given_end(30), 31.0195918624, 5, 'wrong mod at end:%s' % self.mytank.get_mod_for_given_end(30)) def test_end_at_depth(self): """Check Calculated mod at given end.""" self.assertAlmostEqual(self.mytank.get_end_for_given_depth(40), 38.7573409377, 5, 'wrong end at depth:%s' % self.mytank.get_end_for_given_depth(40)) def test_tank_info(self): """Check str output.""" self.assertEqual(self.mytank.tank_info, '12.0l-100.0% (2423.10/2423.10l)', "Wrong Tank infos: %s" % self.mytank.tank_info)
class TestTankisHeliox2080_2(TestTank): """Test Heliox2080 Tank 2.""" def setUp(self): """Init of the tests.""" super().setUp() self.mytank = Tank(f_o2=0.2, f_he=0.8, max_ppo2=1.4) def test_name(self): """Check Name.""" assert str(self.mytank) == 'Heliox 20/80' def test_mod(self): """Check Calculated mod.""" assert self.mytank.mod == 59 def test_mod_at_end(self): """Check Calculated mod at given end.""" self.assertAlmostEqual(self.mytank.get_mod_for_given_end(30), 96.8666243516, 5, 'wrong mod at end:%s' % self.mytank.get_mod_for_given_end(30)) def test_end_at_depth(self): """Check Calculated mod at given end.""" self.assertAlmostEqual(self.mytank.get_end_for_given_depth(40), 8.70562703148, 5, 'wrong end at depth:%s' % self.mytank.get_end_for_given_depth(40))
class TestTankisAir2(TestTank): """Test Air Tank 2.""" def setUp(self): """Init of the tests.""" super().setUp() self.mytank = Tank(max_ppo2=1.4) def test_name(self): """Check Name.""" assert str(self.mytank) == 'Air' def test_mod(self): """Check Calculated mod.""" assert self.mytank.mod == 56 def test_mod_at_end(self): """Check Calculated mod at given end.""" self.assertAlmostEqual(self.mytank.get_mod_for_given_end(30), 31.0195918624, 5, 'wrong mod at end:%s' % self.mytank.get_mod_for_given_end(30)) def test_end_at_depth(self): """Check Calculated mod at given end.""" self.assertAlmostEqual(self.mytank.get_end_for_given_depth(40), 38.7573409377, 5, 'wrong end at depth:%s' % self.mytank.get_end_for_given_depth(40))
class TestTankisTrimix2030_2(TestTank): def setUp(self): self.mytank = Tank(f_o2=0.2, f_he=0.3, max_ppo2=1.4) def test_name(self): assert str(self.mytank) == "Trimix 20/30" def test_mod(self): assert self.mytank.mod == 59 def test_mod_at_end(self): self.assertAlmostEqual( self.mytank.get_mod_for_given_end(30), 43.3498554235, 5, "wrong mod at end:%s" % self.mytank.get_mod_for_given_end(30), ) def test_end_at_depth(self): self.assertAlmostEqual( self.mytank.get_end_for_given_depth(40), 27.4879482229, 5, "wrong end at depth:%s" % self.mytank.get_end_for_given_depth(40), )
class TestTankisO2_2(TestTank): def setUp(self): self.mytank = Tank(f_o2=1, max_ppo2=1.4) def test_name(self): assert str(self.mytank) == "Oxygen" def test_mod(self): assert self.mytank.mod == 4 def test_mod_at_end(self): self.assertAlmostEqual( self.mytank.get_mod_for_given_end(30), 31.0195918624, 5, "wrong mod at end:%s" % self.mytank.get_mod_for_given_end(30), ) def test_end_at_depth(self): self.assertAlmostEqual( self.mytank.get_end_for_given_depth(40), 38.7573409377, 5, "wrong end at depth:%s" % self.mytank.get_end_for_given_depth(40), )
class TestTankVolume4(TestTank): def setUp(self): self.mytank = Tank(tank_vol=15, tank_pressure=207) def test_vol(self): self.mytank.consume_gas(405) self.mytank.consume_gas(2800) self.assertEqual( self.mytank.check_rule(), False, "Wrong tank status : it should fail the remaining " "gas rule test (result:%s)" % self.mytank.check_rule(), )
class TestTankVolume3(TestTank): """Test Tank Volume 3.""" def setUp(self): """Init of the tests.""" super().setUp() self.mytank = Tank(tank_vol=15, tank_pressure=207) def test_vol(self): """Test volume calc.""" self.mytank.consume_gas(405) self.assertAlmostEqual( self.mytank.remaining_gas, 2711, 0, 'Wrong Tank Volume : %s' % self.mytank.remaining_gas)
class TestTankVolume3(TestTank): """Test Tank Volume 3.""" def setUp(self): """Init of the tests.""" super().setUp() self.mytank = Tank(tank_vol=15, tank_pressure=207) def test_vol(self): """Test volume calc.""" self.mytank.consume_gas(405) self.assertAlmostEqual(self.mytank.remaining_gas, 2711, 0, 'Wrong Tank Volume : %s' % self.mytank.remaining_gas)
def runTest(self): """Should raise an error.""" try: Tank(f_o2=0.8, tank_vol=43) except InvalidTank: pass else: self.fail('should raise Invalid Tank')
def runTest(self): """Should raise an error.""" super().setUp() try: Tank(f_o2=1, mod=-7) except InvalidMod: pass else: self.fail('should raise Invalid Mod')
def runTest(self): """Should raise an error.""" super().setUp() try: Tank(f_o2=-0.3) except InvalidGas: pass else: self.fail('should raise Invalid Gas')
def runTest(self): """Should raise an error.""" super().setUp() try: Tank(tank_vol=-150) except InvalidTank: pass else: self.fail('should raise Invalid Tank')
def runTest(self): """Should raise an error.""" super().setUp() try: Tank(f_o2=0.3, tank_pressure=-100) except InvalidTank: pass else: self.fail('should raise Invalid Tank')
class TestTankRefill(TestTank): """Test Tank Refill.""" def setUp(self): """Init of the tests.""" super().setUp() self.mytank = Tank(tank_vol=15, tank_pressure=207) self.mytank.consume_gas(405) self.mytank.consume_gas(2800) def test_vol(self): """Test volume calc.""" self.assertAlmostEqual(self.mytank.remaining_gas, -88.9813390544, 0, 'Wrong Tank Volume : %s' % self.mytank.remaining_gas) def test_refill(self): """Test volume calc after refill.""" self.mytank.refill() self.assertAlmostEqual(self.mytank.remaining_gas, 3116.01866095, 0, 'Wrong Tank Volume : %s' % self.mytank.remaining_gas)
class TestTankisAir(TestTank): def setUp(self): self.mytank = Tank() def test_name(self): assert str(self.mytank) == "Air" def test_mod(self): assert self.mytank.mod == 66 def test_mod_at_end(self): self.assertAlmostEqual( self.mytank.get_mod_for_given_end(30), 31.0195918624, 5, "wrong mod at end:%s" % self.mytank.get_mod_for_given_end(30), ) def test_end_at_depth(self): self.assertAlmostEqual( self.mytank.get_end_for_given_depth(40), 38.7573409377, 5, "wrong end at depth:%s" % self.mytank.get_end_for_given_depth(40), ) def test_tank_info(self): self.assertEqual( self.mytank.get_tank_info(), "12.0l-100.0% (2423.10/2423.10l)", "Wrong Tank infos: %s" % self.mytank.get_tank_info(), )
class TestTankVolume4(TestTank): """Test Tank Volume 4.""" def setUp(self): """Init of the tests.""" super().setUp() self.mytank = Tank(tank_vol=15, tank_pressure=207) def test_vol(self): """Test volume calc.""" self.mytank.consume_gas(405) self.mytank.consume_gas(2800) self.assertEqual( self.mytank.check_rule(), False, 'Wrong tank status : it should fail the remaining ' 'gas rule test (result:%s)' % self.mytank.check_rule())
class TestTankRefill(TestTank): def setUp(self): self.mytank = Tank(tank_vol=15, tank_pressure=207) self.mytank.consume_gas(405) self.mytank.consume_gas(2800) def test_vol(self): self.assertAlmostEqual( self.mytank.remaining_gas, -88.9813390544, 0, "Wrong Tank Volume : %s" % self.mytank.remaining_gas ) def test_refill(self): self.mytank.refill() self.assertAlmostEqual( self.mytank.remaining_gas, 3116.01866095, 0, "Wrong Tank Volume : %s" % self.mytank.remaining_gas )
class TestTankVolume4(TestTank): """Test Tank Volume 4.""" def setUp(self): """Init of the tests.""" super().setUp() self.mytank = Tank(tank_vol=15, tank_pressure=207) def test_vol(self): """Test volume calc.""" self.mytank.consume_gas(405) self.mytank.consume_gas(2800) self.assertEqual(self.mytank.check_rule(), False, 'Wrong tank status : it should fail the remaining ' 'gas rule test (result:%s)' % self.mytank.check_rule())
class TestTankRefill(TestTank): """Test Tank Refill.""" def setUp(self): """Init of the tests.""" super().setUp() self.mytank = Tank(tank_vol=15, tank_pressure=207) self.mytank.consume_gas(405) self.mytank.consume_gas(2800) def test_vol(self): """Test volume calc.""" self.assertAlmostEqual( self.mytank.remaining_gas, -88.9813390544, 0, 'Wrong Tank Volume : %s' % self.mytank.remaining_gas) def test_refill(self): """Test volume calc after refill.""" self.mytank.refill() self.assertAlmostEqual( self.mytank.remaining_gas, 3116.01866095, 0, 'Wrong Tank Volume : %s' % self.mytank.remaining_gas)
def setUp(self): self.mytank = Tank(tank_vol=15, tank_pressure=207)
def no_flight_time(self, altitude=settings.FLIGHT_ALTITUDE, tank=None): """Evaluate the no flight time. by 'ascending' to the choosen flight altitude. Ascending will generate the necessary 'stop' at the current depth (which is 0m) . The stop time represents the no flight time :param int altitude: in meter : altitude used for the calculation :param float flight_ascent_rate: in m/ms :param tank: (optionnal) it is possible to provide a tank while calling no_flight_time to force "no flight deco" with another mix than air. In this case, we will 'consume' the tank When the tank is empty, it automatically switch to air :type tank: :class:`dipplanner.tank.Tank` :returns: no fight time in seconds :rtype: int :raises InfiniteDeco: if the no flight time can not achieve enough decompression to be able to go to give altitude """ no_flight_time = 0 deco_uses_tank = False # set to true when deco is using a tank # need to change gaz to air: # create a 'dummy' air tank no_flight_air_tank = Tank( tank_vol=settings.ABSOLUTE_MAX_TANK_SIZE, tank_pressure=settings.ABSOLUTE_MAX_TANK_PRESSURE, tank_rule="30b") if tank is not None: no_flight_tank = tank deco_uses_tank = True self.logger.info("Accelerating no flight" "time using a tank:%s", tank) else: no_flight_tank = no_flight_air_tank next_stop_pressure = altitude_or_depth_to_absolute_pressure(altitude) # bigger stop time to speed up calculation # (precision is not necesary here) stop_time = 60 # in second - model_copy = copy.deepcopy(self.model) model_ceiling = model_copy.ceiling_in_pabs() while model_ceiling > next_stop_pressure: # loop for "deco" calculation based on the new ceiling model_copy.const_depth( 0.0, stop_time, no_flight_tank.f_he, # f_he no_flight_tank.f_n2, # f_n2 0.0) # ppo2 (for cc) no_flight_time += stop_time model_ceiling = model_copy.ceiling_in_pabs() if deco_uses_tank: if no_flight_tank.remaining_gas <= 0: no_flight_tank = no_flight_air_tank deco_uses_tank = False self.logger.info( "Tank used for accelerating " "no flight time is empty, " "swithing to air at %s s", no_flight_time) else: no_flight_tank.consume_gas(settings.DECO_CONSUMPTION_RATE * stop_time) if no_flight_time > 300000: raise InfiniteDeco("Infinite deco error") self.no_flight_time_value = no_flight_time return no_flight_time
def test_rule_bar_1(self): """Check rule rem bars.""" mytank = Tank(tank_vol=15, tank_pressure=200, tank_rule="50b") self.assertAlmostEqual( mytank.min_gas, 767.5548, 4, "bad Tank rule calculation: %s" % mytank.min_gas)
def setUp(self): self.mytank = Tank(f_o2=0.32)
def check_configs_dives_section(self): """Check configs and change default settings values.""" config = self.config # dives = { 'dive1': { 'tanks': {}, # 'segments': {}, # 'surface_interval':0} } dives = {} dive_number = 1 # initialization while config.has_section('dive%s' % dive_number): section = 'dive%s' % dive_number dives[section] = { 'tanks': {}, 'segments': {}, 'surface_interval': 0 } for parameter_name, parameter_value in config.items(section): if parameter_name == 'surface_interval': dives[section]['surface_interval'] = safe_eval_calculator( parameter_value) elif parameter_name[0:4] == 'tank': # number = parameter_name[4:] (name, f_o2, f_he, volume, pressure, rule) = parameter_value.split(";") dives[section]['tanks'][name] = Tank( float(f_o2), float(f_he), max_ppo2=settings.DEFAULT_MAX_PPO2, tank_vol=float(safe_eval_calculator(volume)), tank_pressure=float(safe_eval_calculator(pressure)), tank_rule=rule) if dives[section]['tanks'] == {}: # no tank provided, try to get the previous tanks try: dives[section]['tanks'] = dives['dive%s' % (dive_number - 1)]['tanks'] except KeyError: print("Error : no tank provided for this dive !") sys.exit(0) for param_name, param_value in config.items(section): if param_name[0:7] == 'segment': # number = parameter_name[4:] (depth, time, tankname, setpoint) = param_value.split(";") try: dives[section]['segments'][param_name] = SegmentDive( float(safe_eval_calculator(depth)), float(safe_eval_calculator(time)), dives[section]['tanks'][tankname], float(setpoint)) except KeyError: print("Error : tank name (%s) in not found" " in tank list !" % tankname) sys.exit(0) except: raise dives[section]['segments'] = OrderedDict( sorted(dives[section]['segments'].items(), key=lambda t: t[0])) dive_number += 1 self.dives = OrderedDict(sorted(dives.items(), key=lambda t: t[0]))
def setUp(self): """Init of the tests.""" super().setUp() self.mytank = Tank(f_o2=0.32)
def setUp(self): self.mytank = Tank()
def setUp(self): self.mytank = Tank(f_o2=1, max_ppo2=1.4)
def setUp(self): """Init of the tests.""" super().setUp() self.mytank = Tank(max_ppo2=1.4)
def setUp(self): """Init of the tests.""" super().setUp() self.mytank = Tank(tank_vol=15, tank_pressure=207)
def setUp(self): self.mytank = Tank(f_o2=0.2, f_he=0.8)
def setUp(self): self.mytank = Tank(f_o2=0.1, f_he=0.7)
def setUp(self): self.mytank = Tank(tank_vol=15, tank_pressure=207) self.mytank.consume_gas(405) self.mytank.consume_gas(2800)
def setUp(self): self.mytank = Tank(f_o2=0.08, f_he=0.7, max_ppo2=1.4)
def test_rule_bar_3(self): """Check rule 1/6.""" mytank = Tank(tank_vol=15, tank_pressure=200, tank_rule="1/6") self.assertAlmostEqual( mytank.min_gas, 2019.24752, 4, "bad Tank rule calculation: %s" % mytank.min_gas)
def setUp(self): """Init of the tests.""" super().setUp() self.mytank = Tank(f_o2=0.2, f_he=0.8, max_ppo2=1.4)
def setUp(self): self.mytank = Tank(f_o2=0.2, f_he=0.8, max_ppo2=1.4)
def check_arguments(self, args): """Parse all command lines options. could also exit from program because of wrong arguments """ parsed_config_files = DipplannerConfigFiles(args.config_files) dives = parsed_config_files.dives if dives is None: dives = OrderedDict() if args.gflow: try: settings.GF_LOW = float( safe_eval_calculator(args.gflow.strip('%'))) / 100 except ValueError: self.parser.error("Error while parsing option gflow : %s" % args.gflow) if args.gfhigh: try: settings.GF_HIGH = float( safe_eval_calculator(args.gfhigh.strip('%'))) / 100 except ValueError: self.parser.error("Error while parsing option gfhigh: %s" % args.gfhigh) if args.water: if args.water.lower() == "sea": settings.WATER_DENSITY = settings.SEA_WATER_DENSITY if args.water.lower() == "fresh": settings.WATER_DENSITY = settings.FRESH_WATER_DENSITY if args.altitude: settings.AMBIANT_PRESSURE_SURFACE = altitude_to_pressure( args.altitude) if args.diveconsrate: try: settings.DIVE_CONSUMPTION_RATE = float( safe_eval_calculator(args.diveconsrate)) / 60 except ValueError: self.parser.error("Error while parsing option " "diveconsrate : %s" % args.diveconsrate) if args.decoconsrate: try: settings.DECO_CONSUMPTION_RATE = float( safe_eval_calculator(args.decoconsrate)) / 60 except ValueError: self.parser.error("Error while parsing option " "decoconsrate : %s" % args.decoconsrate) if args.descentrate: try: settings.DESCENT_RATE = float( safe_eval_calculator(args.descentrate)) / 60 except ValueError: self.parser.error("Error while parsing option " "descentrate : %s" % args.descentrate) if args.ascentrate: try: settings.ASCENT_RATE = float( safe_eval_calculator(args.ascentrate)) / 60 except ValueError: self.parser.error("Error while parsing option " "ascentrate : %s" % args.ascentrate) if args.deco_ascentrate: try: settings.DECO_ASCENT_RATE = float( safe_eval_calculator(args.deco_ascentrate)) / 60 except ValueError: self.parser.error("Error while parsing option " "deco_ascentrate : %s" % args.deco_ascentrate) if args.model: settings.DECO_MODEL = args.model if args.maxppo2: settings.DEFAULT_MAX_PPO2 = args.maxppo2 if args.minppo2: settings.DEFAULT_MIN_PPO2 = args.minppo2 if args.maxend: settings.DEFAULT_MAX_END = args.maxend if args.samegasfordeco: settings.USE_OC_DECO = False if args.forcesegmenttime: settings.RUN_TIME = False if args.depthcalcmethod in ('simple', 'complex'): settings.METHOD_FOR_DEPTH_CALCULATION = args.depthcalcmethod if args.travelswitch in ('late', 'early'): settings.TRAVEL_SWITCH = args.travelswitch if args.surfacetemp is not None: settings.SURFACE_TEMP = args.surfacetemp if args.ambiantpressureatsea: settings.AMBIANT_PRESSURE_SEA_LEVEL = args.ambiantpressureatsea if args.multilevel: settings.MULTILEVEL_MODE = True if args.automatictankrefill: settings.AUTOMATIC_TANK_REFILL = True if args.notankrefill: settings.AUTOMATIC_TANK_REFILL = False # try to find tank(s) and segment(s). # if found, add this dive to the (eventually) other dives defined # in config files. # this will be the last dive tanks = {} if args.tanks: for tank in args.tanks: (name, f_o2, f_he, volume, pressure, rule) = tank.split(";") tanks[name] = Tank( float(f_o2), float(f_he), max_ppo2=settings.DEFAULT_MAX_PPO2, tank_vol=float(safe_eval_calculator(volume)), tank_pressure=float(safe_eval_calculator(pressure)), tank_rule=rule) if tanks == {}: # no tank provided, try to get the previous tanks try: tanks = dives[list(dives.items())[-1][0]]['tanks'] except (KeyError, IndexError): self.parser.error("Error : no tank provided for this dive !") segments = OrderedDict() if args.segments: num_seg = 1 for seg in args.segments: (depth, time, tankname, setpoint) = seg.split(";") # looks for tank in tanks try: # seg_name = 'segment%s' % num_seg # print(seg_name) segments['segment%s' % num_seg] = SegmentDive( float(safe_eval_calculator(depth)), float(safe_eval_calculator(time)), tanks[tankname], float(setpoint)) except KeyError: self.parser.error( "Error : tank name (%s) in not found in tank list !" % tankname) num_seg += 1 segments = OrderedDict(sorted(segments.items(), key=lambda t: t[0])) if args.surfaceinterval: dives['diveCLI'] = { 'tanks': tanks, 'segments': segments, 'surface_interval': safe_eval_calculator(args.surfaceinterval) } else: dives['diveCLI'] = { 'tanks': tanks, 'segments': segments, 'surface_interval': 0 } if args.template: settings.TEMPLATE = args.template # returns self.args = args self.dives = dives
def test_rule_bar_2(self): """Check rule 1/3.""" mytank = Tank(tank_vol=15, tank_pressure=200, tank_rule="1/3") self.assertAlmostEqual( mytank.min_gas, 1009.62376, 4, "bad Tank rule calculation: %s" % mytank.min_gas)
def setUp(self): """Init of the tests.""" # temporary hack (tests): super().setUp() activate_debug_for_tests() # settings.RUN_TIME = True # settings.SURFACE_TEMP = 12 self.air12l = Tank(tank_vol=12.0, tank_pressure=200, tank_rule="10b") self.airtank = Tank(tank_vol=18.0, tank_pressure=200, tank_rule="10b") self.airtank12 = Tank(tank_vol=12.0, tank_pressure=200, tank_rule="10b") self.airdouble = Tank(tank_vol=30.0, tank_pressure=200, tank_rule="10b") # bi15l 200b self.txtank1 = Tank(0.21, 0.30, tank_vol=20.0, tank_pressure=200, tank_rule="10b") self.txtanknormodbl = Tank(0.21, 0.30, tank_vol=30.0, tank_pressure=200, tank_rule="10b") self.txhypo = Tank(0.10, 0.50, tank_vol=30.0, tank_pressure=200) # 2x 15l self.txtravel = Tank(0.21, 0.30, tank_vol=24.0, tank_pressure=200) # 2x S80 self.ccair = Tank(tank_vol=3.0, tank_pressure=200, tank_rule='10b') self.cctxhypo = Tank(0.10, 0.50, tank_vol=3.0, tank_pressure=200, tank_rule='10b') self.setpoint = 1.2 self.deco1 = Tank(0.8, 0.0, tank_vol=7.0, tank_pressure=200, tank_rule="10b") self.deco2 = Tank(0.5, 0.0, tank_vol=7.0, tank_pressure=200, tank_rule="10b") self.decoo2 = Tank(1.0, 0.0, tank_vol=7.0, tank_pressure=200, tank_rule="10b") self.setpoint = 0.0 self.dive_tank = None self.all_tanks = None self.dive_segs = []