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

Commit c578604

Browse files
committed
Alpha Version
1 parent 4b51f20 commit c578604

File tree

7 files changed

+151
-9
lines changed

7 files changed

+151
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
> UNDER DEVELOPMENT!!
1+
> Alpha Version, only works for Linux until now!
22
# TaskTimeTerminate
33

44
> A Tool to record timings for tasks per category and rembering to terminate work sessions.

core/CLI.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public function checkTask(){
2525
break;
2626
case CLIParser::TASK_RECORD:
2727
(new Recorder())->record(true);
28+
if( Config::getStorageReader('config')->isValue(['status']) && !Config::getStorageReader('config')->getValue(['status']) ){
29+
$this->togglePause(); // make sure to enable
30+
}
2831
break;
2932
case CLIParser::TASK_PAUSE:
3033
$this->togglePause();

core/CLIOutput.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ class CLIOutput {
55
const MIDDLE = "------------------------------------------------------------";
66
const MOIN = "Welcome to TTT -- TaskTimeTerminate by KIMB-technologies ";
77

8+
const PAD_SPACING = 2;
9+
810
const RED = "\e[0;31m";
911
const BLACK = "\e[0;30m";
1012
const GREEN = "\e[0;32m";
@@ -40,6 +42,49 @@ public function print( array $s, ?string $color = null, int $ind = 0 ) : void {
4042
}
4143
}
4244

45+
public function table(array $data) : void {
46+
$colsize = array();
47+
foreach( $data as $row ){
48+
foreach( $row as $cid => $col ){
49+
if( !isset($colsize[$cid])){
50+
$colsize[$cid] = strlen($cid);
51+
}
52+
$colsize[$cid] = max( $colsize[$cid], strlen($col) );
53+
}
54+
}
55+
56+
echo PHP_EOL . str_repeat('-', array_sum($colsize) + count($colsize) * 5) . PHP_EOL;
57+
$firstrow = true;
58+
$lastfirstcell = '';
59+
foreach( $data as $row ){
60+
if($firstrow){
61+
echo '| ';
62+
foreach( $row as $cid => $col ){
63+
echo self::BLUE . str_pad($cid, $colsize[$cid] + self::PAD_SPACING ) . self::RESET . '| ';
64+
}
65+
echo PHP_EOL;
66+
echo str_repeat('-', array_sum($colsize) + count($colsize) * 5) . PHP_EOL;
67+
$firstrow = false;
68+
}
69+
echo '| ';
70+
$firstcell = true;
71+
foreach( $row as $cid => $col ){
72+
if($firstcell){
73+
if( $lastfirstcell == $col ){
74+
$col = '';
75+
}
76+
else {
77+
$lastfirstcell = $col;
78+
}
79+
$firstcell = false;
80+
}
81+
echo str_pad($col, $colsize[$cid] + self::PAD_SPACING ) . '| ';
82+
}
83+
echo PHP_EOL;
84+
}
85+
echo str_repeat('-', array_sum($colsize) + count($colsize) * 5) . PHP_EOL . PHP_EOL;
86+
}
87+
4388
public function __destruct(){
4489
$this->print([self::BEGINEND]);
4590
}

core/Stats.php

Lines changed: 96 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ class Stats {
44
private CLIParser $parser;
55
private CLIOutput $output;
66

7+
private bool $todayview = false;
8+
79
public function __construct(CLIParser $parser, CLIOutput $output) {
810
$this->parser = $parser;
911
$this->output = $output;
@@ -23,15 +25,19 @@ private function parseCommands(array $commands) : void {
2325
switch( $commands[0] ) {
2426
case "day":
2527
$this->backUntil(time() - 86400, array_slice($commands, 1));
28+
break;
2629
case "week":
2730
$this->backUntil(time() - 604800, array_slice($commands, 1));
31+
break;
2832
case "month":
2933
$this->backUntil(time() - 2628000, array_slice($commands, 1));
34+
break;
3035
case "all":
3136
$this->backUntil(0, array_slice($commands, 1));
3237
break;
3338
case "today":
3439
default:
40+
$this->todayview = true;
3541
$this->backUntil(strtotime("today"), array_slice($commands, 1));
3642
}
3743
}
@@ -74,12 +80,96 @@ private function backUntil(int $timestamp, array $f) : void {
7480
$this->printDataset($s->getAllDatasets());
7581
}
7682

77-
private function printDataset(array $data){
78-
print_r($data);
79-
/**
80-
* ToDo
81-
*/
83+
private function printDataset(array $data) : void {
84+
$combi = array();
85+
foreach( $data as $d ){
86+
$key = $d['category'] . '++' . $d['name'];
87+
if( !isset($combi[$key])){
88+
$combi[$key] = array(
89+
'category' => $d['category'],
90+
'name' => $d['name'],
91+
'duration' => 0,
92+
'times' => 0
93+
);
94+
}
95+
$combi[$key]['times']++;
96+
$combi[$key]['duration'] += $d['duration'];
97+
}
98+
$combi = array_values($combi);
99+
100+
$table = array();
101+
foreach( $combi as $d ){
102+
$table[] = array(
103+
'Category' => $d['category'],
104+
'Name' => $d['name'],
105+
'Time' => $d['duration'],
106+
'Work Items' => str_pad($d['times'], 4, " ", STR_PAD_LEFT)
107+
);
108+
}
109+
110+
array_multisort(
111+
array_column( $table, 'Category' ), SORT_ASC,
112+
array_column( $table, 'Time' ), SORT_DESC,
113+
array_column( $table, 'Name' ), SORT_ASC,
114+
$table
115+
);
116+
117+
foreach( $table as &$d ){
118+
$d['Time'] = $this->secToTime($d['Time']);
119+
}
120+
121+
$this->output->table($table);
122+
123+
if( $this->todayview ){
124+
$this->printTodayView($data);
125+
}
126+
}
127+
128+
private function secToTime(int $t) : string {
129+
return str_pad(
130+
($t >= 3600 ? intval($t/3600) . 'h ' : '' ) .
131+
str_pad(
132+
intval(($t % 3600) / 60) . 'm',
133+
3,
134+
" ",
135+
STR_PAD_LEFT
136+
),
137+
8,
138+
" ",
139+
STR_PAD_LEFT
140+
);
141+
}
142+
143+
private function printTodayView(array $data) : void {
144+
array_multisort(
145+
array_column( $data, 'begin' ), SORT_ASC,
146+
$data
147+
);
148+
149+
$table = array();
150+
$i = 0;
151+
$lastval = null;
152+
foreach( $data as $d ){
153+
if( $lastval === $d['category'] . '++' . $d['name'] ){
154+
$table[$i-1]['Time'] += $d['duration'];
155+
}
156+
else{
157+
$table[$i++] = array(
158+
'Begin' => date('H:i', $d['begin']),
159+
'Category' => $d['category'],
160+
'Name' => $d['name'],
161+
'Time' => $d['duration']
162+
);
163+
}
164+
$lastval = $d['category'] . '++' . $d['name'];
165+
}
166+
167+
foreach( $table as &$d ){
168+
$d['Time'] = $this->secToTime($d['Time']);
169+
}
170+
171+
$this->output->table($table);
82172
}
83173

84174
}
85-
?>
175+
?>

core/Utilities.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
class Utilities {
66

7-
const VERSION = 'v0.0.0';
7+
const VERSION = 'v0.5.0 alpha';
88

99
/**
1010
* Possible chars for:

core/platform/LinuxDialog.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function open() : void {
1414
'--form',
1515
'--item-separator=,',
1616
'--separator=" "',
17-
'--field="Category:CB" "'. implode(',', $this->categories) .',ss"',
17+
'--field="Category:CB" "'. implode(',', $this->categories) .'"',
1818
'--field="Task:TEXT"',
1919
'--field="Time:TEXT"',
2020
'--field="Time can be a duration like 2h, 2h10m, 25m or time like 12:00.:LBL"',

record.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
$recorder = new Recorder();
66

7+
if( !Config::getStorageReader('config')->isValue(['status']) ){
8+
Config::getStorageReader('config')->setValue(['status'], true);
9+
}
10+
711
while( true ){
812
if( Config::getStorageReader('config')->getValue(['status']) ){
913
$recorder->record();

0 commit comments

Comments
 (0)