feat: update analytics

This commit is contained in:
ivannoskov
2026-02-03 18:55:09 +03:00
parent d87d6e2568
commit e27a171c63
8 changed files with 1529 additions and 461 deletions

View File

@@ -396,9 +396,10 @@ export const demoAwareAnalyticsApi = {
placements: async (
workspaceId: string,
params?: {
project_id?: string;
placement_channel_id?: string;
creative_id?: string;
project_ids?: string;
status_list?: string;
placement_channel_ids?: string;
creative_ids?: string;
date_from?: string;
date_to?: string;
page?: number;
@@ -407,22 +408,22 @@ export const demoAwareAnalyticsApi = {
): Promise<PaginatedResponse<PlacementAnalyticsItem>> => {
if (isDemoWorkspace(workspaceId)) {
let items = demoPlacementAnalytics;
if (params?.project_id) {
items = items.filter((p) => p.project_id === params.project_id);
if (params?.project_ids) {
items = items.filter((p) => p.project_id === params.project_ids);
}
if (params?.placement_channel_id) {
items = items.filter((p) => p.placement_channel_id === params.placement_channel_id);
if (params?.placement_channel_ids) {
items = items.filter((p) => params.placement_channel_ids!.includes(p.channel_id));
}
if (params?.creative_id) {
items = items.filter((p) => p.creative_id === params.creative_id);
if (params?.creative_ids) {
items = items.filter((p) => p.creative_id && params.creative_ids!.includes(p.creative_id));
}
if (params?.date_from) {
const from = new Date(params.date_from);
items = items.filter((p) => new Date(p.placement_date) >= from);
items = items.filter((p) => p.placement_date && new Date(p.placement_date) >= from);
}
if (params?.date_to) {
const to = new Date(params.date_to);
items = items.filter((p) => new Date(p.placement_date) <= to);
items = items.filter((p) => p.placement_date && new Date(p.placement_date) <= to);
}
return paginate(items, params?.page, params?.size);
}
@@ -452,12 +453,12 @@ export const demoAwareAnalyticsApi = {
if (params.date_from) {
const from = new Date(params.date_from);
filtered = filtered.filter((p) => new Date(p.placement_date) >= from);
filtered = filtered.filter((p) => p.placement_date && new Date(p.placement_date) >= from);
}
if (params.date_to) {
const to = new Date(params.date_to);
filtered = filtered.filter((p) => new Date(p.placement_date) <= to);
filtered = filtered.filter((p) => p.placement_date && new Date(p.placement_date) <= to);
}
// Helper to format period label
@@ -483,6 +484,7 @@ export const demoAwareAnalyticsApi = {
// Group by period
const grouped: Record<string, typeof filtered> = {};
filtered.forEach((item) => {
if (!item.placement_date) return;
const date = new Date(item.placement_date);
let periodKey: string;