2012-09-01 22:20:28 -07:00
|
|
|
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
|
2012-08-30 06:33:35 -07:00
|
|
|
import org.jfree.util.SortOrder
|
2012-09-01 22:20:28 -07:00
|
|
|
import org.joda.time.DateTime
|
|
|
|
import org.joda.time.Interval
|
|
|
|
import org.joda.time.Period
|
|
|
|
import org.joda.time.format.PeriodFormat
|
2012-08-30 06:33:35 -07:00
|
|
|
|
|
|
|
pf = PeriodFormat.getDefault()
|
|
|
|
|
2012-09-01 22:20:28 -07:00
|
|
|
printDuration = { duration ->
|
|
|
|
pf.print(duration.toPeriod()) }
|
2012-08-30 06:33:35 -07:00
|
|
|
|
|
|
|
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 }
|
|
|
|
|
2012-09-01 22:20:28 -07:00
|
|
|
makePieFrame = { categoryName, category ->
|
|
|
|
def dataset = makePieDataset(category)
|
2012-08-30 06:33:35 -07:00
|
|
|
return new ChartFrame(categoryName,
|
|
|
|
ChartFactory.createPieChart("Time Spent", dataset, true, true, false)) }
|
2012-09-01 22:20:28 -07:00
|
|
|
|
|
|
|
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 }
|