@@ -7,30 +7,41 @@ export default class Footer {
77
88 public dispatch ( footerType : string , key : string ) : string {
99 let footerInfo : string ;
10- switch ( footerType ) {
11- case FooterType . COUNT_UNIQUE :
12- footerInfo = this . countUnique ( key ) ;
13- break ;
14- case FooterType . COUNT_EMPTY :
15- footerInfo = this . percentEmpty ( key ) ;
16- break ;
17- case FooterType . COUNT_FILLED :
18- footerInfo = this . percentFilled ( key ) ;
19- break ;
20- case FooterType . SUM :
21- footerInfo = this . sum ( key ) ;
22- break ;
23- case FooterType . MIN :
24- footerInfo = this . min ( key ) ;
25- break ;
26- case FooterType . MAX :
27- footerInfo = this . max ( key ) ;
28- break ;
29- case FooterType . NONE :
30- default :
31- footerInfo = "" ;
10+ try {
11+ switch ( footerType ) {
12+ case FooterType . COUNT_UNIQUE :
13+ footerInfo = this . countUnique ( key ) ;
14+ break ;
15+ case FooterType . COUNT_EMPTY :
16+ footerInfo = this . countEmpty ( key ) ;
17+ break ;
18+ case FooterType . PERCENT_EMPTY :
19+ footerInfo = this . percentEmpty ( key ) ;
20+ break ;
21+ case FooterType . COUNT_FILLED :
22+ footerInfo = this . countFilled ( key ) ;
23+ break ;
24+ case FooterType . PERCENT_FILLED :
25+ footerInfo = this . percentFilled ( key ) ;
26+ break ;
27+ case FooterType . SUM :
28+ footerInfo = this . sum ( key ) ;
29+ break ;
30+ case FooterType . MIN :
31+ footerInfo = this . min ( key ) ;
32+ break ;
33+ case FooterType . MAX :
34+ footerInfo = this . max ( key ) ;
35+ break ;
36+ case FooterType . NONE :
37+ default :
38+ footerInfo = "" ;
39+ }
40+ } catch ( e ) {
41+ footerInfo = `Error: ${ e . message } ` ;
42+ } finally {
43+ return footerInfo ;
3244 }
33- return footerInfo ;
3445 }
3546
3647 public sum ( key : string ) : string {
@@ -50,20 +61,32 @@ export default class Footer {
5061
5162 public countUnique ( key : string ) : string {
5263 const uniqueValues = new Set ( ) ;
53- this . rows . forEach ( ( row ) => {
54- uniqueValues . add ( row . getValue ( key ) ) ;
55- } ) ;
64+ this . rows
65+ . filter ( ( row ) => row . getValue ( key ) !== undefined )
66+ . forEach ( ( row ) => {
67+ uniqueValues . add ( row . getValue ( key ) ) ;
68+ } ) ;
5669 return `Unique: ${ uniqueValues . size } ` ;
5770 }
5871
72+ public countEmpty ( key : string ) : string {
73+ const empty = this . rows . filter ( ( row ) => ! row . getValue ( key ) ) . length ;
74+ return `Empty: ${ empty } ` ;
75+ }
76+
5977 public percentEmpty ( key : string ) : string {
6078 const empty = this . rows . filter ( ( row ) => ! row . getValue ( key ) ) . length ;
61- return `Empty: ${ empty } (${ ( empty / this . rows . length * 100 ) . toFixed ( 2 ) } %)` ;
79+ return `Empty: ${ ( empty / this . rows . length * 100 ) . toFixed ( 2 ) } %` ;
80+ }
81+
82+ public countFilled ( key : string ) : string {
83+ const filled = this . rows . filter ( ( row ) => row . getValue ( key ) ) . length ;
84+ return `Filled: ${ filled } ` ;
6285 }
6386
6487 public percentFilled ( key : string ) : string {
6588 const filled = this . rows . filter ( ( row ) => row . getValue ( key ) ) . length ;
66- return `Filled: ${ filled } ( ${ ( filled / this . rows . length * 100 ) . toFixed ( 2 ) } %) ` ;
89+ return `Filled: ${ ( filled / this . rows . length * 100 ) . toFixed ( 2 ) } %` ;
6790 }
6891
6992}
0 commit comments