Browse Source

add day summary for history.

master 0.1.29
Gisle Aune 2 years ago
parent
commit
1b73c83b3b
  1. 5
      frontend/src/lib/components/history/HistoryGroupSection.svelte
  2. 23
      frontend/src/lib/components/project/AggregateAmountRow.svelte
  3. 2
      frontend/src/lib/utils/numbers.ts

5
frontend/src/lib/components/history/HistoryGroupSection.svelte

@ -2,14 +2,19 @@
import type Item from "$lib/models/item";
import type { ItemGroup } from "$lib/models/item";
import Section from "../layout/Section.svelte";
import AggregateAmountRow from "../project/AggregateAmountRow.svelte";
import ItemSubSection from "../project/ItemSubSection.svelte";
export let group: ItemGroup;
export let items: Item[];
let acquiredItems: Item[];
$: acquiredItems = group.list.filter(ref => ref.event === "acquired").map(ref => items[ref.idx]);
</script>
<Section title={group.label}>
{#each group.list as ref (ref.idx)}
<ItemSubSection item={items[ref.idx]} event={ref.event} />
{/each}
<AggregateAmountRow items={acquiredItems} />
</Section>

23
frontend/src/lib/components/project/AggregateAmountRow.svelte

@ -5,26 +5,41 @@ import Amount from "../common/Amount.svelte";
import { getScopeContext } from "../contexts/ScopeContext.svelte";
export let items: Item[];
export let totalAcquired: number;
export let aggregateRequired: number;
export let totalAcquired: number = null;
export let aggregateRequired: number = null;
const {scope} = getScopeContext();
let amounts: {name: string, amount: number}[] = [];
let total;
let required;
$: {
const statMap: Record<number, number> = {};
total = 0;
required = 0;
for (const item of items) {
for (const stat of item.stats) {
statMap[stat.id] = (statMap[stat.id] || 0) + stat.acquired
statMap[stat.id] = (statMap[stat.id] || 0) + stat.acquired;
required += stat.required * stat.weight;
total += stat.acquired * stat.weight;
}
}
if (totalAcquired != null) {
total = totalAcquired;
}
if (aggregateRequired != null) {
required = aggregateRequired;
}
amounts = [];
for (const stat of $scope.stats) {
if (!!statMap[stat.id]) {
amounts.push({name: stat.name, amount: statMap[stat.id]});
}
}
}
@ -34,5 +49,5 @@ import Amount from "../common/Amount.svelte";
{#each amounts as {name, amount} (name)}
<Amount label={name} value={amount} />
{/each}
<Amount weighted right label="" dark value={totalAcquired} target={aggregateRequired} />
<Amount weighted right label="" dark value={total} target={required} />
</AmountRow>

2
frontend/src/lib/utils/numbers.ts

@ -20,7 +20,7 @@ export function significantDecimals(n: number): string {
} else if (n >= 0.001) {
return n.toFixed(3);
} else if (n >= 0) {
return n.toFixed(4);
return n.toFixed(2);
} else {
return "-" + significantDecimals(-n);
}

Loading…
Cancel
Save