32 lines
812 B
TypeScript
32 lines
812 B
TypeScript
import type { IncomeAnalytics } from "@/entities/income";
|
|
|
|
type IncomeDisplayModel = {
|
|
entries: { key: string; operation: IncomeAnalytics["entries"][number] }[];
|
|
};
|
|
|
|
function toIncomeDisplayModel(
|
|
analytics: IncomeAnalytics,
|
|
): IncomeDisplayModel {
|
|
const entries: IncomeDisplayModel["entries"] = [];
|
|
const occurrences = new Map<string, number>();
|
|
|
|
for (const entry of analytics.entries) {
|
|
const occurrenceKey = JSON.stringify([entry.instrumentKey, entry.id]);
|
|
const occurrence = occurrences.get(occurrenceKey) ?? 0;
|
|
occurrences.set(occurrenceKey, occurrence + 1);
|
|
entries.push({
|
|
key: JSON.stringify([
|
|
entry.instrumentKey,
|
|
entry.id,
|
|
occurrence,
|
|
entry.logoName,
|
|
]),
|
|
operation: entry,
|
|
});
|
|
}
|
|
|
|
return { entries };
|
|
}
|
|
|
|
export { type IncomeDisplayModel, toIncomeDisplayModel };
|