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-09-04 10:41:40 -05:00
|
|
|
import static com.jdbernard.timeanalyzer.chart.Util.*
|
2012-08-30 06:33:35 -07:00
|
|
|
|
|
|
|
loadEvents = { file, processor ->
|
|
|
|
fileSource = new FileTimelineSource(file.toURI())
|
|
|
|
timeline = fileSource.read()
|
|
|
|
return processor.process(timeline) }
|
|
|
|
|
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 ->
|
2012-09-04 10:41:40 -05:00
|
|
|
String result = ""
|
2012-09-01 22:20:28 -07:00
|
|
|
topcat.events.eachWithIndex { event, index ->
|
2012-09-04 10:41:40 -05:00
|
|
|
result += "${index}: ${event}\n" }
|
|
|
|
|
|
|
|
return result }
|
2012-09-01 22:20:28 -07:00
|
|
|
|
|
|
|
listCategories = { topcat ->
|
2012-09-04 10:41:40 -05:00
|
|
|
String result = ""
|
2012-09-01 22:20:28 -07:00
|
|
|
topcat.categories.eachWithIndex { cat, index ->
|
2012-09-04 10:41:40 -05:00
|
|
|
result += "${index}: ${cat}\n" }
|
|
|
|
|
|
|
|
return result }
|
2012-09-01 22:20:28 -07:00
|
|
|
|
|
|
|
details = { topcat ->
|
2012-09-04 10:41:40 -05:00
|
|
|
def result = "Categories\n" + listCategories(topcat)
|
|
|
|
result += "Events\n" + listEvents(topcat)
|
|
|
|
|
|
|
|
return "\n" + result }
|
2012-09-01 22:20:28 -07:00
|
|
|
|
|
|
|
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 }
|