Skip to content

Commit 743a84c

Browse files
feat: show how much people spent on their coffee in wrapped
1 parent eedd124 commit 743a84c

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/components/beanconqueror/wrapped/utils.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export type WrappedData = {
3434
totalBrews: number;
3535
totalCoffee: number;
3636
totalWeight: number;
37+
totalCost: number;
38+
hasMissingCosts: boolean;
3739
brewsPerMonth: Record<string, number>;
3840
averageBrewsPerDay: number;
3941
mostCommonDrinkingHour: number;
@@ -58,8 +60,6 @@ function getDefaultDict(initial: number): Record<string | symbol, number> {
5860
});
5961
}
6062

61-
const foo = {};
62-
6363
/**
6464
* Checks if the provided data has either a buy date equal to the provided year, or
6565
* a unix timestamp of the provided year.
@@ -70,10 +70,7 @@ function inYear(data: HasTimeData, year: number): boolean {
7070
if (!!data.buyDate) {
7171
return new Date(data.buyDate).getFullYear() === year;
7272
}
73-
const d = new Date(data.config.unix_timestamp * 1000);
74-
if (d.getFullYear() === year) {
75-
console.log(d.getHours())
76-
}
73+
7774
return new Date(data.config.unix_timestamp * 1000).getFullYear() === year;
7875
}
7976

@@ -195,11 +192,22 @@ export function createWrappedStatistics(data: BCData, year: number): WrappedData
195192
const grinders = brewsInYear.map(b => b.mill);
196193
const preps = brewsInYear.map(b => b.method_of_preparation);
197194

195+
let hasMissingCosts = false;
196+
197+
for (const bean of beansInYear) {
198+
if (!bean.cost) {
199+
hasMissingCosts = true;
200+
break;
201+
}
202+
}
203+
198204
return {
199205
year: year,
200206
totalBrews: mappings.brewMaps.inYear.size,
201207
totalCoffee: mappings.beanMaps.inYear.size,
202208
totalWeight: Array.from(beansInYear).reduce((prev, bean) => prev + bean.weight, 0),
209+
totalCost: beansInYear.reduce((prev, curr) => prev + curr.cost, 0),
210+
hasMissingCosts: hasMissingCosts,
203211
brewsPerMonth: timeStats.countPerMonth,
204212
averageBrewsPerDay: Object.values(timeStats.brewsPerDay).reduce((prev, curr) => prev + curr, 0) / Object.values(timeStats.brewsPerDay).length,
205213
mostCommonDrinkingHour: parseInt(mostCommonDrinkingHour),

src/components/beanconqueror/wrapped/wrapped.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ function WrappedCarousel() {
4747
);
4848
});
4949

50-
console.log(data.mostCommonProcessingMethod);
5150
return (
5251
<Carousel opts={{
5352
align: "start",
@@ -63,6 +62,13 @@ function WrappedCarousel() {
6362
<Text>With a total weight of</Text>
6463
<BigText>{Math.floor(data.totalWeight * 100) / 100} grams</BigText>
6564
</CarouselItem>
65+
{data.totalCost > 0 && (
66+
<CarouselItem className={"flex flex-col items-center justify-center bg-tiles"}>
67+
<Text>You&apos;ve spent</Text>
68+
<BigText>{data.totalCost} 🤫</BigText>
69+
{data.hasMissingCosts && (<div className={"whitespace-pre-wrap"}>Did you enter everything 😉?</div>)}
70+
</CarouselItem>
71+
)}
6672
<CarouselItem className={"flex flex-col items-center justify-center bg-circle-wave-2"}>
6773
<Text>You&apos;ve been busy, you made</Text>
6874
<BigText>{data.totalBrews} brews</BigText>
@@ -126,7 +132,6 @@ function Upload() {
126132

127133
const callback = async () => {
128134
const file = fileRef.current?.files?.[0];
129-
130135
if (!file) {
131136
toast({
132137
title: "Error",
@@ -137,6 +142,7 @@ function Upload() {
137142
}
138143
try {
139144
setData(createWrappedStatistics(await readZipFile(file), year));
145+
console.log("miaw?")
140146
} catch (e) {
141147
const wrappedError = (e as {wrappedError: string}).wrappedError;
142148
if (wrappedError) {

0 commit comments

Comments
 (0)