You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
console.warn(`[PatternSpotter] AI narration failed for rank ${idx+1}, using template: ${(errasError).message}`);
1063
-
// Fall through to template below
1064
-
title='';
1065
-
}
1066
-
}else{
1067
-
title='';// Will be set by template
1068
-
}
1069
1010
1070
-
// Template fallback (used when AI wasn't attempted or failed)
1071
-
if(!title){
1072
-
if(candidate.type==='trend'){
1073
-
title=`Your ${candidate.metric_label} appears to be ${candidate.direction}`;
1074
-
summary=`Over the past ${candidate.weeks_observed} weeks, your ${candidate.metric_label} has ${candidate.direction==='increasing' ? 'increased' : 'decreased'} by ${Math.abs(candidate.change_pct).toFixed(1)}%.`;
1075
-
}elseif(candidate.type==='lagged_effect'){
1076
-
title=`${candidate.segment_label} linked to next-day ${candidate.metric_label}`;
1077
-
summary=`${candidate.segment_label}, your ${candidate.metric_label} the following day tends to be ${Math.abs(candidate.change_pct).toFixed(1)}% ${direction}.`;
title=`Your ${candidate.metric_label} is consistently ${direction==='higher' ? 'higher' : 'lower'} in the ${candidate.segment_label}`;
1080
-
summary=`Your ${candidate.metric_label} during ${candidate.segment_label} is ${Math.abs(candidate.change_pct).toFixed(1)}% ${direction} than your overall average.`;
1081
-
}elseif(candidate.type==='excursion_cluster'){
1082
-
title=`Your ${candidate.metric_label} excursions cluster in the ${candidate.segment_label}`;
1083
-
summary=`Out-of-range ${candidate.metric_label} events tend to occur during ${candidate.segment_label}, significantly more than expected if evenly distributed.`;
summary=`Your ${candidate.metric_label}${changeDir} by ${Math.abs(candidate.change_pct).toFixed(1)}% ${candidate.segment_label}, observed consistently across the analysis period.`;
1088
-
}elseif(candidate.type==='stability_trend'){
1089
-
conststabilityDir=candidate.change_pct<0 ? 'stabilizing' : 'becoming more variable';
1090
-
title=`Your ${candidate.metric_label} is ${stabilityDir}`;
1091
-
summary=`The variability of your ${candidate.metric_label} has ${candidate.change_pct<0 ? 'decreased' : 'increased'} by ${Math.abs(candidate.change_pct).toFixed(1)}% over the analysis period.`;
1092
-
}else{
1093
-
title=`${candidate.segment_label} linked to ${candidate.metric_label}`;
1094
-
summary=`${candidate.segment_label} is associated with ${Math.abs(candidate.change_pct).toFixed(1)}% ${direction}${candidate.metric_label} (p=${candidate.p_value.toFixed(3)}, d=${candidate.effect_size.toFixed(2)}).`;
1095
-
}
1011
+
if(candidate.type==='trend'){
1012
+
title=`Your ${candidate.metric_label} appears to be ${candidate.direction}`;
1013
+
summary=`Over the past ${candidate.weeks_observed} weeks, your ${candidate.metric_label} has ${candidate.direction==='increasing' ? 'increased' : 'decreased'} by ${Math.abs(candidate.change_pct).toFixed(1)}%.`;
1014
+
}elseif(candidate.type==='lagged_effect'){
1015
+
title=`${candidate.segment_label} linked to next-day ${candidate.metric_label}`;
1016
+
summary=`${candidate.segment_label}, your ${candidate.metric_label} the following day tends to be ${Math.abs(candidate.change_pct).toFixed(1)}% ${direction}.`;
title=`Your ${candidate.metric_label} is consistently ${direction==='higher' ? 'higher' : 'lower'} in the ${candidate.segment_label}`;
1019
+
summary=`Your ${candidate.metric_label} during ${candidate.segment_label} is ${Math.abs(candidate.change_pct).toFixed(1)}% ${direction} than your overall average.`;
1020
+
}elseif(candidate.type==='excursion_cluster'){
1021
+
title=`Your ${candidate.metric_label} excursions cluster in the ${candidate.segment_label}`;
1022
+
summary=`Out-of-range ${candidate.metric_label} events tend to occur during ${candidate.segment_label}, significantly more than expected if evenly distributed.`;
summary=`Your ${candidate.metric_label}${changeDir} by ${Math.abs(candidate.change_pct).toFixed(1)}% ${candidate.segment_label}, observed consistently across the analysis period.`;
1027
+
}elseif(candidate.type==='stability_trend'){
1028
+
conststabilityDir=candidate.change_pct<0 ? 'stabilizing' : 'becoming more variable';
1029
+
title=`Your ${candidate.metric_label} is ${stabilityDir}`;
1030
+
summary=`The variability of your ${candidate.metric_label} has ${candidate.change_pct<0 ? 'decreased' : 'increased'} by ${Math.abs(candidate.change_pct).toFixed(1)}% over the analysis period.`;
1031
+
}else{
1032
+
title=`${candidate.segment_label} linked to ${candidate.metric_label}`;
1033
+
summary=`${candidate.segment_label} is associated with ${Math.abs(candidate.change_pct).toFixed(1)}% ${direction}${candidate.metric_label} (p=${candidate.p_value.toFixed(3)}, d=${candidate.effect_size.toFixed(2)}).`;
1096
1034
}
1097
1035
1098
1036
newPatterns.push({
@@ -1101,20 +1039,17 @@ export async function spotPatterns(
0 commit comments