Skip to content
This repository was archived by the owner on Mar 30, 2024. It is now read-only.

Commit 52a67d4

Browse files
authored
Merge pull request #15 from Malte311/extensions
Added stats sum extension (fixes #14)
2 parents 44ea10a + b47ec61 commit 52a67d4

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

extensions/disabled.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
milog
2-
example
2+
example
3+
statsSum

extensions/statsSum/index.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name" : "Stats Sum",
3+
"shortname" : "sum",
4+
"events" : {
5+
"statsViewed" : "TTTStatsSum\\StatsSum::statsViewed"
6+
},
7+
"version" : "v1.0.0"
8+
}

extensions/statsSum/index.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
?>

0 commit comments

Comments
 (0)