Small changes to Category and Event toString()

* Updated Category and Event toString methods to report the duration alongside
  the description.
* Updated QD TicketCategorizationPlan to reflect previous changes to
  CategorizationPlan interface.
This commit is contained in:
Jonathan Bernard 2012-09-04 10:41:40 -05:00
parent 5dff4de089
commit 00a5252542
7 changed files with 57 additions and 47 deletions

View File

@ -1,5 +1,5 @@
#Sat, 01 Sep 2012 22:19:54 -0700 #Mon, 03 Sep 2012 23:38:34 -0500
name=time-analyzer name=time-analyzer
version=1.0 version=1.0
build.number=0 build.number=11
lib.local=true lib.local=true

View File

@ -13,26 +13,13 @@ import org.joda.time.DateTime
import org.joda.time.Interval import org.joda.time.Interval
import org.joda.time.Period import org.joda.time.Period
import org.joda.time.format.PeriodFormat import org.joda.time.format.PeriodFormat
import static com.jdbernard.timeanalyzer.chart.Util.*
pf = PeriodFormat.getDefault()
printDuration = { duration ->
pf.print(duration.toPeriod()) }
loadEvents = { file, processor -> loadEvents = { file, processor ->
fileSource = new FileTimelineSource(file.toURI()) fileSource = new FileTimelineSource(file.toURI())
timeline = fileSource.read() timeline = fileSource.read()
return processor.process(timeline) } return processor.process(timeline) }
makePieDataset = { category ->
DefaultPieDataset dpds = new DefaultPieDataset()
category.categories.each { cat ->
dpds.setValue(cat.description, cat.duration.standardSeconds) }
category.events.each { entry ->
dpds.setValue(entry.description, entry.duration.standardSeconds) }
dpds.sortByValues(SortOrder.DESCENDING)
return dpds }
makePieFrame = { categoryName, category -> makePieFrame = { categoryName, category ->
def dataset = makePieDataset(category) def dataset = makePieDataset(category)
return new ChartFrame(categoryName, return new ChartFrame(categoryName,
@ -62,18 +49,24 @@ analyze = { file ->
return [topcat: topcat, rawEvents: events] } return [topcat: topcat, rawEvents: events] }
listEvents = {topcat -> listEvents = {topcat ->
String result = ""
topcat.events.eachWithIndex { event, index -> topcat.events.eachWithIndex { event, index ->
println "${index}: ${event} (${printDuration(event.duration)})" }} result += "${index}: ${event}\n" }
return result }
listCategories = { topcat -> listCategories = { topcat ->
String result = ""
topcat.categories.eachWithIndex { cat, index -> topcat.categories.eachWithIndex { cat, index ->
println "${index}: ${cat} (${printDuration(cat.duration)})" }} result += "${index}: ${cat}\n" }
return result }
details = { topcat -> details = { topcat ->
println "Categories" def result = "Categories\n" + listCategories(topcat)
listCategories(topcat) result += "Events\n" + listEvents(topcat)
println "Events"
listEvents(topcat) } return "\n" + result }
weeklySummary = { events -> weeklySummary = { events ->
def todayMidnight = new DateTime() def todayMidnight = new DateTime()

View File

@ -2,12 +2,16 @@ package com.jdbernard.timeanalyzer.categories
import com.jdbernard.timeanalyzer.events.Event import com.jdbernard.timeanalyzer.events.Event
import org.joda.time.Duration import org.joda.time.Duration
import org.joda.time.format.PeriodFormat
import org.joda.time.format.PeriodFormatter
/** /**
* A `Category` represents a collection of like `Events` and sub-categories. * A `Category` represents a collection of like `Events` and sub-categories.
*/ */
public abstract class Category implements Comparable<Category> { public abstract class Category implements Comparable<Category> {
public static PeriodFormatter periodFormatter = PeriodFormat.getDefault()
/** List of events directly under this category. */ /** List of events directly under this category. */
public List events public List events
@ -21,11 +25,7 @@ public abstract class Category implements Comparable<Category> {
/** A end-user-friendly text description of the category.*/ /** A end-user-friendly text description of the category.*/
public String description public String description
public Category() { public Category() { this("Unamed Category") }
events = []
categories = []
categorizationPlans = []
description = "Unnamed Category" }
public Category(String description) { public Category(String description) {
events = [] events = []
@ -115,6 +115,7 @@ public abstract class Category implements Comparable<Category> {
public int compareTo(Category other) { public int compareTo(Category other) {
return this.getDuration().compareTo(other.getDuration()) } return this.getDuration().compareTo(other.getDuration()) }
public String toString() { return description } public String toString() {
String period = periodFormatter.print(this.duration.toPeriod())
return "${description} (${period})" }
} }

View File

@ -9,8 +9,11 @@ public class Util {
public static PieDataset makePieDataset(Category category) { public static PieDataset makePieDataset(Category category) {
DefaultPieDataset dpds = new DefaultPieDataset() DefaultPieDataset dpds = new DefaultPieDataset()
category.categories.each { cat ->
dpds.setValue(cat.description, cat.duration.standardSeconds) }
category.events.each { entry ->
dpds.setValue(entry.description, entry.duration.standardSeconds) }
dpds.sortByValues(SortOrder.DESCENDING)
return dpds }
category.categories { subcat ->
dpds.setValue(subcat.description, subcat.duration.getMillis()) }
}
} }

View File

@ -7,35 +7,34 @@ import org.joda.time.format.PeriodFormatter
public class Event implements Cloneable { public class Event implements Cloneable {
public static PeriodFormatter periodFormatter = PeriodFormat.getDefault()
public final String description public final String description
public final String notes public final String notes
public final ReadableDateTime start public final ReadableDateTime start
public Duration duration // bit of a hack, allows modification for the public Duration duration // should be final, allows modification for the
// TimelineEventProcessor // TimelineEventProcessor
public static PeriodFormatter periodFormatter = PeriodFormat.getDefault()
public Event(String desc, String notes, ReadableDateTime start, Duration duration) { public Event(String desc, String notes, ReadableDateTime start, Duration duration) {
this.description = desc this.description = desc
this.notes = notes this.notes = notes
this.start = start this.start = start
this.duration = duration this.duration = duration }
}
public Event(Map params) { public Event(Map params) {
this.description = params.description ?: "" this.description = params.description ?: ""
this.notes = params.notes ?: "" this.notes = params.notes ?: ""
this.start = params.start this.start = params.start
this.duration = params.duration this.duration = params.duration }
}
public Event(Map params, Event e) { public Event(Map params, Event e) {
this.description = params.description ?: e.description this.description = params.description ?: e.description
this.notes = params.notes ?: e.notes this.notes = params.notes ?: e.notes
this.start = params.start ?: e.start this.start = params.start ?: e.start
this.duration = params.duration ?: e.duration this.duration = params.duration ?: e.duration }
}
public String toString() { return description } public String toString() {
String period = periodFormatter.print(this.duration.toPeriod())
return "${description} (${period})" }
} }

View File

@ -2,6 +2,7 @@ package com.jdbernard.timeanalyzer.processors
import com.jdbernard.timeanalyzer.events.Event import com.jdbernard.timeanalyzer.events.Event
import com.jdbernard.timestamper.core.Timeline import com.jdbernard.timestamper.core.Timeline
import com.jdbernard.timestamper.core.TimelineProperties
import org.joda.time.DateTime import org.joda.time.DateTime
import org.joda.time.Duration import org.joda.time.Duration
@ -15,6 +16,10 @@ public class TimelineEventProcessor {
public TimelineEventProcessor(List exclusions) { this.exclusions = exclusions } public TimelineEventProcessor(List exclusions) { this.exclusions = exclusions }
public List<Event> process(File timelinePropFile) {
def timelineProps = new TimelineProperties(timelinePropFile)
return process(timelineProps.timeline) }
public List<Event> process(Timeline timeline) { public List<Event> process(Timeline timeline) {
List<Event> events = [] List<Event> events = []
@ -25,6 +30,8 @@ public class TimelineEventProcessor {
start: new DateTime(marker.timestamp), start: new DateTime(marker.timestamp),
duration: new Duration(0)) duration: new Duration(0))
println e
// if this is not the first event, then we need to update the // if this is not the first event, then we need to update the
// duration of the previous event // duration of the previous event
if (events.size > 0) { if (events.size > 0) {
@ -36,6 +43,9 @@ public class TimelineEventProcessor {
def excluded = events.findAll { event -> def excluded = events.findAll { event ->
exclusions.any { exclusion -> event.description ==~ exclusion } } exclusions.any { exclusion -> event.description ==~ exclusion } }
return events - excluded return events - excluded }
}
public static List<Event> process(def timeline, List exclusions) {
def inst = new TimelineEventProcessor(exclusions)
return inst.process(timeline) }
} }

View File

@ -4,7 +4,7 @@ import com.jdbernard.timeanalyzer.categories.Category
import com.jdbernard.timeanalyzer.categorizationplans.CategorizationPlan import com.jdbernard.timeanalyzer.categorizationplans.CategorizationPlan
import com.jdbernard.timeanalyzer.events.Event import com.jdbernard.timeanalyzer.events.Event
public class TicketCategorizationPlan implements CategorizationPlan { public class TicketCategorizationPlan extends CategorizationPlan {
private static def TICKET_PATTERN = ~/.*#(\d+).*/ private static def TICKET_PATTERN = ~/.*#(\d+).*/
@ -15,7 +15,11 @@ public class TicketCategorizationPlan implements CategorizationPlan {
public Category newCategory(Event e, List<Event> el) { public Category newCategory(Event e, List<Event> el) {
def m = e.description =~ TICKET_PATTERN def m = e.description =~ TICKET_PATTERN
return new TicketCategory(m[0][1] as int) def newCat = new TicketCategory(m[0][1] as int)
setupNewCategory(newCat)
return newCat
} }
public List<Event> findEventsToRecategorize(Event e, public List<Event> findEventsToRecategorize(Event e,