Skip to content

Commit ee11403

Browse files
committed
add median screens per product calculation to GlobalStats component
1 parent 2a98d76 commit ee11403

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

astro/src/components/GlobalStats.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ export const GlobalStats = () => {
77
return sum + (product.stats.screens?.total || 0);
88
}, 0);
99

10+
const medianScreensPerProduct = (() => {
11+
const screens = products
12+
.map(product => product.stats.screens?.total)
13+
.filter(total => total !== undefined)
14+
.sort((a, b) => a - b);
15+
16+
const mid = Math.floor(screens.length / 2);
17+
18+
return screens.length % 2 === 0
19+
? (screens[mid - 1] + screens[mid]) / 2
20+
: screens[mid];
21+
})();
22+
1023
return (
1124
<div className="flex gap-10 items-center">
1225
<div className="flex gap-5 font-mono h-12 items-center">
@@ -25,6 +38,14 @@ export const GlobalStats = () => {
2538
{screenCount.toLocaleString()}
2639
</div>
2740
</div>
41+
<div className="flex gap-5 font-mono h-12 items-center">
42+
<div>
43+
Median Screens per Product
44+
</div>
45+
<div>
46+
{medianScreensPerProduct.toLocaleString()}
47+
</div>
48+
</div>
2849
</div>
2950
)
3051
}

0 commit comments

Comments
 (0)