Support for weekly summaries and daily analysis.

build.xml
---------

Added `build-shell` target. This creates a folder, `build/shell` and copies all
of the required libraries and class files to that folder, excluding the
groovy-all jar that conflicts with groovysh's internal classpath.

Category.groovy
---------------

Fixed a bug in the `addEvent()` function.

CategorizationPlan.groovy
-------------------------

* Rewrote this as groovy code.
* Now is an abstract class instead of an interface.
* Added a property, `newCatSetupFun`, which is a closure that will be run
  whenever this categorization plan creates a new category. A caller can set
  this via the constructor.
* Added a function, `setupNewCategory()` that should be called inside of all
  `newCategory()` implementations. This allows the user to have categorization
  plans added to the subcategories dynamically.
* Updated all the CategorizationPlan implementations to respect this new
  behavior.

start-script.groovy
-------------------

Implemented a more comprehensive analysis.
This commit is contained in:
Jonathan Bernard
2012-09-01 22:20:28 -07:00
parent 2650fca7f1
commit 5dff4de089
9 changed files with 148 additions and 59 deletions

View File

@ -1,27 +1,23 @@
import com.jdbernard.timeanalyzer.processors.*
import com.jdbernard.timeanalyzer.categories.*
import com.jdbernard.timeanalyzer.categorizationplans.*
import com.jdbernard.timeanalyzer.chart.*
import com.jdbernard.timeanalyzer.events.*
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 com.jdbernard.timeanalyzer.categories.FilteredCategory
import com.jdbernard.timeanalyzer.categories.TimeIntervalCategory
import com.jdbernard.timeanalyzer.categorizationplans.DailyCategorizationPlan
import com.jdbernard.timeanalyzer.categorizationplans.DescriptionBasedCategorizationPlan
import com.jdbernard.timeanalyzer.categorizationplans.TwoLevelCategorizationPlan
import com.jdbernard.timeanalyzer.processors.TimelineEventProcessor
import com.jdbernard.timestamper.core.FileTimelineSource
import org.jfree.chart.ChartFactory
import org.jfree.chart.ChartFrame
import org.jfree.data.general.DefaultPieDataset
import org.jfree.util.SortOrder
tep = new TimelineEventProcessor()
tep.exclusions << ~/.*Home.*/
import org.joda.time.DateTime
import org.joda.time.Interval
import org.joda.time.Period
import org.joda.time.format.PeriodFormat
pf = PeriodFormat.getDefault()
topcat = new FilteredCategory("Top Category")
twoLevelCatPlan = new TwoLevelCategorizationPlan()
descriptionBasedCatPlan = new DescriptionBasedCategorizationPlan()
topcat.categorizationPlans << twoLevelCatPlan
topcat.categorizationPlans << descriptionBasedCatPlan
printDuration = { duration ->
pf.print(duration.toPeriod()) }
loadEvents = { file, processor ->
fileSource = new FileTimelineSource(file.toURI())
@ -35,9 +31,61 @@ makePieDataset = { category ->
category.events.each { entry ->
dpds.setValue(entry.description, entry.duration.standardSeconds) }
dpds.sortByValues(SortOrder.DESCENDING)
return dpds }
makeFrame = { categoryName, dataset ->
makePieFrame = { categoryName, category ->
def dataset = makePieDataset(category)
return new ChartFrame(categoryName,
ChartFactory.createPieChart("Time Spent", dataset, true, true, false)) }
analyze = { file ->
def tep = new TimelineEventProcessor()
tep.exclusions << /.*Home.*/
def twoLevelPlan = new TwoLevelCategorizationPlan()
def descriptionPlan = new DescriptionBasedCategorizationPlan()
def setupCat = { cat ->
cat.categorizationPlans << twoLevelPlan
cat.categorizationPlans << descriptionPlan }
def dailyPlan = new DailyCategorizationPlan(setupCat)
def events = loadEvents(file, tep)
def topcat = new FilteredCategory("Time Analysis: Jonathan Bernard")
topcat.categorizationPlans << dailyPlan
topcat.categorizationPlans << twoLevelPlan
topcat.categorizationPlans << descriptionPlan
events.each { if (topcat.matchesEvent(it)) topcat.addEvent(it) }
return [topcat: topcat, rawEvents: events] }
listEvents = {topcat ->
topcat.events.eachWithIndex { event, index ->
println "${index}: ${event} (${printDuration(event.duration)})" }}
listCategories = { topcat ->
topcat.categories.eachWithIndex { cat, index ->
println "${index}: ${cat} (${printDuration(cat.duration)})" }}
details = { topcat ->
println "Categories"
listCategories(topcat)
println "Events"
listEvents(topcat) }
weeklySummary = { events ->
def todayMidnight = new DateTime()
def friday = todayMidnight.withDayOfWeek(5)
def monday = todayMidnight.withDayOfWeek(1)
def week = new Interval(monday, Period.days(7))
def weekCat = new TimeIntervalCategory(
"Week of ${friday.toString('MMM dd, yyyy')}", week)
weekCat.categorizationPlans << new TwoLevelCategorizationPlan()
weekCat.categorizationPlans << new DescriptionBasedCategorizationPlan()
events.each { if (weekCat.matchesEvent(it)) weekCat.addEvent(it) }
return weekCat }