This repository was archived by the owner on Mar 30, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +47
-1
lines changed Expand file tree Collapse file tree 3 files changed +47
-1
lines changed Original file line number Diff line number Diff line change 11milog
2- example
2+ example
3+ statsSum
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " Stats Sum" ,
3+ "shortname" : " sum" ,
4+ "events" : {
5+ "statsViewed" : " TTTStatsSum\\ StatsSum::statsViewed"
6+ },
7+ "version" : " v1.0.0"
8+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace TTTStatsSum ;
4+
5+ class StatsSum {
6+ /**
7+ * Called after the stats output to cli is finished, just before ttt stops execution.
8+ * Adds the sum of worked hours to the stats view.
9+ *
10+ * @param $array the data array from StatsData::getAllDatasets()
11+ * @param $output the CLI Output object
12+ */
13+ public static function statsViewed (array $ data , \CLIOutput $ output ) : void {
14+ $ sums = array ();
15+ foreach ( $ data as $ k => $ d ){
16+ if ( empty ($ sums [$ d ['category ' ]]) ) {
17+ $ sums [$ d ['category ' ]] = 0 ;
18+ }
19+
20+ $ sums [$ d ['category ' ]] += $ d ['duration ' ];
21+ }
22+
23+ $ tab = array ();
24+ foreach ( $ sums as $ k => $ s ){
25+ $ tab [] = array (
26+ 'Category ' => $ k ,
27+ 'Sum ' => \Stats::secToTime ($ s )
28+ );
29+ }
30+
31+ $ output ->table ($ tab );
32+ $ output ->print (array (
33+ 'Total sum: ' . trim (\Stats::secToTime (array_sum ($ sums )))
34+ ), \CLIOutput::RED );
35+ }
36+ }
37+ ?>
You can’t perform that action at this time.
0 commit comments