[kepler-code] r28807 - in trunk/modules: science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn science-pipes-backend/src/edu/cornell/birds/is/bap/actor/crossingboundaries science-pipes-backend/src/edu/cornell/birds/is/bap/actor/survivorship science-pipes-backend/src/edu/cornell/birds/is/bap/actor/survivorship/dataset science-pipes-backend/src/edu/cornell/birds/is/bap/data science-pipes-frontend/WebContent/editor/parts
barseghian at ecoinformatics.org
barseghian at ecoinformatics.org
Mon Oct 17 19:16:42 PDT 2011
Author: barseghian
Date: 2011-10-17 19:16:42 -0700 (Mon, 17 Oct 2011)
New Revision: 28807
Added:
trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/crossingboundaries/CrossingBoundariesDatasetFilter.java
trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/survivorship/SurvivorshipDateRangeFilter.java
trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/survivorship/dataset/DemographyDataFormat.java
trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/DatasetFilter.java
trunk/modules/science-pipes-frontend/WebContent/editor/parts/edu.cornell.birds.is.bap.actor.survivorship.SurvivorshipDateRangeFilter.meta.xml
Removed:
trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNDatasetFilter.java
trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/crossingboundaries/DatasetFilter.java
Modified:
trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNCollectorFilter.java
trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNCountyFilter.java
trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNDateRangeFilter.java
trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNDurationFilter.java
trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNMonthFilter.java
trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNStateFilter.java
trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNYearFilter.java
trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNeBirdDistanceFilter.java
trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNeBirdProtocolFilter.java
trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/crossingboundaries/EcoregionFilter.java
trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/crossingboundaries/TaxonClassFilter.java
trunk/modules/science-pipes-frontend/WebContent/editor/parts/survivorship-actors.xml
Log:
Survivorship date range filter actor, and supporting classes / refactoring
Modified: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNCollectorFilter.java
===================================================================
--- trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNCollectorFilter.java 2011-10-17 22:28:53 UTC (rev 28806)
+++ trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNCollectorFilter.java 2011-10-18 02:16:42 UTC (rev 28807)
@@ -1,5 +1,6 @@
package edu.cornell.birds.is.bap.actor.akn;
+import edu.cornell.birds.is.bap.data.DatasetFilter;
import ptolemy.actor.TypedIOPort;
import ptolemy.data.StringToken;
import ptolemy.data.expr.StringParameter;
@@ -8,7 +9,7 @@
import ptolemy.kernel.util.IllegalActionException;
import ptolemy.kernel.util.NameDuplicationException;
-public class AKNCollectorFilter extends AKNDatasetFilter {
+public class AKNCollectorFilter extends DatasetFilter {
/**
*
Modified: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNCountyFilter.java
===================================================================
--- trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNCountyFilter.java 2011-10-17 22:28:53 UTC (rev 28806)
+++ trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNCountyFilter.java 2011-10-18 02:16:42 UTC (rev 28807)
@@ -1,5 +1,6 @@
package edu.cornell.birds.is.bap.actor.akn;
+import edu.cornell.birds.is.bap.data.DatasetFilter;
import ptolemy.actor.TypedIOPort;
import ptolemy.data.StringToken;
import ptolemy.data.expr.StringParameter;
@@ -8,7 +9,7 @@
import ptolemy.kernel.util.IllegalActionException;
import ptolemy.kernel.util.NameDuplicationException;
-public class AKNCountyFilter extends AKNDatasetFilter {
+public class AKNCountyFilter extends DatasetFilter {
/**
*
Deleted: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNDatasetFilter.java
===================================================================
--- trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNDatasetFilter.java 2011-10-17 22:28:53 UTC (rev 28806)
+++ trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNDatasetFilter.java 2011-10-18 02:16:42 UTC (rev 28807)
@@ -1,110 +0,0 @@
-package edu.cornell.birds.is.bap.actor.akn;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.PrintWriter;
-
-import org.apache.log4j.Logger;
-import org.springframework.util.StringUtils;
-
-import ptolemy.actor.TypedAtomicActor;
-import ptolemy.actor.TypedIOPort;
-import ptolemy.data.StringToken;
-import ptolemy.data.type.BaseType;
-import ptolemy.kernel.CompositeEntity;
-import ptolemy.kernel.util.IllegalActionException;
-import ptolemy.kernel.util.NameDuplicationException;
-
-public abstract class AKNDatasetFilter extends TypedAtomicActor {
-
- /**
- *
- */
- private static final long serialVersionUID = -7565920482937743966L;
-
- protected static final Logger logger = Logger.getLogger(AKNDatasetFilter.class);
- public TypedIOPort inPort;
- public TypedIOPort outPort;
-
- public String columnSeparator = "\t";
- public String targetValue = "";
- public boolean hasHeaderRow = true;
- public int targetColumn = 14; // first index = 1 (NOT zero)
-
- public AKNDatasetFilter(CompositeEntity container, String name)
- throws IllegalActionException, NameDuplicationException {
-
- super(container, name);
-
- inPort = new TypedIOPort(this, "in", true, false);
- inPort.setTypeEquals(BaseType.STRING);
-
- outPort = new TypedIOPort(this, "out", false, true);
- outPort.setTypeEquals(BaseType.STRING);
-
- }
-
- public void fire() throws IllegalActionException {
- if (inPort.hasToken(0)) {
- try {
- StringToken inputFileNameToken = (StringToken) inPort.get(0);
- String inputFileName = inputFileNameToken.stringValue();
-
- String columnDelimiter = columnSeparator;
- if ("\\t".equals(columnDelimiter)) columnDelimiter = "\t";
-
-// int whichColumn = targetColumn - 1;
-
-// String targetMatch = targetValue;
-
- if (!StringUtils.hasLength(targetValue)) {
- // don't filter anything
- outPort.broadcast(new StringToken(inputFileName));
- return;
- }
-
-// logger.debug("Looking for: [" + targetMatch + "]");
-
-// StringBuffer result = new StringBuffer();
-
- BufferedReader reader = new BufferedReader(new FileReader(inputFileName));
- File outputFile = File.createTempFile("akn", null);
- PrintWriter writer = new PrintWriter(new FileWriter(outputFile));
-
- String os = null;
- boolean firstTime = true;
- while((os = reader.readLine()) != null) {
-// logger.debug("line [" + os + "]");
-
- String[] columns = os.split(columnDelimiter);
-// logger.debug("compare [" + columns[whichColumn] + "]");
- if (includeThisRecord(columns)
- || (hasHeaderRow && firstTime)) {
-// logger.debug("match!");
- writer.println(os);
- }
- firstTime = false;
- }
- reader.close();
- writer.close();
- logger.debug("ouput filename: ["+ outputFile.getPath()+ "]");
- outPort.broadcast(new StringToken(outputFile.getPath()));
- }
- catch (FileNotFoundException e) {
- throw new IllegalActionException(this, e, "FileNotFoundException");
- }
- catch (IOException e) {
- throw new IllegalActionException(this, e, "IOException");
- }
- }
- }
-
- protected boolean includeThisRecord(String[] columns) {
- return targetValue.equals(columns[targetColumn-1]);
- }
-
-}
\ No newline at end of file
Modified: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNDateRangeFilter.java
===================================================================
--- trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNDateRangeFilter.java 2011-10-17 22:28:53 UTC (rev 28806)
+++ trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNDateRangeFilter.java 2011-10-18 02:16:42 UTC (rev 28807)
@@ -8,6 +8,7 @@
import ptolemy.kernel.CompositeEntity;
import ptolemy.kernel.util.IllegalActionException;
import ptolemy.kernel.util.NameDuplicationException;
+import edu.cornell.birds.is.bap.data.DatasetFilter;
import edu.cornell.birds.is.bap.ptolemy.StringChoiceParameter;
import edu.cornell.birds.is.bap.ptolemy.StringChoiceProvider;
@@ -17,7 +18,7 @@
* @author pea1
*
*/
-public class AKNDateRangeFilter extends AKNDatasetFilter {
+public class AKNDateRangeFilter extends DatasetFilter {
protected static final Logger logger = Logger.getLogger(AKNDateRangeFilter.class);
/**
Modified: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNDurationFilter.java
===================================================================
--- trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNDurationFilter.java 2011-10-17 22:28:53 UTC (rev 28806)
+++ trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNDurationFilter.java 2011-10-18 02:16:42 UTC (rev 28807)
@@ -3,6 +3,8 @@
import org.apache.log4j.Logger;
import org.springframework.util.StringUtils;
+import edu.cornell.birds.is.bap.data.DatasetFilter;
+
import ptolemy.actor.TypedIOPort;
import ptolemy.data.StringToken;
import ptolemy.data.expr.StringParameter;
@@ -17,7 +19,7 @@
* @author pea1
*
*/
-public class AKNDurationFilter extends AKNDatasetFilter {
+public class AKNDurationFilter extends DatasetFilter {
/**
*
Modified: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNMonthFilter.java
===================================================================
--- trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNMonthFilter.java 2011-10-17 22:28:53 UTC (rev 28806)
+++ trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNMonthFilter.java 2011-10-18 02:16:42 UTC (rev 28807)
@@ -6,10 +6,11 @@
import ptolemy.kernel.CompositeEntity;
import ptolemy.kernel.util.IllegalActionException;
import ptolemy.kernel.util.NameDuplicationException;
+import edu.cornell.birds.is.bap.data.DatasetFilter;
import edu.cornell.birds.is.bap.ptolemy.StringChoiceParameter;
import edu.cornell.birds.is.bap.ptolemy.StringChoiceProvider;
-public class AKNMonthFilter extends AKNDatasetFilter {
+public class AKNMonthFilter extends DatasetFilter {
/**
*
Modified: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNStateFilter.java
===================================================================
--- trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNStateFilter.java 2011-10-17 22:28:53 UTC (rev 28806)
+++ trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNStateFilter.java 2011-10-18 02:16:42 UTC (rev 28807)
@@ -6,10 +6,11 @@
import ptolemy.kernel.CompositeEntity;
import ptolemy.kernel.util.IllegalActionException;
import ptolemy.kernel.util.NameDuplicationException;
+import edu.cornell.birds.is.bap.data.DatasetFilter;
import edu.cornell.birds.is.bap.ptolemy.StringChoiceParameter;
import edu.cornell.birds.is.bap.ptolemy.StringChoiceProvider;
-public class AKNStateFilter extends AKNDatasetFilter {
+public class AKNStateFilter extends DatasetFilter {
/**
*
Modified: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNYearFilter.java
===================================================================
--- trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNYearFilter.java 2011-10-17 22:28:53 UTC (rev 28806)
+++ trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNYearFilter.java 2011-10-18 02:16:42 UTC (rev 28807)
@@ -2,6 +2,8 @@
import java.util.Calendar;
+import edu.cornell.birds.is.bap.data.DatasetFilter;
+
import ptolemy.actor.TypedIOPort;
import ptolemy.data.StringToken;
import ptolemy.data.expr.Parameter;
@@ -11,7 +13,7 @@
import ptolemy.kernel.util.IllegalActionException;
import ptolemy.kernel.util.NameDuplicationException;
-public class AKNYearFilter extends AKNDatasetFilter {
+public class AKNYearFilter extends DatasetFilter {
/**
*
Modified: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNeBirdDistanceFilter.java
===================================================================
--- trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNeBirdDistanceFilter.java 2011-10-17 22:28:53 UTC (rev 28806)
+++ trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNeBirdDistanceFilter.java 2011-10-18 02:16:42 UTC (rev 28807)
@@ -3,6 +3,8 @@
import org.apache.log4j.Logger;
import org.springframework.util.StringUtils;
+import edu.cornell.birds.is.bap.data.DatasetFilter;
+
import ptolemy.actor.TypedIOPort;
import ptolemy.data.StringToken;
import ptolemy.data.expr.StringParameter;
@@ -17,7 +19,7 @@
* @author pea1
*
*/
-public class AKNeBirdDistanceFilter extends AKNDatasetFilter {
+public class AKNeBirdDistanceFilter extends DatasetFilter {
/**
*
Modified: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNeBirdProtocolFilter.java
===================================================================
--- trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNeBirdProtocolFilter.java 2011-10-17 22:28:53 UTC (rev 28806)
+++ trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNeBirdProtocolFilter.java 2011-10-18 02:16:42 UTC (rev 28807)
@@ -2,6 +2,8 @@
import org.apache.log4j.Logger;
+import edu.cornell.birds.is.bap.data.DatasetFilter;
+
import ptolemy.actor.TypedIOPort;
import ptolemy.data.BooleanToken;
import ptolemy.data.StringToken;
@@ -17,7 +19,7 @@
* @author pea1
*
*/
-public class AKNeBirdProtocolFilter extends AKNDatasetFilter {
+public class AKNeBirdProtocolFilter extends DatasetFilter {
/**
*
Copied: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/crossingboundaries/CrossingBoundariesDatasetFilter.java (from rev 28529, trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/crossingboundaries/DatasetFilter.java)
===================================================================
--- trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/crossingboundaries/CrossingBoundariesDatasetFilter.java (rev 0)
+++ trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/crossingboundaries/CrossingBoundariesDatasetFilter.java 2011-10-18 02:16:42 UTC (rev 28807)
@@ -0,0 +1,94 @@
+package edu.cornell.birds.is.bap.actor.crossingboundaries;
+
+import org.apache.log4j.Logger;
+import org.springframework.util.StringUtils;
+
+import ptolemy.actor.TypedAtomicActor;
+import ptolemy.actor.TypedIOPort;
+import ptolemy.data.StringToken;
+import ptolemy.data.type.BaseType;
+import ptolemy.kernel.CompositeEntity;
+import ptolemy.kernel.util.IllegalActionException;
+import ptolemy.kernel.util.NameDuplicationException;
+
+public class CrossingBoundariesDatasetFilter extends TypedAtomicActor {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -1562685816352231649L;
+ protected static final Logger logger = Logger.getLogger(CrossingBoundariesDatasetFilter.class);
+ public TypedIOPort inPort;
+ public TypedIOPort outPort;
+ public String columnSeparator = "\t";
+ public String targetValue = "Reptilia";
+ public boolean hasHeaderRow = true;
+ public int targetColumn = 14;
+ private static String newline = System.getProperty("line.separator");
+
+ public CrossingBoundariesDatasetFilter(CompositeEntity container, String name)
+ throws IllegalActionException, NameDuplicationException {
+
+ super(container, name);
+
+ inPort = new TypedIOPort(this, "in", true, false);
+ inPort.setTypeEquals(BaseType.STRING);
+
+ outPort = new TypedIOPort(this, "out", false, true);
+ outPort.setTypeEquals(BaseType.STRING);
+
+// columnSeparator = new StringParameter(this, "column separator");
+// columnSeparator.setExpression("\\t");
+//
+// targetValue = new StringParameter(this, "target value");
+// targetValue.setExpression("Reptilia");
+//
+// targetColumn = new Parameter(this, "target column");
+// targetColumn.setTypeEquals(BaseType.INT);
+// targetColumn.setExpression("14");
+ }
+
+ public void fire() throws IllegalActionException {
+ if (inPort.hasToken(0)) {
+ StringToken token = (StringToken) inPort.get(0);
+
+ String columnDelimiter = columnSeparator;
+ if ("\\t".equals(columnDelimiter)) columnDelimiter = "\t";
+
+ int whichColumn = targetColumn - 1;
+
+ String targetMatch = targetValue;
+ String input = token.stringValue();
+
+ if (!StringUtils.hasLength(targetMatch)) {
+ // don't filter anything
+ outPort.broadcast(new StringToken(input));
+ return;
+ }
+
+ logger.debug("original string: [" + input + "]");
+
+ String[] lines = input.split(newline);
+
+ logger.debug("lines:" + StringUtils.arrayToDelimitedString(lines, "|"));
+
+ StringBuffer result = new StringBuffer();
+
+ for(int i = 0; i < lines.length; i++) {
+ String s = lines[i];
+
+ String[] columns = s.split(columnDelimiter);
+ logger.debug("compare [" + columns[whichColumn] + "]");
+ if (targetMatch.equals(columns[whichColumn])
+ || (hasHeaderRow && i == 0)) {
+ logger.debug("match!");
+ result.append(s);
+ result.append(newline);
+ }
+ }
+ logger.debug("result: ["+ result + "]");
+ outPort.broadcast(new StringToken(result.toString()));
+ }
+ }
+
+}
\ No newline at end of file
Deleted: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/crossingboundaries/DatasetFilter.java
===================================================================
--- trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/crossingboundaries/DatasetFilter.java 2011-10-17 22:28:53 UTC (rev 28806)
+++ trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/crossingboundaries/DatasetFilter.java 2011-10-18 02:16:42 UTC (rev 28807)
@@ -1,94 +0,0 @@
-package edu.cornell.birds.is.bap.actor.crossingboundaries;
-
-import org.apache.log4j.Logger;
-import org.springframework.util.StringUtils;
-
-import ptolemy.actor.TypedAtomicActor;
-import ptolemy.actor.TypedIOPort;
-import ptolemy.data.StringToken;
-import ptolemy.data.type.BaseType;
-import ptolemy.kernel.CompositeEntity;
-import ptolemy.kernel.util.IllegalActionException;
-import ptolemy.kernel.util.NameDuplicationException;
-
-public class DatasetFilter extends TypedAtomicActor {
-
- /**
- *
- */
- private static final long serialVersionUID = -1562685816352231649L;
- protected static final Logger logger = Logger.getLogger(DatasetFilter.class);
- public TypedIOPort inPort;
- public TypedIOPort outPort;
- public String columnSeparator = "\t";
- public String targetValue = "Reptilia";
- public boolean hasHeaderRow = true;
- public int targetColumn = 14;
- private static String newline = System.getProperty("line.separator");
-
- public DatasetFilter(CompositeEntity container, String name)
- throws IllegalActionException, NameDuplicationException {
-
- super(container, name);
-
- inPort = new TypedIOPort(this, "in", true, false);
- inPort.setTypeEquals(BaseType.STRING);
-
- outPort = new TypedIOPort(this, "out", false, true);
- outPort.setTypeEquals(BaseType.STRING);
-
-// columnSeparator = new StringParameter(this, "column separator");
-// columnSeparator.setExpression("\\t");
-//
-// targetValue = new StringParameter(this, "target value");
-// targetValue.setExpression("Reptilia");
-//
-// targetColumn = new Parameter(this, "target column");
-// targetColumn.setTypeEquals(BaseType.INT);
-// targetColumn.setExpression("14");
- }
-
- public void fire() throws IllegalActionException {
- if (inPort.hasToken(0)) {
- StringToken token = (StringToken) inPort.get(0);
-
- String columnDelimiter = columnSeparator;
- if ("\\t".equals(columnDelimiter)) columnDelimiter = "\t";
-
- int whichColumn = targetColumn - 1;
-
- String targetMatch = targetValue;
- String input = token.stringValue();
-
- if (!StringUtils.hasLength(targetMatch)) {
- // don't filter anything
- outPort.broadcast(new StringToken(input));
- return;
- }
-
- logger.debug("original string: [" + input + "]");
-
- String[] lines = input.split(newline);
-
- logger.debug("lines:" + StringUtils.arrayToDelimitedString(lines, "|"));
-
- StringBuffer result = new StringBuffer();
-
- for(int i = 0; i < lines.length; i++) {
- String s = lines[i];
-
- String[] columns = s.split(columnDelimiter);
- logger.debug("compare [" + columns[whichColumn] + "]");
- if (targetMatch.equals(columns[whichColumn])
- || (hasHeaderRow && i == 0)) {
- logger.debug("match!");
- result.append(s);
- result.append(newline);
- }
- }
- logger.debug("result: ["+ result + "]");
- outPort.broadcast(new StringToken(result.toString()));
- }
- }
-
-}
\ No newline at end of file
Modified: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/crossingboundaries/EcoregionFilter.java
===================================================================
--- trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/crossingboundaries/EcoregionFilter.java 2011-10-17 22:28:53 UTC (rev 28806)
+++ trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/crossingboundaries/EcoregionFilter.java 2011-10-18 02:16:42 UTC (rev 28807)
@@ -12,7 +12,7 @@
* @author pea1
*
*/
-public class EcoregionFilter extends DatasetFilter {
+public class EcoregionFilter extends CrossingBoundariesDatasetFilter {
/**
*
Modified: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/crossingboundaries/TaxonClassFilter.java
===================================================================
--- trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/crossingboundaries/TaxonClassFilter.java 2011-10-17 22:28:53 UTC (rev 28806)
+++ trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/crossingboundaries/TaxonClassFilter.java 2011-10-18 02:16:42 UTC (rev 28807)
@@ -14,7 +14,7 @@
* @author pea1
* @deprecated
*/
-public class TaxonClassFilter extends DatasetFilter {
+public class TaxonClassFilter extends CrossingBoundariesDatasetFilter {
/**
*
Added: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/survivorship/SurvivorshipDateRangeFilter.java
===================================================================
--- trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/survivorship/SurvivorshipDateRangeFilter.java (rev 0)
+++ trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/survivorship/SurvivorshipDateRangeFilter.java 2011-10-18 02:16:42 UTC (rev 28807)
@@ -0,0 +1,98 @@
+package edu.cornell.birds.is.bap.actor.survivorship;
+
+import org.apache.log4j.Logger;
+
+import ptolemy.actor.TypedIOPort;
+import ptolemy.data.StringToken;
+import ptolemy.data.expr.StringParameter;
+import ptolemy.data.type.BaseType;
+import ptolemy.kernel.CompositeEntity;
+import ptolemy.kernel.util.IllegalActionException;
+import ptolemy.kernel.util.NameDuplicationException;
+import edu.cornell.birds.is.bap.data.DatasetFilter;
+import edu.cornell.birds.is.bap.actor.survivorship.dataset.DemographyDataFormat;
+
+
+/**
+ * Allow records of observations made between to month/days.
+ *
+ * @author pea1
+ *
+ */
+public class SurvivorshipDateRangeFilter extends DatasetFilter {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -7661503947208405399L;
+
+ protected static final Logger logger = Logger.getLogger(SurvivorshipDateRangeFilter.class);
+
+ public TypedIOPort criteriaSpecifiedPort;
+
+ public StringParameter toYearValueParameter;
+ public StringParameter fromYearValueParameter;
+ private int toYear;
+ private int fromYear;
+
+ public SurvivorshipDateRangeFilter(CompositeEntity container, String name) throws IllegalActionException, NameDuplicationException {
+
+ super(container, name);
+ columnSeparator = ",";
+
+ // this will ensure that the firing doesn't short circuit because there is no target value
+ targetValue = "something";
+
+ fromYearValueParameter = new StringParameter(this, "fromYear");
+ fromYearValueParameter.setDisplayName("from year (YYYY)");
+ fromYearValueParameter.setExpression("1800");
+
+ toYearValueParameter = new StringParameter(this, "toYear");
+ toYearValueParameter.setDisplayName("to year (YYYY)");
+ toYearValueParameter.setExpression("2020");
+
+ criteriaSpecifiedPort = new TypedIOPort(this, "criteriaSpecified", false, true);
+ criteriaSpecifiedPort.setDisplayName("date range");
+ criteriaSpecifiedPort.setTypeEquals(BaseType.STRING);
+ }
+
+
+ public void fire() throws IllegalActionException {
+
+ String fromYearString = fromYearValueParameter.stringValue();
+ String toYearString = toYearValueParameter.stringValue();
+ String criteria = fromYearString + " - " + toYearString;
+
+ try {
+ fromYear = Integer.parseInt(fromYearString);
+ toYear = Integer.parseInt(toYearString);
+ }
+ catch (NumberFormatException e) {
+ criteria = "invalid";
+ }
+
+ criteriaSpecifiedPort.broadcast(new StringToken(criteria));
+
+ super.fire();
+ }
+
+ /* (non-Javadoc)
+ * @see edu.cornell.birds.is.bap.actor.akn.AKNDatasetFilter#includeThisRecord(java.lang.String[])
+ */
+ @Override
+ protected boolean includeThisRecord(String[] columns) {
+ try {
+ int dataBirthYear = Integer.parseInt(columns[DemographyDataFormat.BIRTH_COLUMN-1]);
+ int dataDeathYear = Integer.parseInt(columns[DemographyDataFormat.DEATH_COLUMN-1]);
+
+ boolean result = (dataBirthYear >= fromYear && dataBirthYear <= toYear
+ && dataDeathYear >= fromYear && dataDeathYear <= toYear);
+
+ return result;
+ }
+ catch (NumberFormatException e) {
+ return false;
+ }
+
+ }
+}
Property changes on: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/survivorship/SurvivorshipDateRangeFilter.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/survivorship/dataset/DemographyDataFormat.java
===================================================================
--- trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/survivorship/dataset/DemographyDataFormat.java (rev 0)
+++ trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/survivorship/dataset/DemographyDataFormat.java 2011-10-18 02:16:42 UTC (rev 28807)
@@ -0,0 +1,20 @@
+package edu.cornell.birds.is.bap.actor.survivorship.dataset;
+
+/**
+ * 1-based column numbering for demography CSV files.
+ *
+ */
+public class DemographyDataFormat {
+
+ public static final int RECORD_ID_COLUMN = 1;
+ public static final int NAME_COLUMN = 2;
+ public static final int BIRTH_COLUMN = 3;
+ public static final int DEATH_COLUMN = 4;
+ public static final int AGE_COLUMN = 5;
+ public static final int LABEL_1_COLUMN = 6;
+ public static final int LABEL_2_COLUMN = 7;
+ public static final int LABEL_3_COLUMN = 8;
+ public static final int LABEL_4_COLUMN = 9;
+ public static final int LABEL_5_COLUMN = 10;
+
+}
Property changes on: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/survivorship/dataset/DemographyDataFormat.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Copied: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/DatasetFilter.java (from rev 28529, trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/akn/AKNDatasetFilter.java)
===================================================================
--- trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/DatasetFilter.java (rev 0)
+++ trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/DatasetFilter.java 2011-10-18 02:16:42 UTC (rev 28807)
@@ -0,0 +1,118 @@
+package edu.cornell.birds.is.bap.data;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import org.apache.log4j.Logger;
+import org.springframework.util.StringUtils;
+
+import ptolemy.actor.TypedAtomicActor;
+import ptolemy.actor.TypedIOPort;
+import ptolemy.data.StringToken;
+import ptolemy.data.type.BaseType;
+import ptolemy.kernel.CompositeEntity;
+import ptolemy.kernel.util.IllegalActionException;
+import ptolemy.kernel.util.NameDuplicationException;
+
+public abstract class DatasetFilter extends TypedAtomicActor {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -7565920482937743966L;
+
+ protected static final Logger logger = Logger.getLogger(DatasetFilter.class);
+ public TypedIOPort inPort;
+ public TypedIOPort outPort;
+
+ public String commentChar = "#";
+ public String columnSeparator = "\t";
+ public String targetValue = "";
+ public boolean hasHeaderRow = true;
+ public int targetColumn = 14; // first index = 1 (NOT zero)
+
+ public DatasetFilter(CompositeEntity container, String name)
+ throws IllegalActionException, NameDuplicationException {
+
+ super(container, name);
+
+ inPort = new TypedIOPort(this, "in", true, false);
+ inPort.setTypeEquals(BaseType.STRING);
+
+ outPort = new TypedIOPort(this, "out", false, true);
+ outPort.setTypeEquals(BaseType.STRING);
+
+ }
+
+ public void fire() throws IllegalActionException {
+ if (inPort.hasToken(0)) {
+ try {
+ StringToken inputFileNameToken = (StringToken) inPort.get(0);
+ String inputFileName = inputFileNameToken.stringValue();
+
+ String columnDelimiter = columnSeparator;
+ if ("\\t".equals(columnDelimiter)) columnDelimiter = "\t";
+
+// int whichColumn = targetColumn - 1;
+
+// String targetMatch = targetValue;
+
+ if (!StringUtils.hasLength(targetValue)) {
+ // don't filter anything
+ outPort.broadcast(new StringToken(inputFileName));
+ return;
+ }
+
+// logger.debug("Looking for: [" + targetMatch + "]");
+
+// StringBuffer result = new StringBuffer();
+
+ BufferedReader reader = new BufferedReader(new FileReader(inputFileName));
+ File outputFile = File.createTempFile("filtered", null);
+ PrintWriter writer = new PrintWriter(new FileWriter(outputFile));
+
+ String os = null;
+ boolean firstTime = true;
+
+ while((os = reader.readLine()) != null) {
+
+ //skip empty and commented out lines
+ if(os.startsWith(commentChar) || os.trim().length() == 0){
+ continue;
+ }
+
+// logger.debug("line [" + os + "]");
+
+ String[] columns = os.split(columnDelimiter);
+// logger.debug("compare [" + columns[whichColumn] + "]");
+ if (includeThisRecord(columns)
+ || (hasHeaderRow && firstTime)) {
+// logger.debug("match!");
+ writer.println(os);
+ }
+ firstTime = false;
+ }
+ reader.close();
+ writer.close();
+ logger.debug("ouput filename: ["+ outputFile.getPath()+ "]");
+ outPort.broadcast(new StringToken(outputFile.getPath()));
+ }
+ catch (FileNotFoundException e) {
+ throw new IllegalActionException(this, e, "FileNotFoundException");
+ }
+ catch (IOException e) {
+ throw new IllegalActionException(this, e, "IOException");
+ }
+ }
+ }
+
+ protected boolean includeThisRecord(String[] columns) {
+ return targetValue.equals(columns[targetColumn-1]);
+ }
+
+}
\ No newline at end of file
Added: trunk/modules/science-pipes-frontend/WebContent/editor/parts/edu.cornell.birds.is.bap.actor.survivorship.SurvivorshipDateRangeFilter.meta.xml
===================================================================
--- trunk/modules/science-pipes-frontend/WebContent/editor/parts/edu.cornell.birds.is.bap.actor.survivorship.SurvivorshipDateRangeFilter.meta.xml (rev 0)
+++ trunk/modules/science-pipes-frontend/WebContent/editor/parts/edu.cornell.birds.is.bap.actor.survivorship.SurvivorshipDateRangeFilter.meta.xml 2011-10-18 02:16:42 UTC (rev 28807)
@@ -0,0 +1,68 @@
+<?xml version="1.0" standalone="no"?>
+<!DOCTYPE entity PUBLIC "-//UC Berkeley//DTD MoML 1//EN" "http://ptolemy.eecs.berkeley.edu/xml/dtd/MoML_1.dtd">
+<entity name="SurvivorshipDateRangeFilter" class="edu.cornell.birds.is.bap.actor.survivorship.SurvivorshipDateRangeFilter">
+ <display name="SurvivorshipDateRangeFilter"/>
+ <property name="fromYear" class="ptolemy.data.expr.StringParameter" value="1800">
+ <display name="Start Year (YYYY)"/>
+ <property name="_parameterHint" class="ptolemy.kernel.util.StringAttribute">
+ </property>
+ <property name="_visibilityHint" class="ptolemy.kernel.util.StringAttribute" value="full">
+ </property>
+ <property name="_uiHint" class="ptolemy.kernel.util.StringAttribute" value="default">
+ </property>
+ </property>
+ <property name="toYear" class="ptolemy.data.expr.StringParameter" value="2020">
+ <display name="End Year (YYYY)"/>
+ <property name="_parameterHint" class="ptolemy.kernel.util.StringAttribute">
+ </property>
+ <property name="_visibilityHint" class="ptolemy.kernel.util.StringAttribute" value="full">
+ </property>
+ <property name="_uiHint" class="ptolemy.kernel.util.StringAttribute" value="default">
+ </property>
+ </property>
+ <property name="KeplerDocumentation" class="ptolemy.vergil.basic.KeplerDocumentationAttribute">
+ <property name="description" class="ptolemy.kernel.util.ConfigurableAttribute">
+ <configure>Filters Survivorship datasets to include data only from the specified date range.</configure>
+ </property>
+ <property name="author" class="ptolemy.kernel.util.ConfigurableAttribute"/>
+ <property name="version" class="ptolemy.kernel.util.ConfigurableAttribute"/>
+ <property name="userLevelDocumentation" class="ptolemy.kernel.util.ConfigurableAttribute">
+ <configure>Observations from the specified year are allowed through this filter. Both the input and output datasets are really references to a local file in the Science Pipes system that contains the data.</configure>
+ </property>
+ <property name="port:in" class="ptolemy.kernel.util.ConfigurableAttribute">
+ <configure>A Survivorship dataset.</configure>
+ </property>
+ <property name="port:out" class="ptolemy.kernel.util.ConfigurableAttribute">
+ <configure>A new Survivorship dataset containing only records with observation dates for the specified range</configure>
+ </property>
+ <property name="port:criteriaSpecified" class="ptolemy.kernel.util.ConfigurableAttribute">
+ <configure>Echoes the range that was specified; useful to connect to title ports of charts</configure>
+ </property>
+ <property name="prop:fromYear" class="ptolemy.kernel.util.ConfigurableAttribute">
+ <configure>The start year, specified as a four-digit number (e.g, 1925)</configure>
+ </property>
+ <property name="prop:toYear" class="ptolemy.kernel.util.ConfigurableAttribute">
+ <configure>The end year, specified as a four-digit number (e.g, 2020)</configure>
+ </property>
+ </property>
+ <property name="_iconSmall" class="ptolemy.kernel.util.StringAttribute" value="icon_filter.png">
+ </property>
+ <property name="_iconMedium" class="ptolemy.kernel.util.StringAttribute" value="icon_filter.png">
+ </property>
+ <property name="_iconLarge" class="ptolemy.kernel.util.StringAttribute" value="icon_filter.png">
+ </property>
+ <property name="_iconXLarge" class="ptolemy.kernel.util.StringAttribute" value="icon_filter.png">
+ </property>
+ <port name="in" class="ptolemy.actor.TypedIOPort">
+ <property name="input"/>
+ <display name="In"/>
+ </port>
+ <port name="out" class="ptolemy.actor.TypedIOPort">
+ <property name="output"/>
+ <display name="Out"/>
+ </port>
+ <port name="criteriaSpecified" class="ptolemy.actor.TypedIOPort">
+ <property name="output"/>
+ <display name="Date Range Selected"/>
+ </port>
+</entity>
Property changes on: trunk/modules/science-pipes-frontend/WebContent/editor/parts/edu.cornell.birds.is.bap.actor.survivorship.SurvivorshipDateRangeFilter.meta.xml
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/modules/science-pipes-frontend/WebContent/editor/parts/survivorship-actors.xml
===================================================================
--- trunk/modules/science-pipes-frontend/WebContent/editor/parts/survivorship-actors.xml 2011-10-17 22:28:53 UTC (rev 28806)
+++ trunk/modules/science-pipes-frontend/WebContent/editor/parts/survivorship-actors.xml 2011-10-18 02:16:42 UTC (rev 28807)
@@ -6,6 +6,7 @@
<group name="Operations" expanded="true" id="ops">
<actor class="edu.cornell.birds.is.bap.actor.survivorship.SurvivalCurveCalc" name="Survival Curve Calculator" guid="edu.cornell.birds.is.bap.actor.survivorship.SurvivalCurveCalc"/>
+ <actor class="edu.cornell.birds.is.bap.actor.survivorship.SurvivorshipDateRangeFilter" name="Date Range Filter" guid="edu.cornell.birds.is.bap.actor.survivorship.SurvivorshipDateRangeFilter"/>
<actor class="edu.cornell.birds.is.bap.actor.crossingboundaries.DataSplitter" name="Data Duplicator" guid="edu.cornell.birds.is.bap.actor.crossingboundaries.DataSplitter"/>
<actor class="edu.cornell.birds.is.bap.actor.crossingboundaries.calc.DistinctDataUnion" name="Data Union" guid="edu.cornell.birds.is.bap.actor.crossingboundaries.calc.DistinctDataUnion"/>
</group>
More information about the Kepler-cvs
mailing list