From 00a5252542ccb2f9d85ce18e69e4b2a318363550 Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Tue, 4 Sep 2012 10:41:40 -0500 Subject: [PATCH] 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. --- project.properties | 4 +-- resources/main/start-script.groovy | 33 ++++++++----------- .../timeanalyzer/categories/Category.groovy | 15 +++++---- .../jdbernard/timeanalyzer/chart/Util.groovy | 11 ++++--- .../timeanalyzer/events/Event.groovy | 19 +++++------ .../processors/TimelineEventProcessor.groovy | 14 ++++++-- .../TicketCategorizationPlan.groovy | 8 +++-- 7 files changed, 57 insertions(+), 47 deletions(-) diff --git a/project.properties b/project.properties index 77c8583..ab54f52 100644 --- a/project.properties +++ b/project.properties @@ -1,5 +1,5 @@ -#Sat, 01 Sep 2012 22:19:54 -0700 +#Mon, 03 Sep 2012 23:38:34 -0500 name=time-analyzer version=1.0 -build.number=0 +build.number=11 lib.local=true diff --git a/resources/main/start-script.groovy b/resources/main/start-script.groovy index 73da9c6..9bfaf18 100644 --- a/resources/main/start-script.groovy +++ b/resources/main/start-script.groovy @@ -13,26 +13,13 @@ import org.joda.time.DateTime import org.joda.time.Interval import org.joda.time.Period import org.joda.time.format.PeriodFormat - -pf = PeriodFormat.getDefault() - -printDuration = { duration -> - pf.print(duration.toPeriod()) } +import static com.jdbernard.timeanalyzer.chart.Util.* loadEvents = { file, processor -> fileSource = new FileTimelineSource(file.toURI()) timeline = fileSource.read() 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 -> def dataset = makePieDataset(category) return new ChartFrame(categoryName, @@ -62,18 +49,24 @@ analyze = { file -> return [topcat: topcat, rawEvents: events] } listEvents = {topcat -> + String result = "" topcat.events.eachWithIndex { event, index -> - println "${index}: ${event} (${printDuration(event.duration)})" }} + result += "${index}: ${event}\n" } + + return result } listCategories = { topcat -> + String result = "" topcat.categories.eachWithIndex { cat, index -> - println "${index}: ${cat} (${printDuration(cat.duration)})" }} + result += "${index}: ${cat}\n" } + + return result } details = { topcat -> - println "Categories" - listCategories(topcat) - println "Events" - listEvents(topcat) } + def result = "Categories\n" + listCategories(topcat) + result += "Events\n" + listEvents(topcat) + + return "\n" + result } weeklySummary = { events -> def todayMidnight = new DateTime() diff --git a/src/main/com/jdbernard/timeanalyzer/categories/Category.groovy b/src/main/com/jdbernard/timeanalyzer/categories/Category.groovy index d5cfe2a..36d1487 100644 --- a/src/main/com/jdbernard/timeanalyzer/categories/Category.groovy +++ b/src/main/com/jdbernard/timeanalyzer/categories/Category.groovy @@ -2,12 +2,16 @@ package com.jdbernard.timeanalyzer.categories import com.jdbernard.timeanalyzer.events.Event 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. */ public abstract class Category implements Comparable { + public static PeriodFormatter periodFormatter = PeriodFormat.getDefault() + /** List of events directly under this category. */ public List events @@ -21,11 +25,7 @@ public abstract class Category implements Comparable { /** A end-user-friendly text description of the category.*/ public String description - public Category() { - events = [] - categories = [] - categorizationPlans = [] - description = "Unnamed Category" } + public Category() { this("Unamed Category") } public Category(String description) { events = [] @@ -115,6 +115,7 @@ public abstract class Category implements Comparable { public int compareTo(Category other) { return this.getDuration().compareTo(other.getDuration()) } - public String toString() { return description } - + public String toString() { + String period = periodFormatter.print(this.duration.toPeriod()) + return "${description} (${period})" } } diff --git a/src/main/com/jdbernard/timeanalyzer/chart/Util.groovy b/src/main/com/jdbernard/timeanalyzer/chart/Util.groovy index 5887706..6f86e38 100644 --- a/src/main/com/jdbernard/timeanalyzer/chart/Util.groovy +++ b/src/main/com/jdbernard/timeanalyzer/chart/Util.groovy @@ -9,8 +9,11 @@ public class Util { public static PieDataset makePieDataset(Category category) { DefaultPieDataset dpds = new DefaultPieDataset() - - category.categories { subcat -> - dpds.setValue(subcat.description, subcat.duration.getMillis()) } - } + 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 } + } diff --git a/src/main/com/jdbernard/timeanalyzer/events/Event.groovy b/src/main/com/jdbernard/timeanalyzer/events/Event.groovy index 1aba147..daaa008 100644 --- a/src/main/com/jdbernard/timeanalyzer/events/Event.groovy +++ b/src/main/com/jdbernard/timeanalyzer/events/Event.groovy @@ -7,35 +7,34 @@ import org.joda.time.format.PeriodFormatter public class Event implements Cloneable { + public static PeriodFormatter periodFormatter = PeriodFormat.getDefault() + public final String description public final String notes 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 - public static PeriodFormatter periodFormatter = PeriodFormat.getDefault() - public Event(String desc, String notes, ReadableDateTime start, Duration duration) { this.description = desc this.notes = notes this.start = start - this.duration = duration - } + this.duration = duration } public Event(Map params) { this.description = params.description ?: "" this.notes = params.notes ?: "" this.start = params.start - this.duration = params.duration - } + this.duration = params.duration } public Event(Map params, Event e) { this.description = params.description ?: e.description this.notes = params.notes ?: e.notes 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})" } } diff --git a/src/main/com/jdbernard/timeanalyzer/processors/TimelineEventProcessor.groovy b/src/main/com/jdbernard/timeanalyzer/processors/TimelineEventProcessor.groovy index 55cd68e..2456d64 100644 --- a/src/main/com/jdbernard/timeanalyzer/processors/TimelineEventProcessor.groovy +++ b/src/main/com/jdbernard/timeanalyzer/processors/TimelineEventProcessor.groovy @@ -2,6 +2,7 @@ package com.jdbernard.timeanalyzer.processors import com.jdbernard.timeanalyzer.events.Event import com.jdbernard.timestamper.core.Timeline +import com.jdbernard.timestamper.core.TimelineProperties import org.joda.time.DateTime import org.joda.time.Duration @@ -15,6 +16,10 @@ public class TimelineEventProcessor { public TimelineEventProcessor(List exclusions) { this.exclusions = exclusions } + public List process(File timelinePropFile) { + def timelineProps = new TimelineProperties(timelinePropFile) + return process(timelineProps.timeline) } + public List process(Timeline timeline) { List events = [] @@ -25,6 +30,8 @@ public class TimelineEventProcessor { start: new DateTime(marker.timestamp), duration: new Duration(0)) + println e + // if this is not the first event, then we need to update the // duration of the previous event if (events.size > 0) { @@ -36,6 +43,9 @@ public class TimelineEventProcessor { def excluded = events.findAll { event -> exclusions.any { exclusion -> event.description ==~ exclusion } } - return events - excluded - } + return events - excluded } + + public static List process(def timeline, List exclusions) { + def inst = new TimelineEventProcessor(exclusions) + return inst.process(timeline) } } diff --git a/src/main/com/quantumdigital/ithelp/timeanalyzer/TicketCategorizationPlan.groovy b/src/main/com/quantumdigital/ithelp/timeanalyzer/TicketCategorizationPlan.groovy index 868f819..85a9b1d 100644 --- a/src/main/com/quantumdigital/ithelp/timeanalyzer/TicketCategorizationPlan.groovy +++ b/src/main/com/quantumdigital/ithelp/timeanalyzer/TicketCategorizationPlan.groovy @@ -4,7 +4,7 @@ import com.jdbernard.timeanalyzer.categories.Category import com.jdbernard.timeanalyzer.categorizationplans.CategorizationPlan import com.jdbernard.timeanalyzer.events.Event -public class TicketCategorizationPlan implements CategorizationPlan { +public class TicketCategorizationPlan extends CategorizationPlan { private static def TICKET_PATTERN = ~/.*#(\d+).*/ @@ -15,7 +15,11 @@ public class TicketCategorizationPlan implements CategorizationPlan { public Category newCategory(Event e, List el) { 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 findEventsToRecategorize(Event e,