Commit e3654299 authored by Matija Obreza's avatar Matija Obreza
Browse files

Include distance to specified country border in case of mismatch

parent 423ef5f0
......@@ -76,6 +76,12 @@ public class CountryProcessServiceImpl implements ProcessService {
outputHeaders.add(pos + 1, ApplicationUtils.HEADER_ORIGCTY_CHECK);
outputMapping.add(pos + 1, null);
}
// Add extra header HEADER_ORIGCTY_DISTANCE
{
final int pos = outputHeaders.indexOf(ApplicationUtils.HEADER_ORIGCTY_CHECK);
outputHeaders.add(pos + 1, ApplicationUtils.HEADER_ORIGCTY_DISTANCE);
outputMapping.add(pos + 1, null);
}
// Add extra header HEADER_DECLATITUDE_CHECK
{
final int pos = outputHeaders.indexOf(ApplicationUtils.HEADER_LATITUDE);
......@@ -114,6 +120,11 @@ public class CountryProcessServiceImpl implements ProcessService {
for (int j = 0; j < 100; j++) {
final String[] nextLine = reader.readNext();
if (nextLine == null) {
LOG.info("No input");
break;
}
lineCount++;
stopWatch.split();
......@@ -123,10 +134,6 @@ public class CountryProcessServiceImpl implements ProcessService {
lastLogTime = processingTimeSeconds;
}
if (nextLine == null) {
LOG.info("No input");
break;
}
inputs.add(nextLine);
}
......@@ -139,6 +146,7 @@ public class CountryProcessServiceImpl implements ProcessService {
@Override
public void run() {
LOG.info("Processing batch size={}", inputs.size());
for (final String[] nextLine : inputs) {
final String[] outputLine = HeaderUtils.toOutputLine(nextLine, outputHeaders, outputMapping);
......@@ -149,12 +157,14 @@ public class CountryProcessServiceImpl implements ProcessService {
}
String result = null;
String distance = null;
// if ("101346".equals(nextLine[0])) {
// LOG.info("!!! Got what we're looking for");
// }
final String declongitude = StringUtils.trimToNull(nextLine[sourceMapping.get(ApplicationUtils.HEADER_LONGITUDE)]);
final String declatitude = StringUtils.trimToNull(nextLine[sourceMapping.get(ApplicationUtils.HEADER_LATITUDE)]);
final String origCty = nextLine[sourceMapping.get(ApplicationUtils.HEADER_ORIGCTY)].trim();
final String origCty = sourceMapping.get(ApplicationUtils.HEADER_ORIGCTY) == null ? null : StringUtils.trimToNull(nextLine[sourceMapping.get(ApplicationUtils.HEADER_ORIGCTY)]);
LOG.trace("({}, {}) in {}", declatitude, declongitude, origCty);
if (StringUtils.isNotBlank(declatitude) && StringUtils.isNotBlank(declongitude)) {
try {
......@@ -164,10 +174,18 @@ public class CountryProcessServiceImpl implements ProcessService {
try {
result = countryOfOriginService.getCountries(longitude, latitude, origCty, ApplicationUtils.ALLOWED_DISTANCE_MARGIN);
} catch (final Exception e) {
result = e.getMessage();
}
if (origCty != null && !result.equals(origCty)) {
try {
distance = "" + (long) countryOfOriginService.distanceToBorder(longitude, latitude, origCty);
} catch (final Throwable e) {
distance = "ERROR: " + e.getMessage();
}
}
try {
outputLine[outputHeaders.indexOf(ApplicationUtils.HEADER_DECLATITUDE_CHECK)] = decimalFormat.format(latitude);
outputLine[outputHeaders.indexOf(ApplicationUtils.HEADER_DECLONGITUDE_CHECK)] = decimalFormat.format(longitude);
......@@ -184,13 +202,14 @@ public class CountryProcessServiceImpl implements ProcessService {
}
outputLine[outputHeaders.indexOf(ApplicationUtils.HEADER_ORIGCTY_CHECK)] = StringUtils.equals(origCty, result) ? ApplicationUtils.CHECK_PASSED : result;
outputLine[outputHeaders.indexOf(ApplicationUtils.HEADER_ORIGCTY_DISTANCE)] = distance;
lines.add(outputLine);
// if ("101346".equals(nextLine[0])) {
// LOG.info("Written what we're looking for");
// }
}
// LOG.info("Done " + cpuId);
LOG.info("Done batch");
}
});
......
......@@ -116,6 +116,10 @@ public class LandOrSeaProcessServiceImpl implements ProcessService {
for (int j = 0; j < 100; j++) {
final String[] nextLine = reader.readNext();
if (nextLine == null) {
LOG.info("No input");
break;
}
lineCount++;
stopWatch.split();
......@@ -124,11 +128,7 @@ public class LandOrSeaProcessServiceImpl implements ProcessService {
LOG.info("FYI, {} entries have been processed in {}s = {} lines/second", lineCount, processingTimeSeconds, (float) lineCount / processingTimeSeconds);
lastLogTime = processingTimeSeconds;
}
if (nextLine == null) {
LOG.info("No input");
break;
}
inputs.add(nextLine);
}
......@@ -207,9 +207,9 @@ public class LandOrSeaProcessServiceImpl implements ProcessService {
LOG.info("FYI, {} entries have been processed in {}s = {}lines/ms = {}ms/line", lineCount, processingTimeSeconds, (float) lineCount / stopWatch.getTime(),
(float) stopWatch.getTime() / lineCount);
}
for (final String[] l : lines) {
System.err.println(Arrays.toString(l));
}
// for (final String[] l : lines) {
// System.err.println(Arrays.toString(l));
// }
return lines;
}
}
......@@ -77,6 +77,7 @@ public class ApplicationUtils {
public static final String HEADER_ORIGCTY = "ORIGCTY";
public static final String HEADER_ORIGCTY_CHECK = "ORIGCTY_check";
public static final String HEADER_ORIGCTY_DISTANCE = "ORIGCTY_distance";
/** The Constant HEADER_LANDORSEA_CHECK. */
public static final String HEADER_LANDORSEA_CHECK = "LANDorSEA_check";
......
......@@ -43,6 +43,7 @@
.x-SUBTAUTHOR_check,
.x-SUBTAXA_check,
.x-ORIGCTY_check,
.x-ORIGCTY_distance,
.x-DECLATITUDE_parsed,
.x-DECLONGITUDE_parsed,
.x-LANDorSEA_check {
......@@ -56,6 +57,7 @@
thead .x-SUBTAUTHOR_check,
thead .x-SUBTAXA_check,
thead .x-ORIGCTY_check,
thead .x-ORIGCTY_distance,
thead .x-DECLATITUDE_parsed,
thead .x-DECLONGITUDE_parsed,
thead .x-LANDorSEA_check {
......@@ -71,7 +73,7 @@
<p class="hint">For numeric values these columns contain the value as parsed by the program. See if setting a different decimal mark character helps.</p>
</div>
<div>
<label>"_check" columns</label>
<label>"_check" and "_distance" columns</label>
<p class="hint">Columns highlighted Yellow were injected into your dataset at most appropriate positions. They contain the results of the validation run.</p>
<p class="hint">
<ul>
......@@ -84,6 +86,10 @@
</ul>
</p>
</div>
<div>
<label>"_distance" columns</label>
<p class="hint">"ORIGCTY_distance" column contains distance between lat/lon to the nearest point on the border of the specified country.</p>
</div>
<h1>Results</h1>
<table>
<thead>
......
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