@smartnet360/svelte-components 0.0.47 → 0.0.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -19,7 +19,52 @@ export async function loadCellTrafficData() {
|
|
|
19
19
|
throw new Error(`Failed to load CSV: ${response.statusText}`);
|
|
20
20
|
}
|
|
21
21
|
const text = await response.text();
|
|
22
|
-
|
|
22
|
+
const records = parseCsvData(text);
|
|
23
|
+
// Log sample of converted dates for debugging
|
|
24
|
+
if (records.length > 0) {
|
|
25
|
+
console.log('📅 Sample date conversions:', {
|
|
26
|
+
first: records[0].date,
|
|
27
|
+
last: records[records.length - 1].date,
|
|
28
|
+
totalRecords: records.length
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return records;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Parse DD-MMM-YY format to ISO date string
|
|
35
|
+
* @param dateStr - Date string in DD-MMM-YY format (e.g., "01-JUL-24" or "01-Jan-24")
|
|
36
|
+
* @returns ISO date string (e.g., "2024-07-01")
|
|
37
|
+
*/
|
|
38
|
+
function parseDateString(dateStr) {
|
|
39
|
+
try {
|
|
40
|
+
// Parse DD-MMM-YY format
|
|
41
|
+
const parts = dateStr.split('-');
|
|
42
|
+
if (parts.length !== 3)
|
|
43
|
+
return dateStr; // Return original if invalid format
|
|
44
|
+
const day = parts[0].padStart(2, '0');
|
|
45
|
+
const monthStr = parts[1].toUpperCase(); // Handle both uppercase and lowercase
|
|
46
|
+
const year = parts[2];
|
|
47
|
+
// Convert month abbreviation to number (uppercase keys)
|
|
48
|
+
const monthMap = {
|
|
49
|
+
'JAN': '01', 'FEB': '02', 'MAR': '03', 'APR': '04',
|
|
50
|
+
'MAY': '05', 'JUN': '06', 'JUL': '07', 'AUG': '08',
|
|
51
|
+
'SEP': '09', 'OCT': '10', 'NOV': '11', 'DEC': '12'
|
|
52
|
+
};
|
|
53
|
+
const month = monthMap[monthStr];
|
|
54
|
+
if (!month) {
|
|
55
|
+
console.warn('Invalid month abbreviation:', monthStr, 'in date:', dateStr);
|
|
56
|
+
return dateStr; // Return original if invalid month
|
|
57
|
+
}
|
|
58
|
+
// Assume 20xx for two-digit years
|
|
59
|
+
const fullYear = year.length === 2 ? `20${year}` : year;
|
|
60
|
+
// Return ISO format: YYYY-MM-DD
|
|
61
|
+
const isoDate = `${fullYear}-${month}-${day}`;
|
|
62
|
+
return isoDate;
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
console.warn('Failed to parse date:', dateStr, error);
|
|
66
|
+
return dateStr; // Return original on error
|
|
67
|
+
}
|
|
23
68
|
}
|
|
24
69
|
/**
|
|
25
70
|
* Parse CSV text into structured records
|
|
@@ -38,7 +83,7 @@ function parseCsvData(csv) {
|
|
|
38
83
|
return null;
|
|
39
84
|
}
|
|
40
85
|
// Fixed columns (metadata) - based on known CSV structure
|
|
41
|
-
const date = parts[0].trim();
|
|
86
|
+
const date = parseDateString(parts[0].trim()); // Convert to ISO format
|
|
42
87
|
const cellName = parts[1].trim();
|
|
43
88
|
const siteName = parts[4].trim();
|
|
44
89
|
const sector = parseInt(parts[5]);
|