Skip to content

Commit

Permalink
output break time in CLI report and mark break times with an asterisk
Browse files Browse the repository at this point in the history
  • Loading branch information
bottomquark committed Jul 21, 2014
1 parent c926524 commit efd4caa
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
8 changes: 5 additions & 3 deletions src/main/java/org/stt/cli/Main.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.stt.cli;

import static com.google.common.base.Preconditions.checkNotNull;

import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
Expand Down Expand Up @@ -34,6 +32,7 @@
import org.stt.persistence.ItemReader;
import org.stt.persistence.ItemReaderProvider;
import org.stt.reporting.WorkingtimeItemProvider;
import org.stt.reporting.WorktimeCategorizer;
import org.stt.searching.DefaultItemSearcher;
import org.stt.searching.ItemSearcher;
import org.stt.stt.importer.CachingItemReader;
Expand All @@ -43,6 +42,8 @@

import com.google.common.base.Optional;

import static com.google.common.base.Preconditions.checkNotNull;

/**
* The starting point for the CLI
*/
Expand Down Expand Up @@ -247,7 +248,8 @@ private DefaultItemSearcher createNewSearcher() {
private ReportPrinter createNewReportPrinter(File source) {
ItemReaderProvider provider = createNewReaderProvider(source);
return new ReportPrinter(provider, configuration,
new WorkingtimeItemProvider(configuration));
new WorkingtimeItemProvider(configuration),
new WorktimeCategorizer(configuration));
}

/**
Expand Down
32 changes: 23 additions & 9 deletions src/main/java/org/stt/cli/ReportPrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import org.stt.persistence.ItemReader;
import org.stt.persistence.ItemReaderProvider;
import org.stt.reporting.ItemCategorizer;
import org.stt.reporting.ItemCategorizer.ItemCategory;
import org.stt.reporting.OvertimeReportGenerator;
import org.stt.reporting.SummingReportGenerator;
import org.stt.reporting.SummingReportGenerator.Report;
import org.stt.reporting.WorkingtimeItemProvider;
import org.stt.reporting.WorktimeCategorizer;
import org.stt.stt.importer.CachingItemReader;

import com.google.common.base.Optional;
Expand All @@ -39,13 +39,16 @@ public class ReportPrinter {
private final ItemReaderProvider readFrom;
private final Configuration configuration;
private final WorkingtimeItemProvider workingtimeItemProvider;
private final ItemCategorizer categorizer;

public ReportPrinter(ItemReaderProvider readFrom,
Configuration configuration,
WorkingtimeItemProvider workingtimeItemProvider) {
WorkingtimeItemProvider workingtimeItemProvider,
ItemCategorizer categorizer) {
this.readFrom = readFrom;
this.configuration = configuration;
this.workingtimeItemProvider = workingtimeItemProvider;
this.categorizer = categorizer;
}

public void report(Collection<String> args, PrintStream printTo) {
Expand Down Expand Up @@ -179,17 +182,28 @@ private void printSums(PrintStream printTo, String searchString,
}
List<ReportingItem> reportingItems = report.getReportingItems();

Duration overallDuration = new Duration(0);
Duration worktimeDuration = new Duration(0);
Duration breakTimeDuration = new Duration(0);
for (ReportingItem i : reportingItems) {
Duration duration = i.getDuration();
overallDuration = overallDuration.plus(duration);
String comment = i.getComment();
printTruncatedString(DateTimeHelper.prettyPrintDuration(duration)
+ " " + comment, printTo, truncateLongLines);
String prefix = " ";
if (ItemCategory.BREAK.equals(categorizer.getCategory(comment))) {
prefix = "*";
breakTimeDuration = breakTimeDuration.plus(duration);
} else {
worktimeDuration = worktimeDuration.plus(duration);
}
printTruncatedString(
prefix + DateTimeHelper.prettyPrintDuration(duration)
+ " " + comment, printTo, truncateLongLines);
}

printTo.println("====== overall sum: ======\n"
+ DateTimeHelper.prettyPrintDuration(overallDuration));
printTo.println("====== overall sum: ======");
printTo.println("work: "
+ DateTimeHelper.prettyPrintDuration(worktimeDuration));
printTo.println("break: "
+ DateTimeHelper.prettyPrintDuration(breakTimeDuration));

IOUtils.closeQuietly(reportReader);
}
Expand Down Expand Up @@ -235,7 +249,7 @@ private void printDetails(PrintStream printTo, String searchString,
}

private OvertimeReportGenerator createOvertimeReportGenerator() {
ItemCategorizer categorizer = new WorktimeCategorizer(configuration);

CachingItemReader cacher = new CachingItemReader(
readFrom.provideReader());
return new OvertimeReportGenerator(cacher, categorizer,
Expand Down
10 changes: 9 additions & 1 deletion src/test/java/org/stt/cli/ReportPrinterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
import org.stt.model.TimeTrackingItem;
import org.stt.persistence.ItemReader;
import org.stt.persistence.ItemReaderProvider;
import org.stt.reporting.ItemCategorizer;
import org.stt.reporting.ItemCategorizer.ItemCategory;
import org.stt.reporting.WorkingtimeItemProvider;

import static org.hamcrest.CoreMatchers.containsString;

import static org.junit.Assert.assertThat;

import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.anyString;

public class ReportPrinterTest {
private ReportPrinter sut;
Expand All @@ -38,14 +41,19 @@ public class ReportPrinterTest {
@Mock
private WorkingtimeItemProvider workingtimeItemProvider;

@Mock
private ItemCategorizer categorizer;

@Before
public void setup() {
MockitoAnnotations.initMocks(this);

given(configuration.getCliReportingWidth()).willReturn(120);
given(readFrom.provideReader()).willReturn(itemReader);
given(categorizer.getCategory(anyString())).willReturn(
ItemCategory.WORKTIME);
sut = new ReportPrinter(readFrom, configuration,
workingtimeItemProvider);
workingtimeItemProvider, categorizer);
}

@Test
Expand Down

0 comments on commit efd4caa

Please sign in to comment.