@@ -10,16 +10,40 @@ var today = new Date().toLocaleDateString("en-US");
1010var setting_range_days ;
1111var restrictionList ;
1212var stat = {
13- 'firstDay' : null ,
14- 'lastDay' : null ,
15- 'activeDays' : null ,
16- 'totalDays' : null ,
17- 'inActiveDay' : null ,
18- 'inActiveDayTime' : null ,
19- 'activeDay' : null ,
20- 'activeDayTime' : null ,
21- 'todayTime' : null ,
22- 'allDaysTime' : null
13+ set firstDay ( value ) {
14+ document . getElementById ( 'statFirstDay' ) . innerHTML = value ;
15+ } ,
16+ set lastDay ( value ) {
17+ document . getElementById ( 'statLastDay' ) . innerHTML = value ;
18+ } ,
19+ set activeDays ( value ) {
20+ document . getElementById ( 'statActiveDays' ) . innerHTML = value ;
21+ } ,
22+ set totalDays ( value ) {
23+ document . getElementById ( 'statTotalDays' ) . innerHTML = value ;
24+ } ,
25+ set inActiveDay ( value ) {
26+ document . getElementById ( 'statInActiveDay' ) . innerHTML = value ;
27+ } ,
28+ set inActiveDayTime ( value ) {
29+ document . getElementById ( 'statInActiveDayTime' ) . innerHTML = '' ;
30+ ui . createElementsForTotalTime ( value , TypeListEnum . ToDay , document . getElementById ( 'statInActiveDayTime' ) ) ;
31+ } ,
32+ set activeDay ( value ) {
33+ document . getElementById ( 'statActiveDay' ) . innerHTML = value ;
34+ } ,
35+ set activeDayTime ( value ) {
36+ document . getElementById ( 'statActiveDayTime' ) . innerHTML = '' ;
37+ ui . createElementsForTotalTime ( value , TypeListEnum . ToDay , document . getElementById ( 'statActiveDayTime' ) ) ;
38+ } ,
39+ set todayTime ( value ) {
40+ document . getElementById ( 'statTodayTime' ) . innerHTML = '' ;
41+ ui . createElementsForTotalTime ( value , TypeListEnum . ToDay , document . getElementById ( 'statTodayTime' ) ) ;
42+ } ,
43+ set allDaysTime ( value ) {
44+ document . getElementById ( 'statAllDaysTime' ) . innerHTML = '' ;
45+ ui . createElementsForTotalTime ( value , TypeListEnum . All , document . getElementById ( 'statAllDaysTime' ) ) ;
46+ } ,
2347} ;
2448
2549document . addEventListener ( 'DOMContentLoaded' , function ( ) {
@@ -295,16 +319,47 @@ function getFirstDay() {
295319 return array . push ( a . date ) ;
296320 } ) ;
297321 } ) ;
322+
298323 array = array . sort ( function ( a , b ) {
299324 return new Date ( a ) - new Date ( b ) ;
300325 } ) ;
301326
327+ setStatData ( array ) ;
302328 return {
303329 'countOfDays' : array . length ,
304330 'minDate' : array [ 0 ]
305331 } ;
306332}
307333
334+ function setStatData ( array ) {
335+ var arrayAscByTime = [ ] ;
336+ tabsFromStorage . forEach ( tab => {
337+ return tab . days . forEach ( day => {
338+ var item = arrayAscByTime . find ( x => x . date == day . date ) ;
339+ if ( item !== undefined ) {
340+ return item . total += day . summary ;
341+ }
342+ if ( item === undefined )
343+ return arrayAscByTime . push ( {
344+ 'date' : day . date ,
345+ 'total' : day . summary
346+ } ) ;
347+ } ) ;
348+ } ) ;
349+
350+ arrayAscByTime = arrayAscByTime . sort ( function ( a , b ) {
351+ return a . total - b . total ;
352+ } ) ;
353+ stat . inActiveDay = arrayAscByTime [ 0 ] . date ;
354+ stat . activeDay = arrayAscByTime [ arrayAscByTime . length - 1 ] . date ;
355+ stat . inActiveDayTime = arrayAscByTime [ 0 ] . total ;
356+ stat . activeDayTime = arrayAscByTime [ arrayAscByTime . length - 1 ] . total ;
357+ stat . firstDay = array [ 0 ] ;
358+ stat . lastDay = array [ array . length - 1 ] ;
359+ stat . activeDays = array . length ;
360+ stat . totalDays = daysBetween ( array [ 0 ] , array [ array . length - 1 ] ) ;
361+ }
362+
308363function getTabsByDays ( tabs ) {
309364 var range = ui . getDateRange ( ) ;
310365 if ( tabs === undefined ) {
0 commit comments