group acquisitions

This commit is contained in:
2024-05-18 19:55:48 +02:00
parent 2756bbb2c2
commit ff4c9c6bf0
2 changed files with 31 additions and 19 deletions

View File

@@ -41,24 +41,36 @@ const marketTaxStore = useMarketTaxStore();
const threshold = useStorage('market-acquisition-threshold', 10); const threshold = useStorage('market-acquisition-threshold', 10);
const filter = ref(""); const filter = ref("");
const { sortedArray, headerProps } = useSort<Result>(computed(() => props.items const { sortedArray, headerProps } = useSort<Result>(computed(() => {
.filter(r => r.type.name.toLowerCase().includes(filter.value.toLowerCase())) const list: Result[] = [];
.map(r => { const groups = Map.groupBy(props.items.filter(r => r.type.name.toLowerCase().includes(filter.value.toLowerCase())), r => r.type);
const precentProfit = marketTaxStore.calculateProfit(r.price, r.sell);
return { groups.forEach((group, type) => {
type: r, const oldest = group.reduce((acc: AcquiredType | undefined, r: AcquiredType) => (acc && acc.date < r.date) ? acc : r, undefined);
typeID: r.type.id,
name: r.type.name, if (!oldest) {
buy: r.buy, return;
sell: r.sell, }
price: r.price,
remaining: r.remaining, const total = group.reduce((acc, r) => acc + r.quantity, 0);
quantity: r.quantity, const totalRemaining = group.reduce((acc, r) => acc + r.remaining, 0);
precentProfit, const price = group.reduce((acc, r) => acc + r.price * r.remaining, 0) / totalRemaining;
iskProfit: r.price * precentProfit * r.remaining const precentProfit = marketTaxStore.calculateProfit(price, group[0].sell);
}; list.push({
})), { type: oldest,
typeID: type.id,
name: type.name,
buy: group[0].buy,
sell: group[0].sell,
price: price,
remaining: totalRemaining,
quantity: total,
precentProfit,
iskProfit: price * precentProfit * totalRemaining
});
});
return list;
}), {
defaultSortKey: 'precentProfit', defaultSortKey: 'precentProfit',
defaultSortDirection: 'desc' defaultSortDirection: 'desc'
}) })

View File

@@ -1,9 +1,9 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "ES2020", "target": "ESNext",
"useDefineForClassFields": true, "useDefineForClassFields": true,
"module": "ESNext", "module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"], "lib": ["ESNext", "DOM", "DOM.Iterable"],
"skipLibCheck": true, "skipLibCheck": true,
/* Bundler mode */ /* Bundler mode */