Fixed, expanded category implementations. Started chart work.

Added FilteredCategory, filters by arbitrary CategoryFilters.
Started on Util class with code to create charts based on categories.
Fixed ITHelp ticket matching to swallow optional space after "ITHelp:"
Fixed TicketCategory to use it's own addEvent logic instead of inheriting the
  default Category implementation.
Updated startscript.groovy to reflect test data for recent changes.
This commit is contained in:
Jonathan Bernard 2011-01-11 08:21:41 -06:00
parent 6de924927a
commit ba04aae34e
20 changed files with 103 additions and 8 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
lib/runtime/gnujaxp.jar Normal file

Binary file not shown.

BIN
lib/runtime/iText-2.1.5.jar Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
lib/runtime/servlet.jar Normal file

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,5 @@
package com.jdbernard.timeanalyzer;
public interface CategoryFilter {
public boolean matchesEvent(Event event);
}

View File

@ -0,0 +1,16 @@
package com.jdbernard.timeanalyzer
public class FilteredCategory extends Category{
List<CategoryFilter> filters = []
public FilteredCategory(String description) {
super()
this.description = description
}
public boolean matchesEvent(Event e) {
return filters.every { filter -> filter.matchesEvent(e) }
}
}

View File

@ -0,0 +1,22 @@
package com.jdbernard.timeanalyzer
import org.joda.time.Interval
import org.joda.time.ReadableInstant
import org.joda.time.ReadableInterval
public class TimeIntervalCategoryFilter implements CategoryFilter {
ReadableInterval interval
public TimeIntervalCategoryFilter(ReadableInterval interval) {
this.interval = interval
}
public TimeIntervalCategoryFilter(ReadableInstant start, ReadableInstant end) {
this.interval = new Interval(start, end)
}
public boolean matchesEvent(Event event) {
return interval.contains(event.start)
}
}

View File

@ -0,0 +1,16 @@
package com.jdbernard.timeanalyzer.chart
import com.jdbernard.timeanalyzer.Category
import org.jfree.data.general.DefaultPieDataset
import org.jfree.data.general.PieDataset
import org.jfree.util.SortOrder
public class Util {
public static PieDataset makePieDataset(Category category) {
DefaultPieDataset dpds = new DefaultPieDataset()
category.categories { subcat ->
dpds.setValue(subcat.description, subcat.
}
}

View File

@ -6,7 +6,7 @@ import com.jdbernard.timeanalyzer.Event
public class ITHelpCategory extends Category {
private def ithelpPattern = ~/^ITHelp:(.*)$/
private def ithelpPattern = ~/^ITHelp:\s*(.*)$/
private def ticketPattern = ~/^ITHelp:.*#(\d+).*/
public boolean matchesEvent(Event e) {

View File

@ -17,4 +17,9 @@ public class TicketCategory extends Category {
return (e.description ==~ /ITHelp:.*#${ticketId}.*/)
}
public TicketEntry addEvent(Event e) {
TicketEntry te = new TicketEntry(this, e)
entries << te
return te
}
}

View File

@ -7,10 +7,10 @@ public class TicketEntry extends Entry {
public int id
public TicketEntry(ITHelpCategory category, Event e) {
public TicketEntry(TicketCategory category, Event e) {
super(category, e)
def m = e.description =~ /^ITHelp:(.*#(\d+).*)$/
def m = e.description =~ /^ITHelp:\s*(.*#(\d+).*)$/
this.description = m[0][1]
this.id = m[0][2] as int
}

View File

@ -1,16 +1,47 @@
import com.jdbernard.timeanalyzer.*
import com.jdbernard.timestamper.core.*
import com.quantumdigital.ithelp.timeanalyzer.*
import org.joda.time.*
import org.joda.time.format.*
import org.jfree.chart.*
import org.jfree.data.general.*
import org.jfree.util.SortOrder
tep = new TimelineEventProcessor()
tep.exclusions << ~/Going Home/
uri = new URI("file:///C:/Documents%20and%20Settings/jbernard/My%20Documents/projects/time-analyzer/timeline.jdbernard.txt")
fileSource = new FileTimelineSource(uri)
pf = PeriodFormat.getDefault()
fileSource = new FileTimelineSource(new File("timeline.jdbernard.txt").toURI())
timeline = fileSource.read()
events = tep.process(timeline)
topcat = new GeneralCategory()
topcat = new FilteredCategory()
topcat.filters << new TimeIntervalCategoryFilter(
new DateTime(2011, 1, 2, 0, 0, 0, 0), new DateTime(2011, 1, 9, 0, 0, 0, 0))
topcat.description = "Top Category"
thelpcat = new ITHelpCategory()
iithelpcat.description = "ITHelp"
ithelpcat = new ITHelpCategory()
ithelpcat.description = "ITHelp"
topcat.categories << ithelpcat
events.each { if (topcat.matchesEvent(it)) topcat.addEvent(it) }
makePieDataset = { category ->
DefaultPieDataset dpds = new DefaultPieDataset()
category.categories.each { cat ->
dpds.setValue(cat.description, cat.duration.standardSeconds) }
category.entries.each { entry ->
dpds.setValue(entry.description, entry.duration.standardSeconds) }
dpds.sortByValues(SortOrder.DESCENDING)
return dpds
}
topcatDataset = makePieDataset(topcat)
ithelpDataset = makePieDataset(ithelpcat)
topcatFrame = new ChartFrame("Top Category",
ChartFactory.createPieChart("Time Spent", topcatDataset, true, true, false))
ithelpFrame = new ChartFrame("ITHelp",
ChartFactory.createPieChart("Time Spent", ithelpDataset, true, true, false))