mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 15:05:22 +02:00
feat: automatic ads data loading and attributed sales line in chart
This commit is contained in:
@@ -352,9 +352,11 @@ export const processAdsCSV = (file: File): Promise<AdsRecord[]> => {
|
||||
});
|
||||
};
|
||||
|
||||
export const processAdsExcel = async (file: File): Promise<AdsRecord[]> => {
|
||||
export const processAdsExcel = async (fileOrBuffer: File | ArrayBuffer): Promise<AdsRecord[]> => {
|
||||
try {
|
||||
const arrayBuffer = await file.arrayBuffer();
|
||||
const arrayBuffer = fileOrBuffer instanceof File
|
||||
? await fileOrBuffer.arrayBuffer()
|
||||
: fileOrBuffer;
|
||||
const workbook = XLSX.read(arrayBuffer);
|
||||
const allData: AdsRecord[] = [];
|
||||
|
||||
@@ -542,6 +544,29 @@ export const mergeSalesAndAdsData = (salesData: SalesRecord[], adsData: AdsRecor
|
||||
|
||||
// --- EXISTING HELPERS ---
|
||||
|
||||
// Filter Ads Data by Country, Year, Week, and ASIN
|
||||
export const filterAdsData = (adsData: AdsRecord[], filters: FilterState): AdsRecord[] => {
|
||||
return adsData.filter(ad => {
|
||||
// Country/Customer match (ads use 'country', sales use 'customer')
|
||||
const countryMatch = filters.customer.length === 0 ||
|
||||
filters.customer.some(c => c.toUpperCase() === ad.country.toUpperCase());
|
||||
|
||||
// Year match
|
||||
const yearMatch = filters.year.length === 0 ||
|
||||
filters.year.includes(ad.year.toString());
|
||||
|
||||
// Week match (filters use "W1", "W2" format)
|
||||
const weekStr = `W${ad.week}`;
|
||||
const weekMatch = filters.week.length === 0 || filters.week.includes(weekStr);
|
||||
|
||||
// ASIN match
|
||||
const asinMatch = filters.asin.length === 0 ||
|
||||
filters.asin.some(a => a.toUpperCase() === ad.asin.toUpperCase());
|
||||
|
||||
return countryMatch && yearMatch && weekMatch && asinMatch;
|
||||
});
|
||||
};
|
||||
|
||||
export const filterData = (data: SalesRecord[], filters: FilterState): SalesRecord[] => {
|
||||
return data.filter(item => {
|
||||
// 1. Month Logic: Handle "Apr-23" matching "Apr" filter
|
||||
|
||||
Reference in New Issue
Block a user