Commit 1548220f authored by Klaus Hamberger's avatar Klaus Hamberger
Browse files

Activated distance calculation for marriages.

git-svn-id: svn+ssh://svn.code.sf.net/p/tip-puck/code/trunk@2324 fbf60bc9-78ff-467a-80f5-d9f1d8e511fc
parent 9bb45e64
......@@ -10,6 +10,7 @@ import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tip.puck.geo.tools.GeotoolsUtils;
import org.tip.puck.graphs.Graph;
import org.tip.puck.net.Attributes;
import org.tip.puck.partitions.Partition;
......@@ -746,6 +747,29 @@ public class Geography {
return result;
}
/**
* @param unit = 'M' is statute miles, 'K' is kilometers (default), 'N' is nautical miles
* @param startName
* @param endName
* @return
*/
public Double getDistance (final String startName, final String endName, char unit){
Double result;
Place start = get(startName);
Place end = get(endName);
if (start != null && end != null){
result = GeotoolsUtils.distance(start, end, unit);
} else {
result = null;
}
//
return result;
}
/**
*
* @param homonym
......
......@@ -193,9 +193,27 @@ public class GeotoolsUtils {
* @param unit = 'M' is statute miles, 'K' is kilometers (default), 'N' is nautical miles
* @return
*/
public static double distance(Place first, Place second, char unit) {
public static Double distance(Place first, Place second, char unit) {
Double result;
return convert(first.getCoordinate2()).distance(convert(second.getCoordinate2()));
if (first.getCoordinate2()!=null && second.getCoordinate2()!=null){
result = convert(first.getCoordinate2()).distance(convert(second.getCoordinate2()));
} else {
if (first.getCoordinate2()==null){
System.err.println("Coordinates missing for "+first);
}
if (second.getCoordinate2()==null){
System.err.println("Coordinates missing for "+second);
}
result = null;
}
//
return result;
// double result;
// double theta = first.longitude() - second.longitude();
......
......@@ -8,6 +8,7 @@ import java.util.List;
import org.tip.puck.PuckException;
import org.tip.puck.PuckManager;
import org.tip.puck.geo.Geography;
import org.tip.puck.graphs.ClusterPair;
import org.tip.puck.graphs.Graph;
import org.tip.puck.graphs.Node;
......@@ -23,6 +24,7 @@ import org.tip.puck.net.relations.Actor;
import org.tip.puck.net.relations.Relation;
import org.tip.puck.net.relations.Relations;
import org.tip.puck.net.workers.FamilyValuator;
import org.tip.puck.net.workers.IndividualValuator;
import org.tip.puck.net.workers.NetUtils;
import org.tip.puck.partitions.Cluster;
import org.tip.puck.partitions.Partition;
......@@ -144,7 +146,7 @@ public class GraphReporter {
* @param source
* @return
*/
public static StringList getSortableList(final Graph<Cluster<Individual>> source) {
public static StringList getSortableList(final Graph<Cluster<Individual>> source, final Geography geography) {
StringList result;
result = new StringList(100);
......@@ -164,7 +166,11 @@ public class GraphReporter {
Individual husband = family.getOtherParent(wife);
if ((husband != null) && (targetNode.getReferent().getItems().contains(husband))) {
String marrYear = "";
Value marrDate = FamilyValuator.get(family, "MARR_DATE");
String husbandBirthPlace = "";
String wifeBirthPlace = "";
Value marrDate = FamilyValuator.get(family, "MARR_DATE", geography);
Value husbandBirtPlaceValue = IndividualValuator.get(husband, "BIRT_PLACE", geography);
Value wifeBirtPlaceValue = IndividualValuator.get(wife, "BIRT_PLACE", geography);
if (marrDate!=null){
marrYear = FamilyValuator.extractYear(marrDate.stringValue());
}
......
......@@ -212,7 +212,7 @@ public class RelationValuator {
} else if (RelationValuator.isDeath(source)){
result = new Value("DEATH");
} else {*/
GeoLevel distance = getDistance(geography,source);
GeoLevel distance = getDistance(geography,source, "START_PLACE", "END_PLACE");
if (distance == null) {
result = null;
} else {
......@@ -226,7 +226,7 @@ public class RelationValuator {
} else if (RelationValuator.isDeath(source)){
result = new Value("DEATH");
} else {*/
GeoLevel distance2 = getDistance(geography,source);
GeoLevel distance2 = getDistance(geography,source,"START_PLACE", "END_PLACE");
if (distance2 == null) {
result = null;
} else {
......@@ -258,11 +258,11 @@ public class RelationValuator {
* @param event
* @return
*/
public static GeoLevel getDistance (Geography geography, Relation event){
public static GeoLevel getDistance (Geography geography, Relation event, String startPlaceLabel, String endPlaceLabel){
GeoLevel result;
result = geography.getDistance(event.getAttributeValue("START_PLACE"), event.getAttributeValue("END_PLACE"));
result = geography.getDistance(event.getAttributeValue(startPlaceLabel), event.getAttributeValue(endPlaceLabel));
/* if (event.getAttributeValue("START_PLACE")!=null && event.getAttributeValue("END_PLACE")!=null){
Place start = geography.getByHomonym(event.getAttributeValue("START_PLACE"));
......
......@@ -9,6 +9,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.tip.puck.geo.Geography;
import org.tip.puck.geo.Place;
import org.tip.puck.net.Attribute;
import org.tip.puck.net.Families;
import org.tip.puck.net.Family;
......@@ -34,7 +35,8 @@ public class FamilyValuator {
MOTHERNAME,
PARENTCOUNT,
UNIONSTATUS,
WIFE_ORDER
WIFE_ORDER,
DISTANCE
}
public static final Pattern YEAR_PATTERN = Pattern.compile("(\\d\\d\\d\\d)");
......@@ -77,7 +79,7 @@ public class FamilyValuator {
public static NumberedValues get(final Families source, final String label) {
NumberedValues result;
result = get(source, label, null);
result = get(source, label, null, null);
//
return result;
......@@ -89,14 +91,14 @@ public class FamilyValuator {
* @param label
* @return
*/
public static NumberedValues get(final Families source, final String label, final Object parameter) {
public static NumberedValues get(final Families source, final String label, final Object parameter, final Geography geography) {
NumberedValues result;
//
result = new NumberedValues();
for (Family family : source) {
result.put(family.getId(), get(family, label, parameter));
result.put(family.getId(), get(family, label, parameter, geography));
}
//
......@@ -109,10 +111,10 @@ public class FamilyValuator {
* @param label
* @return
*/
public static Value get(final Family source, final String label) {
public static Value get(final Family source, final String label, final Geography geography) {
Value result;
result = get(source, label, null);
result = get(source, label, null, geography);
//
return result;
......@@ -125,7 +127,7 @@ public class FamilyValuator {
*
* @return
*/
public static Value get(final Family source, final String label, final Object parameter) {
public static Value get(final Family source, final String label, final Object parameter, final Geography geography) {
Value result;
//
......@@ -245,6 +247,23 @@ public class FamilyValuator {
result = new Value(source.getWifeOrder());
}
}
break;
case DISTANCE:
//* @param unit = 'M' is statute miles, 'K' is kilometers (default), 'N' is nautical miles
result = null;
if (source.getHusband()!=null && source.getWife()!=null){
Value husbandPlaceName = IndividualValuator.get(source.getHusband(), parameter.toString(), geography);
Value wifePlaceName = IndividualValuator.get(source.getWife(), parameter.toString(), geography);
if (husbandPlaceName!=null && wifePlaceName!=null){
result = Value.valueOf(geography.getDistance(husbandPlaceName.stringValue(), wifePlaceName.stringValue(), 'K'));
}
}
break;
default:
result = null;
}
......
......@@ -200,7 +200,7 @@ public class PartitionMaker {
* @return
* @throws PuckException
*/
public static Partition<Family> create(final String title, final Families source, final PartitionCriteria criteria) throws PuckException {
public static Partition<Family> create(final String title, final Families source, final PartitionCriteria criteria, final Geography geography) throws PuckException {
Partition<Family> result;
if ((source == null) || (criteria == null)) {
......@@ -212,7 +212,7 @@ public class PartitionMaker {
result.setCriteria(criteria);
//
NumberedValues values = FamilyValuator.get(source, criteria.getLabel(), criteria.getLabelParameter());
NumberedValues values = FamilyValuator.get(source, criteria.getLabel(), criteria.getLabelParameter(), geography);
//
NumberedValues partitionValues = getPartitionValues(values, criteria);
......@@ -491,7 +491,7 @@ public class PartitionMaker {
} else if (firstItem instanceof Family){
Families map = new Families((List<Family>)source.getItems());
NumberedValues values = FamilyValuator.get((Families)map, criteria.getLabel(), criteria.getLabelParameter());
NumberedValues values = FamilyValuator.get((Families)map, criteria.getLabel(), criteria.getLabelParameter(), geography);
NumberedValues partitionValues = getPartitionValues(values, criteria);
for (Family e : map) {
result.put((E)e, partitionValues.get(e.getId()));
......
......@@ -13,6 +13,7 @@ import org.tip.puck.PuckException;
import org.tip.puck.PuckExceptions;
import org.tip.puck.census.chains.Chain;
import org.tip.puck.evo.EvoGen;
import org.tip.puck.geo.Geography;
import org.tip.puck.graphs.Graph;
import org.tip.puck.graphs.random.RandomGraphReporter;
import org.tip.puck.graphs.workers.GraphReporter;
......@@ -115,7 +116,7 @@ public class ClusterNetworkReporter {
// Build sortable report.
Report report4 = new Report("Sortable list");
report4.outputs().appendln(GraphReporter.getSortableList(graph));
report4.outputs().appendln(GraphReporter.getSortableList(graph, source.getGeography()));
result.outputs().append(report4);
// Build sides report.
......@@ -547,7 +548,7 @@ public class ClusterNetworkReporter {
* Source to report.
* @throws PuckException
*/
public static Report reportSortableList(final Graph<Cluster<Individual>> source) throws PuckException {
public static Report reportSortableList(final Graph<Cluster<Individual>> source, final Geography geography) throws PuckException {
Report result;
if (source == null) {
......@@ -564,7 +565,7 @@ public class ClusterNetworkReporter {
result.setTarget(source.getLabel());
// Build sortable report.
result.outputs().appendln(GraphReporter.getSortableList(source));
result.outputs().appendln(GraphReporter.getSortableList(source, geography));
//
result.setTimeSpent(chrono.stop().interval());
......
......@@ -298,6 +298,10 @@ public class DefaultSegment implements Segment {
public Geography getGeography() {
return geography;
}
public void setGeography(Geography geography) {
this.geography = geography;
}
}
......@@ -368,7 +368,7 @@ public class FamilySegment implements Segment {
this.geography = source.getGeography();
//
this.partition = PartitionMaker.create(this.criteria.toShortString(), source.getCurrentFamilies(), this.criteria);
this.partition = PartitionMaker.create(this.criteria.toShortString(), source.getCurrentFamilies(), this.criteria, source.getGeography());
//
this.outOfPartitionIndividuals = source.getOutOfCurrentClusterIndividuals();
......@@ -541,6 +541,11 @@ public class FamilySegment implements Segment {
public Geography getGeography() {
return geography;
}
public void setGeography(Geography geography) {
this.geography = geography;
}
}
......@@ -569,6 +569,10 @@ public class IndividualSegment implements Segment {
public Geography getGeography() {
return geography;
}
public void setGeography(Geography geography) {
this.geography = geography;
}
}
......@@ -549,6 +549,10 @@ public class RelationSegment implements Segment {
public Geography getGeography() {
return geography;
}
public void setGeography(Geography geography) {
this.geography = geography;
}
}
......@@ -154,4 +154,7 @@ public interface Segment {
public void selectOutOfPartitionCluster() throws PuckException;
public Geography getGeography();
public void setGeography(Geography geography);
}
......@@ -98,7 +98,6 @@ public class Segmentation {
//
Segment targetSegment = addSegment(sourceSegment.getCriteria());
System.out.println("targetSegment=" + targetSegment);
targetSegment.selectCluster(sourceSegment.getCurrentClusterIndex());
}
......@@ -130,6 +129,8 @@ public class Segmentation {
result = this.segments.addSegment(this.getCurrentSegment(), criteria);
this.currentSegmentIndex += 1;
}
result.setGeography(geography);
//
return result;
......
......@@ -769,7 +769,7 @@ public class SequenceValuator<S extends Sequenceable<E>,E> {
result = new HashMap<GeoLevel, Integer>();
for (E event : source.getStations().values()){
GeoLevel distance = RelationValuator.getDistance(geography,(Relation)event);
GeoLevel distance = RelationValuator.getDistance(geography,(Relation)event, "START_PLACE", "END_PLACE");
if (distance!=null){
distance = distance.dynamic();
if (result.containsKey(distance)){
......
......@@ -2178,7 +2178,11 @@ public class StatisticsReporter {
signature += "\t";
} else if (label.equals("MARR_DATE")) {
for (Family family : individual.getPersonalFamilies()) {
signature += FamilyValuator.get(family, label) + "\t";
signature += FamilyValuator.get(family, label, segmentation.getGeography()) + "\t";
}
} else if (label.equals("MARR_PLACE")) {
for (Family family : individual.getPersonalFamilies()) {
signature += FamilyValuator.get(family, label, segmentation.getGeography()) + "\t";
}
} else {
signature += IndividualValuator.get(individual, label, segmentation.getGeography()) + "\t";
......
......@@ -716,7 +716,7 @@ public class GroupNetWindow extends JFrame {
public void actionPerformed(final ActionEvent event) {
// Sortable List.
try {
Report report = ClusterNetworkReporter.reportSortableList(gui.getGroupNet());
Report report = ClusterNetworkReporter.reportSortableList(gui.getGroupNet(),gui.getGeography());
gui.addReportTab(report);
} catch (final Exception exception) {
// Show trace.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment