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:
parent
5dff4de089
commit
00a5252542
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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<Category> {
|
||||
|
||||
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<Category> {
|
||||
/** 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<Category> {
|
||||
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})" }
|
||||
}
|
||||
|
@ -9,8 +9,11 @@ public class Util {
|
||||
|
||||
public static PieDataset makePieDataset(Category 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 }
|
||||
|
||||
category.categories { subcat ->
|
||||
dpds.setValue(subcat.description, subcat.duration.getMillis()) }
|
||||
}
|
||||
}
|
||||
|
@ -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})" }
|
||||
|
||||
}
|
||||
|
@ -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<Event> process(File timelinePropFile) {
|
||||
def timelineProps = new TimelineProperties(timelinePropFile)
|
||||
return process(timelineProps.timeline) }
|
||||
|
||||
public List<Event> process(Timeline timeline) {
|
||||
List<Event> 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<Event> process(def timeline, List exclusions) {
|
||||
def inst = new TimelineEventProcessor(exclusions)
|
||||
return inst.process(timeline) }
|
||||
}
|
||||
|
@ -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<Event> 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<Event> findEventsToRecategorize(Event e,
|
||||
|
Loading…
x
Reference in New Issue
Block a user