mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 12:25:22 +02:00
fix(dataProcessor): improve regex parsing for week number in Ads and Traffic CSV/Excel import
This commit is contained in:
@@ -460,7 +460,8 @@ export const processAdsCSV = (file: File): Promise<AdsRecord[]> => {
|
|||||||
|
|
||||||
if (!asin || !countryRaw || weekRaw === undefined || weekRaw === '') continue;
|
if (!asin || !countryRaw || weekRaw === undefined || weekRaw === '') continue;
|
||||||
|
|
||||||
const weekNum = parseInt(String(weekRaw));
|
const weekMatch = String(weekRaw).match(/\d+/);
|
||||||
|
const weekNum = weekMatch ? parseInt(weekMatch[0], 10) : NaN;
|
||||||
if (isNaN(weekNum) || weekNum < 1 || weekNum > 53) continue;
|
if (isNaN(weekNum) || weekNum < 1 || weekNum > 53) continue;
|
||||||
|
|
||||||
// For CSV without sheet names, assume current year
|
// For CSV without sheet names, assume current year
|
||||||
@@ -540,7 +541,8 @@ export const processAdsExcel = async (fileOrBuffer: File | ArrayBuffer): Promise
|
|||||||
// Skip if missing essential data
|
// Skip if missing essential data
|
||||||
if (!asin || !countryRaw || weekRaw === undefined || weekRaw === '') continue;
|
if (!asin || !countryRaw || weekRaw === undefined || weekRaw === '') continue;
|
||||||
|
|
||||||
const weekNum = parseInt(String(weekRaw));
|
const weekMatch = String(weekRaw).match(/\d+/);
|
||||||
|
const weekNum = weekMatch ? parseInt(weekMatch[0], 10) : NaN;
|
||||||
if (isNaN(weekNum) || weekNum < 1 || weekNum > 53) continue;
|
if (isNaN(weekNum) || weekNum < 1 || weekNum > 53) continue;
|
||||||
|
|
||||||
// Log first parsed row per sheet for column match diagnosis
|
// Log first parsed row per sheet for column match diagnosis
|
||||||
@@ -632,7 +634,8 @@ export const processTrafficExcel = async (fileOrBuffer: File | ArrayBuffer): Pro
|
|||||||
if (!asin || yearRaw === undefined || weekRaw === undefined || !countryRaw) continue;
|
if (!asin || yearRaw === undefined || weekRaw === undefined || !countryRaw) continue;
|
||||||
|
|
||||||
const year = typeof yearRaw === 'number' ? yearRaw : parseInt(String(yearRaw));
|
const year = typeof yearRaw === 'number' ? yearRaw : parseInt(String(yearRaw));
|
||||||
const weekNum = parseInt(String(weekRaw));
|
const weekMatch = String(weekRaw).match(/\d+/);
|
||||||
|
const weekNum = weekMatch ? parseInt(weekMatch[0], 10) : NaN;
|
||||||
if (isNaN(year) || year < 2020 || year > 2100) continue;
|
if (isNaN(year) || year < 2020 || year > 2100) continue;
|
||||||
if (isNaN(weekNum) || weekNum < 1 || weekNum > 53) continue;
|
if (isNaN(weekNum) || weekNum < 1 || weekNum > 53) continue;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user