@@ -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 ) ,
0 commit comments