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 import org.joda.time.DateTime import org.joda.time.Interval import org.joda.time.Period import org.joda.time.format.PeriodFormat import static com.jdbernard.timeanalyzer.chart.Util.* loadEvents = { file, processor -> fileSource = new FileTimelineSource(file.toURI()) timeline = fileSource.read() return processor.process(timeline) } 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 -> String result = "" topcat.events.eachWithIndex { event, index -> result += "${index}: ${event}\n" } return result } listCategories = { topcat -> String result = "" topcat.categories.eachWithIndex { cat, index -> result += "${index}: ${cat}\n" } return result } details = { topcat -> def result = "Categories\n" + listCategories(topcat) result += "Events\n" + listEvents(topcat) return "\n" + result } 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 }