From 974699dd81837248b9a1c34e1f7a30cab4192b13 Mon Sep 17 00:00:00 2001 From: bolade Date: Fri, 21 Nov 2025 14:20:15 +0100 Subject: [PATCH] sighh --- .../context_generator.cpython-312.pyc | Bin 46085 -> 46089 bytes .../graph_generator.cpython-312.pyc | Bin 57999 -> 57999 bytes app/services/context_generator.py | 34 ++++++++++++------ 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/app/services/__pycache__/context_generator.cpython-312.pyc b/app/services/__pycache__/context_generator.cpython-312.pyc index 2fc12bcedf82be2d9aaca30d2af9711456df108e..2e8fc75b5a9b5c035970589f4a254c752b46c042 100644 GIT binary patch delta 161 zcmZpD!PNPJiT5-wFBbz4)Tb$A_HX3fTF7{D^Wj2YX7vYR(sP^_a9@_uxgf2(BI<&L z_X)>~7Je7Z{V#|Fd}L-2l>WfMAgeRkxYU`60Fgz) HKoB#=?^u`o6l_0W8}{eWt8~D03wTofvy1n D-D5WI diff --git a/app/services/__pycache__/graph_generator.cpython-312.pyc b/app/services/__pycache__/graph_generator.cpython-312.pyc index b61675b59930110003f559f1da004c2e085c974d..480e77bb7407ec08e48422ce5a8a4d7d660b4058 100644 GIT binary patch delta 24 ecmeA_%G`gHnfEj=FBbz4u%; Tuple[Optional[Dict], Optional[Dict]]: - """Detect VT1 and VT2 thresholds""" + """Detect VT1 and VT2 thresholds (matching notebook logic)""" + # VT1: First index where carb burn > fat burn AND remains higher condition = self.pnoe_df["CHO_smoothed"] > self.pnoe_df["FAT_smoothed"] crossover_indices = condition[condition].index vt1 = None if len(crossover_indices) > 0: - vt1_idx = crossover_indices[0] - vt1_row = self.pnoe_df.loc[vt1_idx] - vt1 = { - "HeartRate": vt1_row["HR(bpm)_smoothed"], - "Speed": vt1_row["Speed"], - "Time": vt1_row["T(sec)"], - } + # Find first crossover where carbs remain higher for the rest + for idx in crossover_indices: + if all( + self.pnoe_df.loc[idx:]["CHO_smoothed"] + > self.pnoe_df.loc[idx:]["FAT_smoothed"] + ): + vt1_idx = idx + vt1_row = self.pnoe_df.loc[vt1_idx] + vt1 = { + "HeartRate": vt1_row["HR(bpm)_smoothed"], + "Speed": vt1_row["Speed"], + "Time": vt1_row["T(sec)"], + } + break ve_slope = self.pnoe_df["VE(l/min)_smoothed"].diff() second_derivative = ve_slope.diff() @@ -745,9 +753,13 @@ class ContextGenerator: """Calculate detailed metrics for each heart rate zone based on actual data""" import math - # Get zone boundaries - fat_max_idx = self.pnoe_df["FAT_smoothed"].idxmax() - optimal_row = self.pnoe_df.loc[fat_max_idx] + # Get zone boundaries - use optimal fat burning zone (highest fat:carb ratio) + # matching notebook logic + self.pnoe_df["fat_carb_ratio"] = self.pnoe_df["FAT_smoothed"] / ( + self.pnoe_df["CHO_smoothed"] + 0.00000001 + ) + optimal_fat_idx = self.pnoe_df["fat_carb_ratio"].idxmax() + optimal_row = self.pnoe_df.loc[optimal_fat_idx] # Detect VT1 and VT2 vt1 = pnoe_metrics.get("vt1")