Skip to content

Commit

Permalink
#622 impl(only output records which have outlier)
Browse files Browse the repository at this point in the history
  • Loading branch information
qifeng-bai committed Dec 20, 2021
1 parent 7a9ee6c commit 578f75f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,9 @@ public void processElement(ProcessContext c) {
.setBooleans(indexRecord.getBooleans())
.setInts(indexRecord.getInts())
.build();

ouputIR.getDoubles().put(DISTANCE_TO_EDL, outlierRecord.getDistanceOutOfEDL());
if (outlierRecord != null) {
ouputIR.getDoubles().put(DISTANCE_TO_EDL, outlierRecord.getDistanceOutOfEDL());
}

c.output(KV.of(id, ouputIR));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,23 @@ public Iterable<DistributionOutlierRecord> apply(
boolean hasEDL = edl.size() > 0 ? true : false;
double distanceToEDL = hasEDL ? 0 : -1; // 0 -inside, -1: no EDL
// Available EDLD of this species
Map points = new HashMap();
while (iter.hasNext()) {
IndexRecord record = iter.next();
DistributionOutlierRecord dr = convertToDistribution(record, distanceToEDL);
if (dr != null) {
outputs.add(dr);
Map point = new HashMap();
point.put("decimalLatitude", dr.getDecimalLatitude());
point.put("decimalLongitude", dr.getDecimalLongitude());
points.put(dr.getId(), point);
}
}

if (hasEDL) {
Map points = new HashMap();
while (iter.hasNext()) {
IndexRecord record = iter.next();
DistributionOutlierRecord dr = convertToDistribution(record, distanceToEDL);
if (dr != null) {
outputs.add(dr);
Map point = new HashMap();
point.put("decimalLatitude", dr.getDecimalLatitude());
point.put("decimalLongitude", dr.getDecimalLongitude());
points.put(dr.getId(), point);
}
}

log.debug(
String.format("Calculating %d records of the species %s", points.size(), lsid));
Map<String, Double> results = distributionService.outliers(lsid, points);
Iterator<Map.Entry<String, Double>> iterator = results.entrySet().iterator();
while (iterator.hasNext()) {
Expand All @@ -99,14 +102,16 @@ public Iterable<DistributionOutlierRecord> apply(
.forEach(it -> it.setDistanceOutOfEDL(entry.getValue()));
}
}

} catch (ExpertDistributionException e) {
log.error("Error in processing the species: " + lsid + " . Ignored");
log.error(e.getMessage());
throw new RuntimeException(
"Expert distribution service throws a runtime error, please check logs");
// throw new RuntimeException(
// "Expert distribution service throws a runtime error, please check
// logs");
} catch (Exception e) {
log.error("Error in processing the species: " + lsid + " . Ignored");
log.error(e.getMessage());
throw new RuntimeException("Runtime error: " + e.getMessage());
// throw new RuntimeException("Runtime error: " + e.getMessage());
}

return outputs;
Expand Down
3 changes: 0 additions & 3 deletions livingatlas/pipelines/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@

<property name="defaultPattern" value="%-5level [%date{'yyyy-MM-dd HH:mm:ss,SSSZ'}] [%thread] %logger: %msg%n%xEx"/>

log4j.appender.console.layout.ConversionPattern=%d{dd-MMM} %color-black{%d{HH:mm:ss}} [%color-magenta{%X{step}}] [%color-blue{%X{datasetId}}] [%color{%p}] %color-cyan{%c{1}}: %color-blue{%m%n}


<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${defaultPattern}</pattern>
Expand Down

0 comments on commit 578f75f

Please sign in to comment.