Created TimelineEventProcessor. Tested existing implementation.
This commit is contained in:
parent
68b51640af
commit
6de924927a
41
build.xml
41
build.xml
@ -1,44 +1,7 @@
|
||||
<project name="Time Analyzer" default="compile">
|
||||
|
||||
<property environment="env"/>
|
||||
<property file="project.properties"/>
|
||||
<import file="jdb-build-1.5.xml"/>
|
||||
|
||||
<path id="groovy.lib">
|
||||
<fileset dir="${env.GROOVY_HOME}/lib">
|
||||
<include name="*.jar"/>
|
||||
</fileset>
|
||||
</path>
|
||||
<target name="init"/>
|
||||
|
||||
<path id="local.compile.lib">
|
||||
<fileset dir="lib/compile">
|
||||
<include name="*.jar"/>
|
||||
</fileset>
|
||||
</path>
|
||||
|
||||
<path id="local.runtime.lib">
|
||||
<fileset dir="lib/runtime">
|
||||
<include name="*.jar"/>
|
||||
</fileset>
|
||||
</path>
|
||||
|
||||
<taskdef name="groovyc" classpathref="groovy.lib"
|
||||
classname="org.codehaus.groovy.ant.Groovyc"/>
|
||||
|
||||
<target name="clean">
|
||||
<delete dir="build"/>
|
||||
</target>
|
||||
|
||||
<target name="compile">
|
||||
<mkdir dir="build/main"/>
|
||||
<groovyc srcdir="src/main" destdir="build/main"
|
||||
includeAntRuntime="false">
|
||||
|
||||
<classpath>
|
||||
<path refid="groovy.lib"/>
|
||||
<path refid="local.compile.lib"/>
|
||||
</classpath>
|
||||
|
||||
<javac/>
|
||||
</groovyc>
|
||||
</target>
|
||||
</project>
|
||||
|
199
jdb-build-1.5.xml
Normal file
199
jdb-build-1.5.xml
Normal file
@ -0,0 +1,199 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project name="Jonathan Bernard Build Common">
|
||||
|
||||
<property environment="env"/>
|
||||
|
||||
<!--======== INIT TARGETS ========-->
|
||||
<target name="-init" depends="-common-init,init"/>
|
||||
|
||||
<target name="-common-init">
|
||||
<!-- Set default values for some key properties. Since properties are
|
||||
write once, any value set before this point takes precedence. -->
|
||||
|
||||
<property name="versioning.file" value="project.properties"/>
|
||||
|
||||
<property name="src.dir" value="${basedir}/src"/>
|
||||
<property name="build.dir" value="${basedir}/build"/>
|
||||
<property name="lib.dir" value="${basedir}/lib"/>
|
||||
<property name="resources.dir" value="${basedir}/resources"/>
|
||||
<property name="lib.local" value="true"/>
|
||||
|
||||
<!--======== PATHS ========-->
|
||||
<path id="groovy.classpath">
|
||||
<fileset dir="${env.GROOVY_HOME}/lib">
|
||||
<include name="*.jar"/>
|
||||
</fileset>
|
||||
</path>
|
||||
|
||||
<path id="groovy.embeddable">
|
||||
<fileset dir="${env.GROOVY_HOME}/embeddable">
|
||||
<include name="*.jar"/>
|
||||
</fileset>
|
||||
</path>
|
||||
|
||||
<path id="compile-libs">
|
||||
<fileset dir="${build.dir}/lib/compile">
|
||||
<include name="*.jar"/>
|
||||
</fileset>
|
||||
</path>
|
||||
|
||||
<path id="runtime-libs">
|
||||
<fileset dir="${build.dir}/lib/runtime">
|
||||
<include name="*.jar"/>
|
||||
</fileset>
|
||||
</path>
|
||||
|
||||
</target>
|
||||
|
||||
<target name="-init-groovy">
|
||||
<taskdef name="groovyc" classpathref="groovy.classpath"
|
||||
classname="org.codehaus.groovy.ant.Groovyc"/>
|
||||
|
||||
<taskdef name="groovy" classpathref="groovy.classpath"
|
||||
classname="org.codehaus.groovy.ant.Groovy"/>
|
||||
</target>
|
||||
|
||||
<target name="clean" depends="-init">
|
||||
<delete dir="${build.dir}"/>
|
||||
</target>
|
||||
|
||||
<!--======== LIBRARY TARGETS ========-->
|
||||
<target name="lib" depends="-lib-local,-lib-ivy"/>
|
||||
|
||||
<target name="-lib-ivy" unless="${lib.local}"/>
|
||||
|
||||
<target name="-lib-local" if="${lib.local}">
|
||||
<echo message="Resolving libraries locally."/>
|
||||
<mkdir dir="${build.dir}/lib/compile"/>
|
||||
<mkdir dir="${build.dir}/lib/runtime"/>
|
||||
<copy todir="${build.dir}/lib/compile" failonerror="false">
|
||||
<fileset dir="${lib.dir}/compile"/>
|
||||
</copy>
|
||||
|
||||
<copy todir="${build.dir}/lib/runtime" failonerror="false">
|
||||
<fileset dir="${lib.dir}/runtime"/>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<!--======== VERSIONING TARGETS ========-->
|
||||
<target name="increment-build-number" depends="-init">
|
||||
<propertyfile file="${versioning.file}">
|
||||
<entry key="build.number" default="0" type="int" value="1"
|
||||
operation="+"/>
|
||||
</propertyfile>
|
||||
</target>
|
||||
|
||||
<target name="set-version" depends="-init">
|
||||
<input
|
||||
message="The current version is ${version}. Enter a new version: "
|
||||
addproperty="new-version"/>
|
||||
<propertyfile file="${versioning.file}">
|
||||
<entry key="version" value="${new-version}" operation="="
|
||||
type="string"/>
|
||||
</propertyfile>
|
||||
</target>
|
||||
|
||||
<!--======== COMPILATION TARGETS ========-->
|
||||
<target name="-compile-groovy" depends="-init,-init-groovy,lib">
|
||||
<mkdir dir="${build.dir}/main/classes"/>
|
||||
<groovyc srcdir="${src.dir}/main" destdir="${build.dir}/main/classes"
|
||||
includeAntRuntime="false">
|
||||
|
||||
<classpath>
|
||||
<path refid="groovy.classpath"/>
|
||||
<path refid="compile-libs"/>
|
||||
</classpath>
|
||||
<javac/>
|
||||
</groovyc>
|
||||
</target>
|
||||
|
||||
<target name="-compile-java" depends="-init,lib">
|
||||
<mkdir dir="${build.dir}/main/classes"/>
|
||||
<javac srcdir="${src.dir}/main" destdir="${build.dir}/main/classes"
|
||||
includeAntRuntime="false" classpathref="compile-libs"/>
|
||||
</target>
|
||||
|
||||
<target name="compile" depends="-compile-groovy"/>
|
||||
|
||||
<!--======== JUNIT TARGETS ========-->
|
||||
<target name="-compile-tests-groovy" depends="-init,compile">
|
||||
<mkdir dir="${build.dir}/test/classes"/>
|
||||
<groovyc srcdir="${src.dir}/test" destdir="${build.dir}/test/classes"
|
||||
includeAntRuntime="false">
|
||||
|
||||
<classpath>
|
||||
<path refid="groovy.classpath"/>
|
||||
<path refid="compile-libs"/>
|
||||
<path location="${build.dir}/main/classes"/>
|
||||
</classpath>
|
||||
</groovyc>
|
||||
</target>
|
||||
|
||||
<target name="-compile-tests-java" depends="-init,compile">
|
||||
<mkdir dir="${build.dir}/test/classes"/>
|
||||
<javac srcdir="${src.dir}/test" destdir="${build.dir}/test/classes"
|
||||
includeAntRuntime="false">
|
||||
<classpath>
|
||||
<path refid="compile-libs"/>
|
||||
<path location="${build.dir}/main/classes"/>
|
||||
</classpath>
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<target name="compile-tests" depends="-compile-tests-groovy"/>
|
||||
|
||||
<target name="run-tests" depends="compile-tests,resources-test">
|
||||
<junit printsummary="true">
|
||||
<classpath>
|
||||
<path refid="groovy.classpath"/>
|
||||
<path refid="compile-libs"/>
|
||||
<path location="${build.dir}/main/classes"/>
|
||||
<path location="${build.dir}/test/classes"/>
|
||||
</classpath>
|
||||
<formatter type="plain" usefile="false"/>
|
||||
<batchtest>
|
||||
<fileset dir="${build.dir}/test/classes">
|
||||
<include name="**/*"/>
|
||||
</fileset>
|
||||
</batchtest>
|
||||
</junit>
|
||||
</target>
|
||||
|
||||
<!--======== RESOURCES TARGETS ========-->
|
||||
|
||||
<target name="resources" depends="-init">
|
||||
<mkdir dir="${build.dir}/main/classes"/>
|
||||
<copy todir="${build.dir}/main/classes" failonerror="false">
|
||||
<fileset dir="${resources.dir}/main/"/>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<target name="resources-test" depends="-init">
|
||||
<mkdir dir="${build.dir}/test/classes"/>
|
||||
<copy todir="${build.dir}/test/classes" failonerror="false">
|
||||
<fileset dir="${resources.dir}/test/"/>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<!--======== BUILD TARGETS ========-->
|
||||
<target name="-build-modular"
|
||||
depends="compile,increment-build-number,resources">
|
||||
|
||||
<jar destfile="${build.dir}/${name}-${version}.${build.number}.jar"
|
||||
basedir="${build.dir}/main/classes"/>
|
||||
</target>
|
||||
|
||||
<target name="-build-packed-libs"
|
||||
depends="compile,increment-build-number,resources">
|
||||
|
||||
<unjar destdir="${build.dir}/main/classes">
|
||||
<fileset dir="${build.dir}/lib/runtime"/>
|
||||
</unjar>
|
||||
|
||||
<jar destfile="${build.dir}/${name}-${version}.${build.number}.jar"
|
||||
basedir="${build.dir}/main/classes"/>
|
||||
</target>
|
||||
|
||||
<target name="build" depends="-build-modular"/>
|
||||
|
||||
</project>
|
BIN
lib/compile/timestamper-2.0-lib.jar
Normal file
BIN
lib/compile/timestamper-2.0-lib.jar
Normal file
Binary file not shown.
BIN
lib/runtime/timestamper-2.0-lib.jar
Normal file
BIN
lib/runtime/timestamper-2.0-lib.jar
Normal file
Binary file not shown.
@ -7,9 +7,9 @@ import org.joda.time.Duration
|
||||
*/
|
||||
public abstract class Category implements Comparable<Category> {
|
||||
|
||||
List<Entry> entries
|
||||
List<Category> categories
|
||||
String description
|
||||
public List<Entry> entries
|
||||
public List<Category> categories
|
||||
public String description
|
||||
|
||||
public Category() {
|
||||
entries = []
|
||||
@ -23,7 +23,7 @@ public abstract class Category implements Comparable<Category> {
|
||||
Entry entry
|
||||
|
||||
// see if we have a subcategory that will hold this event
|
||||
entry = addToSubCategory(e)
|
||||
entry = addToSubcategory(e)
|
||||
|
||||
if (!entry) {
|
||||
// if not, do we have another entry that could be grouped with
|
||||
@ -34,15 +34,16 @@ public abstract class Category implements Comparable<Category> {
|
||||
// yes
|
||||
if (existingEntry) {
|
||||
// create the new category
|
||||
category = new DescriptionBasedCategory(e.description)
|
||||
def category = new DescriptionBasedCategory(e.description)
|
||||
|
||||
// add the new event to the category
|
||||
entry = category.addEvent(e)
|
||||
|
||||
// remove the existing entry from this category and
|
||||
// add it to the subcategory
|
||||
this.entries -= existingEntry
|
||||
category.entries << existingEntry
|
||||
|
||||
// add the new event to the category
|
||||
entry = category.addEvent(e)
|
||||
existingEntry.category = category
|
||||
|
||||
// add the category to our list of subcategories
|
||||
categories << category
|
||||
@ -69,11 +70,14 @@ public abstract class Category implements Comparable<Category> {
|
||||
}
|
||||
|
||||
public Duration getDuration() {
|
||||
return categories.sum { it.duration } + entries.sum { it.duration }
|
||||
return categories.sum(new Duration(0)) { it.duration } +
|
||||
entries.sum(new Duration(0)) { it.duration }
|
||||
}
|
||||
|
||||
public int compareTo(Category other) {
|
||||
return this.getDuration().compareTo(other.getDuration())
|
||||
}
|
||||
|
||||
public String toString() { return description }
|
||||
|
||||
}
|
||||
|
@ -26,7 +26,10 @@ public class Entry {
|
||||
this.notes = notes;
|
||||
this.start = start;
|
||||
this.duration = duration;
|
||||
this.category = category;
|
||||
this.category = c;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return category.description + ": " + description;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ package com.jdbernard.timeanalyzer;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Duration;
|
||||
import org.joda.time.format.PeriodFormat;
|
||||
import org.joda.time.format.PeriodFormatter;
|
||||
|
||||
public class Event {
|
||||
|
||||
@ -10,4 +12,11 @@ public class Event {
|
||||
public DateTime start;
|
||||
public Duration duration;
|
||||
|
||||
|
||||
|
||||
public static PeriodFormatter periodFormatter = PeriodFormat.getDefault();
|
||||
|
||||
public String toString() {
|
||||
return description;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.jdbernard.timeanalyzer
|
||||
|
||||
public class GeneralCategory {
|
||||
public class GeneralCategory extends Category {
|
||||
|
||||
public GeneralCategory() {
|
||||
super()
|
||||
|
@ -0,0 +1,46 @@
|
||||
package com.jdbernard.timeanalyzer
|
||||
|
||||
import com.jdbernard.timestamper.core.Timeline
|
||||
import org.joda.time.DateTime
|
||||
import org.joda.time.Duration
|
||||
|
||||
public class TimelineEventProcessor {
|
||||
|
||||
/** Events whose description matches one of these regex strings or
|
||||
* patterns are ignored. */
|
||||
List exclusions = []
|
||||
|
||||
public TimelineEventProcessor() {}
|
||||
|
||||
public TimelineEventProcessor(List exclusions) {
|
||||
this.exclusions = exclusions
|
||||
}
|
||||
|
||||
public List<Event> process(Timeline timeline) {
|
||||
List<Event> events = []
|
||||
|
||||
timeline.each { marker ->
|
||||
Event e = new Event()
|
||||
|
||||
e.description = marker.mark
|
||||
e.notes = marker.notes
|
||||
e.start = new DateTime(marker.timestamp)
|
||||
e.duration = new Duration(0)
|
||||
|
||||
// if this is not the first event, then we need to update the
|
||||
// duration of the previous event
|
||||
if (events.size > 0) {
|
||||
Event lastEvent = events[-1]
|
||||
lastEvent.duration = new Duration(lastEvent.start, e.start)
|
||||
}
|
||||
|
||||
events << e
|
||||
}
|
||||
|
||||
def excluded = events.findAll { event ->
|
||||
exclusions.any { exclusion -> event.description ==~ exclusion }
|
||||
}
|
||||
|
||||
return events - excluded
|
||||
}
|
||||
}
|
16
startscript.groovy
Normal file
16
startscript.groovy
Normal file
@ -0,0 +1,16 @@
|
||||
import com.jdbernard.timeanalyzer.*
|
||||
import com.jdbernard.timestamper.core.*
|
||||
import com.quantumdigital.ithelp.timeanalyzer.*
|
||||
|
||||
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)
|
||||
timeline = fileSource.read()
|
||||
events = tep.process(timeline)
|
||||
topcat = new GeneralCategory()
|
||||
topcat.description = "Top Category"
|
||||
thelpcat = new ITHelpCategory()
|
||||
iithelpcat.description = "ITHelp"
|
||||
topcat.categories << ithelpcat
|
||||
events.each { if (topcat.matchesEvent(it)) topcat.addEvent(it) }
|
BIN
timeline.jdbernard.txt
Normal file
BIN
timeline.jdbernard.txt
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user