Exemplo n.º 1
0
class TestDiveTxDiveOutput1(TestDive):
    """Test segments output for tx dive 1."""

    expected_result = [
        " DESCENT: at  30m for   1:30 [RT:  1:30], on Trimix 21/30,  SP:0.0, END:19m",
        "   CONST: at  30m for  28:30 [RT: 30:00], on Trimix 21/30,  SP:0.0, END:19m",
        "  ASCENT: at  15m for   1:30 [RT: 31:30], on Trimix 21/30,  SP:0.0, END:8m",
        "    DECO: at  15m for   0:01 [RT: 31:31], on Trimix 21/30,  SP:0.0, END:8m",
        "  ASCENT: at  12m for   1:00 [RT: 32:31], on Trimix 21/30,  SP:0.0, END:6m",
        "    DECO: at  12m for   0:38 [RT: 33:09], on Trimix 21/30,  SP:0.0, END:6m",
        "  ASCENT: at   9m for   1:00 [RT: 34:09], on Trimix 21/30,  SP:0.0, END:4m",
        "    DECO: at   9m for   3:04 [RT: 37:13], on Trimix 21/30,  SP:0.0, END:4m",
        "  ASCENT: at   6m for   1:00 [RT: 38:13], on Trimix 21/30,  SP:0.0, END:1m",
        "    DECO: at   6m for   6:25 [RT: 44:38], on Trimix 21/30,  SP:0.0, END:1m",
        "  ASCENT: at   3m for   1:00 [RT: 45:38], on Trimix 21/30,  SP:0.0, END:0m",
        "    DECO: at   3m for  16:12 [RT: 61:50], on Trimix 21/30,  SP:0.0, END:0m",
        "  ASCENT: at   0m for   1:00 [RT: 62:50], on Trimix 21/30,  SP:0.0, END:0m",
    ]

    def setUp(self):
        """Init of the tests."""
        super().setUp()
        diveseg1 = SegmentDive(30, 30 * 60, self.txtank1, 0)
        self.profile1 = Dive([diveseg1], [self.txtank1])
        self.profile1.do_dive()

    def test_segments(self):
        """Check all segments."""
        for idx in range(len(self.expected_result)):
            self.assertEqual(
                str(self.profile1.output_segments[idx]),
                self.expected_result[idx], 'bad segment n°%s (%s)' %
                (idx, self.profile1.output_segments[idx]))
Exemplo n.º 2
0
    def do_repetitive_dive(self):
        """do the actual dive.

        self.params is in the form:
            ((depth, time, interval), (depth, time, interval))
        each couple of depth, time, interval is a full dive at the given depth
        interval is done before the dive.
        """
        if not hasattr(self, 'name'):
            self.name = '%s:%s' % (self.params[0][0], self.params[0][1])
        self.profiles = []  # repetive dive profiles.
        for param in self.params:
            if len(self.profiles) > 0:
                self.profiles.append(
                    Dive([
                        SegmentDive(param[0], param[1] * 60, self.dive_tank,
                                    self.setpoint)
                    ], self.all_tanks, self.profiles[-1]))
                self.profiles[-1].do_surface_interval(param[2] * 60)
            else:
                self.profiles.append(
                    Dive([
                        SegmentDive(param[0], param[1] * 60, self.dive_tank,
                                    self.setpoint)
                    ], self.all_tanks))
            self.profiles[-1].do_dive()

        self.profile1 = self.profiles[-1]  # save last dive
Exemplo n.º 3
0
class TestDiveAirDiveOutput_woExc(TestDive):
    """Test segments output for air dive 1 without exc."""

    expected_result = [
        " DESCENT: at  30m for   1:30 [RT:  1:30], on Air,  SP:0.0, END:29m",
        "   CONST: at  30m for  28:30 [RT: 30:00], on Air,  SP:0.0, END:29m",
        "  ASCENT: at  15m for   1:30 [RT: 31:30], on Air,  SP:0.0, END:14m",
        "    DECO: at  15m for   0:01 [RT: 31:31], on Air,  SP:0.0, END:14m",
        "  ASCENT: at  12m for   1:00 [RT: 32:31], on Air,  SP:0.0, END:11m",
        "    DECO: at  12m for   0:20 [RT: 32:51], on Air,  SP:0.0, END:11m",
        "  ASCENT: at   9m for   1:00 [RT: 33:51], on Air,  SP:0.0, END:8m",
        "    DECO: at   9m for   2:39 [RT: 36:30], on Air,  SP:0.0, END:8m",
        "  ASCENT: at   6m for   1:00 [RT: 37:30], on Air,  SP:0.0, END:5m",
        "    DECO: at   6m for   4:59 [RT: 42:29], on Air,  SP:0.0, END:5m",
        "  ASCENT: at   3m for   1:00 [RT: 43:29], on Air,  SP:0.0, END:2m",
        "    DECO: at   3m for  12:42 [RT: 56:11], on Air,  SP:0.0, END:2m",
        "  ASCENT: at   0m for   1:00 [RT: 57:11], on Air,  SP:0.0, END:0m", ]


    def setUp(self):
        """Init of the tests."""
        super().setUp()
        diveseg1 = SegmentDive(30, 30 * 60, self.airtank, 0)
        self.profile1 = Dive([diveseg1], [self.airtank])
        self.profile1.do_dive_without_exceptions()

    def test_segments(self):
        """Check all segments."""
        for idx in range(len(self.expected_result)):
            self.assertEqual(
                str(self.profile1.output_segments[idx]),
                self.expected_result[idx],
                'bad segment n°%s (%s)' % (
                    idx, self.profile1.output_segments[idx]))
Exemplo n.º 4
0
class TestDiveTxDiveOutput1(TestDive):
    """Test segments output for tx dive 1."""

    expected_result = [
        " DESCENT: at  30m for   1:30 [RT:  1:30], on Trimix 21/30,  SP:0.0, END:19m",
        "   CONST: at  30m for  28:30 [RT: 30:00], on Trimix 21/30,  SP:0.0, END:19m",
        "  ASCENT: at  15m for   1:30 [RT: 31:30], on Trimix 21/30,  SP:0.0, END:8m",
        "    DECO: at  15m for   0:01 [RT: 31:31], on Trimix 21/30,  SP:0.0, END:8m",
        "  ASCENT: at  12m for   1:00 [RT: 32:31], on Trimix 21/30,  SP:0.0, END:6m",
        "    DECO: at  12m for   0:38 [RT: 33:09], on Trimix 21/30,  SP:0.0, END:6m",
        "  ASCENT: at   9m for   1:00 [RT: 34:09], on Trimix 21/30,  SP:0.0, END:4m",
        "    DECO: at   9m for   3:04 [RT: 37:13], on Trimix 21/30,  SP:0.0, END:4m",
        "  ASCENT: at   6m for   1:00 [RT: 38:13], on Trimix 21/30,  SP:0.0, END:1m",
        "    DECO: at   6m for   6:25 [RT: 44:38], on Trimix 21/30,  SP:0.0, END:1m",
        "  ASCENT: at   3m for   1:00 [RT: 45:38], on Trimix 21/30,  SP:0.0, END:0m",
        "    DECO: at   3m for  16:12 [RT: 61:50], on Trimix 21/30,  SP:0.0, END:0m",
        "  ASCENT: at   0m for   1:00 [RT: 62:50], on Trimix 21/30,  SP:0.0, END:0m", ]

    def setUp(self):
        """Init of the tests."""
        super().setUp()
        diveseg1 = SegmentDive(30, 30 * 60, self.txtank1, 0)
        self.profile1 = Dive([diveseg1], [self.txtank1])
        self.profile1.do_dive()

    def test_segments(self):
        """Check all segments."""
        for idx in range(len(self.expected_result)):
            self.assertEqual(
                str(self.profile1.output_segments[idx]),
                self.expected_result[idx],
                'bad segment n°%s (%s)' % (
                    idx, self.profile1.output_segments[idx]))
Exemplo n.º 5
0
class TestDiveAirDiveOutput2(TestDive):
    """Test segments output for air dive 2."""

    expected_result = [
        " DESCENT: at  20m for   1:00 [RT:  1:00], on Air,  SP:0.0, END:19m",
        "   CONST: at  20m for  29:00 [RT: 30:00], on Air,  SP:0.0, END:19m",
        "  ASCENT: at   9m for   1:06 [RT: 31:06], on Air,  SP:0.0, END:8m",
        "    DECO: at   9m for   0:01 [RT: 31:07], on Air,  SP:0.0, END:8m",
        "  ASCENT: at   6m for   1:00 [RT: 32:07], on Air,  SP:0.0, END:5m",
        "    DECO: at   6m for   0:01 [RT: 32:08], on Air,  SP:0.0, END:5m",
        "  ASCENT: at   3m for   1:00 [RT: 33:08], on Air,  SP:0.0, END:2m",
        "    DECO: at   3m for   0:50 [RT: 33:58], on Air,  SP:0.0, END:2m",
        "  ASCENT: at   0m for   1:00 [RT: 34:58], on Air,  SP:0.0, END:0m",
    ]

    def setUp(self):
        """Init of the tests."""
        super().setUp()
        diveseg2 = SegmentDive(20, 30 * 60, self.airtank, 0)
        self.profile1 = Dive([diveseg2], [self.airtank])
        self.profile1.do_dive()

    def test_segments(self):
        """Check all segments."""
        for idx in range(len(self.expected_result)):
            self.assertEqual(
                str(self.profile1.output_segments[idx]),
                self.expected_result[idx], 'bad segment n°%s (%s)' %
                (idx, self.profile1.output_segments[idx]))
Exemplo n.º 6
0
    def setUp(self):
        TestDive.setUp(self)

        diveseg1 = SegmentDive(55, 20 * 60, self.txtank1, 0)
        self.profile0 = Dive([diveseg1], [self.txtank1])
        self.profile0.do_dive()

        diveseg2 = SegmentDive(50, 20 * 60, self.txtank1, 0)
        self.profile1 = Dive([diveseg2], [self.txtank1], self.profile0)
        self.profile1.do_surface_interval(30 * 60)
        self.profile1.do_dive()

        diveseg3 = SegmentDive(35, 35 * 60, self.txtank1, 0)
        self.profile2 = Dive([diveseg3], [self.txtank1], self.profile1)
        self.profile2.do_surface_interval(60 * 60)

        # self.profile2.refill_tanks()

        self.profile2.do_dive()

        diveseg4 = SegmentDive(55, 20 * 60, self.txtank1, 0)
        self.profile3 = Dive([diveseg4], [self.txtank1], self.profile2)
        self.profile3.do_surface_interval(12 * 60 * 60)

        # self.profile3.refill_tanks()

        self.profile3.do_dive()
Exemplo n.º 7
0
class TestDiveAirDiveOutput2(TestDive):
    """Test segments output for air dive 2."""

    expected_result = [
        " DESCENT: at  20m for   1:00 [RT:  1:00], on Air,  SP:0.0, END:19m",
        "   CONST: at  20m for  29:00 [RT: 30:00], on Air,  SP:0.0, END:19m",
        "  ASCENT: at   9m for   1:06 [RT: 31:06], on Air,  SP:0.0, END:8m",
        "    DECO: at   9m for   0:01 [RT: 31:07], on Air,  SP:0.0, END:8m",
        "  ASCENT: at   6m for   1:00 [RT: 32:07], on Air,  SP:0.0, END:5m",
        "    DECO: at   6m for   0:01 [RT: 32:08], on Air,  SP:0.0, END:5m",
        "  ASCENT: at   3m for   1:00 [RT: 33:08], on Air,  SP:0.0, END:2m",
        "    DECO: at   3m for   0:50 [RT: 33:58], on Air,  SP:0.0, END:2m",
        "  ASCENT: at   0m for   1:00 [RT: 34:58], on Air,  SP:0.0, END:0m", ]

    def setUp(self):
        """Init of the tests."""
        super().setUp()
        diveseg2 = SegmentDive(20, 30 * 60, self.airtank, 0)
        self.profile1 = Dive([diveseg2], [self.airtank])
        self.profile1.do_dive()

    def test_segments(self):
        """Check all segments."""
        for idx in range(len(self.expected_result)):
            self.assertEqual(
                str(self.profile1.output_segments[idx]),
                self.expected_result[idx],
                'bad segment n°%s (%s)' % (
                    idx, self.profile1.output_segments[idx]))
Exemplo n.º 8
0
class TestDiveAirDiveOutput_woExc(TestDive):
    """Test segments output for air dive 1 without exc."""

    expected_result = [
        " DESCENT: at  30m for   1:30 [RT:  1:30], on Air,  SP:0.0, END:29m",
        "   CONST: at  30m for  28:30 [RT: 30:00], on Air,  SP:0.0, END:29m",
        "  ASCENT: at  15m for   1:30 [RT: 31:30], on Air,  SP:0.0, END:14m",
        "    DECO: at  15m for   0:01 [RT: 31:31], on Air,  SP:0.0, END:14m",
        "  ASCENT: at  12m for   1:00 [RT: 32:31], on Air,  SP:0.0, END:11m",
        "    DECO: at  12m for   0:20 [RT: 32:51], on Air,  SP:0.0, END:11m",
        "  ASCENT: at   9m for   1:00 [RT: 33:51], on Air,  SP:0.0, END:8m",
        "    DECO: at   9m for   2:39 [RT: 36:30], on Air,  SP:0.0, END:8m",
        "  ASCENT: at   6m for   1:00 [RT: 37:30], on Air,  SP:0.0, END:5m",
        "    DECO: at   6m for   4:59 [RT: 42:29], on Air,  SP:0.0, END:5m",
        "  ASCENT: at   3m for   1:00 [RT: 43:29], on Air,  SP:0.0, END:2m",
        "    DECO: at   3m for  12:42 [RT: 56:11], on Air,  SP:0.0, END:2m",
        "  ASCENT: at   0m for   1:00 [RT: 57:11], on Air,  SP:0.0, END:0m",
    ]

    def setUp(self):
        """Init of the tests."""
        super().setUp()
        diveseg1 = SegmentDive(30, 30 * 60, self.airtank, 0)
        self.profile1 = Dive([diveseg1], [self.airtank])
        self.profile1.do_dive_without_exceptions()

    def test_segments(self):
        """Check all segments."""
        for idx in range(len(self.expected_result)):
            self.assertEqual(
                str(self.profile1.output_segments[idx]),
                self.expected_result[idx], 'bad segment n°%s (%s)' %
                (idx, self.profile1.output_segments[idx]))
Exemplo n.º 9
0
 def setUp(self):
     """Init of the tests."""
     super().setUp()
     diveseg3 = SegmentDive(55, 30 * 60, self.airdouble, 0)
     self.profile1 = Dive([diveseg3],
                          [self.airdouble, self.decoo2, self.deco2])
     self.profile1.do_dive()
Exemplo n.º 10
0
class TestDiveAirDiveRunTime2(TestDive):

    def runTest(self):
        diveseg2 = SegmentDive(20, 30 * 60, self.airtank, 0)
        self.profile2 = Dive([diveseg2], [self.airtank])
        self.profile2.do_dive()
        self.assertEqual(seconds_to_mmss(self.profile2.run_time),
                         ' 32:04', 'bad dive runtime (%s)'
                         % seconds_to_mmss(self.profile2.run_time))
Exemplo n.º 11
0
class TestDiveAirDiveRunTime3(TestDive):

    def runTest(self):
        diveseg3 = SegmentDive(55, 30 * 60, self.airdouble, 0)
        self.profile3 = Dive([diveseg3], [self.airdouble])
        self.profile3.do_dive()
        self.assertEqual(seconds_to_mmss(self.profile3.run_time),
                         '131:05', 'bad dive runtime (%s)'
                         % seconds_to_mmss(self.profile3.run_time))
Exemplo n.º 12
0
class TestDiveTxDiveRunTime1(TestDive):

    def runTest(self):
        diveseg1 = SegmentDive(30, 30 * 60, self.txtank1, 0)
        self.profile1 = Dive([diveseg1], [self.txtank1])
        self.profile1.do_dive()
        self.assertEqual(seconds_to_mmss(self.profile1.run_time),
                         ' 55:03', 'bad dive runtime (%s)'
                         % seconds_to_mmss(self.profile1.run_time))
Exemplo n.º 13
0
 def runTest(self):
     """Not enought gas test"""
     diveseg1 = SegmentDive(60, 30 * 60, self.air12l, 0)
     self.profile1 = Dive([diveseg1], [self.air12l])
     self.profile1.do_dive()
     self.assertEqual(
         self.profile1.tanks[0].check_rule(), False,
         'Wrong tank status : it should fail the remaining '
         'gas rule test (result:%s)' % self.profile1.tanks[0].check_rule())
Exemplo n.º 14
0
class TestDiveAirDiveRunTime1(TestDive):

    def runTest(self):
        diveseg1 = SegmentDive(30, 30 * 60, self.airtank, 0)
        self.profile1 = Dive([diveseg1], [self.airtank])
        self.profile1.do_dive()
        self.assertEqual(seconds_to_mmss(self.profile1.run_time),
                         ' 48:24', 'bad dive runtime ? (%s)'
                         % seconds_to_mmss(self.profile1.run_time))
Exemplo n.º 15
0
class TestDiveNotEnoughGas1(TestDive):

    def runTest(self):
        diveseg1 = SegmentDive(60, 30 * 60, self.air12l, 0)
        self.profile1 = Dive([diveseg1], [self.air12l])
        self.profile1.do_dive()
        self.assertEqual(self.profile1.tanks[0].check_rule(), False,
                         'Wrong tank status : it should fail the remaining '
                         'gas rule test (result:%s)'
                         % self.profile1.tanks[0].check_rule())
Exemplo n.º 16
0
class TestRepetitiveDive1(TestDive):

    def setUp(self):
        TestDive.setUp(self)

        diveseg1 = SegmentDive(40, 20 * 60, self.airtank12, 0)
        self.profile0 = Dive([diveseg1], [self.airtank12])
        self.profile0.do_dive()

        diveseg2 = SegmentDive(40, 20 * 60, self.airtank, 0)
        self.profile1 = Dive([diveseg2], [self.airtank], self.profile0)
        self.profile1.do_surface_interval(20 * 60)
        self.profile1.do_dive()

    def test_rt(self):
        assert seconds_to_mmss(self.profile1.run_time) == ' 68:09', \
            'bad dive runtime ? (%s)' \
            % seconds_to_mmss(self.profile1.run_time)

    def test_otu(self):
        self.assertAlmostEqual(self.profile1.model.ox_tox.otu,
                               40.0702502936, 7, 'bad dive OTU ? (%s)'
                               % self.profile1.model.ox_tox.otu)

    def test_cns(self):
        self.assertAlmostEqual(self.profile1.model.ox_tox.cns * 100,
                               14.3091665925, 7, 'bad dive CNS ? (%s)'
                               % (self.profile1.model.ox_tox.cns * 100))

    def test_tank_cons(self):
        self.assertAlmostEqual(self.airtank12.used_gas, 2115.5196384,
                               7, 'bad used gas (%s)'
                               % self.airtank12.used_gas)

    def test_tank_cons_rule(self):
        self.assertEqual(self.profile1.tanks[0].check_rule(), True,
                         'Wrong tank status : it should pass the remaining '
                         'gas rule test (result:%s)'
                         % self.profile1.tanks[0].check_rule())

    def test_no_flight(self):
        no_flight_time = self.profile1.no_flight_time()
        self.assertEqual(no_flight_time, 5460, 'Bad no flight time: %s'
                         % no_flight_time)

    def test_no_flight_wo_exc(self):
        no_flight_time = self.profile1.no_flight_time_wo_exception()
        self.assertEqual(no_flight_time, 5460, 'Bad no flight time: %s'
                         % no_flight_time)

    def test_surfaceint(self):
        self.assertEqual(self.profile1.get_surface_interval(),
                         ' 20:00',
                         'wrong surface interval:%s'
                         % self.profile1.get_surface_interval())
Exemplo n.º 17
0
    def setUp(self):
        TestDive.setUp(self)

        diveseg1 = SegmentDive(40, 20 * 60, self.airtank12, 0)
        self.profile0 = Dive([diveseg1], [self.airtank12])
        self.profile0.do_dive()

        diveseg2 = SegmentDive(40, 20 * 60, self.airtank, 0)
        self.profile1 = Dive([diveseg2], [self.airtank], self.profile0)
        self.profile1.do_surface_interval(20 * 60)
        self.profile1.do_dive()
Exemplo n.º 18
0
 def runTest(self):
     """Run one test."""
     try:
         diveseg1 = SegmentDive(self.params[0][0], self.params[0][1] * 60,
                                self.airdouble, 0)
         self.profile1 = Dive([diveseg1], [self.airdouble])
         self.profile1.do_dive()
     except UnauthorizedMod:
         pass
     else:
         self.fail("should raise UnauthorizedMod")
Exemplo n.º 19
0
 def runTest(self):
     """Run one test."""
     try:
         diveseg1 = SegmentDive(self.params[0][0], self.params[0][1] * 60,
                                self.txhypo, 0)
         self.profile1 = Dive([diveseg1],
                              [self.txtravel, self.txhypo, self.deco1])
         self.profile1.do_dive()
     except UnauthorizedMod:
         pass
     else:
         self.fail('should raise UnauthorizedMod')
Exemplo n.º 20
0
 def runTest(self):
     """Run one test."""
     try:
         self.setpoint = 1.2
         self.dive_tank = self.ccair
         self.all_tanks = [self.ccair]
         diveseg1 = SegmentDive(self.params[0][0], self.params[0][1] * 60,
                                self.dive_tank, self.setpoint)
         self.profile1 = Dive([diveseg1], self.all_tanks)
         self.profile1.do_dive()
     except UnauthorizedMod:
         pass
     else:
         self.fail("should raise UnauthorizedMod")
Exemplo n.º 21
0
def main(cli_arguments=None):
    """Main entry point.

    main uses the parameters, tanks and dives given in config file(s)
    and/or command line, calculates the dives and return the output in stdout.

    :param list cli_arguments: list of arguments, like sys.argv
    """
    if sys.version_info < (3, 4):
        raise SystemExit("ERROR: This programm needs python 3.4 or greater")

    if cli_arguments is None:
        cli_arguments = sys.argv

    activate_debug()

    # get the version
    try:
        version_file = open("RELEASE-VERSION", "r")
        try:
            version = version_file.readlines()[0]
            settings.__VERSION__ = version.strip()
        finally:
            version_file.close()
    except IOError:
        settings.__VERSION__ = "unknown"

    dipplanner_arguments = DipplannerCliArguments(cli_arguments)
    dives = dipplanner_arguments.dives

    profiles = []
    current_dive = None
    previous_dive = None
    for dive in dives:
        if previous_dive is None:
            current_dive = Dive(dives[dive]['segments'].values(),
                                dives[dive]['tanks'].values())
        else:
            current_dive = Dive(dives[dive]['segments'].values(),
                                dives[dive]['tanks'].values(), previous_dive)
        if dives[dive]['surface_interval']:
            current_dive.do_surface_interval(dives[dive]['surface_interval'])

        current_dive.do_dive_without_exceptions()
        profiles.append(current_dive)
        previous_dive = current_dive
        # now, dive exceptins do not stop the program anymore, but can be
        # displayed in the output template instead. The used MUST take care of
        # the result.

    # now calculate no flight time based on the last dive
    ######current_dive.no_flight_time_wo_exception()

    # now Prepare the output
    env = Environment(loader=PackageLoader('dipplanner', 'templates'))
    tpl = env.get_template(settings.TEMPLATE)
    # pylint: disable=no-member
    text = tpl.render(settings=settings, dives=profiles)
    # pylint: enable=no-member
    print(text)
Exemplo n.º 22
0
    def setUp(self):
        TestDive.setUp(self)

        diveseg1 = SegmentDive(55, 20 * 60, self.txtank1, 0)
        self.profile0 = Dive([diveseg1], [self.txtank1])
        self.profile0.do_dive()

        diveseg2 = SegmentDive(50, 20 * 60, self.txtank1, 0)
        self.profile1 = Dive([diveseg2], [self.txtank1], self.profile0)
        self.profile1.do_surface_interval(20 * 60)

        # self.profile1.refill_tanks()

        self.profile1.do_dive()
Exemplo n.º 23
0
class TestDiveAirDiveOutput2(TestDive):

    def setUp(self):
        TestDive.setUp(self)
        diveseg2 = SegmentDive(20, 30 * 60, self.airtank, 0)
        self.profile2 = Dive([diveseg2], [self.airtank])
        self.profile2.do_dive()

    def test_segment1(self):
        self.assertEqual(str(self.profile2.output_segments[0]),
                         ' DESCENT: at  20m for   1:00 [RT:  1:00], '
                         'on Air,  SP:0.0, END:19m',
                         'bad segment (%s)'
                         % self.profile2.output_segments[0])

    def test_segment2(self):
        self.assertEqual(str(self.profile2.output_segments[1]),
                         '   CONST: at  20m for  29:00 [RT: 30:00], '
                         'on Air,  SP:0.0, END:19m',
                         'bad segment (%s)'
                         % self.profile2.output_segments[1])

    def test_segment3(self):
        self.assertEqual(str(self.profile2.output_segments[2]),
                         '  ASCENT: at   9m for   1:06 [RT: 31:06], '
                         'on Air,  SP:0.0, END:8m',
                         'bad segment (%s)'
                         % self.profile2.output_segments[2])

    def test_segment4(self):
        self.assertEqual(str(self.profile2.output_segments[3]),
                         '    DECO: at   9m for   0:01 [RT: 31:07], '
                         'on Air,  SP:0.0, END:8m',
                         'bad segment (%s)'
                         % self.profile2.output_segments[3])

    def test_segment5(self):
        self.assertEqual(str(self.profile2.output_segments[4]),
                         '    DECO: at   6m for   0:01 [RT: 31:08], '
                         'on Air,  SP:0.0, END:5m',
                         'bad segment (%s)'
                         % self.profile2.output_segments[4])

    def test_segment6(self):
        self.assertEqual(str(self.profile2.output_segments[5]),
                         '    DECO: at   3m for   0:56 [RT: 32:04], '
                         'on Air,  SP:0.0, END:2m',
                         'bad segment (%s)'
                         % self.profile2.output_segments[5])
Exemplo n.º 24
0
    def do_dive(self):
        """do the actual dive.

        self.params is in the form ((depth, time), (depth, time))
        each couple of depth, time is a segment of the same dive.
        """
        if not hasattr(self, 'name'):
            self.name = '%s:%s' % (self.params[0][0], self.params[0][1])

        for param in self.params:
            self.dive_segs.append(
                SegmentDive(param[0], param[1] * 60, self.dive_tank,
                            self.setpoint))
        self.profile1 = Dive(self.dive_segs, self.all_tanks)
        self.profile1.do_dive()
Exemplo n.º 25
0
class TestDiveAirDecoNx8070m10min(TestDive):
    """Test air 70m 10min."""

    params = ((70, 10), )

    def runTest(self):
        """Run one test."""
        try:
            diveseg1 = SegmentDive(self.params[0][0], self.params[0][1] * 60,
                                   self.airdouble, 0)
            self.profile1 = Dive([diveseg1], [self.airdouble])
            self.profile1.do_dive()
        except UnauthorizedMod:
            pass
        else:
            self.fail("should raise UnauthorizedMod")
Exemplo n.º 26
0
class TestDiveAir70m10min(TestDive):
    """Test air 70m 10min."""

    params = ((70, 10), )

    def runTest(self):
        """Run one test."""
        try:
            diveseg1 = SegmentDive(self.params[0][0], self.params[0][1] * 60,
                                   self.airdouble, 0)
            self.profile1 = Dive([diveseg1], [self.airdouble])
            self.profile1.do_dive()
        except UnauthorizedMod:
            pass
        else:
            self.fail("should raise UnauthorizedMod")
Exemplo n.º 27
0
 def setUp(self):
     """Init of the tests."""
     super().setUp()
     diveseg3 = SegmentDive(55, 30 * 60, self.airdouble, 0)
     self.profile1 = Dive([diveseg3], [self.airdouble, self.decoo2,
                                       self.deco2])
     self.profile1.do_dive()
Exemplo n.º 28
0
class TestDiveTxHypo160m10min(TestDive):
    """Test TxHypo 160m 10min."""

    params = ((160, 10), )

    def runTest(self):
        """Run one test."""
        try:
            diveseg1 = SegmentDive(self.params[0][0], self.params[0][1] * 60,
                                   self.txhypo, 0)
            self.profile1 = Dive([diveseg1], [self.txtravel,
                                              self.txhypo, self.deco1])
            self.profile1.do_dive()
        except UnauthorizedMod:
            pass
        else:
            self.fail('should raise UnauthorizedMod')
Exemplo n.º 29
0
 def runTest(self):
     diveseg3 = SegmentDive(55, 30 * 60, self.airdouble, 0)
     self.profile3 = Dive([diveseg3], [self.airdouble, self.deco2,
                          self.decoo2])
     self.profile3.do_dive()
     self.assertEqual(seconds_to_mmss(self.profile3.run_time),
                      ' 70:21', 'bad dive runtime (%s)'
                      % seconds_to_mmss(self.profile3.run_time))
Exemplo n.º 30
0
class TestDiveTxNormoDecoNx8070m10min(TestDive):
    """Test txnormo 70m 10min."""

    params = ((70, 10), )

    def runTest(self):
        """Run one test."""
        try:
            diveseg1 = SegmentDive(self.params[0][0], self.params[0][1] * 60,
                                   self.txtanknormodbl, 0)
            self.profile1 = Dive([diveseg1], [self.txtanknormodbl,
                                              self.deco1])
            self.profile1.do_dive()
        except UnauthorizedMod:
            pass
        else:
            self.fail("should raise UnauthorizedMod")
class TestDiveTxHypo160m10min(TestDive):
    """Test tx hypo 160m 10min."""

    params = ((160, 10),)

    def runTest(self):
        """Should raise an error."""
        try:
            diveseg1 = SegmentDive(self.params[0][0], self.params[0][1] * 60, self.txhypo, 0)
            self.profile1 = Dive(
                [SegmentDive(40, 130, self.txtravel, 0), SegmentDive(40, 30, self.txhypo, 0), diveseg1],
                [self.txtravel, self.txhypo, self.deco1],
            )
            self.profile1.do_dive()
        except UnauthorizedMod:
            pass
        else:
            self.fail("should raise UnauthorizedMod")
Exemplo n.º 32
0
class TestDiveCCAir50m10min(TestDive):
    """Test air 70m 10min."""

    params = ((50, 10),)

    def runTest(self):
        """Run one test."""
        try:
            self.setpoint = 1.2
            self.dive_tank = self.ccair
            self.all_tanks = [self.ccair]
            diveseg1 = SegmentDive(self.params[0][0], self.params[0][1] * 60, self.dive_tank, self.setpoint)
            self.profile1 = Dive([diveseg1], self.all_tanks)
            self.profile1.do_dive()
        except UnauthorizedMod:
            pass
        else:
            self.fail("should raise UnauthorizedMod")
Exemplo n.º 33
0
class TestDiveAirDiveOutput4(TestDive):
    """Test segments output for air dive 4."""

    expected_result = [
        " DESCENT: at  55m for   2:45 [RT:  2:45], on Air,  SP:0.0, END:53m",
        "   CONST: at  55m for  27:15 [RT: 30:00], on Air,  SP:0.0, END:53m",
        "  ASCENT: at  30m for   2:30 [RT: 32:30], on Air,  SP:0.0, END:29m",
        "    DECO: at  30m for   0:01 [RT: 32:31], on Air,  SP:0.0, END:29m",
        "  ASCENT: at  27m for   1:00 [RT: 33:31], on Air,  SP:0.0, END:26m",
        "    DECO: at  27m for   1:11 [RT: 34:42], on Air,  SP:0.0, END:26m",
        "  ASCENT: at  24m for   1:00 [RT: 35:42], on Air,  SP:0.0, END:23m",
        "    DECO: at  24m for   1:27 [RT: 37:09], on Air,  SP:0.0, END:23m",
        "  ASCENT: at  21m for   1:00 [RT: 38:09], on Air,  SP:0.0, END:20m",
        "    DECO: at  21m for   1:35 [RT: 39:44], on Nitrox 50,  SP:0.0, END:20m",
        "  ASCENT: at  18m for   1:00 [RT: 40:44], on Nitrox 50,  SP:0.0, END:17m",
        "    DECO: at  18m for   2:03 [RT: 42:47], on Nitrox 50,  SP:0.0, END:17m",
        "  ASCENT: at  15m for   1:00 [RT: 43:47], on Nitrox 50,  SP:0.0, END:14m",
        "    DECO: at  15m for   2:55 [RT: 46:42], on Nitrox 50,  SP:0.0, END:14m",
        "  ASCENT: at  12m for   1:00 [RT: 47:42], on Nitrox 50,  SP:0.0, END:11m",
        "    DECO: at  12m for   4:13 [RT: 51:55], on Nitrox 50,  SP:0.0, END:11m",
        "  ASCENT: at   9m for   1:00 [RT: 52:55], on Nitrox 50,  SP:0.0, END:8m",
        "    DECO: at   9m for   6:41 [RT: 59:36], on Nitrox 50,  SP:0.0, END:8m",
        "  ASCENT: at   6m for   1:00 [RT: 60:36], on Nitrox 50,  SP:0.0, END:5m",
        "    DECO: at   6m for   7:20 [RT: 67:56], on Oxygen,  SP:0.0, END:5m",
        "  ASCENT: at   3m for   1:00 [RT: 68:56], on Oxygen,  SP:0.0, END:2m",
        "    DECO: at   3m for  12:32 [RT: 81:28], on Oxygen,  SP:0.0, END:2m",
        "  ASCENT: at   0m for   1:00 [RT: 82:28], on Oxygen,  SP:0.0, END:0m", ]

    def setUp(self):
        """Init of the tests."""
        super().setUp()
        diveseg3 = SegmentDive(55, 30 * 60, self.airdouble, 0)
        self.profile1 = Dive([diveseg3], [self.airdouble, self.decoo2,
                                          self.deco2])
        self.profile1.do_dive()

    def test_segments(self):
        """Check all segments."""
        for idx in range(len(self.expected_result)):
            self.assertEqual(
                str(self.profile1.output_segments[idx]),
                self.expected_result[idx],
                'bad segment n°%s (%s)' % (
                    idx, self.profile1.output_segments[idx]))
Exemplo n.º 34
0
class TestDiveAirDiveOutput4(TestDive):
    """Test segments output for air dive 4."""

    expected_result = [
        " DESCENT: at  55m for   2:45 [RT:  2:45], on Air,  SP:0.0, END:53m",
        "   CONST: at  55m for  27:15 [RT: 30:00], on Air,  SP:0.0, END:53m",
        "  ASCENT: at  30m for   2:30 [RT: 32:30], on Air,  SP:0.0, END:29m",
        "    DECO: at  30m for   0:01 [RT: 32:31], on Air,  SP:0.0, END:29m",
        "  ASCENT: at  27m for   1:00 [RT: 33:31], on Air,  SP:0.0, END:26m",
        "    DECO: at  27m for   1:11 [RT: 34:42], on Air,  SP:0.0, END:26m",
        "  ASCENT: at  24m for   1:00 [RT: 35:42], on Air,  SP:0.0, END:23m",
        "    DECO: at  24m for   1:27 [RT: 37:09], on Air,  SP:0.0, END:23m",
        "  ASCENT: at  21m for   1:00 [RT: 38:09], on Air,  SP:0.0, END:20m",
        "    DECO: at  21m for   1:35 [RT: 39:44], on Nitrox 50,  SP:0.0, END:20m",
        "  ASCENT: at  18m for   1:00 [RT: 40:44], on Nitrox 50,  SP:0.0, END:17m",
        "    DECO: at  18m for   2:03 [RT: 42:47], on Nitrox 50,  SP:0.0, END:17m",
        "  ASCENT: at  15m for   1:00 [RT: 43:47], on Nitrox 50,  SP:0.0, END:14m",
        "    DECO: at  15m for   2:55 [RT: 46:42], on Nitrox 50,  SP:0.0, END:14m",
        "  ASCENT: at  12m for   1:00 [RT: 47:42], on Nitrox 50,  SP:0.0, END:11m",
        "    DECO: at  12m for   4:13 [RT: 51:55], on Nitrox 50,  SP:0.0, END:11m",
        "  ASCENT: at   9m for   1:00 [RT: 52:55], on Nitrox 50,  SP:0.0, END:8m",
        "    DECO: at   9m for   6:41 [RT: 59:36], on Nitrox 50,  SP:0.0, END:8m",
        "  ASCENT: at   6m for   1:00 [RT: 60:36], on Nitrox 50,  SP:0.0, END:5m",
        "    DECO: at   6m for   7:20 [RT: 67:56], on Oxygen,  SP:0.0, END:5m",
        "  ASCENT: at   3m for   1:00 [RT: 68:56], on Oxygen,  SP:0.0, END:2m",
        "    DECO: at   3m for  12:32 [RT: 81:28], on Oxygen,  SP:0.0, END:2m",
        "  ASCENT: at   0m for   1:00 [RT: 82:28], on Oxygen,  SP:0.0, END:0m",
    ]

    def setUp(self):
        """Init of the tests."""
        super().setUp()
        diveseg3 = SegmentDive(55, 30 * 60, self.airdouble, 0)
        self.profile1 = Dive([diveseg3],
                             [self.airdouble, self.decoo2, self.deco2])
        self.profile1.do_dive()

    def test_segments(self):
        """Check all segments."""
        for idx in range(len(self.expected_result)):
            self.assertEqual(
                str(self.profile1.output_segments[idx]),
                self.expected_result[idx], 'bad segment n°%s (%s)' %
                (idx, self.profile1.output_segments[idx]))
Exemplo n.º 35
0
class TestDiveAirDiveOutput3(TestDive):
    """Test segments output for air dive 3."""

    expected_result = [
        " DESCENT: at  55m for   2:45 [RT:  2:45], on Air,  SP:0.0, END:53m",
        "   CONST: at  55m for  27:15 [RT: 30:00], on Air,  SP:0.0, END:53m",
        "  ASCENT: at  30m for   2:30 [RT: 32:30], on Air,  SP:0.0, END:29m",
        "    DECO: at  30m for   0:01 [RT: 32:31], on Air,  SP:0.0, END:29m",
        "  ASCENT: at  27m for   1:00 [RT: 33:31], on Air,  SP:0.0, END:26m",
        "    DECO: at  27m for   1:11 [RT: 34:42], on Air,  SP:0.0, END:26m",
        "  ASCENT: at  24m for   1:00 [RT: 35:42], on Air,  SP:0.0, END:23m",
        "    DECO: at  24m for   1:27 [RT: 37:09], on Air,  SP:0.0, END:23m",
        "  ASCENT: at  21m for   1:00 [RT: 38:09], on Air,  SP:0.0, END:20m",
        "    DECO: at  21m for   2:34 [RT: 40:43], on Air,  SP:0.0, END:20m",
        "  ASCENT: at  18m for   1:00 [RT: 41:43], on Air,  SP:0.0, END:17m",
        "    DECO: at  18m for   3:17 [RT: 45:00], on Air,  SP:0.0, END:17m",
        "  ASCENT: at  15m for   1:00 [RT: 46:00], on Air,  SP:0.0, END:14m",
        "    DECO: at  15m for   5:24 [RT: 51:24], on Air,  SP:0.0, END:14m",
        "  ASCENT: at  12m for   1:00 [RT: 52:24], on Air,  SP:0.0, END:11m",
        "    DECO: at  12m for   7:02 [RT: 59:26], on Air,  SP:0.0, END:11m",
        "  ASCENT: at   9m for   1:00 [RT: 60:26], on Air,  SP:0.0, END:8m",
        "    DECO: at   9m for  13:49 [RT: 74:15], on Air,  SP:0.0, END:8m",
        "  ASCENT: at   6m for   1:00 [RT: 75:15], on Air,  SP:0.0, END:5m",
        "    DECO: at   6m for  25:28 [RT:100:43], on Air,  SP:0.0, END:5m",
        "  ASCENT: at   3m for   1:00 [RT:101:43], on Air,  SP:0.0, END:2m",
        "    DECO: at   3m for  52:20 [RT:154:03], on Air,  SP:0.0, END:2m",
        "  ASCENT: at   0m for   1:00 [RT:155:03], on Air,  SP:0.0, END:0m",
    ]

    def setUp(self):
        """Init of the tests."""
        super().setUp()
        diveseg3 = SegmentDive(55, 30 * 60, self.airdouble, 0)
        self.profile1 = Dive([diveseg3], [self.airdouble])
        self.profile1.do_dive()

    def test_segments(self):
        """Check all segments."""
        for idx in range(len(self.expected_result)):
            self.assertEqual(
                str(self.profile1.output_segments[idx]),
                self.expected_result[idx], 'bad segment n°%s (%s)' %
                (idx, self.profile1.output_segments[idx]))
Exemplo n.º 36
0
class TestDiveCCTxHypo110m10min(TestDive):
    """test CC tx hypo 110m 10min."""

    params = ((110, 10), )

    def runTest(self):
        """Should raise and error."""
        try:
            self.setpoint = 1.2
            self.dive_tank = self.cctxhypo
            self.all_tanks = [self.cctxhypo]
            diveseg1 = SegmentDive(self.params[0][0], self.params[0][1] * 60,
                                   self.dive_tank, self.setpoint)
            self.profile1 = Dive([diveseg1], self.all_tanks)
            self.profile1.do_dive()
        except UnauthorizedMod:
            pass
        else:
            self.fail("should raise UnauthorizedMod")
Exemplo n.º 37
0
class TestDiveCCRDiveOutput1(TestDive):
    """Test segments output for ccr dive 1."""

    expected_result = [
        " DESCENT: at  55m for   2:45 [RT:  2:45], on Trimix 21/30,  SP:1.4, END:38m",
        "   CONST: at  55m for  27:15 [RT: 30:00], on Trimix 21/30,  SP:1.4, END:38m",
        "  ASCENT: at  30m for   2:30 [RT: 32:30], on Trimix 21/30,  SP:1.4, END:21m",
        "    DECO: at  30m for   0:01 [RT: 32:31], on Trimix 21/30,  SP:1.4, END:21m",
        "  ASCENT: at  27m for   1:00 [RT: 33:31], on Trimix 21/30,  SP:1.4, END:19m",
        "    DECO: at  27m for   0:31 [RT: 34:02], on Trimix 21/30,  SP:1.4, END:19m",
        "  ASCENT: at  24m for   1:00 [RT: 35:02], on Trimix 21/30,  SP:1.4, END:17m",
        "    DECO: at  24m for   1:02 [RT: 36:04], on Trimix 21/30,  SP:1.4, END:17m",
        "  ASCENT: at  21m for   1:00 [RT: 37:04], on Trimix 21/30,  SP:1.4, END:15m",
        "    DECO: at  21m for   1:26 [RT: 38:30], on Trimix 21/30,  SP:1.4, END:15m",
        "  ASCENT: at  18m for   1:00 [RT: 39:30], on Trimix 21/30,  SP:1.4, END:13m",
        "    DECO: at  18m for   1:55 [RT: 41:25], on Trimix 21/30,  SP:1.4, END:13m",
        "  ASCENT: at  15m for   1:00 [RT: 42:25], on Trimix 21/30,  SP:1.4, END:11m",
        "    DECO: at  15m for   2:21 [RT: 44:46], on Trimix 21/30,  SP:1.4, END:11m",
        "  ASCENT: at  12m for   1:00 [RT: 45:46], on Trimix 21/30,  SP:1.4, END:9m",
        "    DECO: at  12m for   3:21 [RT: 49:07], on Trimix 21/30,  SP:1.4, END:9m",
        "  ASCENT: at   9m for   1:00 [RT: 50:07], on Trimix 21/30,  SP:1.4, END:7m",
        "    DECO: at   9m for   5:15 [RT: 55:22], on Trimix 21/30,  SP:1.4, END:7m",
        "  ASCENT: at   6m for   1:00 [RT: 56:22], on Trimix 21/30,  SP:1.4, END:4m",
        "    DECO: at   6m for   6:44 [RT: 63:06], on Oxygen,  SP:0.0, END:5m",
        "  ASCENT: at   3m for   1:00 [RT: 64:06], on Oxygen,  SP:0.0, END:2m",
        "    DECO: at   3m for  12:26 [RT: 76:32], on Oxygen,  SP:0.0, END:2m",
        "  ASCENT: at   0m for   1:00 [RT: 77:32], on Oxygen,  SP:0.0, END:0m",
    ]

    def setUp(self):
        """Init of the tests."""
        super().setUp()
        diveseg1 = SegmentDive(55, 30 * 60, self.txtank1, 1.4)
        self.profile1 = Dive([diveseg1], [self.txtank1, self.decoo2])
        self.profile1.do_dive()

    def test_segments(self):
        """Check all segments."""
        for idx in range(len(self.expected_result)):
            self.assertEqual(
                str(self.profile1.output_segments[idx]),
                self.expected_result[idx], 'bad segment n°%s (%s)' %
                (idx, self.profile1.output_segments[idx]))
Exemplo n.º 38
0
class TestDiveTxHypo160m10min(TestDive):
    """Test tx hypo 160m 10min."""

    params = ((160, 10), )

    def runTest(self):
        """Should raise an error."""
        try:
            diveseg1 = SegmentDive(self.params[0][0], self.params[0][1] * 60,
                                   self.txhypo, 0)
            self.profile1 = Dive([
                SegmentDive(40, 130, self.txtravel, 0),
                SegmentDive(40, 30, self.txhypo, 0), diveseg1
            ], [self.txtravel, self.txhypo, self.deco1])
            self.profile1.do_dive()
        except UnauthorizedMod:
            pass
        else:
            self.fail('should raise UnauthorizedMod')
Exemplo n.º 39
0
    def setUp(self):
        TestDive.setUp(self)

        diveseg1 = SegmentDive(40, 20 * 60, self.airtank12, 0)
        self.profile0 = Dive([diveseg1], [self.airtank12])
        self.profile0.do_dive()

        diveseg2 = SegmentDive(30, 40 * 60, self.airtank, 0)
        self.profile1 = Dive([diveseg2], [self.airtank], self.profile0)
        self.profile1.do_surface_interval(30 * 60)
        self.profile1.do_dive()

        diveseg3 = SegmentDive(25, 35 * 60, self.airtank, 0)
        self.profile2 = Dive([diveseg3], [self.airtank], self.profile1)
        self.profile2.do_surface_interval(60 * 60)

        # self.profile2.refill_tanks()

        self.profile2.do_dive()
Exemplo n.º 40
0
class TestDiveAirDiveOutput3(TestDive):
    """Test segments output for air dive 3."""

    expected_result = [
        " DESCENT: at  55m for   2:45 [RT:  2:45], on Air,  SP:0.0, END:53m",
        "   CONST: at  55m for  27:15 [RT: 30:00], on Air,  SP:0.0, END:53m",
        "  ASCENT: at  30m for   2:30 [RT: 32:30], on Air,  SP:0.0, END:29m",
        "    DECO: at  30m for   0:01 [RT: 32:31], on Air,  SP:0.0, END:29m",
        "  ASCENT: at  27m for   1:00 [RT: 33:31], on Air,  SP:0.0, END:26m",
        "    DECO: at  27m for   1:11 [RT: 34:42], on Air,  SP:0.0, END:26m",
        "  ASCENT: at  24m for   1:00 [RT: 35:42], on Air,  SP:0.0, END:23m",
        "    DECO: at  24m for   1:27 [RT: 37:09], on Air,  SP:0.0, END:23m",
        "  ASCENT: at  21m for   1:00 [RT: 38:09], on Air,  SP:0.0, END:20m",
        "    DECO: at  21m for   2:34 [RT: 40:43], on Air,  SP:0.0, END:20m",
        "  ASCENT: at  18m for   1:00 [RT: 41:43], on Air,  SP:0.0, END:17m",
        "    DECO: at  18m for   3:17 [RT: 45:00], on Air,  SP:0.0, END:17m",
        "  ASCENT: at  15m for   1:00 [RT: 46:00], on Air,  SP:0.0, END:14m",
        "    DECO: at  15m for   5:24 [RT: 51:24], on Air,  SP:0.0, END:14m",
        "  ASCENT: at  12m for   1:00 [RT: 52:24], on Air,  SP:0.0, END:11m",
        "    DECO: at  12m for   7:02 [RT: 59:26], on Air,  SP:0.0, END:11m",
        "  ASCENT: at   9m for   1:00 [RT: 60:26], on Air,  SP:0.0, END:8m",
        "    DECO: at   9m for  13:49 [RT: 74:15], on Air,  SP:0.0, END:8m",
        "  ASCENT: at   6m for   1:00 [RT: 75:15], on Air,  SP:0.0, END:5m",
        "    DECO: at   6m for  25:28 [RT:100:43], on Air,  SP:0.0, END:5m",
        "  ASCENT: at   3m for   1:00 [RT:101:43], on Air,  SP:0.0, END:2m",
        "    DECO: at   3m for  52:20 [RT:154:03], on Air,  SP:0.0, END:2m",
        "  ASCENT: at   0m for   1:00 [RT:155:03], on Air,  SP:0.0, END:0m", ]

    def setUp(self):
        """Init of the tests."""
        super().setUp()
        diveseg3 = SegmentDive(55, 30 * 60, self.airdouble, 0)
        self.profile1 = Dive([diveseg3], [self.airdouble])
        self.profile1.do_dive()

    def test_segments(self):
        """Check all segments."""
        for idx in range(len(self.expected_result)):
            self.assertEqual(
                str(self.profile1.output_segments[idx]),
                self.expected_result[idx],
                'bad segment n°%s (%s)' % (
                    idx, self.profile1.output_segments[idx]))
Exemplo n.º 41
0
class TestDiveCCRDiveOutput1(TestDive):
    """Test segments output for ccr dive 1."""

    expected_result = [
        " DESCENT: at  55m for   2:45 [RT:  2:45], on Trimix 21/30,  SP:1.4, END:38m",
        "   CONST: at  55m for  27:15 [RT: 30:00], on Trimix 21/30,  SP:1.4, END:38m",
        "  ASCENT: at  30m for   2:30 [RT: 32:30], on Trimix 21/30,  SP:1.4, END:21m",
        "    DECO: at  30m for   0:01 [RT: 32:31], on Trimix 21/30,  SP:1.4, END:21m",
        "  ASCENT: at  27m for   1:00 [RT: 33:31], on Trimix 21/30,  SP:1.4, END:19m",
        "    DECO: at  27m for   0:31 [RT: 34:02], on Trimix 21/30,  SP:1.4, END:19m",
        "  ASCENT: at  24m for   1:00 [RT: 35:02], on Trimix 21/30,  SP:1.4, END:17m",
        "    DECO: at  24m for   1:02 [RT: 36:04], on Trimix 21/30,  SP:1.4, END:17m",
        "  ASCENT: at  21m for   1:00 [RT: 37:04], on Trimix 21/30,  SP:1.4, END:15m",
        "    DECO: at  21m for   1:26 [RT: 38:30], on Trimix 21/30,  SP:1.4, END:15m",
        "  ASCENT: at  18m for   1:00 [RT: 39:30], on Trimix 21/30,  SP:1.4, END:13m",
        "    DECO: at  18m for   1:55 [RT: 41:25], on Trimix 21/30,  SP:1.4, END:13m",
        "  ASCENT: at  15m for   1:00 [RT: 42:25], on Trimix 21/30,  SP:1.4, END:11m",
        "    DECO: at  15m for   2:21 [RT: 44:46], on Trimix 21/30,  SP:1.4, END:11m",
        "  ASCENT: at  12m for   1:00 [RT: 45:46], on Trimix 21/30,  SP:1.4, END:9m",
        "    DECO: at  12m for   3:21 [RT: 49:07], on Trimix 21/30,  SP:1.4, END:9m",
        "  ASCENT: at   9m for   1:00 [RT: 50:07], on Trimix 21/30,  SP:1.4, END:7m",
        "    DECO: at   9m for   5:15 [RT: 55:22], on Trimix 21/30,  SP:1.4, END:7m",
        "  ASCENT: at   6m for   1:00 [RT: 56:22], on Trimix 21/30,  SP:1.4, END:4m",
        "    DECO: at   6m for   6:44 [RT: 63:06], on Oxygen,  SP:0.0, END:5m",
        "  ASCENT: at   3m for   1:00 [RT: 64:06], on Oxygen,  SP:0.0, END:2m",
        "    DECO: at   3m for  12:26 [RT: 76:32], on Oxygen,  SP:0.0, END:2m",
        "  ASCENT: at   0m for   1:00 [RT: 77:32], on Oxygen,  SP:0.0, END:0m", ]

    def setUp(self):
        """Init of the tests."""
        super().setUp()
        diveseg1 = SegmentDive(55, 30 * 60, self.txtank1, 1.4)
        self.profile1 = Dive([diveseg1], [self.txtank1, self.decoo2])
        self.profile1.do_dive()

    def test_segments(self):
        """Check all segments."""
        for idx in range(len(self.expected_result)):
            self.assertEqual(
                str(self.profile1.output_segments[idx]),
                self.expected_result[idx],
                'bad segment n°%s (%s)' % (
                    idx, self.profile1.output_segments[idx]))
Exemplo n.º 42
0
class TestDiveCCTxHypo110m10min(TestDive):
    """test CC tx hypo 110m 10min."""

    params = ((110, 10), )

    def runTest(self):
        """Should raise and error."""
        try:
            self.setpoint = 1.2
            self.dive_tank = self.cctxhypo
            self.all_tanks = [self.cctxhypo]
            diveseg1 = SegmentDive(self.params[0][0], self.params[0][1] * 60,
                                   self.dive_tank, self.setpoint)
            self.profile1 = Dive([diveseg1], self.all_tanks)
            self.profile1.do_dive()
        except UnauthorizedMod:
            pass
        else:
            self.fail("should raise UnauthorizedMod")
Exemplo n.º 43
0
 def runTest(self):
     """Run one test."""
     try:
         diveseg1 = SegmentDive(self.params[0][0], self.params[0][1] * 60,
                                self.txtanknormodbl, 0)
         self.profile1 = Dive([diveseg1], [self.txtanknormodbl,
                                           self.deco1])
         self.profile1.do_dive()
     except UnauthorizedMod:
         pass
     else:
         self.fail("should raise UnauthorizedMod")
Exemplo n.º 44
0
    def do_dive(self):
        """do the actual dive.

        self.params is in the form ((depth, time), (depth, time))
        each couple of depth, time is a segment of the same dive.
        """
        if not hasattr(self, 'name'):
            self.name = '%s:%s' % (self.params[0][0], self.params[0][1])

        for param in self.params:
            self.dive_segs.append(SegmentDive(param[0], param[1] * 60,
                                              self.dive_tank, self.setpoint))
        self.profile1 = Dive(self.dive_segs, self.all_tanks)
        self.profile1.do_dive()
Exemplo n.º 45
0
class TestRepetitiveTxDive1(TestDive):

    def setUp(self):
        TestDive.setUp(self)

        diveseg1 = SegmentDive(55, 20 * 60, self.txtank1, 0)
        self.profile0 = Dive([diveseg1], [self.txtank1])
        self.profile0.do_dive()

        diveseg2 = SegmentDive(50, 20 * 60, self.txtank1, 0)
        self.profile1 = Dive([diveseg2], [self.txtank1], self.profile0)
        self.profile1.do_surface_interval(20 * 60)

        # self.profile1.refill_tanks()

        self.profile1.do_dive()

    def test_rt(self):
        assert seconds_to_mmss(self.profile1.run_time) == '124:44', \
            'bad dive runtime ? (%s)' \
            % seconds_to_mmss(self.profile1.run_time)

    def test_otu(self):
        self.assertAlmostEqual(self.profile1.model.ox_tox.otu,
                               55.5549635111, 7, 'bad dive OTU ? (%s)'
                               % self.profile1.model.ox_tox.otu)

    def test_cns(self):
        self.assertAlmostEqual(self.profile1.model.ox_tox.cns * 100,
                               21.1631708375, 7, 'bad dive CNS ? (%s)'
                               % (self.profile1.model.ox_tox.cns * 100))

    def test_tank_cons(self):
        self.assertAlmostEqual(self.txtank1.used_gas, 4006.7619273, 7,
                               'bad used gas (%s)'
                               % self.txtank1.used_gas)

    def test_tank_cons_rule(self):
        self.assertEqual(self.profile1.tanks[0].check_rule(), True,
                         'Wrong tank status : it should pass the remaining '
                         'gas rule test (result:%s)'
                         % self.profile1.tanks[0].check_rule())

    def test_no_flight(self):
        no_flight_time = self.profile1.no_flight_time()
        self.assertEqual(no_flight_time, 12660, 'Bad no flight time: %s'
                         % no_flight_time)
Exemplo n.º 46
0
def main(cli_arguments=None):
    """Main entry point.

    main uses the parameters, tanks and dives given in config file(s)
    and/or command line, calculates the dives and return the output in stdout.

    :param list cli_arguments: list of arguments, like sys.argv
    """
    if sys.version_info < (3, 4):
        raise SystemExit("ERROR: This programm needs python 3.4 or greater")

    if cli_arguments is None:
        cli_arguments = sys.argv

    activate_debug()

    # get the version
    try:
        version_file = open("RELEASE-VERSION", "r")
        try:
            version = version_file.readlines()[0]
            settings.__VERSION__ = version.strip()
        finally:
            version_file.close()
    except IOError:
        settings.__VERSION__ = "unknown"

    dipplanner_arguments = DipplannerCliArguments(cli_arguments)
    dives = dipplanner_arguments.dives

    profiles = []
    current_dive = None
    previous_dive = None
    for dive in dives:
        if previous_dive is None:
            current_dive = Dive(
                dives[dive]['segments'].values(),
                dives[dive]['tanks'].values())
        else:
            current_dive = Dive(
                dives[dive]['segments'].values(),
                dives[dive]['tanks'].values(),
                previous_dive
            )
        if dives[dive]['surface_interval']:
            current_dive.do_surface_interval(dives[dive]['surface_interval'])

        current_dive.do_dive_without_exceptions()
        profiles.append(current_dive)
        previous_dive = current_dive
        # now, dive exceptins do not stop the program anymore, but can be
        # displayed in the output template instead. The used MUST take care of
        # the result.

    # now calculate no flight time based on the last dive
    ######current_dive.no_flight_time_wo_exception()

    # now Prepare the output
    env = Environment(loader=PackageLoader('dipplanner', 'templates'))
    tpl = env.get_template(settings.TEMPLATE)
    # pylint: disable=no-member
    text = tpl.render(settings=settings, dives=profiles)
    # pylint: enable=no-member
    print(text)
Exemplo n.º 47
0
 def setUp(self):
     TestDive.setUp(self)
     diveseg1 = SegmentDive(30, 30 * 60, self.airtank, 0)
     self.profile1 = Dive([diveseg1], [self.airtank])
     self.profile1.do_dive()
Exemplo n.º 48
0
 def setUp(self):
     """Init of the tests."""
     super().setUp()
     diveseg1 = SegmentDive(30, 30 * 60, self.airtank, 0)
     self.profile1 = Dive([diveseg1], [self.airtank])
     self.profile1.do_dive_without_exceptions()
Exemplo n.º 49
0
 def setUp(self):
     """Init of the tests."""
     super().setUp()
     diveseg1 = SegmentDive(55, 30 * 60, self.txtank1, 1.4)
     self.profile1 = Dive([diveseg1], [self.txtank1, self.decoo2])
     self.profile1.do_dive()
Exemplo n.º 50
0
class TestDive(unittest.TestCase):
    """Generic Test Dive class."""

    params = ((0, 0), )

    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 = []

    def do_dive(self):
        """do the actual dive.

        self.params is in the form ((depth, time), (depth, time))
        each couple of depth, time is a segment of the same dive.
        """
        if not hasattr(self, 'name'):
            self.name = '%s:%s' % (self.params[0][0], self.params[0][1])

        for param in self.params:
            self.dive_segs.append(
                SegmentDive(param[0], param[1] * 60, self.dive_tank,
                            self.setpoint))
        self.profile1 = Dive(self.dive_segs, self.all_tanks)
        self.profile1.do_dive()
        # self.write_details()

    def do_repetitive_dive(self):
        """do the actual dive.

        self.params is in the form:
            ((depth, time, interval), (depth, time, interval))
        each couple of depth, time, interval is a full dive at the given depth
        interval is done before the dive.
        """
        if not hasattr(self, 'name'):
            self.name = '%s:%s' % (self.params[0][0], self.params[0][1])
        self.profiles = []  # repetive dive profiles.
        for param in self.params:
            if len(self.profiles) > 0:
                self.profiles.append(
                    Dive([
                        SegmentDive(param[0], param[1] * 60, self.dive_tank,
                                    self.setpoint)
                    ], self.all_tanks, self.profiles[-1]))
                self.profiles[-1].do_surface_interval(param[2] * 60)
            else:
                self.profiles.append(
                    Dive([
                        SegmentDive(param[0], param[1] * 60, self.dive_tank,
                                    self.setpoint)
                    ], self.all_tanks))
            self.profiles[-1].do_dive()

        self.profile1 = self.profiles[-1]  # save last dive
        # self.write_details()

    def tearDown(self):
        """After tests."""
        # settings.SURFACE_TEMP = 20
        settings.RUN_TIME = True

    @property
    def details(self):
        """Output details of the dive.

        :returns: string
        :rtype: str
        """
        return '"%s": ["%s", %f, %f, %d, %d, %f, %s], ' % (
            self.name, seconds_to_mmss(self.profile1.run_time),
            self.profile1.model.ox_tox.otu, self.profile1.model.ox_tox.cns *
            100, self.profile1.no_flight_time(),
            self.profile1.full_desat_time(), self.profile1.tanks[0].used_gas,
            str(self.profile1.tanks[0].check_rule()).lower())

    def print_details(self):
        """print detailed results."""
        print(self.details)

    def write_details(self):
        """write in /tmp/details.txt the detailed results."""
        with open('/tmp/details.txt', 'a') as myfile:
            myfile.write(self.details + '\n')
Exemplo n.º 51
0
 def setUp(self):
     """Init of the tests."""
     super().setUp()
     diveseg2 = SegmentDive(20, 30 * 60, self.airtank, 0)
     self.profile1 = Dive([diveseg2], [self.airtank])
     self.profile1.do_dive()