Spaces:
Running
Running
fix thousands parsing
Browse files- src/utils/csvParser.ts +6 -6
src/utils/csvParser.ts
CHANGED
|
@@ -77,7 +77,7 @@ export function parseCSV(file: File, userFTP: number = 343, thresholdHR: number
|
|
| 77 |
// First, check if TSS is already provided in CSV
|
| 78 |
const tssStr = row['Training Stress Score®'] || row['Training Stress Score'] || row['TSS'];
|
| 79 |
if (tssStr && tssStr !== '--' && tssStr !== '0.0' && tssStr !== '0') {
|
| 80 |
-
const parsed = parseFloat(tssStr);
|
| 81 |
if (!isNaN(parsed) && parsed > 0) {
|
| 82 |
trainingStressScore = parsed;
|
| 83 |
}
|
|
@@ -91,7 +91,7 @@ export function parseCSV(file: File, userFTP: number = 343, thresholdHR: number
|
|
| 91 |
if (npKey) {
|
| 92 |
const npStr = row[npKey];
|
| 93 |
if (npStr && npStr !== '--' && npStr !== '0.0' && npStr !== '0') {
|
| 94 |
-
normalizedPower = parseFloat(npStr);
|
| 95 |
if (isNaN(normalizedPower) || normalizedPower <= 0) {
|
| 96 |
normalizedPower = undefined;
|
| 97 |
}
|
|
@@ -100,7 +100,7 @@ export function parseCSV(file: File, userFTP: number = 343, thresholdHR: number
|
|
| 100 |
|
| 101 |
// Use FTP from CSV if available, otherwise use user-provided FTP
|
| 102 |
const ftpStr = row['FTP'] || row['Functional Threshold Power'];
|
| 103 |
-
const ftp = ftpStr && ftpStr !== '--' ? parseFloat(ftpStr) : userFTP;
|
| 104 |
|
| 105 |
if (normalizedPower && normalizedPower > 0 && ftp && ftp > 0) {
|
| 106 |
const calculatedTSS = calculateTSS({
|
|
@@ -124,7 +124,7 @@ export function parseCSV(file: File, userFTP: number = 343, thresholdHR: number
|
|
| 124 |
let averageHR: number | undefined;
|
| 125 |
const avgHRStr = row['Avg HR'] || row['Average HR'] || row['Average Heart Rate'];
|
| 126 |
if (avgHRStr && avgHRStr !== '--') {
|
| 127 |
-
const parsed = parseFloat(avgHRStr);
|
| 128 |
if (!isNaN(parsed) && parsed > 0) {
|
| 129 |
averageHR = parsed;
|
| 130 |
}
|
|
@@ -133,7 +133,7 @@ export function parseCSV(file: File, userFTP: number = 343, thresholdHR: number
|
|
| 133 |
let maxHR: number | undefined;
|
| 134 |
const maxHRStr = row['Max HR'] || row['Maximum HR'] || row['Max Heart Rate'];
|
| 135 |
if (maxHRStr && maxHRStr !== '--') {
|
| 136 |
-
const parsed = parseFloat(maxHRStr);
|
| 137 |
if (!isNaN(parsed) && parsed > 0) {
|
| 138 |
maxHR = parsed;
|
| 139 |
}
|
|
@@ -164,7 +164,7 @@ export function parseCSV(file: File, userFTP: number = 343, thresholdHR: number
|
|
| 164 |
const caloriesStr = row['Calories'];
|
| 165 |
let calories: number | undefined;
|
| 166 |
if (caloriesStr && caloriesStr !== '--') {
|
| 167 |
-
const parsed = parseFloat(caloriesStr);
|
| 168 |
if (!isNaN(parsed) && parsed > 0) {
|
| 169 |
calories = parsed;
|
| 170 |
}
|
|
|
|
| 77 |
// First, check if TSS is already provided in CSV
|
| 78 |
const tssStr = row['Training Stress Score®'] || row['Training Stress Score'] || row['TSS'];
|
| 79 |
if (tssStr && tssStr !== '--' && tssStr !== '0.0' && tssStr !== '0') {
|
| 80 |
+
const parsed = parseFloat(tssStr.replace(/,/g, ''));
|
| 81 |
if (!isNaN(parsed) && parsed > 0) {
|
| 82 |
trainingStressScore = parsed;
|
| 83 |
}
|
|
|
|
| 91 |
if (npKey) {
|
| 92 |
const npStr = row[npKey];
|
| 93 |
if (npStr && npStr !== '--' && npStr !== '0.0' && npStr !== '0') {
|
| 94 |
+
normalizedPower = parseFloat(npStr.replace(/,/g, ''));
|
| 95 |
if (isNaN(normalizedPower) || normalizedPower <= 0) {
|
| 96 |
normalizedPower = undefined;
|
| 97 |
}
|
|
|
|
| 100 |
|
| 101 |
// Use FTP from CSV if available, otherwise use user-provided FTP
|
| 102 |
const ftpStr = row['FTP'] || row['Functional Threshold Power'];
|
| 103 |
+
const ftp = ftpStr && ftpStr !== '--' ? parseFloat(ftpStr.replace(/,/g, '')) : userFTP;
|
| 104 |
|
| 105 |
if (normalizedPower && normalizedPower > 0 && ftp && ftp > 0) {
|
| 106 |
const calculatedTSS = calculateTSS({
|
|
|
|
| 124 |
let averageHR: number | undefined;
|
| 125 |
const avgHRStr = row['Avg HR'] || row['Average HR'] || row['Average Heart Rate'];
|
| 126 |
if (avgHRStr && avgHRStr !== '--') {
|
| 127 |
+
const parsed = parseFloat(avgHRStr.replace(/,/g, ''));
|
| 128 |
if (!isNaN(parsed) && parsed > 0) {
|
| 129 |
averageHR = parsed;
|
| 130 |
}
|
|
|
|
| 133 |
let maxHR: number | undefined;
|
| 134 |
const maxHRStr = row['Max HR'] || row['Maximum HR'] || row['Max Heart Rate'];
|
| 135 |
if (maxHRStr && maxHRStr !== '--') {
|
| 136 |
+
const parsed = parseFloat(maxHRStr.replace(/,/g, ''));
|
| 137 |
if (!isNaN(parsed) && parsed > 0) {
|
| 138 |
maxHR = parsed;
|
| 139 |
}
|
|
|
|
| 164 |
const caloriesStr = row['Calories'];
|
| 165 |
let calories: number | undefined;
|
| 166 |
if (caloriesStr && caloriesStr !== '--') {
|
| 167 |
+
const parsed = parseFloat(caloriesStr.replace(/,/g, ''));
|
| 168 |
if (!isNaN(parsed) && parsed > 0) {
|
| 169 |
calories = parsed;
|
| 170 |
}
|