def _strTask(self, todo, indent=""): sessionTime = todo.x_kde_ktimetracker_totalsessiontime or '0' totalTime = todo.x_kde_ktimetracker_totaltasktime or '0' out = '%s%s [%s] (%s, total:%s)\n' % (indent, todo.summary, todo.uid, prettyTime(int(sessionTime)), prettyTime(int(totalTime))) # loop through the children recursively for todo in todo.todos.values(): out += self._strTask(todo, '%s ' % indent) return out
def main(**kwargs): defaults = { "time": 30, "difficulty": 1, "initial_move": "child", "warmup": True, "cooldown": True, "aerobics": 0, "strength": 0, "target": "plank", "verbose":1, "memory":5, "outfile": None, } defaults.update(kwargs) if defaults["outfile"]: f = open(defaults["outfile"], "a") f.write(str(datetime.datetime.now()) + "\n") f.write(str(defaults) + "\n") else: f = None utils.speak('Beginning in') utils.countdown(3) if defaults["verbose"] >= 2: print(utils.wrapper.fill(str(defaults))) elif defaults["verbose"] >= 1: print("Workout length:", defaults['time'], "minutes.", "Beginning in:") # setup total_time = defaults['time']*60 movesGraph = moves.generateMoves(difficulty=defaults["difficulty"]) stretches.defineStretches(movesGraph, difficulty=defaults["difficulty"]) start = time.time() end = start + total_time class Times(Enum): warmup_end = start + min(max(45,total_time//15),300) halfway = start + total_time//2.4 - 30 cooldown_begin = (end - max(60, total_time//5)) if defaults['cooldown'] else end imbalance = [] prev = collections.deque([],defaults["memory"]) try: pose = movesGraph[defaults['initial_move']] except KeyError: pose = movesGraph['child'] try: #warmup if defaults["warmup"]: pose = pose(time=min(30,max(15, total_time//120+7)), imbalance=imbalance, prev=prev, verbose=defaults["verbose"], f=f) while time.time() < Times.warmup_end.value: pose = pose(imbalance=imbalance, extended=True, early=True, prev=prev, verbose=defaults["verbose"], f=f) #start slower #get me to my target: moves.linkMain(movesGraph, defaults['difficulty']) if defaults['aerobics']: strengthaerobics.linkAerobics(movesGraph, defaults["difficulty"], defaults["aerobics"]) if defaults['strength']: strengthaerobics.linkStrength(movesGraph, defaults["difficulty"], defaults["strength"]) if defaults['aerobics']: strengthaerobics.linkStrengthAerobics(movesGraph, defaults["difficulty"], defaults["strength"], defaults["aerobics"]) if defaults['warmup']: pose = fixImbalance(pose, imbalance, maxTime=max(45,total_time//12.5), prev=prev, verbose=defaults['verbose'], f=f) imbalance = moves.unlinkWarmup(movesGraph, imbalance=imbalance, difficulty=defaults["difficulty"]) try: target = movesGraph[defaults['target']] except KeyError: target = movesGraph['plank'] pose = get_me_to(pose, target, imbalance=imbalance, playLast=False, prev=prev, verbose=defaults["verbose"], f=f) if defaults["warmup"]: utils.tee("Warmup Over: " + utils.prettyTime(time.time() - start), f, say="Alright, warmup over.") pose = pose(imbalance=imbalance, prev=prev, verbose=defaults["verbose"], f=f) #starting main part of workout while time.time() < Times.halfway.value: pose = fixImbalance(pose, imbalance, maxImbalance=10 + total_time//600, maxTime=max(60,total_time//12), prev=prev, verbose=defaults["verbose"], f=f) pose = pose(imbalance=imbalance, prev=prev, verbose=defaults["verbose"], f=f) #add harder poses in here if defaults["difficulty"] >= 1: moves.linkHarder(movesGraph, defaults["difficulty"]) if defaults["strength"]: strengthaerobics.linkStrengthHarder(movesGraph, defaults["difficulty"], defaults["strength"]) pose = fixImbalance(pose, imbalance, maxTime=max(60, total_time//10), prev=prev, verbose=defaults["verbose"], f=f) try: pose = get_me_to(pose, movesGraph[defaults['target']], imbalance=imbalance, prev=prev, verbose=defaults["verbose"], f=f) except KeyError: pass if defaults["verbose"] >= 1: utils.tee("Halfway point: " + utils.prettyTime(time.time()-start), f, say="We have reached the halway point") #end adding harder poses harder = defaults["difficulty"] >= 1 while time.time() < Times.cooldown_begin.value: extendedChance = (time.time() - start)/total_time extended = random.random() < extendedChance pose = fixImbalance(pose, imbalance, maxImbalance=8+total_time//800, maxTime=max(110,total_time//10), prev=prev, verbose=defaults["verbose"], \ f=f, harder=harder) pose = pose(harder=harder, imbalance = imbalance, extended=extended, prev=prev, verbose=defaults["verbose"], f=f) moves.linkEnding(movesGraph) while time.time() < (end - max(60, total_time//10)): pose = fixImbalance(pose, imbalance, maxImbalance=max(1,total_time//800), maxTime=max(120, total_time//8), prev=prev, verbose=defaults["verbose"], f=f) pose = pose(imbalance = imbalance, prev=prev, verbose=defaults["verbose"], f=f) if defaults["cooldown"]: pose = fixImbalance(pose, imbalance, maxImbalance=1, maxTime=max(75, total_time//10+15), prev=prev, verbose=defaults["verbose"], f=f) utils.tee("Cooldown begins: " + utils.prettyTime(time.time() - start), f, say="Cooldown begins") stretches.linkCooldown(movesGraph, difficulty=defaults["difficulty"]) if defaults["strength"]: strengthaerobics.linkStrengthCooldown(movesGraph,difficulty=defaults["difficulty"], strength = defaults["strength"]) if defaults["aerobics"]: strengthaerobics.linkAerobicsCooldown(movesGraph,difficulty=defaults["difficulty"], aerobics = defaults["aerobics"]) pose = get_me_to(pose, movesGraph['wheel'], imbalance=imbalance, prev=prev, verbose=defaults['verbose'], f=f) pose = fixImbalance(pose, imbalance, maxImbalance=1, maxTime=max(60, total_time//10), prev=prev, verbose=defaults['verbose'], f=f) while time.time() < (end-max(30, total_time//10)) if defaults["cooldown"] else end: #pose = pose(imbalance=imbalance, extended=True, prev=prev, verbose=defaults['verbose'], f=f) pose = fixImbalance(pose, imbalance, maxImbalance=1, maxTime=max(30, total_time//10), prev=prev, verbose=defaults['verbose'], f=f) if defaults['cooldown']: moves.linkSavasana(movesGraph, difficulty=defaults['difficulty']) pose = fixImbalance(pose, imbalance, maxImbalance=1, maxTime=max(30, total_time//10), prev=prev, verbose=defaults['verbose'], f=f) pose = get_me_to(pose, movesGraph['savasana'], imbalance=imbalance, prev=prev, verbose=defaults['verbose'], f=f) except (KeyboardInterrupt, BrokenPipeError): moves.linkSavasana(movesGraph, difficulty=defaults['difficulty']) pose = get_me_to(pose, movesGraph['savasana'], imbalance=imbalance, prev=prev, verbose=defaults['verbose'], f=f) finally: final_time = utils.prettyTime(time.time() - start) utils.tee('\nTotal Time: %s' % final_time, f=f, say='Done! Total time was %s' % final_time.replace('(','').replace(')','')) if f: f.close() sys.stdout.write(colorama.Style.RESET_ALL) print(utils.wrapper.fill(str(imbalance))) return imbalance