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
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)
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 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())
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")
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')
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")
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()
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 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 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()