@smartnet360/svelte-components 0.0.46 → 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]);
|
|
@@ -46,20 +46,31 @@ export function expandLayoutForCells(baseLayout, data, stylingConfig) {
|
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
48
|
* Expand a single KPI into multiple KPIs (one per cell)
|
|
49
|
-
*
|
|
49
|
+
* If stylingConfig is provided: creates styled KPIs with band colors and sector line styles
|
|
50
|
+
* If stylingConfig is undefined: returns base KPIs as-is for Chart component default behavior
|
|
50
51
|
*
|
|
51
52
|
* @param baseKPIs - Array of base KPIs from layout
|
|
52
53
|
* @param cells - Array of [cellName, record] tuples
|
|
53
54
|
* @param stylingConfig - Optional cell styling configuration
|
|
54
|
-
* @returns Expanded array of KPIs
|
|
55
|
+
* @returns Expanded array of KPIs (styled or default)
|
|
55
56
|
*/
|
|
56
57
|
function expandKPIs(baseKPIs, cells, stylingConfig) {
|
|
57
58
|
const expandedKPIs = [];
|
|
58
59
|
baseKPIs.forEach((baseKPI) => {
|
|
59
60
|
cells.forEach(([cellName, record]) => {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
if (stylingConfig) {
|
|
62
|
+
// Apply custom styling (band colors, sector line styles)
|
|
63
|
+
const styledKPI = createStyledKPI(baseKPI.rawName, record, baseKPI.unit, stylingConfig);
|
|
64
|
+
expandedKPIs.push(styledKPI);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
// Use Chart component default behavior: keep base KPI name
|
|
68
|
+
// Just update rawName to reference the pivoted column
|
|
69
|
+
expandedKPIs.push({
|
|
70
|
+
...baseKPI,
|
|
71
|
+
rawName: `${baseKPI.rawName}_${cellName}`
|
|
72
|
+
});
|
|
73
|
+
}
|
|
63
74
|
});
|
|
64
75
|
});
|
|
65
76
|
return expandedKPIs;
|