def getImmuneMaintenance(self): logger = logging.getLogger(__name__) p_set = self.session_day.session.parameterset return calc_maintenance(p_set.immune_parameter_1, p_set.immune_parameter_2, p_set.immune_parameter_3, self.immune_activity, self.immune_activity, 240)
def getHeartMaintenance(self): logger = logging.getLogger(__name__) p_set = self.session_day.session.parameterset return calc_maintenance(p_set.heart_parameter_1, p_set.heart_parameter_2, p_set.heart_parameter_3, self.heart_activity, self.heart_activity, 15)
def test_calc_maintenance(self): ''' test the maintainence calculations ''' #wolfram alpha #solve y = a * x + 0.5 * (1 + x) * (1 - a * x) * ((z/n)^b / (c + (z/n)^b)), a=0.6, b=3, c=6, x=0.6, z=30, n=15 self.assertEqual(0.65, calc_activity(30/15, 0.6, 3, 6, 0.6, True)) self.assertEqual(1.0, calc_activity(300/15, 0.6, 3, 6, 1.0, True)) self.assertEqual(0.5, calc_activity(0/15, 0.5, 3, 6, 0.99, True)) self.assertEqual(0.89, calc_activity(480/240, 0.2, 4, 2.5, 1, True)) self.assertEqual(0.73, calc_activity(480/240, 0.2, 4, 2.5, 0.6, True)) #wolfram alpha #x = 2 ^(1/b) * n * ((a*c*y - c*z)/(a * y^2 - a * y - y + 2 * z - 1))^(1/b), a = 0.5, b=3,c=6, y=0.99,z=0.99 self.assertEqual(30, math.ceil(calc_maintenance(0.6, 3, 6, 0.6, 0.65, 15))) self.assertEqual(55, math.ceil(calc_maintenance(0.5, 3, 6, 0.5, 0.75, 15))) self.assertEqual(111, math.ceil(calc_maintenance(0.5, 3, 6, 0.99, 0.99, 15))) self.assertEqual(140, math.ceil(calc_maintenance(0.5, 3, 6, 1, 1, 15)))
def getTodaysHeartImprovmentMinutes(self): logger = logging.getLogger(__name__) #check that not maxed out if self.heart_activity >= 1.0: logger.info('getTodaysHeartImprovmentMinutes already at max') return { "target_activity": '--', "target_minutes": '--', "target_bpm": '--' } p_set = self.session_day.session.parameterset max_activity = self.calcHeartActivity(1440, self.heart_activity, True) target_activity = (float(self.heart_activity) + max_activity) / 2 target_activity = round_half_away_from_zero(target_activity, 2) target_minutes = calc_maintenance(p_set.heart_parameter_1, p_set.heart_parameter_2, p_set.heart_parameter_3, self.heart_activity, target_activity, 15) logger.info( f'getTodaysHeartImprovmentMinutes heart_activity {self.heart_activity} max_activity {max_activity} target_activity {target_activity} target_minutes {target_minutes}' ) target_minutes = math.ceil(target_minutes) if self.session_day.session.treatment == "I": target_activity = int(target_activity * 100) else: target_activity = f'{target_activity:0.2f}' return { "target_activity": f'{target_activity}', "target_minutes": f' {target_minutes}mins', "target_bpm": f'{self.fitbit_min_heart_rate_zone_bpm}bpm' }
def getTodaysImmuneImprovmentHours(self): logger = logging.getLogger(__name__) p_set = self.session_day.session.parameterset #check that not maxed out if self.immune_activity >= 1.0: logger.info('getTodaysHeartImprovmentMinutes already at max') return {"target_activity": '--', "target_hours": '--'} max_activity = self.calcImmuneActivity(1440, self.immune_activity, True) target_activity = (float(self.immune_activity) + max_activity) / 2 target_activity = round_half_away_from_zero(target_activity, 2) target_minutes = calc_maintenance(p_set.immune_parameter_1, p_set.immune_parameter_2, p_set.immune_parameter_3, self.immune_activity, target_activity, 240) logger.info( f'getTodaysimmuneImprovmentMinutes immune_activity {self.immune_activity} max_activity {max_activity} target_activity {target_activity} target_minutes {target_minutes}' ) target_minutes = math.ceil(target_minutes) if self.session_day.session.treatment == "I": target_activity = int(target_activity * 100) else: target_activity = f'{target_activity:0.2f}' return { "target_activity": f'{target_activity}', "target_hours": f'{math.floor(target_minutes/60)}hrs {target_minutes%60}mins' }